NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

Re: skip, stride reading...

Tom Rink wrote:

Hi John,

John Caron wrote:

Tom Rink wrote:

Hi,

How can skip or stride reading be done in the Java
implementation of NetCDF? Is there an equivalent
operation?

Tom Rink



Hi Tom:

I seem to have overlooked implementing a stride-based read, probably because the original (version 1) library doesnt have one. I will add this to the to-do list.

Meanwhile, you can get a strided subset of an Array, which will be equivilent except that you probably have to read more than you need:

Suppose you have a 3D Array, and you want to access it with stride 2, 1, and 3 in the three dimensions. The following will give you a logical view of the data with those strides, using the same backing data as the original:

Array data = var.read();
int[] shape = data.getShape();
Array dataS;
Range[] ranges = new Range[] { new Range(0,shape[0]-1, 2), null, new Range(0,shape[2]-1, 3) };

try {
dataS = data.section( ranges);
} catch (InvalidRangeException e) {
System.out.println("testStride failed == "+ e);
}


Thanks for the work-around, but the read() in this case would be much too much: I have MODIS on a remote server that I'm accessing via DODS and I want to produce a low-res image of the entire swath so the user can decide what channels or regions are important,
then subsetting/slicing can be used to focus on the point of interest.

For now, I'll have to sub-sample on the client, Is there any way to know
when the stride capability will be implemened?

Thanks again for you help,

Tom

ah! a DODS file. thats much easier.

I just put out an experimental version that has this method in DODSVariable:

 /**
* Read data from the DODS dataset with strides, and return a memory resident Array. * This Array has the same element type as the IOArray, and the requested shape.
  * <p>
* <code>assert(origin[ii] + shape[ii]*stride[i] <= Variable.shape[ii]); </code>
  * <p>
  * @param origin int array specifying the starting index.
* @param shape int array specifying the extents in each dimension. This becomes the shape of the returned Array.
  * @param stride  int array specifying the stride in each dimension.
  * @return the requested data in a memory-resident Array
  */
public Array read(int [] origin, int [] shape, int stride[]) throws IOException, InvalidRangeException;

its in

ftp://ftp.unidata.ucar.edu/pub/netcdf-java/v2.1/netcdfAll-05.jar

ive tested it a bit, i would appreciate it if youd try it and check the results and let me know if you see any problems.



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