private void readMetadata() { // must open a prototype in order to get the data variable TimedCollection.Dataset td = pointCollections.getPrototype(); if (td == null) throw new RuntimeException("No datasets in the collection"); Formatter errlog = new Formatter(); try (FeatureDatasetPoint openDataset = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(FeatureType.POINT, td.getLocation(), null, errlog)) { if (openDataset != null) { dataVariables = openDataset.getDataVariables(); globalAttributes = openDataset.getGlobalAttributes(); } } catch (IOException ioe) { throw new RuntimeException(ioe); } }
private void readMetadata() { // must open a prototype in order to get the data variable TimedCollection.Dataset td = pointCollections.getPrototype(); if (td == null) throw new RuntimeException("No datasets in the collection"); Formatter errlog = new Formatter(); FeatureDatasetPoint openDataset = null; try { openDataset = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(FeatureType.POINT, td.getLocation(), null, errlog); if (openDataset != null) { dataVariables = openDataset.getDataVariables(); globalAttributes = openDataset.getGlobalAttributes(); } } catch (IOException ioe) { throw new RuntimeException(ioe); } finally { try { if (openDataset != null) openDataset.close(); } catch (Throwable t) { } } }
private static int writePointFeatureCollection(FeatureDatasetPoint fdpoint, PointFeatureCollection pfc, String fileOut, NetcdfFileWriter.Version version) throws IOException { if (debug) System.out.printf("write to file %s%n ", fileOut); WriterCFPointCollection writer = new WriterCFPointCollection(version, fileOut, fdpoint.getGlobalAttributes()); int count = 0; while (pfc.hasNext()) { PointFeature pf = pfc.next(); if (count == 0) { writer.writeHeader(fdpoint.getDataVariables(), pf.getTimeUnit(), null); } writer.writeRecord(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; }
@Override protected StationHelper createStationHelper() throws IOException { TimedCollection.Dataset td = dataCollection.getPrototype(); if (td == null) throw new RuntimeException("No datasets in the collection"); Formatter errlog = new Formatter(); try (FeatureDatasetPoint openDataset = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(FeatureType.STATION, td.getLocation(), null, errlog)) { if (openDataset == null) throw new IllegalStateException("Cant open FeatureDatasetPoint " + td.getLocation()); StationHelper stationHelper = new StationHelper(); List<DsgFeatureCollection> fcList = openDataset.getPointFeatureCollectionList(); StationTimeSeriesCollectionImpl openCollection = (StationTimeSeriesCollectionImpl) fcList.get(0); List<StationFeature> stns = openCollection.getStationFeatures(); for (StationFeature stnFeature : stns) { stationHelper.addStation(new CompositeStationFeature(stnFeature, timeUnit, altUnits, stnFeature.getFeatureData(), this.dataCollection)); } dataVariables = openDataset.getDataVariables(); globalAttributes = openDataset.getGlobalAttributes(); return stationHelper; } }
private static int writeProfileFeatureCollection(FeatureDatasetPoint fdpoint, ProfileFeatureCollection fc, String fileOut, CFPointWriterConfig config) throws IOException { try (WriterCFProfileCollection cfWriter = new WriterCFProfileCollection(fileOut, fdpoint.getGlobalAttributes(), fdpoint.getDataVariables(), fc.getTimeUnit(), fc.getAltUnits(), config)) { cfWriter.setExtraVariables( fc.getExtraVariables()); // LOOK not always needed int count = 0; int name_strlen = 0; int nprofiles = fc.size(); if (nprofiles < 0) { for (ProfileFeature pf : fc) { name_strlen = Math.max(name_strlen, pf.getName().length()); count++; } nprofiles = count; } cfWriter.setFeatureAuxInfo(nprofiles, name_strlen); count = 0; for (ProfileFeature profile : fc) { count += cfWriter.writeProfile(profile); if (debug && count % 10 == 0) System.out.printf("%d ", count); if (debug && count % 100 == 0) System.out.printf("%n "); } cfWriter.finish(); return count; } }
private static int writePointFeatureCollection(FeatureDatasetPoint fdpoint, PointFeatureCollection pfc, String fileOut, CFPointWriterConfig config) throws IOException { try (WriterCFPointCollection pointWriter = new WriterCFPointCollection(fileOut, fdpoint.getGlobalAttributes(), fdpoint.getDataVariables(), pfc.getTimeUnit(), pfc.getAltUnits(), config)) { pointWriter.setExtraVariables( pfc.getExtraVariables()); int count = 0; for (PointFeature pf : pfc) { if (count == 0) pointWriter.writeHeader(pf); pointWriter.writeRecord(pf, pf.getFeatureData()); count++; if (debug && count % 100 == 0) System.out.printf("%d ", count); if (debug && count % 1000 == 0) System.out.printf("%n "); } pointWriter.finish(); return count; } }
private static int writeTrajectoryFeatureCollection(FeatureDatasetPoint fdpoint, TrajectoryFeatureCollection fc, String fileOut, CFPointWriterConfig config) throws IOException { try (WriterCFTrajectoryCollection cfWriter = new WriterCFTrajectoryCollection(fileOut, fdpoint.getGlobalAttributes(), fdpoint.getDataVariables(), fc.getTimeUnit(), fc.getAltUnits(), config)) { cfWriter.setExtraVariables( fc.getExtraVariables()); // LOOK not always needed int count = 0; int name_strlen = 0; int ntrajs = fc.size(); if (ntrajs < 0) { for (TrajectoryFeature traj : fc) { name_strlen = Math.max(name_strlen, traj.getName().length()); count++; } ntrajs = count; } cfWriter.setFeatureAuxInfo(ntrajs, name_strlen); count = 0; for (TrajectoryFeature traj : fc) { count += cfWriter.writeTrajectory(traj); if (debug && count % 10 == 0) System.out.printf("%d ", count); if (debug && count % 100 == 0) System.out.printf("%n "); } cfWriter.finish(); return count; } }
@Override protected StationHelper createStationHelper() throws IOException { TimedCollection.Dataset td = dataCollection.getPrototype(); if (td == null) throw new RuntimeException("No datasets in the collection"); Formatter errlog = new Formatter(); try (FeatureDatasetPoint openDataset = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open( FeatureType.STATION, td.getLocation(), null, errlog)) { StationHelper stationHelper = new StationHelper(); List<FeatureCollection> fcList = openDataset.getPointFeatureCollectionList(); StationTimeSeriesCollectionImpl openCollection = (StationTimeSeriesCollectionImpl) fcList.get(0); List<Station> stns = openCollection.getStations(); for (Station s : stns) { StationTimeSeriesFeature stnFeature = openCollection.getStationFeature(s); stationHelper.addStation(new CompositeStationFeature(s, timeUnit, altUnits, stnFeature.getFeatureData(), this.dataCollection)); } dataVariables = openDataset.getDataVariables(); globalAttributes = openDataset.getGlobalAttributes(); return stationHelper; } }
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; }
private static int writeTrajectoryProfileFeatureCollection(FeatureDatasetPoint dataset, TrajectoryProfileFeatureCollection fc, String fileOut, CFPointWriterConfig config) throws IOException { try (WriterCFTrajectoryProfileCollection cfWriter = new WriterCFTrajectoryProfileCollection(fileOut, dataset.getGlobalAttributes(), dataset.getDataVariables(), fc.getTimeUnit(), fc.getAltUnits(), config)) {
private static int writePointFeatureCollection(FeatureDatasetPoint fdpoint, PointFeatureCollection pfc, String fileOut, CFPointWriterConfig config) throws IOException { try (WriterCFPointCollection pointWriter = new WriterCFPointCollection(fileOut, fdpoint.getGlobalAttributes(), fdpoint.getDataVariables(), pfc.getExtraVariables(), pfc.getTimeUnit(), pfc.getAltUnits(), config)) { int count = 0; pfc.resetIteration(); while(pfc.hasNext()) { PointFeature pf = pfc.next(); if (count == 0) pointWriter.writeHeader(pf); pointWriter.writeRecord(pf, pf.getFeatureData()); count++; if (debug && count % 100 == 0) System.out.printf("%d ", count); if (debug && count % 1000 == 0) System.out.printf("%n "); } pointWriter.finish(); return count; } }
private static int writeTrajectoryFeatureCollection(FeatureDatasetPoint fdpoint, TrajectoryFeatureCollection pds, String fileOut, CFPointWriterConfig config) throws IOException { WriterCFTrajectoryCollection cfWriter = new WriterCFTrajectoryCollection(fileOut, fdpoint.getGlobalAttributes(), fdpoint.getDataVariables(), pds.getExtraVariables(), pds.getTimeUnit(), pds.getAltUnits(), config); // LOOK not always needed int count = 0; int name_strlen = 0; int ntrajs = pds.size(); if (ntrajs < 0) { pds.resetIteration(); while (pds.hasNext()) { TrajectoryFeature feature = pds.next(); name_strlen = Math.max(name_strlen, feature.getName().length()); count++; } ntrajs = count; } cfWriter.setFeatureAuxInfo(ntrajs, name_strlen); count = 0; pds.resetIteration(); while (pds.hasNext()) { TrajectoryFeature feature = pds.next(); count += cfWriter.writeTrajectory(feature); if (debug && count % 10 == 0) System.out.printf("%d ", count); if (debug && count % 100 == 0) System.out.printf("%n "); } cfWriter.finish(); return count; }
private static int writeProfileFeatureCollection(FeatureDatasetPoint fdpoint, ProfileFeatureCollection pds, String fileOut, NetcdfFileWriter.Version version) throws IOException { if (debug) System.out.printf("write to file %s%n ", fileOut); WriterCFProfileCollection writer = new WriterCFProfileCollection(fileOut, fdpoint.getGlobalAttributes(), version); int count = 0; List<String> profiles = new ArrayList<String>(); pds.resetIteration(); while (pds.hasNext()) { profiles.add(pds.next().getName()); } pds.resetIteration(); while (pds.hasNext()) { ucar.nc2.ft.ProfileFeature profile = pds.next(); profile.resetIteration(); while (profile.hasNext()) { ucar.nc2.ft.PointFeature pf = profile.next(); if (count == 0) { writer.writeHeader(profiles, fdpoint.getDataVariables(), pf.getTimeUnit(), null); // LOOK altitude units ?? } writer.writeRecord(profile.getName(), 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; }
private static int writeStationProfileFeatureCollection(FeatureDatasetPoint dataset, StationProfileFeatureCollection fc, String fileOut, CFPointWriterConfig config) throws IOException { try (WriterCFStationProfileCollection cfWriter = new WriterCFStationProfileCollection(fileOut, dataset.getGlobalAttributes(), dataset.getDataVariables(), fc.getTimeUnit(), fc.getAltUnits(), config)) {
private static int writeProfileFeatureCollection(FeatureDatasetPoint fdpoint, ProfileFeatureCollection pds, String fileOut, CFPointWriterConfig config) throws IOException { WriterCFProfileCollection cfWriter = new WriterCFProfileCollection(fileOut, fdpoint.getGlobalAttributes(), fdpoint.getDataVariables(), pds.getExtraVariables(), pds.getTimeUnit(), pds.getAltUnits(), config); // LOOK not always needed int count = 0; int name_strlen = 0; int nprofiles = pds.size(); if (nprofiles < 0) { pds.resetIteration(); while (pds.hasNext()) { ProfileFeature pf = pds.next(); name_strlen = Math.max(name_strlen, pf.getName().length()); count++; } nprofiles = count; } cfWriter.setFeatureAuxInfo(nprofiles, name_strlen); count = 0; pds.resetIteration(); while (pds.hasNext()) { ucar.nc2.ft.ProfileFeature profile = pds.next(); count += cfWriter.writeProfile(profile); if (debug && count % 10 == 0) System.out.printf("%d ", count); if (debug && count % 100 == 0) System.out.printf("%n "); } cfWriter.finish(); return count; }
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; }
private static int writeTrajectoryProfileFeatureCollection(FeatureDatasetPoint dataset, SectionFeatureCollection fc, String fileOut, CFPointWriterConfig config) throws IOException { WriterCFTrajectoryProfileCollection cfWriter = new WriterCFTrajectoryProfileCollection(fileOut, dataset.getGlobalAttributes(), dataset.getDataVariables(), fc.getExtraVariables(), fc.getTimeUnit(), fc.getAltUnits(), config);
private static int writeStationProfileFeatureCollection(FeatureDatasetPoint dataset, StationProfileFeatureCollection fc, String fileOut, CFPointWriterConfig config) throws IOException { WriterCFStationProfileCollection cfWriter = new WriterCFStationProfileCollection(fileOut, dataset.getGlobalAttributes(), dataset.getDataVariables(), fc.getExtraVariables(), fc.getTimeUnit(), fc.getAltUnits(), config); cfWriter.setStations(fc.getStationFeatures());
@Override public void finishConstruction() { super.finishConstruction(); finish(); ThreddsMetadata tmi = getLocalMetadataInheritable(); // pull out ACDD metadata from feature collection and put into the catalog MetadataExtractorAcdd acdd = new MetadataExtractorAcdd( Attribute.makeMap(fd.getGlobalAttributes()), this, tmi); acdd.extract(); finish(); // spatial coverage if (fd.getBoundingBox() == null) { // pull out catalog BB, put into the feature collection. this will override ACDD thredds.catalog.ThreddsMetadata.GeospatialCoverage coverage = getGeospatialCoverage(); if (coverage != null) ((PointDatasetImpl) fd).setBoundingBox(coverage.getBoundingBox()); // override in fd } else if (getGeospatialCoverage() == null) { tmi.setGeospatialCoverage( MetadataExtractor.extractGeospatial(fd)); } tmi.addVariables(MetadataExtractor.extractVariables(fd)); finish(); }