1 | <%inherit file="base.html"/>
|
---|
2 |
|
---|
3 | <!-- do the plotting -->
|
---|
4 | <%
|
---|
5 | import matplotlib.pyplot as plt
|
---|
6 | import os.path
|
---|
7 | import numpy as np
|
---|
8 |
|
---|
9 | plt.figure()
|
---|
10 |
|
---|
11 | sourceid = context['sourceid']
|
---|
12 | spectrum = context['spectrum']
|
---|
13 |
|
---|
14 | try:
|
---|
15 | xaxis_data = spectrum.axis.data
|
---|
16 | except:
|
---|
17 | xaxis_data = np.arange(len(spectrum.data))
|
---|
18 |
|
---|
19 | # sometimes xaxis is not monotonic
|
---|
20 | xaxis_sort = np.argsort(xaxis_data)
|
---|
21 |
|
---|
22 | try:
|
---|
23 | xaxis_title = spectrum.axis.title
|
---|
24 | except:
|
---|
25 | xaxis_title = None
|
---|
26 |
|
---|
27 | try:
|
---|
28 | xaxis_units = spectrum.axis.units
|
---|
29 | except:
|
---|
30 | xaxis_units = None
|
---|
31 |
|
---|
32 | if spectrum.data.dtype==np.complex:
|
---|
33 | plt.plot(xaxis_data[xaxis_sort], spectrum.data.real[xaxis_sort],
|
---|
34 | color='blue')
|
---|
35 | plt.plot(xaxis_data[xaxis_sort], spectrum.data.imag[xaxis_sort],
|
---|
36 | color='red')
|
---|
37 | plt.figtext(0.2, 0.25, 'real', color='blue')
|
---|
38 | plt.figtext(0.2, 0.2, 'imag', color='red')
|
---|
39 | else:
|
---|
40 | plt.plot(xaxis_data[xaxis_sort], spectrum.data[xaxis_sort])
|
---|
41 |
|
---|
42 | plt.title('Source %s' % sourceid)
|
---|
43 | xlabel = ' '.join([v for v in [xaxis_title, xaxis_units] if v is not None])
|
---|
44 | plt.xlabel(xlabel)
|
---|
45 |
|
---|
46 | plt.savefig(os.path.join(context['dirname'], 'sourcespectrum%s.png' % sourceid))
|
---|
47 | plt.close()
|
---|
48 | %>
|
---|
49 |
|
---|
50 | <!-- link to the plot from html -->
|
---|
51 |
|
---|
52 | <img src='sourcespectrum${sourceid}.png' alt="Source spectrum">
|
---|