@Override public String getFullName() { return getName(); }
@Override public String getShortName() { return getName(); }
TimeseriesIterator() { varIters = new ArrayList<>(); for (VarData vd : varData) { Array data = vd.array.getData(); if (debug) System.out.printf("%s shape=%s%n", vd.cov.getName(), Misc.showInts(data.getShape())); varIters.add(new VarIter(vd.cov, vd.array, data.getIndexIterator())); nvalues = (int) data.getSize(); if (timeAxis == null) { // assume they are all the same (!) CoverageCoordSys csys = vd.array.getCoordSysForData(); timeAxis = (CoverageCoordAxis1D) csys.getTimeAxis(); // LOOK may not be right } } }
protected CoverageAsFeatureDatasetPoint(FeatureType featureType) { super(featureType); CoverageAsStationFeatureCollection fc = new CoverageAsStationFeatureCollection(gcd.getName() + " AsStationFeatureCollection", dateUnit, null); setPointFeatureCollection(fc); List<VariableSimpleIF> dataVars = new ArrayList<>(); for (VarData vd : varData) { // String name, String desc, String units, DataType dt VariableSimpleIF simple = VariableSimpleImpl.makeScalar(vd.cov.getName(), vd.cov.getDescription(), vd.cov.getUnitsString(), vd.cov.getDataType()); dataVars.add(simple); } this.dataVariables = dataVars; } }
public Coverage(Coverage from, CoverageCoordSys coordSysSubset) { this.name = from.getName(); this.dataType = from.getDataType(); this.atts = from.atts; this.units = from.getUnitsString(); this.description = from.getDescription(); this.coordSysName = (coordSysSubset != null) ? coordSysSubset.getName() : from.coordSysName; this.reader = from.reader; this.user = from.user; }
private void writeCoverageData(CoverageCollection gdsOrg, SubsetParams subsetParams, CoverageCollection subsetDataset, NetcdfFileWriter writer) throws IOException, InvalidRangeException { for (Coverage coverage : subsetDataset.getCoverages()) { // we need to call readData on the original Coverage coverageOrg = gdsOrg.findCoverage(coverage.getName()); GeoReferencedArray array = coverageOrg.readData(subsetParams); // test conform to whatever axis.getCoordsAsArray() returns checkConformance(coverage, array, gdsOrg.getName()); Variable v = writer.findVariable(coverage.getName()); if (show) System.out.printf("CFGridCoverageWriter2 write coverage %s%n", v.getNameAndDimensions()); writer.write(v, array.getData()); } }
private static boolean readRandom(FeatureDatasetCoverage covDataset, PrintWriter pw ) throws IOException, InvalidRangeException { CoverageCollection cc = covDataset.getCoverageCollections().get(0); int ncov = cc.getCoverageCount(); Random r = new Random(System.currentTimeMillis()); int randomIdx = r.nextInt(ncov); int count = 0; Coverage randomCov = null; for (Coverage c : cc.getCoverages()) { if (count == randomIdx) { randomCov = c; break; } count++; } if (randomCov == null) { pw.format("Bad random coverage"); return false; } SubsetParams subset = new SubsetParams().setTimePresent(); GeoReferencedArray geo = randomCov.readData(subset); Array data = geo.getData(); System.out.printf(" read data from %s shape = %s%n", randomCov.getName(), Misc.showInts(data.getShape())); return true; }
private List<CoordSysSet> wireObjectsTogether(List<Coverage> coverages) { for (CoverageCoordAxis axis : coordAxes) axisMap.put(axis.getName(), axis); for (CoverageCoordAxis axis : coordAxes) axis.setDataset(this); // wire dependencies Map<String, CoordSysSet> map = new HashMap<>(); for (Coverage coverage : coverages) { coverageMap.put(coverage.getName(), coverage); CoordSysSet gset = map.get(coverage.getCoordSysName()); // duplicates get eliminated here if (gset == null) { CoverageCoordSys ccsys = findCoordSys(coverage.getCoordSysName()); if (ccsys == null) { throw new IllegalStateException("Cant find "+coverage.getCoordSysName()); } gset = new CoordSysSet(ccsys); // must use findByName because objects arent wired up yet map.put(coverage.getCoordSysName(), gset); gset.getCoordSys().setDataset(this); // wire dataset into coordSys } gset.addCoverage(coverage); coverage.setCoordSys(gset.getCoordSys()); // wire coordSys into coverage } // sort the coordsys sets List<CoordSysSet> csets = new ArrayList<>(map.values()); Collections.sort(csets, (o1, o2) -> o1.getCoordSys().getName().compareTo(o2.getCoordSys().getName())); return csets; }
private void addCoverages(CoverageCollection subsetDataset, NetcdfFileWriter writer) { for (Coverage grid : subsetDataset.getCoverages()) { Variable v = writer.addVariable(null, grid.getName(), grid.getDataType(), grid.getIndependentAxisNamesOrdered()); addVariableAttributes(v, grid.getAttributes()); } }
@Override public PointFeature next() { double obsTime = timeAxis.getCoordMidpoint(curr); StructureDataScalar coords = new StructureDataScalar("Coords"); for (VarIter vi : varIters) { coords.addMember(vi.cov.getName(), null, null, vi.cov.getDataType(), (Number) vi.dataIter.getObjectNext()); } curr++; PointFeature pf = new MyPointFeature(MyStationFeature.this, obsTime, 0.0, timeUnit, coords); calcBounds(pf); return pf; }
private void readCoverageData(Coverage cover, SubsetParams coords) throws IOException, InvalidRangeException { countReadsForVariable++; if (MAX_READS > 0 && countReadsForVariable > MAX_READS) return; GribDataReader.currentDataRecord = null; GeoReferencedArray geoArray = cover.readData(coords); int[] shape = geoArray.getData().getShape(); if (shape[1] != 1) { cover.readData(coords); } for (int i = 0; i < shape.length - 2; i++) { Assert.assertEquals(Misc.showInts(shape), 1, shape[i]); } if (isGrib1) readAndTestGrib1(cover.getName(), coords); else readAndTestGrib2(cover.getName(), coords); this.cover = null; }
CdmrFeatureProto.Coverage.Builder encodeGrid(Coverage grid) { CdmrFeatureProto.Coverage.Builder builder = CdmrFeatureProto.Coverage.newBuilder(); builder.setName(grid.getName()); builder.setDataType(NcStream.convertDataType(grid.getDataType())); for (Attribute att : grid.getAttributes()) builder.addAtts(NcStream.encodeAtt(att)); builder.setUnits(grid.getUnitsString()); builder.setDescription(grid.getDescription()); builder.setCoordSys(grid.getCoordSysName()); return builder; }
private Element writeGrid(Coverage grid) { Element varElem = new Element("grid"); varElem.setAttribute("name", grid.getName()); String desc = grid.getDescription() != null ? grid.getDescription() : "No description"; varElem.setAttribute("desc", desc); /* StringBuilder buff = new StringBuilder(); List dims = grid.getDimensions(); for (int i = 0; i < dims.size(); i++) { Dimension dim = (Dimension) dims.get(i); if (i > 0) buff.append(" "); if (dim.isShared()) buff.append(dim.getShortName()); else buff.append(dim.getLength()); } if (buff.length() > 0) varElem.setAttribute("shape", buff.toString()); */ DataType dt = grid.getDataType(); if (dt != null) varElem.setAttribute("type", dt.toString()); //GridCoordSystem cs = grid.getCoordinateSystem(); //varElem.setAttribute("coordSys", cs.getName()); // attributes for (ucar.nc2.Attribute att : grid.getAttributes()) { varElem.addContent(ncmlWriter.makeAttributeElement(att)); } return varElem; }
@Test public void testIndexOutOfBounds() throws IOException, InvalidRangeException { //String endpoint = TestOnLocalServer.withHttpPath("cdmrfeature/grid/rdaTest/ds094.2_t/GaussLatLon_880X1760-0p0000N-180p0000E"); //String ccName = "ds094.2_t#GaussLatLon_880X1760-0p0000N-180p0000E"; String covName = "Temperature_height_above_ground_Mixed_intervals_AverageNforecasts"; //System.out.printf("%s%n", endpoint); Catalog cat = TdsLocalCatalog.open("catalog/rdaTest/ds094.2_t/catalog.xml"); Assert.assertNotNull(cat); Dataset ds = cat.findDatasetByID("rdaTest/ds094.2_t/GaussLatLon_880X1760-0p0000N-180p0000E"); DataFactory fac = new DataFactory(); try ( DataFactory.Result result = fac.openFeatureDataset(ds, null)) { Assert.assertFalse(result.errLog.toString(), result.fatalError); Assert.assertNotNull(result.featureDataset); Assert.assertEquals(FeatureDatasetCoverage.class, result.featureDataset.getClass()); FeatureDatasetCoverage fdc = (FeatureDatasetCoverage) result.featureDataset; CoverageCollection cc = fdc.findCoverageDataset(FeatureType.GRID); Assert.assertNotNull(FeatureType.GRID.toString(), cc); Coverage cov = cc.findCoverage(covName); Assert.assertNotNull(covName, cov); SubsetParams subset = new SubsetParams().setTimePresent(); GeoReferencedArray geo = cov.readData(subset); Array data = geo.getData(); System.out.printf(" read data from %s shape = %s%n", cov.getName(), Misc.showInts(data.getShape())); } }
@Test public void testBadSize() throws IOException, InvalidRangeException { String covName = "Geopotential_height_isobaric"; Catalog cat = TdsLocalCatalog.open("catalog/rdaTest/ds084.3/catalog.xml"); Assert.assertNotNull(cat); Dataset ds = cat.findDatasetByID("rdaTest/ds084.3/TwoD"); DataFactory fac = new DataFactory(); try ( DataFactory.Result result = fac.openFeatureDataset(ds, null)) { Assert.assertFalse(result.errLog.toString(), result.fatalError); Assert.assertNotNull(result.featureDataset); Assert.assertEquals(FeatureDatasetCoverage.class, result.featureDataset.getClass()); FeatureDatasetCoverage fdc = (FeatureDatasetCoverage) result.featureDataset; CoverageCollection cc = fdc.findCoverageDataset(FeatureType.FMRC); Assert.assertNotNull(FeatureType.FMRC.toString(), cc); Coverage cov = cc.findCoverage(covName); Assert.assertNotNull(covName, cov); SubsetParams subset = new SubsetParams().setTimePresent(); GeoReferencedArray geo = cov.readData(subset); Array data = geo.getData(); System.out.printf(" read data from %s shape = %s%n", cov.getName(), Misc.showInts(data.getShape())); } } }
@Test public void testBadSize() throws IOException, InvalidRangeException { // Grib.setDebugFlags(new DebugFlagsImpl("Grib/debugGbxIndexOnly")); String endpoint = "D:/work/rdavm/ds084.3/ds084.3.ncx4"; String covName = "Geopotential_height_isobaric"; try (FeatureDatasetCoverage fdc = CoverageDatasetFactory.open(endpoint)) { Assert.assertNotNull(endpoint, fdc); CoverageCollection cc = fdc.findCoverageDataset(FeatureType.GRID); Assert.assertNotNull(FeatureType.FMRC.toString(), cc); Coverage cov = cc.findCoverage(covName); Assert.assertNotNull(covName, cov); SubsetParams subset = new SubsetParams().setTimePresent(); GeoReferencedArray geo = cov.readData(subset); Array data = geo.getData(); System.out.printf(" read data from %s shape = %s%n", cov.getName(), Misc.showInts(data.getShape())); } Grib.setDebugFlags(new DebugFlagsImpl("")); }
public void testWrongRuntime() throws IOException, InvalidRangeException { Grib.setDebugFlags(new DebugFlagsImpl("Grib/debugGbxIndexOnly")); String endpoint = "D:/work/rdavm/index/ds083.2_Grib2.ncx4"; String covName = "Soil_temperature_depth_below_surface_layer"; try (FeatureDatasetCoverage fdc = CoverageDatasetFactory.open(endpoint)) { Assert.assertNotNull(endpoint, fdc); CoverageCollection cc = fdc.findCoverageDataset(FeatureType.GRID); Assert.assertNotNull(FeatureType.GRID.toString(), cc); Coverage cov = cc.findCoverage(covName); Assert.assertNotNull(covName, cov); SubsetParams subset = new SubsetParams().setTimePresent(); GeoReferencedArray geo = cov.readData(subset); Array data = geo.getData(); System.out.printf(" read data from %s shape = %s%n", cov.getName(), Misc.showInts(data.getShape())); } Grib.setDebugFlags(new DebugFlagsImpl("")); }
@Test public void testNonOrthMRUTC() throws IOException, InvalidRangeException { Grib.setDebugFlags(new DebugFlagsImpl("Grib/debugGbxIndexOnly")); String endpoint = "D:/work/rdavm/ds277.6/monthly/ds277.6.ncx4"; String ccName = "ds277.6#MRUTC-LatLon_418X360-4p83S-179p50W"; String covName = "Salinity_depth_below_sea_Average"; try (FeatureDatasetCoverage fdc = CoverageDatasetFactory.open(endpoint)) { Assert.assertNotNull(endpoint, fdc); CoverageCollection cc = fdc.findCoverageDataset(ccName); Assert.assertNotNull(ccName, cc); Coverage cov = cc.findCoverage(covName); Assert.assertNotNull(covName, cov); SubsetParams subset = new SubsetParams().setTimePresent(); GeoReferencedArray geo = cov.readData(subset); Array data = geo.getData(); System.out.printf(" read data from %s shape = %s%n", cov.getName(), Misc.showInts(data.getShape())); } Grib.setDebugFlags(new DebugFlagsImpl("")); }
@Test public void testNegDataSize() throws IOException, InvalidRangeException { Grib.setDebugFlags(new DebugFlagsImpl("Grib/debugGbxIndexOnly")); String endpoint = "D:/work/rdavm/ds084.3/ds084.3.ncx4"; String covName = "v-component_of_wind_potential_vorticity_surface"; try (FeatureDatasetCoverage fdc = CoverageDatasetFactory.open(endpoint)) { Assert.assertNotNull(endpoint, fdc); CoverageCollection cc = fdc.findCoverageDataset(FeatureType.GRID); Assert.assertNotNull(FeatureType.FMRC.toString(), cc); Coverage cov = cc.findCoverage(covName); Assert.assertNotNull(covName, cov); SubsetParams subset = new SubsetParams().setTimePresent(); GeoReferencedArray geo = cov.readData(subset); Array data = geo.getData(); System.out.printf(" read data from %s shape = %s%n", cov.getName(), Misc.showInts(data.getShape())); } Grib.setDebugFlags(new DebugFlagsImpl("")); }