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 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(); }
@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"; } } }
stations = sobs.getStationFeatures(bb); else if (names != null) stations = sobs.getStationFeatures(Arrays.asList(names)); else stations = sobs.getStationFeatures();
@Test public void testStationVarMulti() throws Exception { String file = TestDir.cdmLocalTestDataDir + "point/stationMultidim.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() == 5) : "Should be 5 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"; } } }
@Test public void testStationVarSingle() throws Exception { String file = TestDir.cdmLocalTestDataDir + "point/stationSingle.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() > 0) : "No stations"; Station s = stations.get(0); assert s.getName().equals("666") : "name should be '666'"; assert !Double.isNaN(s.getAltitude()) : "No altitude on station"; assert s.getDescription() != null : "No description on station"; assert s.getDescription().equalsIgnoreCase("flabulous") : "description should equal 'flabulous'"; assert s.getWmoId() != null : "No wmoId on station"; assert s.getWmoId().equalsIgnoreCase("whoa") : "wmoId should equal 'whoa' but ='"+s.getWmoId()+"'"; } }
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; } }
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; }
Assert.assertEquals(1, stColl.getStationFeatures().size());
assert fc instanceof StationTimeSeriesFeatureCollection; StationTimeSeriesFeatureCollection sc = (StationTimeSeriesFeatureCollection) fc; List<StationFeature> stations = sc.getStationFeatures(); for (StationFeature s : stations) { StructureData sdata = s.getFeatureData();