/** * Instances which have same name and coordinate system are equal. */ public boolean equals(Object oo) { if (this == oo) return true; if (!(oo instanceof GeoGrid)) return false; GeoGrid d = (GeoGrid) oo; if (!getFullName().equals(d.getFullName())) return false; if (!getCoordinateSystem().equals(d.getCoordinateSystem())) return false; return true; }
public GridDatatype makeSubset(Range t_range, Range z_range, LatLonRect bbox, int z_stride, int y_stride, int x_stride) throws InvalidRangeException { return subset(t_range, z_range, bbox, z_stride, y_stride, x_stride); }
/** * @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); }
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]; }
public GridDatatype makeSubset(Range rt_range, Range e_range, Range t_range, Range z_range, Range y_range, Range x_range) throws InvalidRangeException { // get the ranges list int rank = getRank(); Range[] ranges = new Range[rank]; if (null != getXDimension()) ranges[xDimOrgIndex] = x_range; if (null != getYDimension()) ranges[yDimOrgIndex] = y_range; if (null != getZDimension()) ranges[zDimOrgIndex] = z_range; if (null != getTimeDimension()) ranges[tDimOrgIndex] = t_range; if (null != getRunTimeDimension()) ranges[rtDimOrgIndex] = rt_range; if (null != getEnsembleDimension()) ranges[eDimOrgIndex] = e_range; List<Range> rangesList = Arrays.asList(ranges); // subset the variable VariableDS v_section = (VariableDS) vs.section( new Section(rangesList)); List<Dimension> dims = v_section.getDimensions(); for (Dimension dim : dims) { dim.setShared(true); // make them shared (section will make them unshared) } // subset the axes in the GridCoordSys GridCoordSys gcs_section = new GridCoordSys(gcs, rt_range, e_range, t_range, z_range, y_range, x_range); // now we can make the geogrid return new GeoGrid(dataset, v_section, gcs_section); }
@Test @Category(NeedsCdmUnitTest.class) public void testVerticalAxis() throws Exception { String uri = TestDir.cdmUnitTestDir + "ncml/nc/cg/CG2006158_120000h_usfc.nc"; String varName = "CGusfc"; try (GridDataset dataset = GridDataset.open(uri)) { GeoGrid grid = dataset.findGridByName(varName); assert null != grid; GridCoordSystem gcsi = grid.getCoordinateSystem(); assert null != gcsi; assert (gcsi.getVerticalAxis() != null); GridCoordSys gcs = (GridCoordSys) grid.getCoordinateSystem(); assert null != gcs; assert gcs.hasVerticalAxis(); // returns true. // subset geogrid GeoGrid subg = grid.subset(null, null, null, 1, 1, 1); assert null != subg; GridCoordSystem gcsi2 = subg.getCoordinateSystem(); assert null != gcsi2; assert (gcsi2.getVerticalAxis() != null); GridCoordSys gcs2 = (GridCoordSys) subg.getCoordinateSystem(); assert null != gcs2; assert !gcs2.hasVerticalAxis(); // fails } }
GridCoordSystem gcsOrg = grid.getCoordinateSystem(); CoordinateAxis1DTime timeAxis = gcsOrg.getTimeAxis1D(); CoordinateAxis1D vertAxis = gcsOrg.getVerticalAxis(); grid = grid.subset(timeRange, zRangeUse, y_range, x_range); LatLonRect gridBB = grid.getCoordinateSystem().getLatLonBoundingBox(); if (resultBB == null) resultBB = gridBB; resultBB.extend(gridBB); Variable gridV = grid.getVariable(); varList.add(gridV); total_size += gridV.getSize() * gridV.getElementSize(); GridCoordSystem gcs = grid.getCoordinateSystem();
@Test @Category(NeedsExternalResource.class) public void testScaleOffset() throws Exception { try (GridDataset dataset = GridDataset.open("http://esrl.noaa.gov/psd/thredds/dodsC/Datasets/noaa.oisst.v2/sst.wkmean.1990-present.nc")) { GeoGrid grid = dataset.findGridByName("sst"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; logger.debug("original bbox = {} ({})", gcs.getBoundingBox(), gcs.getLatLonBoundingBox()); LatLonRect llbb = gcs.getLatLonBoundingBox(); LatLonRect llbb_subset = new LatLonRect(llbb.getLowerLeftPoint(), 20.0, llbb.getWidth() / 2); GeoGrid grid2 = grid.subset(null, null, llbb_subset, 1, 1, 1); GridCoordSystem gcs2 = grid2.getCoordinateSystem(); assert null != gcs2; logger.debug("subset bbox = {} ({})", gcs2.getBoundingBox(), gcs2.getLatLonBoundingBox()); logger.debug("original grid var = {}", grid.getVariable()); logger.debug("subset grid var = {}", grid2.getVariable()); Array data = grid.readDataSlice(0, 0, 159, 0); Array data2 = grid2.readDataSlice(0, 0, 0, 0); logger.debug(NCdumpW.toString(data, "org", null)); logger.debug(NCdumpW.toString(data2, "subset", null)); ucar.unidata.util.test.CompareNetcdf.compareData(data, data2); } }
GeoGrid grid = dataset.findGridByName("air"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; LatLonRect llbb_subset = new LatLonRect(llbb.getLowerLeftPoint(), 20.0, llbb.getWidth() / 2); GeoGrid grid2 = grid.subset(null, null, llbb_subset, 1, 1, 1); GridCoordSystem gcs2 = grid2.getCoordinateSystem(); assert null != gcs2; logger.debug("original grid var = {}", grid.getVariable()); logger.debug("subset grid var = {}", grid2.getVariable()); Array data = grid.readVolumeData(0); Array data2 = grid2.readVolumeData(0);
@Test @Category(NeedsCdmUnitTest.class) public void testCoordExtract() throws IOException { try (ucar.nc2.dt.grid.GridDataset dataset = GridDataset.open(TestDir.cdmUnitTestDir + "formats/grib2/coordExtract/TestCoordExtract.grib2")) { System.out.printf("%s%n", dataset.getLocation()); GeoGrid grid = dataset.findGridByName("Convective_inhibition_surface"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 3; System.out.printf("%s%n", gcs); int result[] = gcs.findXYindexFromLatLon(41.3669944444, -91.140575, null); System.out.printf("%d %d %n", result[0], result[1]); assert result[0] == 538; assert result[1] == 97; } }
private int[] getWeights( GeoGrid gg) { int rank = gg.getRank(); int[] w = new int[rank]; for (int n=0; n<rank; n++) { Dimension dim = gg.getDimension(n); String dimName = dim.getShortName(); if (dimName.equals("time")) w[n] = 1000; if (dimName.equals("z")) w[n] = 100; if (dimName.equals("y")) w[n] = 10; if (dimName.equals("x")) w[n] = 1; } return w; }
private double[] getVertTransformationForPoint(ProjectionPoint point, int timeIndex, GeoGrid grid) throws IOException, InvalidRangeException{ VerticalTransform vt = grid.getCoordinateSystem().getVerticalTransform(); //System.out.println(vt.isTimeDependent()); int[] pointIndices = new int[]{0,0}; grid.getCoordinateSystem().findXYindexFromCoord( point.getX(), point.getY(), pointIndices); ArrayDouble.D1 dataArr = vt.getCoordinateArray1D(timeIndex, pointIndices[0], pointIndices[1]); return (double[])dataArr.copyTo1DJavaArray(); }
private void testGrid( GeoGrid grid) throws IOException, InvalidRangeException { assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 4; Array data = grid.readDataSlice(0, -1, -1, -1); assert data.getRank() == 3; CoordinateAxis zaxis = gcs.getVerticalAxis(); assert data.getShape()[0] == zaxis.getSize() : zaxis.getSize(); CoordinateAxis yaxis = gcs.getYHorizAxis(); assert data.getShape()[1] == yaxis.getSize() : yaxis.getSize(); CoordinateAxis xaxis = gcs.getXHorizAxis(); assert data.getShape()[2] == xaxis.getSize() : xaxis.getSize(); VerticalTransform vt = gcs.getVerticalTransform(); assert vt != null; assert vt.getUnitString() != null; ucar.ma2.ArrayDouble.D3 vcoord = vt.getCoordinateArray(0); assert vcoord.getShape()[0] == zaxis.getSize() : vcoord.getShape()[0]; assert vcoord.getShape()[1] == yaxis.getSize() : vcoord.getShape()[1]; assert vcoord.getShape()[2] == xaxis.getSize() : vcoord.getShape()[2]; }
/** * nicely formatted information */ public String getInfo() { StringBuilder buf = new StringBuilder(200); buf.setLength(0); buf.append(getFullName()); Format.tab(buf, 30, true); buf.append(getUnitsString()); Format.tab(buf, 60, true); buf.append(hasMissingData()); Format.tab(buf, 66, true); buf.append(getDescription()); return buf.toString(); }
@Test @Ignore("Does this dataset exist on a public server?") public void testFMRCSubset() throws Exception { try (GridDataset dataset = GridDataset.open("dods://localhost:8080/thredds/dodsC/data/cip/fmrcCase1/CIPFMRCCase1_best.ncd")) { GeoGrid grid = dataset.findGridByName("Latitude__90_to_+90"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; Range timeRange = new Range(2, 2); int bestZIndex = 5; GeoGrid subset = grid.subset(timeRange, new Range(bestZIndex, bestZIndex), null, null); Array yxData = subset.readYXData(0, 0); logger.debug(NCdumpW.toString(yxData, "xyData", null)); } }
/** * get the z Dimension, if it exists */ public Dimension getZDimension() { return zDimNewIndex < 0 ? null : getDimension(zDimNewIndex); }
public void testSubset() throws Exception { ucar.nc2.dt.grid.GridDataset dataset = GridDataset.open(TestDir.cdmUnitTestDir + "ft/grid/stag/bora_feb.nc"); GeoGrid grid = dataset.findGridByName("u"); assert null != grid; System.out.printf("u shape= %s%n", showShape(grid.getShape())); GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 4; ucar.unidata.geoloc.vertical.VerticalTransform vt = gcs.getVerticalTransform(); Array a = vt.getCoordinateArray(0); System.out.printf("vt shape= %s%n", showShape(a.getShape())); dataset.close(); }
@Test public void testGridDomain() throws Exception { System.err.printf("%nOpen %s grid='%s'%n", filename, gridName); Grib.setDebugFlags(new DebugFlagsImpl("Grib/indexOnly")); try (GridDataset dataset = GridDataset.open(filename)) { GeoGrid grid = dataset.findGridByName(gridName); GridCoordSystem gcs = grid.getCoordinateSystem(); System.err.printf("%s%n", gcs); testDomain("original grid", grid.getDimensions(), gcs.getCoordinateAxes()); GridDatatype gridSubset = grid.makeSubset(null, null, new Range(0, 0), null, null, null); GridCoordSystem gcsSubset = gridSubset.getCoordinateSystem(); System.err.printf("%s%n", gcsSubset); testDomain("subset grid", gridSubset.getDimensions(), gcsSubset.getCoordinateAxes()); } finally { Grib.setDebugFlags(new DebugFlagsImpl("")); } }
/** * string representation */ public String toString() { return getFullName(); }
@Test public void testAWIPSsatLatlon() throws IOException { try (GridDataset ds = GridDataset.open(TestDir.cdmUnitTestDir + "conventions/awips/20150602_0830_sport_imerg_noHemis_rr.nc")) { GeoGrid grid = ds.findGridByName("image"); assert grid != null; GridCoordSystem gcs = grid.getCoordinateSystem(); assert gcs.isLatLon(); Assert.assertEquals(DataType.BYTE, grid.getDataType()); } }