Re: [netcdf-java] Can I tell if a GridDatatype is "enhanced"?

Sorry for the late response.


A. yes, you do have to be careful about applying scale/offset twice.

1) as ethan said:

VariableDS vds = GridDatatype.getVariable();

this is not guaranteed to exist, so you need to check for null.

2) now we have to start breaking a lot of encapsolation, so probably we should 
make public

 EnumSet<NetcdfDataset.Enhance> enhanceMode = VariableDS.getEnhanceMode();

and you want to see if
 enhanceMode.contains( Enhance.ScaleMissingDefer);

if so, then scale/offset was not applied, but the scale/offset has been 
calculated, so that

 convertScaleOffsetMissing( Array)

should do the right thing.

Unfortunately, theres a few edge cases that might screw things up, as you can see by looking at
 VariableDS._read()

and
VariableDS.enhance().

Also, there are some changes coming in 4.2 that will handle things a bit 
different.

But I think for your purposes, the above will work 99.44% of the time, so I can make VariableDS.getEnhanceMode() public in next 4.1 release.
BTW, when you say "GridDatatype is being passed to me by "foreign" code", how 
foreign is it? Can we assume they have set the NetcdfDataset.setDefaultEnhanceMode() ?


B. GridDataset has:

 /** @return  underlying NetcdfFile, or null if none. */
 public ucar.nc2.NetcdfFile getNetcdfFile();

which will give you the underlying NetcdfDataset, from which you can call 
getFileType(). Its not guarenteed to be non-null, but so far all 
implementations will have one.




Ethan Davis wrote:
Hi Jon,

Whoops! Sorry about that.

A few possibilities:

1) It would be pretty easy to change the TDS to give you back a
NetcdfDataset instead of a GridDataset. You could use that for the
enhancement information and convert it to a GridDataset to get all the
grid goodness out of it.

2) We could (probably should) expose the enhancement information in
GridDataset.

3) Yuck! Dipping into implementation details. -- The only implementation
of ucar.nc2.dt.GridDataset is by ucar.nc2.dt.grid.GridDataset which has
a public getNetcdfDataset() method.

Number 2 would be my first choice. Though I'm trying to think of any
other reasons it would be useful for the WMS code to have a
NetcdfDataset instead of GridDataset.

Ethan

On 2/11/2010 1:46 PM, Jonathan Blower wrote:
Hi Ethan,

Thanks but there's no public getEnhanceMode() method on VariableDS
(http://www.unidata.ucar.edu/software/netcdf-java/v4.1/javadoc/ucar/nc2/
dataset/VariableDS.html).  There's a similar method on NetcdfDataset
though:
http://www.unidata.ucar.edu/software/netcdf-java/v4.1/javadoc/ucar/nc2/d
ataset/class-use/NetcdfDataset.Enhance.html.

But I can't get a handle to the NetcdfDataset if all I have is a
GridDataset (I think).

Along similar lines, is there a way to get the underlying file type of a
GridDataset/GridDatatype (so I can optimise data-reading algorithms
based on what sort of file I'm reading from)?
NetcdfDataset.getFileTypeId() works for a NetcdfDataset, but again I
can't get this if all I have is a GridDataset.

In case you hadn't guessed, this is all part of my effort to refactor
ncWMS to be more integrable with TDS.  From our previous conversations I
believe that TDS will give me GridDataset objects, so that's why I'm
trying to work at this level, but if there's a way that the TDS config
system could pass me higher-level objects that could work too.  Any
thoughts?

Cheers, Jon



-----Original Message-----
From: Ethan Davis [mailto:edavis@xxxxxxxxxxxxxxxx] Sent: 11 February 2010 18:34
To: Jonathan Blower
Cc: netcdf-java@xxxxxxxxxxxxxxxx
Subject: Re: Can I tell if a GridDatatype is "enhanced"?

Hi Jon,

Not very straight forward and there may be some loopholes I'm missing
that John can comment on when he returns.

If you call getVariable() on your GridDataype, you will get the backing
VariableDS. Call getEnhanceMode() on that and you'll get an
EnumSet<NetcdfDataset.Enhance>. If that Set contains
Enhance.ScaleMissing, the data you get back will have already had the
scale/offset/missing applied. If that set contains
Enhance.ScaleMissingDefer, you can directly use
VariableDS.convertScaleOffsetMissing() to convert the data.

VariableDs also implements VariableEnhance.enhance(Set<Enhance>) but the
comments say "DO NOT USE DIRECTLY. public by accident". I'll leave it to
John to explain that and comment on the possibility of exposing any of
this directly through the GridDatatype.

Ethan

On 2/8/2010 8:05 AM, Jonathan Blower wrote:
Hi,

I'm writing a method along the lines of:

double[] extractDataFrom(GridDatatype grid);

where the GridDatatype is being passed to me by "foreign" code out of
my
control.  Do I have any way of telling whether the GridDatatype is
"enhanced", i.e. whether scale/offset/missing attributes are
automatically applied when I extract data?

And does it matter?  Can I program defensively to take care of both
situations (enhanced and not enhanced)?  I'm worried that simply
applying convertScaleOffsetMissing() to a value from an enhanced
GridDatatype might actually apply the enhancements twice and hence
give
me the wrong answer.

Thanks,
Jon

_______________________________________________
netcdf-java mailing list
netcdf-java@xxxxxxxxxxxxxxxx
For list information or to unsubscribe, visit: http://www.unidata.ucar.edu/mailing_lists/



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