script: display AREA files without bundle

Post any questions, ideas, or topics related to Jython and Python scripting.
Post Reply
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

script: display AREA files without bundle

Post by joleenf »

Hi,

I want to display an IMAGE file. In my case it is an ADDE area file, but could be a local AREA file. I have a script that begins this process, but there are a number of things I would like it to do, but don't know what calls will make it work. The goal: display and AREA, center on a certain latlon, change the color table, customize the layer label, save it.

In the end, I want to be able to use this script for any area, from any server, enter a specific date/time and possible other specifics about the area like SIZE, UNIT, DOC (I must have the line documentation for scan line time).

I have attached the script that I have at this point. Thanks to TomW, I have been able to get the data from a server, make it ready for the display and load it. There are still a few hurdles.

This is similar to functionality in the IMGDISP command and was hoping to use it as a tool to easily move my McIDAS-X scripts over to McIDAS-V.

The script so far:
from edu.wisc.ssec.mcidas import AreaFile as af;

# The contents of the mydata dictionary was copied directly from the Field Selector. This data was loaded through the chooser.
# Right click on the data and select properties>Details. This information was under location, BAND=ALL was changed to BAND=10.

server="adde://rets3.ssec.wisc.edu/imagedata?" #server where data resides
portname="PORT=112&COMPRESS=gzip" #port information (I think 112 is default)
project="USER=idv&PROJ=0" #project name and project number
GROUP="GROUP=CIMSSP3&DESCRIPTOR=SABI_137W" #adde GROUP/DESCR
date="DAY=2008178&TIME=21:00:00 21:00:00 I"
keywords="BAND=10&LATLON=31.2 -100.5&PLACE=CENTER&SIZE=250 250&UNIT=TEMP&MAG=1&SPAC=4&AUX=YES"
lat=31.2
lon=-100.5

remote_area=server+"&"+portname+"&"+project+"&VERSION=1&DEBUG=false&TRACE=0&"+GROUP+"&"+date+"&"+keywords

setOffScreen(1) #run in background
a=load(remote_area) #load finds the adapter for this data so that it can be displayed
createDisplay('imagedisplay',a) #get this image into the display
pause()

#---center on the chosen lat/lon location. The Parameters in "centerAndZoom() are latlon,0,zoomFactor---
lalo=Util.makeEarthLocation(lat,lon)
vms=idv.getVMManager().getViewManagers()
vms.get(0).getMapDisplay().centerAndZoom(lalo, 0, 2.0)
vms.get(0).getMapDisplay().centerAndZoom(lalo, 0, 1.0)
vms.get(0).getMapDisplay().centerAndZoom(lalo, 0, 1.0)
#---end of commands which center the image to user chosen location---

#---changing the color table---#
#I would like to change the color table here, to one of my own color tables like "GA20P" or "mylatestcolortable"
###---end of commands for changing the color table---###

#---Change the layer label---#
#My new label "GOES-15 (0.65 um Brightness Temperature) - %timestamp%"

#---Add a color bar---#

#save this image - Another place where I could customize my label, but I don't have access to the %timestamp% and other macros?
writeImage("/Users/joleenf/mcidas/images/test_image2.jpg",\
"overlay text=GOES-R place=LM,0,-20 anchor=LM color=red")


Thanks,
Joleen
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: script: display AREA files without bundle

Post by joleenf »

Here is TomW's solution for changing the color table, it worked for me.

"Blues" is the new color table.

#---changing the color table---#
ctm=idv.getColorTableManager()
ct=ctm.getColorTable("Blues")
df=findDisplayControl("class:edu.wisc.ssec.mcidasv.control.ImagePlanViewControl")
df.setColorTable(ct)
###---end of commands for changing the color table---###
User avatar
tomw
Posts: 296
Joined: Tue Dec 23, 2008 3:40 pm

Re: script: display AREA files without bundle

Post by tomw »

....and if you want to get the date-time (assuming variable 'df' is the DisplayControl, as in your example),

dtg = str ( df.getTimeSet() [0] )

which you can then use for making labels. The string format looks like this:
2010-08-04 17:10:00Z
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: script: display AREA files without bundle

Post by joleenf »

I have not been able to get the time information with the getNominalTime method. I thought it might be the way the directory information had been constructed for the simulated data, so I switched to real-time data. When I did that, I made a silly error and specified a band that did not exist. I am guessing that when load tried to get information from the area adapter, the ADDE server's error code was returned and load assumed that it was not an AREA format. I believe that is why I got this error:

visad.data.BadFormException: visad.data.BadFormException: Data object "adde://eastl.ssec.wisc.edu/imagedata?&PORT=112&COMPRESS=gzip&USER=JMF&PROJ=6533&VERSION=1&DEBUG=false&TRACE=0&GROUP=EASTL&DESCRIPTOR= ONUS&POS=-1&BAND=10&LATLON=31.2 -100.5&PLACE=CENTER&SIZE=250 250&UNIT=TEMP&MAG=1&SPAC=4&AUX=YES" not compatible with "visad.python.JPythonMethods" data family

