Previous: The Basics Next: Contours Table of contents Frames User guide
Unidata IDV Workshop for version 6.2u2 > Accessing and Displaying Data > Working with WRF Output > Jython

3.13.1.1 Units
How to change the units shown in a display.

Changing units on a display can be done by modifying one line of code and adding one new line:



filename = './wrfprs_d01.060'
file_opener = 'file.grid'
ds = makeDataSource(filename, file_opener)
variable = 'Pressure_reduced_to_MSL @ msl'
display_type = 'planviewcontour'
image_dimensions = (800, 600)
output_name = 'contour2D.png'
setOffScreen(1)
idv.getStateManager().setViewSize(java.awt.Dimension(image_dimensions[0], image_dimensions[1]))
pressure = getData(ds.getName(), variable)
dc = createDisplay(display_type, pressure)
dc.setDisplayUnitName('mb')
pause()
image = getImage()
writeImage(output_name)




Note that we've created a DisplayControlBase object dc(specifically a ContourPlanViewControl object, a subclass of DisplayControlBase), and changed the unit using the method setDisplayUnitName. While the goal of changing units has been accomplished, notice that it seems as though we have lost the characteristic of the contours to be colored based on value. However, this is not the case - we simply need to update the color range, as it still reflects the range of values in units of Pa:



filename = './wrfprs_d01.060'
file_opener = 'file.grid'
ds = makeDataSource(filename, file_opener)
variable = 'Pressure_reduced_to_MSL @ msl'
display_type = 'planviewcontour'
image_dimensions = (800, 600)
output_name = 'contour2D.png'
setOffScreen(1)
idv.getStateManager().setViewSize(java.awt.Dimension(image_dimensions[0], image_dimensions[1]))
pressure = getData(ds.getName(), variable)
dc = createDisplay(display_type, pressure)
old_unit = dc.getDisplayUnit()
dc.setDisplayUnitName('mb')
new_range = dc.convertColorRange(dc.getRange(),old_unit)
dc.setRange(new_range)
pause()
image = getImage()
writeImage(output_name)




The first thing needed is to save the old_unit (Pa), which has to be used in the function to get the new_range (the range after converting the display unit to mb). Finally, we set the color range to new_range using the setRange method, and voilà!

 


Previous: The Basics Next: Contours Table of contents Frames User guide
Unidata IDV Workshop for version 6.2u2 > Accessing and Displaying Data > Working with WRF Output > Jython