[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

20041102: 20041029: IDV - jython method for adding dataset



>From: "John C Cartwright" <address@hidden>
>Organization: NOAA/NGDC
>Keywords: 200411022201.iA2M1svV019767 IDV jython

Hi John-

>followup to my earlier message. I now have a jython method that 
>correctly plots outside of IDV. However, IDV complains about the use of 
>RealTupleType.

I've never had this problem but others have.  In some cases, 
"from visad import *" does not seem to get picked up.  Try
adding the following (in the body of the procedure):

   from visad import RealTupleType
   from visad import FunctionType
   from visad import Gridded2DSet
   from visad import FlatField

(those seem to be the ones that are needed, add others as necessary).

>Attached is samply.py which demonstrates the successful field creation 
>and listed below is the formula that complains in IDV.

Okay, thanks.

>Can you tell me what's wrong here and clarify for me when one uses the 
>methods in visad.python.JPython  methods vs. when one uses the visad.* 
>classes directly?

Here's what I got to work:

from visad import *
from visad.python.JPythonMethods import *

def generateTestField():
    row = getRealType("ROW")
    col = getRealType("COLUMN")

    domain_tuple = RealTupleType(row,col)

    pixel = getRealType("PIXEL")
    func_dom_pix = FunctionType(domain_tuple, pixel)

    NROWS = 9
    NCOLS = 18
    grid = [None]*2
    grid[0] = [None] * (NROWS*NCOLS)
    grid[1] = [None] * (NROWS*NCOLS)

    i = 0
    flat_samples = [None]
    flat_samples[0] = [None]* (NROWS*NCOLS)
    for lat in range(-90,90,20):
       for lon in range(-180,180,20):
          grid[0][i] = lon
          grid[1][i] = lat
          flat_samples[0][i] = i
          i = i+1

    domain_set = Gridded2DSet(domain_tuple,grid,NCOLS,NROWS)
    vals_ff = FlatField(func_dom_pix,domain_set)
    vals_ff.setSamples(flat_samples)
    return vals_ff

Note I did not have to do the explicit imports. If you still have
problems, try the explicit imports.

Here's what I changed:

1) I had to add in the declaration of flat_samples = [None] otherwise
I got an error.

2) You specify ROW and COLUMN as the RealTypes, but then put
lon values in for ROW and lat values for COLUMN.  That aside, I
could get this to display in the Omni control after the change
in #1.

3) To display this in the IDV, I changed:

    row = getRealType("Longitude")
    col = getRealType("Latitude")

and then displayed using one of the Plan View Displays.

>from visad import *
>from visad.python.JPythonMethods import *
>
>def generateTestField():
>    row = getRealType("ROW")
>    col = getRealType("COLUMN")
>
>    domain_tuple = RealTupleType(row,col)
>
>    pixel = getRealType("PIXEL")
>    func_dom_pix = FunctionType(domain_tuple, pixel)
>
>    NROWS = 9
>    NCOLS = 18
>    grid = [None]*2
>    grid[0] = [None] * (NROWS*NCOLS)
>    grid[1] = [None] * (NROWS*NCOLS)
>
>    i = 0
>    flat_samples[0] = [None]* (NROWS*NCOLS)
>    for lat in range(-90,90,20):
>       for lon in range(-180,180,20):
>          grid[0][i] = lon
>          grid[1][i] = lat
>          flat_samples[0][i] = i
>          i = i+1
>
>    domain_set = Gridded2DSet(domain_tuple,grid,NCOLS,NROWS)
>    vals_ff = FlatField(func_dom_pix,domain_set)
>    vals_ff.setSamples(flat_samples)
>    return vals_ff

Let me know if you have problems with what I sent.

Don
NOTE: All email exchanges with Unidata User Support are recorded in the
Unidata inquiry tracking system and then made publicly available
through the web.  If you do not want to have your interactions made
available in this way, you must let us know in each email you send to us.