public int writeProfile (ProfileFeature profile) throws IOException { int count = 0; for (PointFeature pf : profile) { if (!headerDone) { if (id_strlen == 0) id_strlen = profile.getName().length() * 2; writeHeader(profile, pf); headerDone = true; } writeObsData(pf); count++; } writeProfileData(profile, count); return count; }
public int writeProfile (StationProfileFeature spf, ProfileFeature profile) throws IOException { int count = 0; for (PointFeature pf : profile) { if (!headerDone) { if (id_strlen == 0) id_strlen = profile.getName().length() * 2; writeHeader(spf, profile, pf); headerDone = true; } writeObsData(pf); count++; } Integer stnIndex = stationIndexMap.get(spf.getName()); if (stnIndex == null) { System.out.printf("BAD station %s%n", spf.getName()); } else { writeProfileData(stnIndex, profile, count); } return count; }
public int writeProfile (TrajectoryProfileFeature section, ProfileFeature profile) throws IOException { int count = 0; for (PointFeature pf : profile) { if (!headerDone) { if (id_strlen == 0) id_strlen = profile.getName().length() * 2; writeHeader(section, profile, pf); headerDone = true; } writeObsData(pf); count++; } Integer sectionIndex = trajIndexMap.get(section.getName()); if (sectionIndex == null) { sectionIndex = writeSectionData(section); trajIndexMap.put(section.getName(), sectionIndex); } writeProfileData(sectionIndex, profile, count); return count; }
public int writeProfile (ProfileFeature profile) throws IOException { profile.resetIteration(); int count = 0; while (profile.hasNext()) { PointFeature pf = profile.next(); if (!headerDone) { if (id_strlen == 0) id_strlen = profile.getName().length() * 2; writeHeader(profile, pf); headerDone = true; } writeObsData(pf); count++; } writeProfileData(profile, count); return count; }
public int writeProfile (StationProfileFeature spf, ProfileFeature profile) throws IOException { profile.resetIteration(); int count = 0; while (profile.hasNext()) { PointFeature pf = profile.next(); if (!headerDone) { if (id_strlen == 0) id_strlen = profile.getName().length() * 2; writeHeader(spf, profile, pf); headerDone = true; } writeObsData(pf); count++; } Integer stnIndex = stationIndexMap.get(spf.getName()); if (stnIndex == null) { System.out.printf("BAD station %s%n", spf.getName()); } else { writeProfileData(stnIndex, profile, count); } return count; }
public int writeProfile (SectionFeature section, ProfileFeature profile) throws IOException { profile.resetIteration(); int count = 0; while (profile.hasNext()) { PointFeature pf = profile.next(); if (!headerDone) { if (id_strlen == 0) id_strlen = profile.getName().length() * 2; writeHeader(section, profile, pf); headerDone = true; } writeObsData(pf); count++; } Integer sectionIndex = trajIndexMap.get(section.getName()); if (sectionIndex == null) { sectionIndex = writeSectionData(section); trajIndexMap.put(section.getName(), sectionIndex); } writeProfileData(sectionIndex, profile, count); return count; }
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 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; }
@Test public void testProfileSingleId() throws Exception { String file = TestDir.cdmLocalTestDataDir + "point/profileSingle.ncml"; Formatter buf = new Formatter(); try (FeatureDatasetPoint pods = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(ucar.nc2.constants.FeatureType.PROFILE, 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 ProfileFeatureCollection; ProfileFeatureCollection pc = (ProfileFeatureCollection) fc; int count = 0; pc.resetIteration(); while (pc.hasNext()) { ProfileFeature pf = pc.next(); assert pf.getName().equals("666") : pf.getName() + " should be '666'"; count++; } assert count == 1; } }
static int checkSectionFeatureCollection(TrajectoryProfileFeatureCollection sectionFeatureCollection, boolean show) throws IOException { long start = System.currentTimeMillis(); int count = 0; for (TrajectoryProfileFeature section : sectionFeatureCollection) { checkDsgFeatureCollection(section); Assert.assertNotNull("SectionFeature featureData", section.getFeatureData()); Set<String> profileNames = new HashSet<>(); for (ProfileFeature profile : section) { checkDsgFeatureCollection(profile); Assert.assertNotNull("ProfileFeature time", profile.getTime()); Assert.assertNotNull("ProfileFeature latlon", profile.getLatLon()); Assert.assertNotNull("ProfileFeature featureData", profile.getFeatureData()); Assert.assertTrue(!profileNames.contains(profile.getName())); profileNames.add(profile.getName()); if (show) System.out.printf(" ProfileFeature=%s %n", profile.getName()); count += checkPointFeatureCollection(profile, show); } } long took = System.currentTimeMillis() - start; if (show) System.out.println(" testStationProfileFeatureCollection complete count= " + count + " full iter took= " + took + " msec"); return count; }
static int checkProfileFeatureCollection(ProfileFeatureCollection profileFeatureCollection, boolean show) throws IOException { long start = System.currentTimeMillis(); int count = 0; Set<String> profileNames = new HashSet<>(); for (ProfileFeature profile : profileFeatureCollection) { checkDsgFeatureCollection(profile); Assert.assertNotNull("ProfileFeature time", profile.getTime()); Assert.assertNotNull("ProfileFeature latlon", profile.getLatLon()); Assert.assertNotNull("ProfileFeature featureData", profile.getFeatureData()); Assert.assertTrue(!profileNames.contains(profile.getName())); profileNames.add(profile.getName()); // assert pf.getTime() != null; count += checkPointFeatureCollection(profile, show); } long took = System.currentTimeMillis() - start; if (show) System.out.println(" testStationProfileFeatureCollection complete count= " + count + " full iter took= " + took + " msec"); return count; }
static int checkStationProfileFeatureCollection(StationProfileFeatureCollection stationProfileFeatureCollection, boolean show) throws IOException { long start = System.currentTimeMillis(); int count = 0; for (StationProfileFeature spf : stationProfileFeatureCollection) { checkDsgFeatureCollection(spf); Assert.assertNotNull("StationProfileFeature latlon", spf.getLatLon()); Assert.assertNotNull("StationProfileFeature featureData", spf.getFeatureData()); // iterates through the profile but not the profile data List<CalendarDate> times = spf.getTimes(); if (showAll) { System.out.printf(" times= "); for (CalendarDate t : times) System.out.printf("%s, ", t); System.out.printf("%n"); } Set<String> profileNames = new HashSet<>(); for (ProfileFeature profile : spf) { checkDsgFeatureCollection(profile); Assert.assertNotNull("ProfileFeature time", profile.getTime()); Assert.assertNotNull("ProfileFeature latlon", profile.getLatLon()); Assert.assertNotNull("ProfileFeature featureData", profile.getFeatureData()); Assert.assertTrue(!profileNames.contains(profile.getName())); profileNames.add(profile.getName()); if (show) System.out.printf(" ProfileFeature=%s %n", profile.getName()); count += checkPointFeatureCollection(profile, show); } } long took = System.currentTimeMillis() - start; if (show) System.out.println(" testStationProfileFeatureCollection complete count= " + count + " full iter took= " + took + " msec"); return count; }
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; }
while (spf.hasNext()) { ProfileFeature profile = spf.next(); prof_strlen = Math.max(prof_strlen, profile.getName().length()); countProfiles++;
public void writeProfileData(ProfileFeature profile, int nobs) throws IOException { trackBB(profile.getLatLon(), profile.getTime()); StructureDataScalar profileCoords = new StructureDataScalar("Coords"); profileCoords.addMember(latName, null, null, DataType.DOUBLE, profile.getLatLon().getLatitude()); profileCoords.addMember(lonName, null, null, DataType.DOUBLE, profile.getLatLon().getLongitude()); if (profile.getTime() != null) // LOOK time not always part of profile profileCoords.addMember(profileTimeName, null, null, DataType.DOUBLE, timeUnit.makeOffsetFromRefDate(profile.getTime())); profileCoords.addMemberString(profileIdName, null, null, profile.getName().trim(), id_strlen); profileCoords.addMember(numberOfObsName, null, null, DataType.INT, nobs); StructureData profileData = profile.getFeatureData(); StructureDataComposite sdall = new StructureDataComposite(); sdall.add(profileCoords); // coords first so it takes precedence sdall.add(profileData); profileRecno = super.writeStructureData(profileRecno, profileStruct, sdall, featureVarMap); }
public void writeProfileData(int stnIndex, ProfileFeature profile, int nobs) throws IOException { trackBB(profile.getLatLon(), CalendarDate.of(profile.getTime())); StructureDataScalar profileCoords = new StructureDataScalar("Coords"); profileCoords.addMember(latName, null, null, DataType.DOUBLE, false, profile.getLatLon().getLatitude()); profileCoords.addMember(lonName, null, null, DataType.DOUBLE, false, profile.getLatLon().getLongitude()); //Date date = (profile.getTime() != null) ? (double) profile.getTime().getTime() : 0.0; // LOOK (profile.getTime() != null) ??? double timeInMyUnits = timeUnit.makeValue(profile.getTime()); profileCoords.addMember(profileTimeName, null, null, DataType.DOUBLE, false, timeInMyUnits); // LOOK time not always part of profile profileCoords.addMemberString(profileIdName, null, null, profile.getName().trim(), id_strlen); profileCoords.addMember(numberOfObsName, null, null, DataType.INT, false, nobs); profileCoords.addMember(stationIndexName, null, null, DataType.INT, false, stnIndex); StructureDataComposite sdall = new StructureDataComposite(); sdall.add(profileCoords); // coords first so it takes precedence sdall.add(profile.getFeatureData()); profileRecno = super.writeStructureData(profileRecno, profileStruct, sdall, profileVarMap); }
public void writeProfileData(ProfileFeature profile, int nobs) throws IOException { trackBB(profile.getLatLon(), CalendarDate.of(profile.getTime())); StructureDataScalar profileCoords = new StructureDataScalar("Coords"); profileCoords.addMember(latName, null, null, DataType.DOUBLE, false, profile.getLatLon().getLatitude()); profileCoords.addMember(lonName, null, null, DataType.DOUBLE, false, profile.getLatLon().getLongitude()); if (profile.getTime() != null) profileCoords.addMember(profileTimeName, null, null, DataType.DOUBLE, false, timeUnit.makeValue(profile.getTime())); // LOOK time not always part of profile profileCoords.addMemberString(profileIdName, null, null, profile.getName().trim(), id_strlen); profileCoords.addMember(numberOfObsName, null, null, DataType.INT, false, nobs); StructureData profileData = profile.getFeatureData(); StructureDataComposite sdall = new StructureDataComposite(); sdall.add(profileCoords); // coords first so it takes precedence sdall.add(profileData); profileRecno = super.writeStructureData(profileRecno, profileStruct, sdall, featureVarMap); }
public void writeProfileData(int sectionIndex, ProfileFeature profile, int nobs) throws IOException { trackBB(profile.getLatLon(), profile.getTime()); StructureDataScalar profileCoords = new StructureDataScalar("Coords"); profileCoords.addMember(latName, null, null, DataType.DOUBLE, profile.getLatLon().getLatitude()); profileCoords.addMember(lonName, null, null, DataType.DOUBLE, profile.getLatLon().getLongitude()); // double time = (profile.getTime() != null) ? (double) profile.getTime().getTime() : 0.0; double timeInMyUnits = timeUnit.makeOffsetFromRefDate(profile.getTime()); profileCoords.addMember(profileTimeName, null, null, DataType.DOUBLE, timeInMyUnits); // LOOK time not always part of profile profileCoords.addMemberString(profileIdName, null, null, profile.getName().trim(), id_strlen); profileCoords.addMember(numberOfObsName, null, null, DataType.INT, nobs); profileCoords.addMember(trajectoryIndexName, null, null, DataType.INT, sectionIndex); StructureDataComposite sdall = new StructureDataComposite(); sdall.add(profileCoords); // coords first so it takes precedence sdall.add(profile.getFeatureData()); profileRecno = super.writeStructureData(profileRecno, profileStruct, sdall, profileVarMap); }
public void writeProfileData(int stnIndex, ProfileFeature profile, int nobs) throws IOException { trackBB(profile.getLatLon(), profile.getTime()); StructureDataScalar profileCoords = new StructureDataScalar("Coords"); profileCoords.addMember(latName, null, null, DataType.DOUBLE, profile.getLatLon().getLatitude()); profileCoords.addMember(lonName, null, null, DataType.DOUBLE, profile.getLatLon().getLongitude()); //Date date = (profile.getTime() != null) ? (double) profile.getTime().getTime() : 0.0; // LOOK (profile.getTime() != null) ??? double timeInMyUnits = timeUnit.makeOffsetFromRefDate(profile.getTime()); profileCoords.addMember(profileTimeName, null, null, DataType.DOUBLE, timeInMyUnits); // LOOK time not always part of profile profileCoords.addMemberString(profileIdName, null, null, profile.getName().trim(), id_strlen); profileCoords.addMember(numberOfObsName, null, null, DataType.INT, nobs); profileCoords.addMember(stationIndexName, null, null, DataType.INT, stnIndex); StructureDataComposite sdall = new StructureDataComposite(); sdall.add(profileCoords); // coords first so it takes precedence sdall.add(profile.getFeatureData()); profileRecno = super.writeStructureData(profileRecno, profileStruct, sdall, profileVarMap); }
public void writeProfileData(int sectionIndex, ProfileFeature profile, int nobs) throws IOException { trackBB(profile.getLatLon(), CalendarDate.of(profile.getTime())); StructureDataScalar profileCoords = new StructureDataScalar("Coords"); profileCoords.addMember(latName, null, null, DataType.DOUBLE, false, profile.getLatLon().getLatitude()); profileCoords.addMember(lonName, null, null, DataType.DOUBLE, false, profile.getLatLon().getLongitude()); // double time = (profile.getTime() != null) ? (double) profile.getTime().getTime() : 0.0; double timeInMyUnits = timeUnit.makeValue(profile.getTime()); profileCoords.addMember(profileTimeName, null, null, DataType.DOUBLE, false, timeInMyUnits); // LOOK time not always part of profile profileCoords.addMemberString(profileIdName, null, null, profile.getName().trim(), id_strlen); profileCoords.addMember(numberOfObsName, null, null, DataType.INT, false, nobs); profileCoords.addMember(trajectoryIndexName, null, null, DataType.INT, false, sectionIndex); StructureDataComposite sdall = new StructureDataComposite(); sdall.add(profileCoords); // coords first so it takes precedence sdall.add(profile.getFeatureData()); profileRecno = super.writeStructureData(profileRecno, profileStruct, sdall, profileVarMap); }