Previous: Contours Next: Combining Displays 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.3 Labels and Color Scales
Labeling your images and adding a color scale.

The default display label for a variable can be very useful; however, sometimes it's not so great (as in our case, where the label says "Data - Contour Plan View - timestamp"). Changing the string that composes the label isn't much work, but changing the color of the text requires a bit more care. In order to change the color of the label text, we need to import the Java AWT class Color using import java.awt.Color as Color. The last bit of the import statement (as Color) allows us to refer to the java.awt.Color class by simply using Color (it reduces typing in the end if you have multiple calls to Color).

Built-in to the IDV display label is a macro sub-language. This will allow us to refer to information contained within the datafile, such as longname, shortname, and timestamp, through easy commands like %longname%, %shortname%, and %timestamp%. That said, sometimes the macro for things like %longname% and %shortname% return not-so-informative strings, like "Data" (which is what happens in our example). Not to worry, as you have complete control over the text in the label, as shown in the example below. Note that a list of display name macros can be found in source code for DisplayControlbase and are listed as variables named MACRO_*.

Also included in the example below is a demonstration of how a color scale can be added to your display. Note that all of the work is being done to a ColorScaleInfo object (which we have stored in the variable colorScaleInfo).



import java.awt.Color as Color
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)
ctm = idv.getColorTableManager()
dc.setColorTable(ctm.getColorTable('White'))
old_unit = dc.getDisplayUnit()
dc.setDisplayUnitName('mb')
new_range = dc.convertColorRange(dc.getRange(),old_unit)
dc.setRange(new_range)
dc.setDisplayListTemplate(variable+' - %timestamp% | Woot!')
dc.setDisplayListColor('Color.white')
colorScaleInfo = dc.getColorScaleInfo()
colorScaleInfo.setOrientation(colorScaleInfo.VERTICAL)
colorScaleInfo.setPlacement(colorScaleInfo.LEFT)
colorScaleInfo.setIsVisible(True)
pause()
image = getImage()
writeImage(output_name)



 


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