I tried running the script with the -trace command, but as far as I can tell, it does not list the error from the ADDE server, area adapter or otherwise. Is there any way to get more information. In this case, the problem was solved by actually requesting a band that existed.

It is a small issue, but I am curious.

Thanks,
Joleen
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: script: display AREA files without bundle

Post by joleenf »

When the data is loaded through

a=load(remote_area),

the class of a is visad.meteorology.NavigatedImage. TomW. then showed me that if I look under the class of NavigatedImage, one of the methods is getStartTime()
(See http://www.ssec.wisc.edu/visad-docs/jav ... Image.html)

In my script, I added the line,

image_time=str(a.getStartTime())

and

print image_time

confirms that the getStartTime() method actually returned the image date and time.

Thanks,
Joleen
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: script: display AREA files without bundle

Post by joleenf »

This is the script so far, with the result attached. I have highlighted in blue some of the remaining questions. I have a way to get the information from the area directory block, but have not included it here because other display label issues still need to be resolved.

1. How do I resize the image display so that the display used for the image is changed before the image is displayed?

2. How do I keep the "-Image Display" label from being stamped on the bottom of the image or change it to something that makes more sense.

3. I have not looked into getting values for the colorbar from the data, but that is another step.


from edu.wisc.ssec.mcidas import AreaFile as af;

lat=47
lon=-89.5

local_area=("/Users/joleenf/mcidas/data/AREA0100")

setOffScreen(1) #run in background
a=load(local_area) #load finds data adapter for display
createDisplay('imagedisplay',a) #get this image into the display (Can I change the size?)
#how do I remove "Image Display" from label

pause()

#Get time of image from data
image_time=str(a.getStartTime()) #get the time from my data retrieved throught the load function
label='GOES-13 (3.9 um Temperature) '+image_time.replace('GMT','UTC') #replace the GMT text in string with UTC

#find the display control which allows a connection to change stuff on the image
df=findDisplayControl("class:edu.wisc.ssec.mcidasv.control.ImagePlanViewControl")
my_image=df.getImage() #use the getImage() method on the display control
resizeImage(my_image,1000,1000) #now I can resize my image?
dlt=df.getDisplayListTemplate()
dlt=dlt.replace("%datasourcename%","nope")
dlt=dlt.replace("%displayname%","nope")
dlt=dlt.replace("%timestamp%",label)
df.setDisplayListTemplate(dlt) #trying to reset the Display List to the label that I created...doesn't work.


#---center on the chosen lat/lon. Parameters in "centerAndZoom():latlon,rotate in (for interactive sessions),zoomFactor---
lalo=Util.makeEarthLocation(lat,lon)
vms=idv.getVMManager().getViewManagers()
vms.get(0).getMapDisplay().centerAndZoom(lalo, 0, 2.0)
vms.get(0).getMapDisplay().centerAndZoom(lalo, 0, 1.0)
vms.get(0).getMapDisplay().centerAndZoom(lalo, 0, 1.0)
#---end of commands which center the image to user chosen location---

#---changing the color table---#
ctm=idv.getColorTableManager()
ct=ctm.getColorTable("ColorTable_VIZ")
df.setColorTable(ct)
###---end of commands for changing the color table---###

#---Add a color bar---#

writeImage("/Users/joleenf/mcidas/images/test_image2.jpg",\
"matte background=black top=60;colorbar width=300 height=20 anchor=UM place=UM,0,20;\
overlay text="+label+" place=LM,0,-20 anchor=LM color=red") #label works but Image Display is underneath, would like to get values for colorbar from data
Attachments
Result of script.  I have the desired display label along with the "- Image Display" from the DisplayListTemplate.  I have a colorbar, but no labels.
Result of script. I have the desired display label along with the "- Image Display" from the DisplayListTemplate. I have a colorbar, but no labels.
User avatar
tomw
Posts: 296
Joined: Tue Dec 23, 2008 3:40 pm

Re: script: display AREA files without bundle

Post by tomw »

To change the size of the display: before you do a createDisplay(), do this:

idv.getStateManager().setViewSize(java.awt.Dimension(www,hhh))

where "www" is the width, and "hhh" is the height you want.
User avatar
tomw
Posts: 296
Joined: Tue Dec 23, 2008 3:40 pm

Re: script: display AREA files without bundle

Post by tomw »

To "hide" the normal Display List output, just do this:

df.setShowInDisplayList(0)

And then just put all your labeling using the writeImage(....) like you have.
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: script: display AREA files without bundle

Post by joleenf »

The script fails with a null pointer exception in McIDAS-V Version 1.00 and 1.01 stable releases. However, in the current nightly build: McIDAS-V 1.01 build 2011-05-02, the null pointer exception has been fixed. However, now the lat/lon lines that I have added do not appear to be on the top layer. Does this look like the case to anyone else? Is there a quick way to fix this?
Attachments
test_image2.jpg
Post Reply