Re: [netcdf-java] combining and writing geogrids

John et al,

Thanks for the input.  I actually came across the NetcdfCFFileWriter class 
right after I sent the email and am having great success using it to write out 
subsetted files.  I haven't tried combining datasets yet, but when I get to it 
I'm sure I'll be back to ask questions!!

For now - I have a question regarding Structures/groups.  My procedures work 
great for the majority of the gridded datasets I've come across thus far.  
However, if the file contains structures (which themselves contain variables), 
I'm running into problems when I go to write the file to disk.  Essentially, 
the problem is that the variable names contain "." in them (for example 
"N4YRH.absuu") and are raising a "NetcdfFileWriteable.write illegal variable 
name = N4YRH.absuu" error (complete error message below).
How can I deal with this?  I've tried replacing the "." with a "_" before I 
pass the variable list to the FileWriter.writeVariables(), but the "Structure" 
name ("N4YRH") still gets appended and the same error occurs except instead of 
"N4YRH.absuu", the illegal name is "N4YRH.N4YRH_absuu".

Here is the link to the dataset I'm referring to above:
http://iridl.ldeo.columbia.edu/SOURCES/.CHRIS/dods


and here's the error message:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: 
NetcdfFileWriteable.write illegal variable name = N4YRH.absuu
        at ucar.nc2.NetcdfFileWriteable.write(NetcdfFileWriteable.java:538)
        at ucar.nc2.NetcdfFileWriteable.write(NetcdfFileWriteable.java:477)
        at ucar.nc2.FileWriter.copyAll(FileWriter.java:267)
        at ucar.nc2.FileWriter.copyVarData(FileWriter.java:223)
        at ucar.nc2.FileWriter.finish(FileWriter.java:459)
        at 
com.asascience.opendaptest.NetcdfGridWriter.writeFile(NetcdfGridWriter.java:117)
        at 
com.asascience.opendaptest.GridReader.extractData2(GridReader.java:161)
        at 
com.asascience.opendaptest.OpendapInterface.extractData(OpendapInterface.java:314)
        at 
com.asascience.opendaptest.LinkingPanel$5.actionPerformed(LinkingPanel.java:485)
        at 
javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1882)
        at 
javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2202)
        at 
javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
        at 
javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
        at 
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
        at 
java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:231)
        at java.awt.Component.processMouseEvent(Component.java:5554)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
        at java.awt.Component.processEvent(Component.java:5319)
        at java.awt.Container.processEvent(Container.java:2010)
        at java.awt.Component.dispatchEventImpl(Component.java:4021)
        at java.awt.Container.dispatchEventImpl(Container.java:2068)
        at java.awt.Component.dispatchEvent(Component.java:3869)
        at 
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4256)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3936)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3866)
        at java.awt.Container.dispatchEventImpl(Container.java:2054)
        at java.awt.Window.dispatchEventImpl(Window.java:1774)
        at java.awt.Component.dispatchEvent(Component.java:3869)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
        at 
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
        at 
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)


Thanks for the help!!!

Chris

Christopher Mueller  |  Scientist
Applied Science Associates
70 Dean Knauss Drive   |    Narragansett, RI  02882 USA
p:  +1 401-789-6224  |  f:  +1 401-789-1932
e:  cmueller@xxxxxxxxxxxxxx  |  www.asascience.com
 
ASA | Science. Services. Solutions.




-----Original Message-----
From: John Caron [mailto:caron@xxxxxxxxxxxxxxxx] 
Sent: Wednesday, September 26, 2007 7:34 PM
To: Christopher Mueller
Cc: netcdf-java@xxxxxxxxxxxxxxxx
Subject: Re: [netcdf-java] combining and writing geogrids



Christopher Mueller wrote:
> Greetings all,
> 
>  
> 
> I'm curious if anyone out there can help me with some questions I have 
> about GeoGrids.  Specifically I'm wondering if anyone knows how I can go 
> about the process of combining multiple GeoGrids into one "object" and 
> then write that object to a local .nc file.  Thus far, I've succeeded in 
> connecting to an opendap server, getting a single geogrid, subsampling 
> it and using the GeoGrid.writeFile() method to create a local file.  
> I've noticed that the javadoc for GeoGrid says not to use the writeFile 
> method - but I couldn't see another way of getting the data to disk.
> 
>  
> 
> So my first question is - what is the correct method for writing the 
> contents of a GeoGrid to a local file??  I've checked out 
> NetcdfFileWriteable, but that doesn't allow me to add a GeoGrid (at 
> least not directly).

ucar.nc2.dt.grid.NetcdfCFWriter is a helper class that replaces 
grid.writeFile(). It writes CF compliant files. It's still a bit rough but 
probably will work for you.

> 
>  
> 
> My second question is - is there a way to combine multiple geogrids so 
> that their contents can be written to a single file.  For example - if 
> my opendap dataset has U, V, and Temp variables, I'd like them all to be 
> written to a single file.  My geogrid.writeFile method produces a 
> dataset for each at this point

As you will see from the API, you have to construct a ucar.nc2.dt.GridDataset 
object. You can do this from an opendap dataset, just like any other dataset, 
see ucar.nc2.dt.grid.GridDataset.open(). If you dont want all the Geogrids, you 
will have to remove the ones you dont want. It should work, but we havent 
tested that particular case.

> 
>  
> 
> In relation to this second question - how would I combine geogrids from 
> 2 separate opendap sources - assuming that they are identical aside from 
> the variable(s) of interest?

Again, you would construct a ucar.nc2.dt.GridDataset and use NetcdfCFWriter to 
write it out. It may be tricky to get the GridDataset right, we've never 
attempted to combine from 2 different sources.

> 
>  
> 
>  
> 
> Thank you in advance for your help - it's most appreciated.

good luck!

> 
>  
> 
> Chris
> 
>  
> 
>  
> 
> *Christopher Mueller/  /*|  Scientist
> 
> Applied Science Associates
> 
> 70 Dean Knauss Drive   |    Narragansett, RI  02882 USA
> 
> p:  +1 401-789-6224  |  f:  +1 401-789-1932
> 
> e:  cmueller@xxxxxxxxxxxxxx <mailto:ehowlett@xxxxxxxxxxxxxx>  |  
> www.asascience.com <http://www.asascience.com/>
> 
>  
> 
> *ASA **|** Science. Services. Solutions.***
> 
>  
> 
>  
> 
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> netcdf-java mailing list
> netcdf-java@xxxxxxxxxxxxxxxx
> For list information or to unsubscribe, visit: 
> http://www.unidata.ucar.edu/mailing_lists/ 


  • 2007 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: