/** * @throws java.io.IOException on read error * @deprecated use readDataSlice */ public Array getDataSlice(int t, int z, int y, int x) throws java.io.IOException { return readDataSlice(t, z, y, x); }
/** * @throws java.io.IOException on read error * @deprecated use readDataSlice */ public Array getDataSlice(int t, int z, int y, int x) throws java.io.IOException { return readDataSlice(t, z, y, x); }
/** * @throws java.io.IOException on read error * @deprecated use readDataSlice */ public Array getDataSlice(int t, int z, int y, int x) throws java.io.IOException { return readDataSlice(t, z, y, x); }
/** * Reads a Z-Y "vertical slice" at the given time and x index. * If its a product set, put into canonical order (z-y). * * @param t time index; ignored if no time axis. * @param x x index; ignored if no x axis. * @return data[z,y] * @throws java.io.IOException on read error */ public Array readZYData(int t, int x) throws java.io.IOException { return readDataSlice(t, -1, -1, x); }
/** * Reads a Y-X "horizontal slice" at the given time and vertical index. * If its a product set, put into canonical order (y-x). * * @param t time index; ignored if no time axis. * @param z vertical index; ignored if no z axis. * @return data[y,x] * @throws java.io.IOException on read error */ public Array readYXData(int t, int z) throws java.io.IOException { return readDataSlice(t, z, -1, -1); }
/** * Reads a Z-Y "vertical slice" at the given time and x index. * If its a product set, put into canonical order (z-y). * * @param t time index; ignored if no time axis. * @param x x index; ignored if no x axis. * @return data[z,y] * @throws java.io.IOException on read error */ public Array readZYData(int t, int x) throws java.io.IOException { return readDataSlice(t, -1, -1, x); }
/** * Reads a Y-X "horizontal slice" at the given time and vertical index. * If its a product set, put into canonical order (y-x). * * @param t time index; ignored if no time axis. * @param z vertical index; ignored if no z axis. * @return data[y,x] * @throws java.io.IOException on read error */ public Array readYXData(int t, int z) throws java.io.IOException { return readDataSlice(t, z, -1, -1); }
/** * Reads a Y-X "horizontal slice" at the given time and vertical index. * If its a product set, put into canonical order (y-x). * * @param t time index; ignored if no time axis. * @param z vertical index; ignored if no z axis. * @return data[y,x] * @throws java.io.IOException on read error */ public Array readYXData(int t, int z) throws java.io.IOException { return readDataSlice(t, z, -1, -1); }
/** * Reads a Z-Y "vertical slice" at the given time and x index. * If its a product set, put into canonical order (z-y). * * @param t time index; ignored if no time axis. * @param x x index; ignored if no x axis. * @return data[z,y] * @throws java.io.IOException on read error */ public Array readZYData(int t, int x) throws java.io.IOException { return readDataSlice(t, -1, -1, x); }
/** * This reads an arbitrary data slice, returning the data in * canonical order (t-z-y-x). If any dimension does not exist, ignore it. * * @param t if < 0, get all of time dim; if valid index, fix slice to that value. * @param z if < 0, get all of z dim; if valid index, fix slice to that value. * @param y if < 0, get all of y dim; if valid index, fix slice to that value. * @param x if < 0, get all of x dim; if valid index, fix slice to that value. * @return data[t,z,y,x], eliminating missing or fixed dimension. */ public Array readDataSlice(int t, int z, int y, int x) throws java.io.IOException { return readDataSlice(0, 0, t, z, y, x); }
/** * This reads an arbitrary data slice, returning the data in * canonical order (t-z-y-x). If any dimension does not exist, ignore it. * * @param t if < 0, get all of time dim; if valid index, fix slice to that value. * @param z if < 0, get all of z dim; if valid index, fix slice to that value. * @param y if < 0, get all of y dim; if valid index, fix slice to that value. * @param x if < 0, get all of x dim; if valid index, fix slice to that value. * @return data[t,z,y,x], eliminating missing or fixed dimension. */ public Array readDataSlice(int t, int z, int y, int x) throws java.io.IOException { return readDataSlice(0, 0, t, z, y, x); }
/** * This reads an arbitrary data slice, returning the data in * canonical order (t-z-y-x). If any dimension does not exist, ignore it. * * @param t if < 0, get all of time dim; if valid index, fix slice to that value. * @param z if < 0, get all of z dim; if valid index, fix slice to that value. * @param y if < 0, get all of y dim; if valid index, fix slice to that value. * @param x if < 0, get all of x dim; if valid index, fix slice to that value. * @return data[t,z,y,x], eliminating missing or fixed dimension. */ public Array readDataSlice(int t, int z, int y, int x) throws java.io.IOException { return readDataSlice(0, 0, t, z, y, x); }
private void doRead3( GridDataset ds, String varName) throws IOException { GeoGrid gg = ds.findGridByName( varName); Array aa = gg.readDataSlice(-1,-1,-1,-1); int[] shape = aa.getShape(); int[] w = getWeights( gg); Index ima = aa.getIndex(); for (int i=0; i<shape[0]; i++) { for (int j=0; j<shape[1]; j++) { for (int k=0; k<shape[2]; k++) { double got = aa.getDouble( ima.set(i,j,k)); double want = ((double) (i*w[0] + j*w[1] + k*w[2])); assert (got == want) : "got "+got+ " want "+want; } } } System.out.println("ok reading "+varName); }
private void doRead3( GridDataset ds, String varName) throws IOException { GeoGrid gg = ds.findGridByName( varName); Array aa = gg.readDataSlice(-1,-1,-1,-1); int[] shape = aa.getShape(); int[] w = getWeights( gg); Index ima = aa.getIndex(); for (int i=0; i<shape[0]; i++) { for (int j=0; j<shape[1]; j++) { for (int k=0; k<shape[2]; k++) { double got = aa.getDouble( ima.set(i,j,k)); double want = ((double) (i*w[0] + j*w[1] + k*w[2])); assert (got == want) : "got "+got+ " want "+want; } } } System.out.println("ok reading "+varName); }
@Test public void testEcmwf() throws IOException { // scanMode 192 String filename = TestDir.cdmUnitTestDir + "formats/grib2/MSG1-SEVI-MSGCLMK-0100-0100-20060102111500.000000000Z-12774.grb.grb"; logger.debug("Reading File {}", filename); GridDataset gds = GridDataset.open(filename); GeoGrid grid = gds.findGridByName("Cloud_mask"); assert grid != null; assert (grid.getDimensions().size() == 3); GridCoordSystem gcs = grid.getCoordinateSystem(); int[] result = gcs.findXYindexFromCoord(0, 0, null); logger.debug("x,y={},{}", result[0], result[1]); // should be non NAN Array data = grid.readDataSlice(0, 0, result[1], result[0]); logger.debug("{}", NCdumpW.toString(data)); Index ima = data.getIndex(); float val = data.getFloat(ima); Assert2.assertNearlyEquals(val, 0.0); gds.close(); } }
private void doRead4( GridDataset ds, String varName) throws IOException { GeoGrid gg = ds.findGridByName( varName); Array aa = gg.readDataSlice(-1,-1,-1,-1); int[] shape = aa.getShape(); Index ima = aa.getIndex(); int[] w = getWeights( gg); for (int i=0; i<shape[0]; i++) { for (int j=0; j<shape[1]; j++) { for (int k=0; k<shape[2]; k++) { for (int m=0; m<shape[3]; m++) { double got = aa.getDouble( ima.set(i,j,k,m)); double want = ((double) (i*w[0] + j*w[1] + k*w[2] + m*w[3])); assert (got == want) : "got "+got+ " want "+want; // System.out.println("got "+got+ " want "+want); } } } } System.out.println("ok reading "+varName); }
private void doRead2( GridDataset ds, String varName) throws IOException { GeoGrid gg = ds.findGridByName( varName); if (gg == null) return; testOrder( gg); Array aa = gg.readDataSlice(-1,-1,-1,-1); int[] shape = aa.getShape(); int[] w = getWeights( gg); Index ima = aa.getIndex(); for (int i=0; i<shape[0]; i++) { for (int j=0; j<shape[1]; j++) { double got = aa.getDouble( ima.set(i,j)); double want = ((double) (i*w[0] + j*w[1])); assert (got == want) : "got "+got+ " want "+want; } } System.out.println("ok reading "+varName); }
private void doRead3( GridDataset ds, String varName) throws IOException { GeoGrid gg = ds.findGridByName( varName); testOrder( gg); Array aa = gg.readDataSlice(-1,-1,-1,-1); int[] shape = aa.getShape(); int[] w = getWeights( gg); Index ima = aa.getIndex(); for (int i=0; i<shape[0]; i++) { for (int j=0; j<shape[1]; j++) { for (int k=0; k<shape[2]; k++) { double got = aa.getDouble( ima.set(i,j,k)); double want = ((double) (i*w[0] + j*w[1] + k*w[2])); assert (got == want) : "got "+got+ " want "+want; } } } System.out.println("ok reading "+varName); }
private void testLatLonSubset(GeoGrid grid, LatLonRect bbox, int[] shape) throws Exception { logger.debug("grid bbox = {}", grid.getCoordinateSystem().getLatLonBoundingBox().toString2()); logger.debug("constrain bbox = {}", bbox.toString2()); GeoGrid grid_section = grid.subset(null, null, bbox, 1, 1, 1); GridCoordSystem gcs2 = grid_section.getCoordinateSystem(); assert null != gcs2; assert grid_section.getRank() == 2; logger.debug("resulting bbox = {}", gcs2.getLatLonBoundingBox().toString2()); Array data = grid_section.readDataSlice(0, 0, -1, -1); assert data != null; assert data.getRank() == 2; assert data.getShape()[0] == shape[0] : data.getShape()[0]; assert data.getShape()[1] == shape[1] : data.getShape()[1]; }
@Test @Category(NeedsCdmUnitTest.class) public void testGrib() throws Exception { try(GridDataset dataset = GridDataset.open(TestDir.cdmUnitTestDir + "formats/grib1/AVN.wmo")) { GeoGrid grid = dataset.findGridDatatypeByAttribute(Grib.VARIABLE_ID_ATTNAME, "VAR_7-0-2-11_L100"); // "Temperature_isobaric"); assert null != grid : dataset.getLocation(); GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 4; GeoGrid grid_section = grid.subset(null, null, null, 3, 3, 3); Array data = grid_section.readDataSlice(-1, -1, -1, -1); assert data.getShape()[0] == 3 : data.getShape()[0]; assert data.getShape()[1] == 3 : data.getShape()[1]; assert data.getShape()[2] == 13 : data.getShape()[2]; assert data.getShape()[3] == 15 : data.getShape()[3]; } }