error loading NetCDF dataset

Post any questions, ideas, or topics related to Jython and Python scripting.
User avatar
kbedka1
Posts: 428
Joined: Wed Jan 28, 2009 7:27 pm

error loading NetCDF dataset

Post by kbedka1 »

We are using the following command sequence in an effort to load a NetCDF parameter into a variable for display. We have focused on simply accessing the NetCDF data first and then we will work on display stuff later.

setOffScreen(1)
idv.getStateManager().setViewSize(java.awt.Dimension(400,400))
ds=makeDataSource("/Users/kbedka/TEST.NC","netcdf.grid")
a=getData(ds.getName(),"solar_zenith_angle")

I tried this today on a 1.02 beta 1 nightly build (Mac OSX) in the Mc-V jython shell, and the makeDataSource command failed with the following error:

Error: Traceback (most recent call last): File " ", line 1, in File "/Applications/McIDAS-V-System/idv.jar/ucar/unidata/idv/resources/python/shell.py", line 101, in makeDataSource NameError: global name 'idv' is not defined

My colleague, Baojuan Shan said that she tried this on 1.01 on Mac and Linux and the MakeDataSource command worked, but the getData failed.

What are we doing wrong? For reference, you can find the TEST.NC file at: ftp://ftp.ssec.wisc.edu/pub/incoming/TEST.NC
User avatar
kbedka1
Posts: 428
Joined: Wed Jan 28, 2009 7:27 pm

Re: error loading NetCDF dataset

Post by kbedka1 »

Here is the getData error Bao received:

Error: Traceback .....
In getDataChoice java.lang.NullPointerException at
ucar.unidata.data.DataSourceImp1.equals(DataSourceImp1.java:1500) at
ucar.unidata.data.FileDataSource.equals(DataSorceImp1.java:546) at ......
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: error loading NetCDF dataset

Post by joleenf »

Kris,

I have also seen this same behavoir.

Joleen
User avatar
Rick
Posts: 404
Joined: Fri Jan 16, 2009 8:20 pm

Re: error loading NetCDF dataset

Post by Rick »

Hi Kris and Joleen,

For a temporary solution, please add the following lines to the top of the script:

import shell
shell.idv = idv


Let us know how it goes.

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

Re: error loading NetCDF dataset

Post by joleenf »

Rick,

This would only work for the unstable build, correct?

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

Re: error loading NetCDF dataset

Post by joleenf »

Hi,

I have tested adding the

import shell
shell.idv = idv

fix to my script and running it with Version: 1.02beta1 Build-date: 2011-06-22 09:30.

I now get this error:

<type 'ucar.visad.data.GeoGridFlatField'>
Traceback (most recent call last):
File "<string>", line 8, in <module>
File "<string>", line 72, in createDisplay
AttributeError: 'module' object has no attribute 'toFront'
Error running jython script:/Users/joleenf/mcidas/scripts/netcdfload.py
Traceback (most recent call last):
File "<string>", line 8, in <module>
File "<string>", line 72, in createDisplay
AttributeError: 'module' object has no attribute 'toFront'


without the fix, the error is

Traceback (most recent call last):
File "<string>", line 3, in <module>
File "/Users/joleenf/Applications/McIDAS-V-System/idv.jar/ucar/unidata/idv/resources/python/shell.py", line 101, in makeDataSource
NameError: global name 'idv' is not defined
Error running jython script:/Users/joleenf/mcidas/scripts/netcdfload.py
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "/Users/joleenf/Applications/McIDAS-V-System/idv.jar/ucar/unidata/idv/resources/python/shell.py", line 101, in makeDataSource
NameError: global name 'idv' is not defined

in the stable version (McIDAS V1.01)

java.lang.NullPointerException: java.lang.NullPointerException
Error running jython script:/Users/joleenf/mcidas/scripts/netcdfload.py
Traceback (most recent call last):
File "<string>", line 4, in <module>
File "<string>", line 130, in getData
File "<string>", line 119, in getDataChoice

This is the error for the stable version with or without the fix. The error from version 1.01 was what Tom Rink addressed for the nightly fix, which then uncovered the other NPE error. The "import shell" fix was to get around the NPE error but then the toFront error appears?

Joleen
User avatar
Jon
Posts: 192
Joined: Fri Jan 09, 2009 8:44 pm
Location: Madison, WI

Re: error loading NetCDF dataset

Post by Jon »

Hmm. It looks as though there's a naming conflict within shell.py from Unidata:

Code: Select all

def createDisplay(displayType, data, dataName='Data'):
        import ucar.unidata.data.DataDataChoice as DataDataChoice
        import ucar.unidata.data.DataChoice as DataChoice
        if(isinstance(data, java.util.List)==0):
                tmp = java.util.ArrayList();           
                tmp.add(data);
                data = tmp;

        dataList = java.util.ArrayList();
        for i in range(data.size()):
            obj = data.get(i)
            if(isinstance(obj, DataChoice)==0):
                label = dataName
                if(data.size()>1):
                    label = label +str(i)
                obj = DataDataChoice(label,obj);
            dataList.add(obj);
        control = idv.doMakeControl(displayType, dataList);
        if (shell != None):
            shell.toFront();
        return control


Note that the filename is "shell.py" (and imported like so "import shell"). Apparently the import overwrites the "shell" global variable at the beginning of shell.py…

I'll see what I can do!
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: error loading NetCDF dataset

Post by joleenf »

import shell as myShell
myShell.idv = idv

seems to do the trick. However, I had to add a whole bunch of pause() lines to make the script work as it does in the interactive jython shell. I have not had to worry about adding pause() lines in the past, though I did because someone told me to. That could be my computer suddenly deciding to be fussy.

import shell as myShell
myShell.idv = idv
setOffScreen(1)
idv.getStateManager().setViewSize(java.awt.Dimension(400,400))
ds = makeDataSource("/Users/joleenf/mcidas/data/netcdf/Simple_AVG_reprojected_Validation_1km_sim_abi_band01_2006_0719_1200utc.nc","netcdf.grid")
a = getData(ds.getName(),'ABI_Refl_b01')
print a.__class__
dc = createDisplay('planviewcolor',a)
pause()
dc.setDisplayListTemplate("This is My Stuff!");
pause()
dc.applyPreferences();
pause()
writeImage("/Users/joleenf/mcidas/images/kbah_image.png")

Joleen
User avatar
tomw
Posts: 296
Joined: Tue Dec 23, 2008 3:40 pm

Re: error loading NetCDF dataset

Post by tomw »

Good (temporary) solution, Joleen!!
User avatar
barryr
Posts: 213
Joined: Thu Jan 08, 2009 5:42 pm
Contact:

Re: error loading NetCDF dataset

Post by barryr »

Thanks, everyone, for the comments and suggestions. We created an inquiry to resolve the problem:

http://mcidas.ssec.wisc.edu/inquiry-v/?inquiry=1073
Post Reply