1 | <%inherit file="base.html"/>
|
---|
2 |
|
---|
3 | <!-- do the plotting -->
|
---|
4 | <%
|
---|
5 | import matplotlib.pyplot as plt
|
---|
6 | import numpy as np
|
---|
7 | import os.path
|
---|
8 | import string
|
---|
9 |
|
---|
10 | _valid_chars = "_.%s%s" % (string.ascii_letters, string.digits)
|
---|
11 |
|
---|
12 | def _char_replacer(s):
|
---|
13 | '''A small utility function that echoes the argument or returns '_' if the
|
---|
14 | argument is in a list of forbidden characters.
|
---|
15 | '''
|
---|
16 | if s not in _valid_chars:
|
---|
17 | return '_'
|
---|
18 | return s
|
---|
19 |
|
---|
20 | def sanitize(text):
|
---|
21 | filename = ''.join(_char_replacer(c) for c in text)
|
---|
22 | return filename
|
---|
23 |
|
---|
24 |
|
---|
25 | plt.figure()
|
---|
26 |
|
---|
27 | iwn = context['iwn']
|
---|
28 | stagename = context['stagename']
|
---|
29 |
|
---|
30 | clean_image = context['data'][stagename]['cleanimage'][:,:,iwn]
|
---|
31 | residual_image = context['data'][stagename]['residualimage'][:,:,iwn]
|
---|
32 | spatial_axis = context['data'][stagename]['spatial axis']
|
---|
33 | wn = context['wn']
|
---|
34 |
|
---|
35 | plt.subplot(121)
|
---|
36 | plt.imshow(clean_image, interpolation='nearest', origin='lower',
|
---|
37 | aspect='equal', extent=[spatial_axis[0], spatial_axis[-1],
|
---|
38 | spatial_axis[0], spatial_axis[-1]])
|
---|
39 | plt.colorbar(orientation='vertical')
|
---|
40 | plt.axis('image')
|
---|
41 | plt.title('Clean image %6.4gcm-1' % wn)
|
---|
42 |
|
---|
43 | plt.subplot(122)
|
---|
44 | plt.imshow(residual_image, interpolation='nearest', origin='lower',
|
---|
45 | aspect='equal', extent=[spatial_axis[0], spatial_axis[-1],
|
---|
46 | spatial_axis[0], spatial_axis[-1]])
|
---|
47 | plt.colorbar(orientation='vertical')
|
---|
48 | plt.axis('image')
|
---|
49 | plt.title('Residual image %6.4gcm-1' % wn)
|
---|
50 |
|
---|
51 | filename = '%splane%s.png' % (stagename, wn)
|
---|
52 | filename = sanitize(filename)
|
---|
53 | filename = os.path.join(context['dirname'], filename)
|
---|
54 | plt.savefig(filename)
|
---|
55 | plt.close()
|
---|
56 | %>
|
---|
57 |
|
---|
58 | <!-- link to the plot from html -->
|
---|
59 |
|
---|
60 | <img src='${os.path.basename(filename)}' alt="The clean result should appear here<br>">
|
---|