Re: [idvdevelopers] [idvusers] problem using Contour2DDisplayable

Hi Don, you are so right, my code was a comedy of errors. I should have RTFM for GeoGrids. What gives me a nice contoured image from a nc Variable is this:

        
        String netcdfUrl = args[0];
        GeoGridDataSource ggds = new GeoGridDataSource(null, netcdfUrl, null);
        GridDataset gds = ggds.getDataset();
        
        // get the geogrid by name, as Don says
        GeoGrid gg = gds.findGridByName( "surface_temperature" );
        GeoGridAdapter gga = new GeoGridAdapter( ggds, gg );
        FieldImpl fi = gga.getData();

// sample 1 is 2nd time value, in my data set 1st time sample is missing for this variable
       FlatField ff = (FlatField)fi.getSample(1);

        // now build the Displayable
        Contour2DDisplayable cdd = new Contour2DDisplayable( "foo" );

        // we have to set the realType, I was missing this      
cdd.setC2DRealType( (RealType) ((FunctionType)ff.getType()).getRange() );
        
        cdd.setData( fi );
        cdd.setContourLevels( new RegularContourLevels( 5, 273, 273, 310 ) );

My biggest error was missing the line to setC2DRealType. i was under the impression that the IDV code could 'figure out' the RealType from the FieldImpl passed in. Of ocurse this cannot be the case since the FieldImpl could have many ranges, ie it could be realTupleType. Maybe if the ((FunctionType)ff.getType()).getRange() call returns a RealType that could be used automatically?

Thanks again Don!

Stuart


On Apr 4, 2008, at 7:22 AM, Don Murray wrote:

Hi Stuart-

Just a followup to this since I'm now looking at your first
message.  In your code you have:


Stuart Maclean wrote:

I am now trying to contour a field from a netcdf grid file. The IDV does this Ok, but my image is simply a white polygon of the grid itself. My code is this:
        String netcdfUrl = args[0];
GeoGridDataSource ggds = new GeoGridDataSource(null, netcdfUrl, null);
        GridDataset gds = ggds.getDataset();
        GeoGrid gg = (GeoGrid)gds.getGrids().get(0);

This will just get the first grid in the GridDataset.  What you want
to do is:

       GeoGrid gg = gds.findGridByName("surface_temperature");

(or substitute whatever the variable name is for "surface_temperature").

        GeoGridAdapter gga = new GeoGridAdapter( ggds, gg,
                                                 "surface_temperature" );
        FieldImpl fi = gga.getData();
        System.out.println( fi.getType().prettyString() );
which gives
(Time -> ((XC[unit:km], YC[unit:km]) -> surface_temperature[unit:Pa]))
Not sure why temp units are Pa??

The first grid in the GridDataset must be a pressure grid of
some sort.

        FlatField ff = (FlatField)fi.getSample(1);
        System.out.println( ff.getType().prettyString() );
which I presume extracts some time element, and gives
((XC[unit:km], YC[unit:km]) -> surface_temperature[unit:Pa])


Don
*************************************************************
Don Murray                               UCAR Unidata Program
dmurray@xxxxxxxxxxxxxxxx                        P.O. Box 3000
(303) 497-8628                              Boulder, CO 80307
http://www.unidata.ucar.edu/staff/donm
*************************************************************



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