Plot western hemisphere cities

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

Plot western hemisphere cities

Post by joleenf »

Hi,

I am trying to find a way to plot the place names of western hemisphere cities regardless of the location of the data (Northern or Southern Hemisphere). I did not see a locations list already built in McV which included what I needed, so I made a custom list in userstations.xml. Then, I wanted to use these locations in a script. Since I did not know how to plot locations using any of the scripting API, I saved the displayed locations in a bundle whcih was projected to the World view, and had Auto-Set projection off.

I tested a script which displayed some data and then loaded the bundle in the interactive McV jython shell. As long as I loaded the bundle after the data was projected and zoomed, everything looked okay. However, when I ran the script in the background, I discovered that the MERGE mode in the bundle was not working. Please use the attached files to replicate the problem. Try running the attached script both in the interactive jython shell and in the background. On a mac and a unix machine, the MERGE appears to display the locations bundle in a new window when run in the background.

quick_bundle_load.py
(591 Bytes) Downloaded 212 times


This is a poorly named bundle, it should be called WesternHemisphereCities.
WorldCities.mcvz
(5.93 KiB) Downloaded 208 times


Place in McIDAS-V directory.
userstations.xml
(45.12 KiB) Downloaded 303 times


Joleen
User avatar
bobc
Posts: 938
Joined: Mon Nov 15, 2010 5:57 pm

Re: Plot western hemisphere cities

Post by bobc »

Hi Joleen,

Thanks for a thorough description of the problem. I'm replicating that 'MERGE' doesn't appear to be working from the background. I did find a workaround, though. Basically, I did the following:

  1. I changed the mode to load the bundle to "NEWWINDOW".
  2. Since a new window was being built through openBundle, I switched the order that layers were added to the display. First, I load the bundle, and then I add the image layer to the active display.

Here is a script you can try:
quick_bundle_load_bob.py
(585 Bytes) Downloaded 203 times

I'll take a look and see if there is an inquiry already written up for 'MERGE' not working from the background. If one doesn't exist, I'll write one up for evaluation. I'll also take a look and see if I can find a way to add location labels through a script using a method other than loading a bundle. If I can't find a way to do this, I'll write up an inquiry for this as well.

Please let me know if you have any questions or problems with my workaround.

Thanks,
Bob
User avatar
joleenf
Posts: 1120
Joined: Mon Jan 19, 2009 7:16 pm

Re: Plot western hemisphere cities

Post by joleenf »

Hi Bob,

The NEWWINDOW (height=2160, width=2160) method was the first thing I tried, but I found that for the Mesoscale sectors, I did not get the same result for the reset project by mesoscale layer and then setting the scale factor to 2. When I use a regular buildWindow, the mesoscale sector filled the window, but not when I used the openBundle method. In addition, the fonts did scale as well either.

Joleen
User avatar
bobc
Posts: 938
Joined: Mon Nov 15, 2010 5:57 pm

Re: Plot western hemisphere cities

Post by bobc »

Hi Joleen,

With some help from Jon, I figured out how to add location labels through a script. See the full script that displays GOES-16 imagery and overlays it with location labels is here:
quick_bundle_load_bob.py
(662 Bytes) Downloaded 210 times

The chunk of code that adds the location labels is here:

Code: Select all

# add location labels to display
gs = getStaticMcv()
loc = gs.locationList.get(0)
controlDesc = gs.getControlDescriptor('locationcontrol')
gs.uiManager.addStationDisplay(loc, controlDesc)

If you run this through the Jython Shell, you'll be able to verify that the loc= line is correct for you by running "print loc". This looks to be a 0-based list of location labels. For me, a value of 0 returns "My Custom Stations>western_hemisphere(435)", whereas a value of 1 returns "My Custom Stations>Great Lakes(5)".

If you give this a try and have any questions, please let me know.

Thanks,
Bob
User avatar
joleenf
Posts: 1120
Joined: Mon Jan 19, 2009 7:16 pm

Re: Plot western hemisphere cities

Post by joleenf »

