def testBasic(self): f = cdms2.open( vcs.sample_data + '/dar.meteo.mod.cam3.era.v31.h0.l3.nrstpt.cp.2000070100.2000080100.tau.12.36.nc' ) s = f('ta', time=slice(0, 1), squeeze=1) th = thermo.Gth(x=self.x, name='my') try: th.plot_TP(s) failed = False except: failed = True pass if not failed: print(failed) raise "Error should have raised an exception on all missing data!" th.clear() s = f('ta', time=slice(1, 2), squeeze=1) th.type = 'stuve' th.plot_TP(s) th.clear() th.type = 'emagram' th.plot_TP(s) th.clear() th.type = 'tephigram' th.plot_TP(s) th.clear() th.type = 'skewT' th.plot_TP(s) th.clear()
# Adapted for numpy/ma/cdms2 by convertcdms.py # First import necessary modules import os, sys, thermo, vcs, cdms2 as cdms # initialize the VCS Canvas and creates the "Thermodynamic Diagram" graphic method x = vcs.init() x.portrait() th = thermo.Gth(x=x, name='test') ## Setting type of thermodynamic diagram, you can choose from: 'emagram', 'tephigram', 'stuve' or 'skewT' th.type = 'skewT' ## World Coordinates ## Temperatures at the bottom of the graph (in C) th.datawc_x1 = -50. th.datawc_x2 = 50. ## Pressure at bottom and top of graph (in hPa) ## WARNING: worldcoordinate here are set in hPA but data level axis must be in Pa, not consistent th.datawc_y1 = 1050. th.datawc_y2 = 100. ## Drawing of paper, decide what to draw or not (1:yes , 0: no) th.drawisothermsfilled = 1 th.drawisotherms = 1 th.drawisobars = 1 th.drawdryadiabats = 1 th.drawpseudoadiabats = 1 th.drawmixingratio = 1 ## Create a template for T(P) i.e skewT paper template = x.createtemplate('new')
def testBasic(self): th = thermo.Gth(x=self.x, name='test') # List setable stuff # th.list() # Type of thermodynamic diagram # th.type='emagram' # th.type='tephigram' # th.type='stuve' th.type = 'skewT' # Skewness of the plot # th.skewness=-35. # Graphic finess th.detail = 75 # World Coordinates # Temperatures at the bottom of the grap (in C) th.datawc_x1 = -50. th.datawc_x2 = 50. # Pressure at bottom and top of page (in hPa) th.datawc_y1 = 1050. th.datawc_y2 = 100. # Drawing of paper # th.isotherms.level=vcs.mkscale(-200,200) th.drawisothermsfilled = 1 th.drawisotherms = 1 th.drawisobars = 1 th.drawdryadiabats = 1 th.drawpseudoadiabats = 1 th.drawmixingratio = 1 # Create a template for T(P) i.e skewT paper template = self.x.createtemplate('new') template.data.x1 = .1 template.data.x2 = .85 template.data.y1 = .1 template.data.y2 = .9 template.box1.x1 = template.data.x1 template.box1.x2 = template.data.x2 template.box1.y1 = template.data.y1 template.box1.y2 = template.data.y2 template.xlabel1.y = template.data.y1 * .9 template.ylabel1.x = template.data.x1 * .9 # Open the file, read the T f = cdms2.open(os.path.join(vcs.sample_data, 'thermo.nc')) t = f('t') # P axis must be in Pa # (I know it's not consistent with worldcoordinates, need to be updated ?) p = t.getLevel() p = cdms2.createAxis(p[:] * 100) p.id = 'level' t.setAxis(1, p) # Reset the axis on T th.plot_TP(t, template=template) self.checkImage("test_thermo_basic_1.png") # Create a template for the windbarbs template = self.x.createtemplate('new2') template.data.x1 = .86 template.data.x2 = .96 template.data.y1 = .1 template.data.y2 = .9 template.box1.x1 = template.data.x1 template.box1.x2 = template.data.x2 template.box1.y1 = template.data.y1 template.box1.y2 = template.data.y2 template.xlabel1.y = template.data.y1 * .9 template.ylabel1.x = template.data.x1 * .9 # Read winds from a file f = cdms2.open(os.path.join(vcs.sample_data, 'thermo.nc')) u = f('ua', time=slice(0, 1), longitude=0, latitude=0, squeeze=1) v = f('va', time=slice(0, 1), longitude=0, latitude=0, squeeze=1) # Windbarbs scale (triangle, long bar, small bar) th.windbarbsscales = [5, 2, 1] # Plot the windbarbs, passing the P values (in Pa) th.plot_windbarb(u, v, P=u.getLevel()[:] * 100., template=template) self.checkImage("test_thermo_basic_windbarbs.png")
# Adapted for numpy/ma/cdms2 by convertcdms.py import cdms2 as cdms,thermo,vcs.test.support bg=vcs.test.support.bg f=cdms.open('dar.meteo.mod.cam3.era.v31.h0.l3.nrstpt.cp.2000070100.2000080100.tau.12.36.nc') s=f('ta',time=slice(0,1),squeeze=1) th = thermo.Gth(name='my') try: th.plot_TP(s,bg=bg) failed = False except: failed = True pass if not failed: print failed raise "Error should have raised an exception on all missing data!" vcs.test.support.check_plot(th.x) # Make sure we have an empty plot! th.clear() s=f('ta',time=slice(1,2),squeeze=1) th.type='stuve' th.plot_TP(s,bg=bg) vcs.test.support.check_plot(th.x) th.clear()
def aThermo(parent, template, type, vars): th = thermo.Gth(x=parent.vcs[parent.vcs_id], name="my") ot = th.x.gettemplate(template) if not hasattr(parent, 'thermo_profiles_count'): parent.thermo_profiles_count = 0 if parent.panelGC.var_overlay.get(): parent.thermo_profiles_count += 1 else: parent.thermo_profiles_count = 0 if len(vars) == 1 or len(vars) > 2: th.type = type # createtemplate template = th.x.createtemplate(source=ot) ## World Coordinates ## Temperatures at the bottom of the grap (in C) goportrait = True if parent.menu.main_menu.thermo_options.get(): try: dialog = Pmw.Dialog( parent, title="Options for Thermodynamic Diagram", buttons=('OK', ), ## defaultbutton = 'Cancel', ## command = gui_control.Command(thermo_options, parent) ) f = Tkinter.Frame(dialog.interior()) f.pack(expand=1, fill='both') dialog.portrait = Pmw.RadioSelect( f, labelpos='w', buttontype='checkbutton', orient='vertical', label_text='Preserve Orientation', hull_borderwidth=2, hull_relief='ridge', ) dialog.portrait.pack(side='top', fill='x', expand=1) for text in ('(no auto-portrait)', ): dialog.portrait.add(text) dialog.x1 = Pmw.EntryField( f, label_text='Temp. Left', labelpos='w', value='-50.', validate={'validator': 'real'}, ) dialog.x1.pack(side='top', fill='x', expand=1) dialog.x2 = Pmw.EntryField( f, label_text='Temp. Right', labelpos='w', validate={'validator': 'real'}, value='50.', ) dialog.x2.pack(side='top', fill='x', expand=1) dialog.y1 = Pmw.EntryField( f, label_text='Pressure Bottom', labelpos='w', value='1050.', validate={'validator': 'real'}, ) dialog.y1.pack(side='top', fill='x', expand=1) dialog.y2 = Pmw.EntryField( f, label_text='Pressure Top', labelpos='w', validate={'validator': 'real'}, value='100.', ) dialog.y2.pack(side='top', fill='x', expand=1) dialog.draw = Pmw.RadioSelect( f, labelpos='w', buttontype='checkbutton', orient='vertical', label_text='Do you want to draw:', hull_borderwidth=2, hull_relief='ridge', ) dialog.draw.pack(side='top', fill='x', expand=1) for text in ('Filled Isotherms', 'Isotherms', 'Isobars', 'Dry Adiabatics', 'Pseudo Adiabatics', 'Mixing Ratio'): dialog.draw.add(text) dialog.draw.invoke(text) dialog.transient(parent) # Keep widget on top of its parent results = dialog.activate() x1 = dialog.x1.get() x2 = dialog.x2.get() y1 = dialog.y1.get() y2 = dialog.y2.get() draws = dialog.draw.getvalue() d = [ 0, ] * dialog.draw.numbuttons() for i in range(dialog.draw.numbuttons()): b = dialog.draw.button(i) nm = b.cget("text") if nm in draws: d[i] = 1 if len(dialog.portrait.getvalue()) != 0: goportrait = False th.datawc_x1 = float(x1) th.datawc_x2 = float(x2) th.datawc_y1 = float(y1) th.datawc_y2 = float(y2) th.drawisothermsfilled = d[0] th.drawisotherms = d[1] th.drawisobars = d[2] th.drawdryadiabats = d[3] th.drawpseudoadiabats = d[4] th.drawmixingratio = d[5] dialog.destroy() except Exception, err: print err else: th.datawc_x1 = -50. th.datawc_x2 = 50. th.datawc_y1 = 1050. th.datawc_y2 = 100. th.line.color = [ 241 + parent.thermo_profiles_count, ] if goportrait and th.x.orientation() == 'landscape': th.x.portrait() if len(vars) > 2: template.reset('x', ot.data.x1, ot.data.x1 + (ot.data.x2 - ot.data.x1) * .95) #template.reset('y',.1,.9) th.plot_TP(vars[0], template=template)