private static int writeStationFeatureCollection(FeatureDatasetPoint dataset, StationTimeSeriesFeatureCollection fc, String fileOut, CFPointWriterConfig config) throws IOException { try (WriterCFStationCollection cfWriter = new WriterCFStationCollection(fileOut, dataset.getGlobalAttributes(), dataset.getDataVariables(), fc.getTimeUnit(), fc.getAltUnits(), config)) { cfWriter.setExtraVariables( fc.getExtraVariables()); ucar.nc2.ft.PointFeatureCollection pfc = fc.flatten(null, null, null); // all data, but no need to sort by station int count = 0; for (PointFeature pf : pfc) { StationPointFeature spf = (StationPointFeature) pf; if (count == 0) cfWriter.writeHeader(fc.getStationFeatures(), spf); cfWriter.writeRecord(spf.getStation(), pf, pf.getFeatureData()); count++; if (debug && count % 100 == 0) System.out.printf("%d ", count); if (debug && count % 1000 == 0) System.out.printf("%n "); } cfWriter.finish(); return count; } }
@Override public void getDetailInfo(java.util.Formatter sf) { super.getDetailInfo(sf); int count = 0; for (FeatureCollection fc : collectionList) { sf.format("%nFeatureCollection %d %n", count++); if (fc instanceof PointFeatureCollection) { PointFeatureCollection pfc = (PointFeatureCollection) fc; sf.format(" %s %s\n", pfc.getCollectionFeatureType(), pfc.getName()); sf.format(" npts = %d %n", pfc.size()); sf.format(" bb = %s %n", pfc.getBoundingBox() == null ? "" : pfc.getBoundingBox().toString2()); sf.format(" dates = %s %n", pfc.getDateRange() == null ? "" : pfc.getDateRange().toString()); } else if (fc instanceof StationTimeSeriesFeatureCollection) { StationTimeSeriesFeatureCollection npfc = (StationTimeSeriesFeatureCollection) fc; sf.format(" %s %s\n", npfc.getCollectionFeatureType(), npfc.getName()); sf.format(" npts = %d %n", npfc.size()); sf.format(" bb = %s %n", npfc.getBoundingBox() == null ? "" : npfc.getBoundingBox().toString2()); // sf.format(" dates = %s %n", npfc.getDateRange() == null ? "" : npfc.getDateRange().toString()); } } }
private PointFeatureIterator getNextIterator() throws IOException { if (!iter.hasNext()) return null; TimedCollection.Dataset td = iter.next(); Formatter errlog = new Formatter(); currentDataset = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(FeatureType.STATION, td.getLocation(), null, errlog); List<FeatureCollection> fcList = currentDataset.getPointFeatureCollectionList(); StationTimeSeriesFeatureCollection stnCollection = (StationTimeSeriesFeatureCollection) fcList.get(0); Station s = stnCollection.getStation(getName()); if (s == null) { System.out.printf("CompositeStationFeatureIterator dataset: %s missing station %s%n", td.getLocation(), getName()); return getNextIterator(); } StationTimeSeriesFeature stnFeature = stnCollection.getStationFeature(s); if (CompositeDatasetFactory.debug) System.out.printf("CompositeStationFeatureIterator open dataset: %s for %s%n", td.getLocation(), s.getName()); return stnFeature.getPointFeatureIterator(bufferSize); }
private PointFeatureIterator getNextIterator() throws IOException { if (!iter.hasNext()) return null; TimedCollection.Dataset td = iter.next(); Formatter errlog = new Formatter(); // open the next dataset currentDataset = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(FeatureType.STATION, td.getLocation(), null, errlog); if (currentDataset == null) { logger.error("FeatureDatasetFactoryManager failed to open: " + td.getLocation() + " \nerrlog = " + errlog); return getNextIterator(); } if (CompositeDatasetFactory.debug) System.out.printf("CompositeStationCollectionFlattened.Iterator open new dataset: %s%n", td.getLocation()); // it will have a StationTimeSeriesFeatureCollection List<DsgFeatureCollection> fcList = currentDataset.getPointFeatureCollectionList(); StationTimeSeriesFeatureCollection stnCollection = (StationTimeSeriesFeatureCollection) fcList.get(0); PointFeatureCollection pc; if (wantStationsubset) { pc = stnCollection.flatten(stationsSubset, dateRange, varList); } else if (bbSubset == null) { pc = stnCollection.flatten(null, dateRange, null); } else { List<StationFeature> stations = stnCollection.getStationFeatures(bbSubset); List<String> names = new ArrayList<>(); for (StationFeature s : stations) names.add(s.getName()); pc = stnCollection.flatten(names, dateRange, null); } return pc.getPointFeatureIterator(); }
static int checkStationFeatureCollection(StationTimeSeriesFeatureCollection sfc) throws IOException { System.out.printf("--------------------------\nComplete Iteration for %s %n", sfc.getName()); int countStns = countLocations(sfc); LatLonRect bb = sfc.getBoundingBox(); Assert.assertNotNull(bb); LatLonRect bb2 = new LatLonRect(bb.getLowerLeftPoint(), bb.getHeight() / 2, bb.getWidth() / 2); System.out.println(" BB Subset= " + bb2.toString2()); StationTimeSeriesFeatureCollection sfcSub = sfc.subset(bb2); int countSub = countLocations(sfcSub); Assert.assertTrue(countSub <= countStns); System.out.println(" nobs= " + sfcSub.size()); PointFeatureCollection flatten = sfc.flatten(bb2, null); int countFlat = countLocations(flatten); assert countFlat <= countStns; flatten = sfc.flatten(null, null, null); return countObs(flatten);
if (this.boundingBox == null) { if (bb == null) { bb = sc.getBoundingBox(); } else if (sc.getBoundingBox() != null) { bb.extend(sc.getBoundingBox()); PointFeatureCollection pfc = sc.flatten(null, (CalendarDateRange) null); pfc.calcBounds(); if (dates == null)
PointFeatureCollection pfcAll = sfc.flatten(null, (CalendarDateRange) null); System.out.printf("Unique Locations all = %d %n", countLocations(pfcAll)); LatLonRect bb = sfc.getBoundingBox(); assert bb != null; LatLonRect bb2 = new LatLonRect(bb.getLowerLeftPoint(), bb.getHeight() / 2, bb.getWidth() / 2); PointFeatureCollection pfcSub = sfc.flatten(bb2, (CalendarDateRange) null); System.out.printf("Unique Locations sub1 = %d %n", countLocations(pfcSub)); StationTimeSeriesFeatureCollection sfcSub = sfc.subset(bb2); PointFeatureCollection pfcSub2 = sfcSub.flatten(null, (CalendarDateRange) null); System.out.printf("Unique Locations sub2 = %d %n", countLocations(pfcSub2)); sfc = sfc.subset(bb2); PointFeatureCollection subDon = sfc.flatten(bb2, (CalendarDateRange) null); System.out.printf("Unique Locations subDon = %d %n", countLocations(subDon));
assert fc instanceof StationTimeSeriesFeatureCollection; StationTimeSeriesFeatureCollection sc = (StationTimeSeriesFeatureCollection) fc; List<StationFeature> stations = sc.getStationFeatures(); for (StationFeature s : stations) { StructureData sdata = s.getFeatureData(); PointFeatureCollectionIterator iter = sc.getPointFeatureCollectionIterator(); while (iter.hasNext()) { PointFeatureCollection pfc = iter.next(); PointFeatureCollection pfc = sc.flatten(null, (CalendarDateRange) null, null); PointFeatureIterator iter2 = pfc.getPointFeatureIterator(); while (iter2.hasNext()) {
private static int writeStationFeatureCollection(FeatureDatasetPoint fdpoint, StationTimeSeriesFeatureCollection fds, String fileOut, NetcdfFileWriter.Version version) throws IOException { if (debug) System.out.printf("write to file %s%n ", fileOut); WriterCFStationCollection writer = new WriterCFStationCollection(version, fileOut, fdpoint.getGlobalAttributes()); ucar.nc2.ft.PointFeatureCollection pfc = fds.flatten(null, (CalendarDateRange) null); int count = 0; while (pfc.hasNext()) { PointFeature pf = pfc.next(); if (count == 0) { writer.writeHeader(fds.getStations(), fdpoint.getDataVariables(), pf.getTimeUnit(), ""); } StationPointFeature spf = (StationPointFeature) pf; writer.writeRecord(spf.getStation(), pf, pf.getData()); count++; if (debug && count % 100 == 0) System.out.printf("%d ", count); if (debug && count % 1000 == 0) System.out.printf("%n "); } writer.finish(); return count; }
PointFeatureCollection pfc = stsfc.flatten( new LatLonRect(new LatLonPointImpl(-90, -180), new LatLonPointImpl(90, 180)), CalendarDateRange.of(CalendarDate.parseISOformat(null, "1900-01-01"), CalendarDate.parseISOformat(null, "2100-01-01"))); Assert.assertNotNull(sdata); StationFeature stnFeat = stsfc.getStationFeature(pf); Assert.assertNotNull(stnFeat); StructureData stnData = stnFeat.getFeatureData();
static int countLocations(StationTimeSeriesFeatureCollection sfc) throws IOException { System.out.printf(" Station List Size = %d %n", sfc.getStationFeatures().size()); // check uniqueness Map<String, StationTimeSeriesFeature> stns = new HashMap<>(5000); Map<MyLocation, StationTimeSeriesFeature> locs = new HashMap<>(5000); int dups = 0; for (StationTimeSeriesFeature sf : sfc) { StationTimeSeriesFeature other = stns.get(sf.getName()); if (other != null && dups < 10) { System.out.printf(" duplicate name = %s %n", sf); System.out.printf(" of = %s %n", other); dups++; } else stns.put(sf.getName(), sf); MyLocation loc = new MyLocation(sf); StationTimeSeriesFeature already = locs.get(loc); if (already != null) { System.out.printf(" duplicate location %s(%s) of %s(%s) %n", sf.getName(), sf.getDescription(), already.getName(), already.getDescription()); } else locs.put(loc, sf); } System.out.printf(" duplicate names = %d %n", dups); System.out.printf(" unique locs = %d %n", locs.size()); System.out.printf(" unique stns = %d %n", stns.size()); return stns.size(); }
private PointFeatureIterator getNextIterator() throws IOException { if (!iter.hasNext()) return null; TimedCollection.Dataset td = iter.next(); Formatter errlog = new Formatter(); // open the next dataset currentDataset = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(FeatureType.STATION, td.getLocation(), null, errlog); if (currentDataset == null) { logger.error("FeatureDatasetFactoryManager failed to open: " + td.getLocation() + " \nerrlog = " + errlog); return getNextIterator(); } if (CompositeDatasetFactory.debug) System.out.printf("CompositeStationCollectionFlattened.Iterator open new dataset: %s%n", td.getLocation()); // it will have a StationTimeSeriesFeatureCollection List<FeatureCollection> fcList = currentDataset.getPointFeatureCollectionList(); StationTimeSeriesFeatureCollection stnCollection = (StationTimeSeriesFeatureCollection) fcList.get(0); PointFeatureCollection pc = null; if (wantStationsubset) pc = stnCollection.flatten(stationsSubset, dateRange, varList); else pc = stnCollection.flatten(bbSubset, dateRange); return pc.getPointFeatureIterator(bufferSize); }
stations = sobs.getStations(bb); else if (names != null) stations = sobs.getStations(Arrays.asList(names)); else stations = sobs.getStations();
bb = sc.getBoundingBox(); else bb.extend(sc.getBoundingBox()); PointFeatureCollection pfc = sc.flatten(null, (CalendarDateRange) null); pfc.calcBounds(); if (dates == null)
stations = sobs.getStationFeatures(bb); else if (names != null) stations = sobs.getStationFeatures(Arrays.asList(names)); else stations = sobs.getStationFeatures();
private PointFeatureIterator getNextIterator() throws IOException { if (!iter.hasNext()) return null; TimedCollection.Dataset td = iter.next(); Formatter errlog = new Formatter(); // open the next dataset currentDataset = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(FeatureType.STATION, td.getLocation(), null, errlog); if (currentDataset == null) { logger.error("FeatureDatasetFactoryManager failed to open: " + td.getLocation() + " \nerrlog = " + errlog); return getNextIterator(); } if (CompositeDatasetFactory.debug) System.out.printf("CompositeStationCollectionFlattened.Iterator open new dataset: %s%n", td.getLocation()); // it will have a StationTimeSeriesFeatureCollection List<FeatureCollection> fcList = currentDataset.getPointFeatureCollectionList(); StationTimeSeriesFeatureCollection stnCollection = (StationTimeSeriesFeatureCollection) fcList.get(0); PointFeatureCollection pc = null; if (wantStationsubset) pc = stnCollection.flatten(stationsSubset, dateRange, varList); else pc = stnCollection.flatten(bbSubset, dateRange); PointFeatureIterator result = pc.getPointFeatureIterator(bufferSize); if (calcBounds) result.setCalculateBounds(pc); // LOOK barf return result; }
stations = sobs.getStations(bb); else if (names != null) stations = sobs.getStations(Arrays.asList(names)); else stations = sobs.getStations();
private static int writeStationFeatureCollection(FeatureDatasetPoint dataset, StationTimeSeriesFeatureCollection fc, String fileOut, CFPointWriterConfig config) throws IOException { WriterCFStationCollection cfWriter = new WriterCFStationCollection(fileOut, dataset.getGlobalAttributes(), dataset.getDataVariables(), fc.getExtraVariables(), fc.getTimeUnit(), fc.getAltUnits(), config); ucar.nc2.ft.PointFeatureCollection pfc = fc.flatten(null, (CalendarDateRange) null); // LOOK int count = 0; while (pfc.hasNext()) { PointFeature pf = pfc.next(); StationPointFeature spf = (StationPointFeature) pf; if (count == 0) cfWriter.writeHeader(fc.getStationFeatures(), spf); cfWriter.writeRecord(spf.getStation(), pf, pf.getFeatureData()); count++; if (debug && count % 100 == 0) System.out.printf("%d ", count); if (debug && count % 1000 == 0) System.out.printf("%n "); } cfWriter.finish(); return count; }
@Test public void testStationVarRagged() throws Exception { String file = TestDir.cdmLocalTestDataDir + "point/stationRaggedContig.ncml"; Formatter buf = new Formatter(); try (FeatureDatasetPoint pods = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(ucar.nc2.constants.FeatureType.STATION, file, null, buf)) { List<DsgFeatureCollection> collectionList = pods.getPointFeatureCollectionList(); assert (collectionList.size() == 1) : "Can't handle point data with multiple collections"; DsgFeatureCollection fc = collectionList.get(0); assert fc instanceof StationTimeSeriesFeatureCollection; StationTimeSeriesFeatureCollection sc = (StationTimeSeriesFeatureCollection) fc; List<StationFeature> stations = sc.getStationFeatures(); assert (stations.size() == 3) : "Should be 3 stations"; for (Station s : stations) { System.out.printf("%s%n", s); assert !Double.isNaN(s.getAltitude()) : "No altitude on station"; assert s.getDescription() != null && !s.getDescription().isEmpty() : "No description on station"; assert s.getWmoId() != null && !s.getWmoId().isEmpty() : "No wmoId on station"; } } }