@Override public Station getStation(PointFeature feature) throws IOException { StationPointFeature stationFeature = (StationPointFeature) feature; // LOOK probably will fail here return stationFeature.getStation(); }
@Override public int compare(StationPointFeature left, StationPointFeature right) { return -Double.compare(left.getObservationTime(), right.getObservationTime()); } };
public StationPointFeature deepCopy(StationPointFeature from) throws IOException { StationFeature s = from.getStation(); StationFeatureImpl sUse = stationMap.get(s.getName()); if (sUse == null) { sUse = new StationFeatureImpl(s); stationMap.put(s.getName(), sUse); } sUse.incrNobs(); StationPointFeatureCopy deep = new StationPointFeatureCopy(sUse, from); deep.data = StructureDataDeep.copy(from.getFeatureData(), sm); return deep; }
assert pf instanceof StationPointFeature; StationPointFeature s = (StationPointFeature) pf; StructureData sdata = s.getFeatureData(); StructureMembers.Member m = sdata.findMember("stnInfo"); assert m == null : "stnInfo in leaf"; StructureData sdata2 = s.getDataAll(); m = sdata2.findMember("stnInfo"); assert m != null : "missing stnInfo";
public StationFeatureCopyFactory(StationPointFeature proto) throws IOException { stationMap = new HashMap<>(); StructureData sdata = proto.getFeatureData(); sm = new StructureMembers(sdata.getStructureMembers()); sizeInBytes = OBJECT_SIZE + POINTER_SIZE + // PointFeatureCopy - 1 pointer 48 2 * 8 + 2 * POINTER_SIZE + // PointFeatureImpl - 2 doubles and 2 pointers 32 OBJECT_SIZE + 3 * 8 + // Earth Location - 3 doubles 64 OBJECT_SIZE + // StructureDataDeep 4 + POINTER_SIZE + // StructureDataA - 1 int and 1 pointer OBJECT_SIZE + 4 + 2 * POINTER_SIZE + // ArrayStructureBB - 1 int and 2 pointers (heap is optional) 2 * POINTER_SIZE + 4 + // ArrayStructure - 2 pointers and an int OBJECT_SIZE + 8 * 4 + 8 + POINTER_SIZE + // ByteBuffer - 8 ints, 1 long, 1 pointer sm.getStructureSize(); // LOOK vlens, Strings (Heap Size) }
public StationFeatureCopyFactory(StationPointFeature proto, DateUnit du) throws IOException { this.du = du; stationMap = new HashMap<>(); StructureData sdata = proto.getDataAll(); sm = new StructureMembers(sdata.getStructureMembers()); sizeInBytes = OBJECT_SIZE + POINTER_SIZE + // PointFeatureCopy - 1 pointer 48 2 * 8 + 2 * POINTER_SIZE + // PointFeatureImpl - 2 doubles and 2 pointers 32 OBJECT_SIZE + 3 * 8 + // Earth Location - 3 doubles 64 OBJECT_SIZE + // StructureDataDeep 4 + POINTER_SIZE + // StructureDataA - 1 int and 1 pointer OBJECT_SIZE + 4 + 2 * POINTER_SIZE + // ArrayStructureBB - 1 int and 2 pointers (heap is optional) 2 * POINTER_SIZE + 4 + // ArrayStructure - 2 pointers and an int OBJECT_SIZE + 8 * 4 + 8 + POINTER_SIZE + // ByteBuffer - 8 ints, 1 long, 1 pointer sm.getStructureSize(); // LOOK vlens, Strings (Heap Size) }
public StationPointFeature deepCopy(StationPointFeature from) throws IOException { StationFeature s = from.getStation(); StationFeatureImpl sUse = stationMap.get(s.getName()); if (sUse == null) { sUse = new StationFeatureImpl(s); stationMap.put(s.getName(), sUse); } sUse.incrNobs(); StationPointFeatureCopy deep = new StationPointFeatureCopy(sUse, from); deep.data = StructureDataDeep.copy(from.getFeatureData(), sm); return deep; }
StationFeature sf = spf.getStation(); StructureData stnData = sf.getFeatureData(); StructureData obsData = spf.getFeatureData();
public Station getStation(PointFeature feature) throws IOException { StationPointFeature stationFeature = (StationPointFeature) feature; // LOOK probably will fail here return stationFeature.getStation(); }
StationFeature sf = spf.getStation(); StructureData stnData = sf.getFeatureData(); StructureData obsData = spf.getFeatureData();
public Station getStation(PointFeature feature) throws IOException { StationPointFeature stationFeature = (StationPointFeature) feature; return stationFeature.getStation(); }
public Station getStation(PointFeature feature) throws IOException { StationPointFeature stationFeature = (StationPointFeature) feature; return stationFeature.getStation(); }
@Override public int compare(StationPointFeature o1, StationPointFeature o2) { return -Integer.compare(o1.getStation().getName().length(), o2.getStation().getName().length()); } };
public static boolean equals(StationPointFeature stationPointFeat1, StationPointFeature stationPointFeat2) throws IOException { if (stationPointFeat1 == stationPointFeat2) { return true; } else if (stationPointFeat1 == null || stationPointFeat2 == null) { return false; } if (!equals((PointFeature) stationPointFeat1, stationPointFeat2)) { return false; } else if (!equals(stationPointFeat1.getStation(), stationPointFeat2.getStation())) { return false; } return true; }
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; }
@Test public void test2() throws IOException, NoFactoryFoundException, URISyntaxException { File testFile = new File(getClass().getResource("orthogonal.ncml").toURI()); Comparator<StationPointFeature> reverseStationNameComparator = Ordering.from(SortingStationPointFeatureCache.stationNameComparator).reverse(); SortingStationPointFeatureCache cache = new SortingStationPointFeatureCache(reverseStationNameComparator); cache.addAll(testFile); List<String> expectedStationNames = Arrays.asList("CCC", "BBB", "AAA"); List<String> actualStationNames = new LinkedList<>(); try (PointFeatureIterator iter = cache.getPointFeatureIterator()) { while (iter.hasNext()) { StationPointFeature stationPointFeat = (StationPointFeature) iter.next(); actualStationNames.add(stationPointFeat.getStation().getName()); } } Assert.assertEquals(expectedStationNames, actualStationNames); }
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; }