Changeset 27


Ignore:
Timestamp:
May 20, 2014 3:20:17 PM (10 years ago)
Author:
JohnLightfoot
Message:

various improvements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/templates/skymodelplane.html

    r17 r27  
    44<%
    55import matplotlib.pyplot as plt
     6import numpy as np
    67import os.path
     8import string
     9
     10_valid_chars = "_.%s%s" % (string.ascii_letters, string.digits)
     11
     12def _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
     20def sanitize(text):
     21    filename = ''.join(_char_replacer(c) for c in text)
     22    return filename
     23
    724
    825plt.figure()
    926
    1027iwn = context['iwn']
    11 sky_image = context['data']['skygenerator']['sky model'][:,:,iwn]
    12 spatial_axis = context['data']['skygenerator']['spatial axis']
     28stagename = context['stagename']
     29resultname = context['resultname']
     30print 'resultname', resultname
     31sky_image = context['data'][stagename][resultname][:,:,iwn]
     32spatial_axis = context['data'][stagename]['spatial axis']
     33wn = context['wn']
    1334
    14 plt.imshow(sky_image, interpolation='nearest', origin='lower',
     35plt.subplot(211)
     36plt.imshow(sky_image.real, interpolation='nearest', origin='lower',
    1537  aspect='equal', extent=[spatial_axis[0], spatial_axis[-1],
    16   spatial_axis[0], spatial_axis[-1]])
     38  spatial_axis[0], spatial_axis[-1]],
     39  vmax=np.max(sky_image.real)*1.1,
     40  vmin=np.min(sky_image.real)*0.9)
     41plt.colorbar(orientation='vertical')
    1742plt.axis('image')
     43plt.title('Sky model real %6.4gcm-1' % wn)
    1844
    19 wn = context['wn']
    20 plt.title('Sky model plane %6.4gcm-1' % wn)
     45plt.subplot(212)
     46plt.imshow(sky_image.imag, interpolation='nearest', origin='lower',
     47  aspect='equal', extent=[spatial_axis[0], spatial_axis[-1],
     48  spatial_axis[0], spatial_axis[-1]],
     49  vmax=np.max(sky_image.imag)*1.1,
     50  vmin=np.min(sky_image.imag)*0.9)
     51plt.colorbar(orientation='vertical')
     52plt.axis('image')
     53plt.title('Sky model imag %6.4gcm-1' % wn)
    2154
    22 plt.colorbar(orientation='vertical')
    23 plt.savefig(os.path.join(context['dirname'], 'skymodelplane%s.png' % wn))
     55filename = '%splane%s.png' % (resultname, wn)
     56filename = sanitize(filename)
     57filename = os.path.join(context['dirname'], filename)
     58print 'filename', filename
     59plt.savefig(filename)
    2460plt.close()
    2561%>
     
    2763<!-- link to the plot from html -->
    2864
    29 <img src='skymodelplane${wn}.png' alt="The sky model should appear here<br>">
     65<img src='${os.path.basename(filename)}' alt="The sky model should appear here<br>">
Note: See TracChangeset for help on using the changeset viewer.