Hi Bob,

What is getStaticMcV()? I am seeing an error that says it is undefined.

Joleen
User avatar
bobc
Posts: 938
Joined: Mon Nov 15, 2010 5:57 pm

Re: Plot western hemisphere cities

Post by bobc »

Hi Joleen,

You need to lower-case the "V" at the end, it's getStaticMcv(). From looking at the javadoc, getStaticMcv() returns a reference to the current McIDAS-V object. From how I've used it in the past, it can be a way to get at different UI controls through scripting. In this case, it allows you to get at the locations. In the past, I've used it to add a background image to the display. Please let me know if you have any more questions about getStaticMcv().

Thanks,
Bob
User avatar
joleenf
Posts: 1120
Joined: Mon Jan 19, 2009 7:16 pm

Re: Plot western hemisphere cities

Post by joleenf »

Thanks Bob, that is working.

Joleen
User avatar
bobc
Posts: 938
Joined: Mon Nov 15, 2010 5:57 pm

Re: Plot western hemisphere cities

Post by bobc »

Hi Joleen,

When you called the Help Desk, one of your questions was the best way of getting a reference to the Locations layer in the display. Assuming this is the last layer added to the display, you could use index "-1" when using getLayers:

Code: Select all

locLayer = panel[0].getLayers()[-1]

An alternative way of doing this would be to use getLayers again, but return the index in the layer list whose string matches "Locations". This assumes that there is only one Locations layer in the display. A benefit of this is that it should work regardless of the order that the layer was added to the display. After creating your display, you could run something like:

Code: Select all

dispLayers = panel[0].getLayers()
for i, j in enumerate(dispLayers):
    if str(j) == 'Locations':
        locLayer = dispLayers[i]

At this point, "locLayer" could be used as a reference to the Locations layer in the display. For example, you could run a command like:

Code: Select all

locLayer.setLayerVisible(False)

... to turn the visibility of the Locations layer off in the display.

Please let me know if you have any questions about this.

Thanks,
Bob
User avatar
joleenf
Posts: 1120
Joined: Mon Jan 19, 2009 7:16 pm

Re: Plot western hemisphere cities

Post by joleenf »

Hi Bob,

This seems to work fine on my mac, except that the locations layer is not accessible with panel[0].getLayers() (Could you test attached script and tell me if you see the locations layer?).

When I run this through a vnc server, if I place the locations on the display before I display the sandwich, my script hangs, when plotted afterward, I don't have the location layer handle, which I do need later in the script.

Code: Select all

panel = buildWindow()

m1Parms = dict(
    server = 'lead.unidata.ucar.edu',
    dataset = 'RTGOESR',
    descriptor = 'M1',
    size = (500,500),
    position = -1,
    )

vis = loadADDEImage(band=2, mag=(-4,-4), unit='ALB', **m1Parms)
ir = loadADDEImage(band=13, mag=(1,1), unit='TEMP', **m1Parms)

sandData = sandwich(ir,vis)

panel=buildWindow(2160,2160)

# add location labels to display
visLayer = panel[0].createLayer('Image Display', vis)
sandLayer = panel[0].createLayer('RGB Composite', sandData)

print ('Done with Image Display')

# add location labels to display
gs = getStaticMcv()
loc = gs.locationList.get(0)
controlDesc = gs.getControlDescriptor('locationcontrol')
gs.uiManager.addStationDisplay(loc, controlDesc)

for layer in panel[0].getLayers():
    print (layer)

home_directory = os.path.expanduser('~')
image_path = os.path.join(home_directory,'check')
panel[0].captureImage('%s/test2.gif' % image_path)




rgb_and_locs.py
(928 Bytes) Downloaded 193 times
User avatar
jayh
Posts: 415
Joined: Thu Jan 15, 2009 10:34 pm

Re: Plot western hemisphere cities

Post by jayh »

Hi Joleen-

Your script showed the locations layer for me... v1.8 on my Mac. Partial pic attached.

-Jay
Attachments
Untitled.png
Post Reply