static private boolean isGrid(java.util.List<CoordinateSystem> csysList) { CoordinateSystem use = null; for (CoordinateSystem csys : csysList) { if (use == null) use = csys; else if (csys.getCoordinateAxes().size() > use.getCoordinateAxes().size()) use = csys; } if (use == null) return false; CoordinateAxis lat = use.getLatAxis(); CoordinateAxis lon = use.getLonAxis(); if ((lat != null) && (lat.getSize() <= 1)) return false; // COARDS singletons if ((lon != null) && (lon.getSize() <= 1)) return false; // hueristics - cant say i like this, multidim point features could easily violate return (use.getRankDomain() > 2) && (use.getRankDomain() <= use.getRankRange()); }
static private boolean isGrid(java.util.List<CoordinateSystem> csysList) { CoordinateSystem use = null; for (CoordinateSystem csys : csysList) { if (use == null) use = csys; else if (csys.getCoordinateAxes().size() > use.getCoordinateAxes().size()) use = csys; } if (use == null) return false; CoordinateAxis lat = use.getLatAxis(); CoordinateAxis lon = use.getLonAxis(); if ((lat != null) && (lat.getSize() <= 1)) return false; // COARDS singletons if ((lon != null) && (lon.getSize() <= 1)) return false; // hueristics - cant say i like this, multidim point features could easily violate return (use.getRankDomain() > 2) && (use.getRankDomain() <= use.getRankRange()); }
/** * Get the list of times as Dates. * If 2D, return list of unique dates. * * @return array of java.util.Date, or Date[0]. * @deprecated use getCalendarDates */ public java.util.Date[] getTimeDates() { if ((timeTaxis != null) && (timeTaxis.getSize() > 0)) { return timeTaxis.getTimeDates(); } else if ((tAxis != null) && (tAxis.getSize() > 0)) { return makeTimes2D(); } return new Date[0]; }
/** * Get the list of times as Dates. * If 2D, return list of unique dates. * * @return array of java.util.Date, or Date[0]. * @deprecated use getCalendarDates */ public java.util.Date[] getTimeDates() { if ((timeTaxis != null) && (timeTaxis.getSize() > 0)) { return timeTaxis.getTimeDates(); } else if ((tAxis != null) && (tAxis.getSize() > 0)) { return makeTimes2D(); } return new Date[0]; }
/** * Get the list of times as Dates. * If 2D, return list of unique dates. * * @return array of java.util.Date, or Date[0]. * @deprecated use getCalendarDates */ public java.util.Date[] getTimeDates() { if ((timeTaxis != null) && (timeTaxis.getSize() > 0)) { return timeTaxis.getTimeDates(); } else if ((tAxis != null) && (tAxis.getSize() > 0)) { return makeTimes2D(); } return new Date[0]; }
public BufferedImage openDataset( GridDatatype grid) throws java.io.IOException { this.grid = grid; this.time = 0; GridCoordSystem gcsys = grid.getCoordinateSystem(); if (gcsys.getTimeAxis() != null) ntimes = (int) gcsys.getTimeAxis().getSize(); Array data = grid.readDataSlice( this.time, 0, -1, -1); return ImageArrayAdapter.makeGrayscaleImage( data); }
public BufferedImage openDataset( GridDatatype grid) throws java.io.IOException { this.grid = grid; this.time = 0; GridCoordSystem gcsys = grid.getCoordinateSystem(); if (gcsys.getTimeAxis() != null) ntimes = (int) gcsys.getTimeAxis().getSize(); Array data = grid.readDataSlice( this.time, 0, -1, -1); return ImageArrayAdapter.makeGrayscaleImage( data, grid); }
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]; }
private void addMissing(Variable v, GridCoordSystem gcs, Grid grid) { if (gribIosp == null) return; if (gcs.getVerticalAxis() == null && gcs.getEnsembleAxis() == null) return; int ntimes = (int) gcs.getTimeAxis().getSize(); int nverts = 1; if (gcs.getVerticalAxis() != null )
assert runtime != null; assert time != null; assert runtime.getSize() == time.getSize(); assert runtime.getSize() == 2; assert runtime.getDimension(0) == time.getDimension(0); assert runtime != null; assert time != null; assert runtime.getSize() == time.getSize(); assert runtime.getSize() == 1; Assert.assertEquals(runtime.getDimension(0), time.getDimension(0));
private Element writeAxis2(CoordinateAxis axis, String name) { if (axis == null) return null; NcMLWriter ncmlWriter = new NcMLWriter(); Element varElem = new Element(name); varElem.setAttribute("name", axis.getFullName()); varElem.setAttribute("shape", getShapeString(axis.getShape())); // axis.getDimensionsString()); DataType dt = axis.getDataType(); varElem.setAttribute("type", dt.toString()); AxisType axisType = axis.getAxisType(); if (null != axisType) varElem.setAttribute("axisType", axisType.toString()); // attributes for (Attribute att : axis.getAttributes()) varElem.addContent(ncmlWriter.makeAttributeElement(att)); try { Element values = ncmlWriter.makeValuesElement(axis, false); values.setAttribute("npts", Long.toString(axis.getSize())); varElem.addContent(values); } catch (IOException e) { String message = String.format( "Couldn't read values for %s. Omitting <values> element.", axis.getFullName()); logger.warn(message, e); } return varElem; }
int n = (int) dtCoordAxis.getSize(); double[] result = new double[2 * n]; double[] bounds1 = axis1D.getBound1();
@Test @Category(NeedsCdmUnitTest.class) public void testBBSubsetUnits() throws Exception { try (GridDataset dataset = GridDataset.open(TestDir.cdmUnitTestDir + "ncml/testBBSubsetUnits.ncml")) { logger.debug("file = {}", dataset.getLocation()); GeoGrid grid = dataset.findGridByName("pr"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; logger.debug("original bbox = {}", gcs.getBoundingBox()); logger.debug("lat/lon bbox = {}", gcs.getLatLonBoundingBox()); ucar.unidata.geoloc.LatLonRect llbb_subset = new LatLonRect(new LatLonPointImpl(38, -110), new LatLonPointImpl(42, -90)); logger.debug("subset lat/lon bbox = {}", llbb_subset); GeoGrid grid_section = grid.subset(null, null, llbb_subset, 1, 1, 1); GridCoordSystem gcs2 = grid_section.getCoordinateSystem(); assert null != gcs2; logger.debug("result lat/lon bbox = {}", gcs2.getLatLonBoundingBox()); logger.debug("result bbox = {}", gcs2.getBoundingBox()); ProjectionRect pr = gcs2.getProjection().getDefaultMapArea(); logger.debug("projection mapArea = {}", pr); assert (pr.nearlyEquals(gcs2.getBoundingBox())); CoordinateAxis xaxis = gcs.getXHorizAxis(); CoordinateAxis yaxis = gcs.getYHorizAxis(); logger.debug("(nx,ny)= {}, {}", xaxis.getSize(), yaxis.getSize()); } }
private Element writeAxis2(CoordinateAxis axis, String name) { if (axis == null) return null; Element varElem = new Element(name); varElem.setAttribute("name", axis.getFullName()); varElem.setAttribute("shape", getShapeString(axis.getShape())); // axis.getDimensionsString()); DataType dt = axis.getDataType(); varElem.setAttribute("type", dt.toString()); AxisType axisType = axis.getAxisType(); if (null != axisType) varElem.setAttribute("axisType", axisType.toString()); // attributes for (Attribute att : axis.getAttributes()) varElem.addContent(ucar.nc2.ncml.NcMLWriter.writeAttribute(att, "attribute", null)); Element values = ucar.nc2.ncml.NcMLWriter.writeValues(axis, null, false); values.setAttribute("npts", Long.toString(axis.getSize())); varElem.addContent(values); return varElem; }
private Element writeAxis2(CoordinateAxis axis, String name) { if (axis == null) return null; Element varElem = new Element(name); varElem.setAttribute("name", axis.getFullName()); varElem.setAttribute("shape", getShapeString(axis.getShape())); // axis.getDimensionsString()); DataType dt = axis.getDataType(); varElem.setAttribute("type", dt.toString()); AxisType axisType = axis.getAxisType(); if (null != axisType) varElem.setAttribute("axisType", axisType.toString()); // attributes for (Attribute att : axis.getAttributes()) varElem.addContent(ucar.nc2.ncml.NcMLWriter.writeAttribute(att, "attribute", null)); Element values = ucar.nc2.ncml.NcMLWriter.writeValues(axis, null, false); values.setAttribute("npts", Long.toString(axis.getSize())); varElem.addContent(values); return varElem; }
@Test @Category(NeedsCdmUnitTest.class) public void testWRF() throws Exception { try(GridDataset dataset = GridDataset.open(TestDir.cdmUnitTestDir + "conventions/wrf/wrfout_v2_Lambert.nc")) { GeoGrid grid = dataset.findGridByName("T"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 4; CoordinateAxis zaxis = gcs.getVerticalAxis(); assert zaxis.getSize() == 27; VerticalTransform vt = gcs.getVerticalTransform(); assert vt != null; assert vt.getUnitString().equals("Pa"); GeoGrid grid_section = grid.subset(null, null, null, 3, 3, 3); Array data = grid_section.readDataSlice(-1, -1, -1, -1); assert data.getShape()[0] == 13 : data.getShape()[0]; assert data.getShape()[1] == 9 : data.getShape()[1]; assert data.getShape()[2] == 20 : data.getShape()[2]; assert data.getShape()[3] == 25 : data.getShape()[3]; GridCoordSystem gcs_section = grid_section.getCoordinateSystem(); CoordinateAxis zaxis2 = gcs_section.getVerticalAxis(); assert zaxis2.getSize() == 9 : zaxis2.getSize(); assert zaxis2.getUnitsString().equals(zaxis.getUnitsString()); assert gcs_section.getTimeAxis().equals(gcs.getTimeAxis()); VerticalTransform vt_section = gcs_section.getVerticalTransform(); assert vt_section != null; assert vt_section.getUnitString().equals(vt.getUnitString()); } }
Assert.assertEquals(36, time.getSize());
@Test public void testSingleDataset() throws IOException { Catalog cat = TdsLocalCatalog.open(null); Dataset ds = cat.findDatasetByID("testDataset2"); assert (ds != null) : "cant find dataset 'testDataset'"; assert ds.getFeatureType() == FeatureType.GRID; DataFactory fac = new DataFactory(); try (DataFactory.Result dataResult = fac.openFeatureDataset(ds, null)) { Assert.assertTrue(dataResult.errLog.toString(), !dataResult.fatalError); Assert.assertNotNull(dataResult.featureDataset); Assert.assertEquals( ucar.nc2.dt.grid.GridDataset.class, dataResult.featureDataset.getClass()); ucar.nc2.dt.grid.GridDataset gds = ( ucar.nc2.dt.grid.GridDataset) dataResult.featureDataset; String gridName = "Z_sfc"; VariableSimpleIF vs = gds.getDataVariable(gridName); Assert.assertNotNull(gridName, vs); GeoGrid grid = gds.findGridByShortName(gridName); Assert.assertNotNull(gridName, grid); GridCoordSystem gcs = grid.getCoordinateSystem(); Assert.assertNotNull(gcs); assert null == gcs.getVerticalAxis(); CoordinateAxis time = gcs.getTimeAxis(); Assert.assertNotNull("time axis", time); Assert.assertEquals(1, time.getSize()); Array data = time.read(); Assert2.assertNearlyEquals(102840.0, data.getFloat(0)); } }
public void testSubset() throws Exception { ucar.nc2.dt.grid.GridDataset dataset = GridDataset.open(TestDir.cdmLocalTestDataDir+"rankTest.nc"); GeoGrid grid = dataset.findGridByName("full4"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 4; doRead4(grid); GeoGrid grid_section = grid.subset(null, new Range(0,3,2), null, null); GridCoordSystem gcs_section = grid_section.getCoordinateSystem(); CoordinateAxis zaxis = gcs_section.getVerticalAxis(); assert zaxis.getSize() == 2; assert gcs_section.getXHorizAxis().equals( gcs.getXHorizAxis()); assert gcs_section.getYHorizAxis().equals( gcs.getYHorizAxis()); assert gcs_section.getTimeAxis().equals( gcs.getTimeAxis()); Array data = grid_section.readDataSlice(-1, -1, -1, -1); logger.debug(NCdumpW.toString( data, "grid_section", null)); dataset.close(); }
@Test @Category(NeedsCdmUnitTest.class) public void testRegular() throws Exception { try(GridDataset dataset = GridDataset.open(TestDir.cdmUnitTestDir + "conventions/nuwg/03061219_ruc.nc")) { GeoGrid grid = dataset.findGridByName("T"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 4; CoordinateAxis zaxis = gcs.getVerticalAxis(); assert zaxis.getUnitsString().equals("hectopascals"); GeoGrid grid_section = grid.subset(null, null, null, 3, 3, 3); GridCoordSystem gcs_section = grid_section.getCoordinateSystem(); CoordinateAxis zaxis2 = gcs_section.getVerticalAxis(); assert zaxis2.getSize() == 7; assert zaxis2.getUnitsString().equals("hectopascals"); assert gcs_section.getTimeAxis().equals(gcs.getTimeAxis()); Array data = grid_section.readDataSlice(-1, -1, -1, -1); assert data.getShape()[0] == 2 : data.getShape()[0]; assert data.getShape()[1] == 7 : data.getShape()[1]; assert data.getShape()[2] == 22 : data.getShape()[2]; assert data.getShape()[3] == 31 : data.getShape()[3]; // check axes for (CoordinateAxis axis : gcs_section.getCoordinateAxes()) { assert axis.getAxisType() != null; } } }