public void writeHeader(PointFeature pf) throws IOException { List<VariableSimpleIF> coords = new ArrayList<>(); coords.add(VariableSimpleImpl.makeScalar(timeName, "time of measurement", timeUnit.getUdUnit(), DataType.DOUBLE) .add(new Attribute(CF.CALENDAR, timeUnit.getCalendar().toString()))); coords.add(VariableSimpleImpl.makeScalar(latName, "latitude of measurement", CDM.LAT_UNITS, DataType.DOUBLE)); coords.add(VariableSimpleImpl.makeScalar(lonName, "longitude of measurement", CDM.LON_UNITS, DataType.DOUBLE)); Formatter coordNames = new Formatter().format("%s %s %s", timeName, latName, lonName); if (altUnits != null) { coords.add( VariableSimpleImpl.makeScalar(altName, "altitude of measurement", altUnits, DataType.DOUBLE) .add(new Attribute(CF.POSITIVE, CF1Convention.getZisPositive(altName, altUnits)))); coordNames.format(" %s", altName); } super.writeHeader(coords, null, pf.getDataAll(), coordNames.toString()); }
private void writeHeader(TrajectoryFeature feature, PointFeature obs) throws IOException { // obs data List<VariableSimpleIF> coords = new ArrayList<>(); coords.add(VariableSimpleImpl.makeScalar(timeName, "time of measurement", timeUnit.getUdUnit(), DataType.DOUBLE) .add(new Attribute(CF.CALENDAR, timeUnit.getCalendar().toString()))); coords.add(VariableSimpleImpl.makeScalar(latName, "latitude of measurement", CDM.LAT_UNITS, DataType.DOUBLE)); coords.add(VariableSimpleImpl.makeScalar(lonName, "longitude of measurement", CDM.LON_UNITS, DataType.DOUBLE)); Formatter coordNames = new Formatter().format("%s %s %s", timeName, latName, lonName); if (altUnits != null) { coords.add( VariableSimpleImpl.makeScalar(altName, "altitude of measurement", altUnits, DataType.DOUBLE) .add(new Attribute(CF.POSITIVE, CF1Convention.getZisPositive(altName, altUnits)))); coordNames.format(" %s", altName); } super.writeHeader(coords, feature.getFeatureData(), obs.getFeatureData(), coordNames.toString()); }
protected boolean checkTimeVarForCalendar (Variable var) { boolean hasChanged = false; String unit = var.getUnitsString(); if (unit != null) { unit = unit.trim(); if (SimpleUnit.isDateUnit(unit)) { Attribute calAttr = var.findAttributeIgnoreCase(CF.CALENDAR); if (calAttr == null) { calAttr = new Attribute(CF.CALENDAR, Calendar.gregorian.toString()); var.addAttribute(calAttr); hasChanged = true; } } } return hasChanged; }
private Element writeTimeUnit(CalendarDateUnit dateUnit) { Element elem = new Element("TimeUnit"); elem.addContent(dateUnit.getUdUnit()); elem.setAttribute("calendar", dateUnit.getCalendar().toString()); return elem; }
protected void makeFeatureVariables(StructureData featureData, boolean isExtended) throws IOException { // LOOK why not unlimited here ? Dimension profileDim = writer.addDimension(null, profileDimName, nfeatures); // Dimension profileDim = isExtendedModel ? writer.addUnlimitedDimension(profileDimName) : writer.addDimension(null, profileDimName, nprofiles); // add the profile Variables using the profile dimension List<VariableSimpleIF> profileVars = new ArrayList<>(); profileVars.add(VariableSimpleImpl.makeScalar(latName, "profile latitude", CDM.LAT_UNITS, DataType.DOUBLE)); profileVars.add(VariableSimpleImpl.makeScalar(lonName, "profile longitude", CDM.LON_UNITS, DataType.DOUBLE)); profileVars.add(VariableSimpleImpl.makeString(profileIdName, "profile identifier", null, id_strlen) .add(new Attribute(CF.CF_ROLE, CF.PROFILE_ID))); // profileId:cf_role = "profile_id"; profileVars.add(VariableSimpleImpl.makeScalar(numberOfObsName, "number of obs for this profile", null, DataType.INT) .add(new Attribute(CF.SAMPLE_DIMENSION, recordDimName))); // rowSize:sample_dimension = "obs" profileVars.add(VariableSimpleImpl.makeScalar(profileTimeName, "nominal time of profile", timeUnit.getUdUnit(), DataType.DOUBLE) .add(new Attribute(CF.CALENDAR, timeUnit.getCalendar().toString()))); for (StructureMembers.Member m : featureData.getMembers()) { VariableSimpleIF dv = getDataVar(m.getName()); if (dv != null) profileVars.add(dv); } if (isExtended) { profileStruct = (Structure) writer.addVariable(null, profileStructName, DataType.STRUCTURE, profileDimName); addCoordinatesExtended(profileStruct, profileVars); } else { addCoordinatesClassic(profileDim, profileVars, featureVarMap); } }
@Override protected void makeMiddleVariables(StructureData profileData, boolean isExtended) throws IOException { Dimension profileDim = writer.addDimension(null, profileDimName, nfeatures); // add the profile Variables using the profile dimension List<VariableSimpleIF> profileVars = new ArrayList<>(); profileVars.add(VariableSimpleImpl.makeString(profileIdName, "profile identifier", null, id_strlen) .add(new Attribute(CF.CF_ROLE, CF.PROFILE_ID)) // profileId:cf_role = "profile_id"; .add(new Attribute(CDM.MISSING_VALUE, String.valueOf(idMissingValue)))); profileVars.add(VariableSimpleImpl.makeScalar(latName, "profile latitude", CDM.LAT_UNITS, DataType.DOUBLE)); profileVars.add(VariableSimpleImpl.makeScalar(lonName, "profile longitude", CDM.LON_UNITS, DataType.DOUBLE)); profileVars.add(VariableSimpleImpl.makeScalar(profileTimeName, "nominal time of profile", timeUnit.getUdUnit(), DataType.DOUBLE) .add(new Attribute(CF.CALENDAR, timeUnit.getCalendar().toString()))); profileVars.add(VariableSimpleImpl.makeScalar(trajectoryIndexName, "trajectory index for this profile", null, DataType.INT) .add(new Attribute(CF.INSTANCE_DIMENSION, trajDimName))); profileVars.add(VariableSimpleImpl.makeScalar(numberOfObsName, "number of obs for this profile", null, DataType.INT) .add(new Attribute(CF.SAMPLE_DIMENSION, recordDimName))); for (StructureMembers.Member m : profileData.getMembers()) { VariableSimpleIF dv = getDataVar(m.getName()); if (dv != null) profileVars.add(dv); } if (isExtended) { profileStruct = (Structure) writer.addVariable(null, profileStructName, DataType.STRUCTURE, profileDimName); addCoordinatesExtended(profileStruct, profileVars); } else { addCoordinatesClassic(profileDim, profileVars, profileVarMap); } }
@Override protected void makeMiddleVariables(StructureData profileData, boolean isExtended) throws IOException { Dimension profileDim = writer.addDimension(null, profileDimName, nfeatures); // add the profile Variables using the profile dimension List<VariableSimpleIF> profileVars = new ArrayList<>(); profileVars.add(VariableSimpleImpl.makeString(profileIdName, "profile identifier", null, id_strlen) .add(new Attribute(CF.CF_ROLE, CF.PROFILE_ID)) // profileId:cf_role = "profile_id"; .add(new Attribute(CDM.MISSING_VALUE, String.valueOf(idMissingValue)))); profileVars.add(VariableSimpleImpl.makeScalar(numberOfObsName, "number of obs for this profile", null, DataType.INT) .add(new Attribute(CF.SAMPLE_DIMENSION, recordDimName))); // rowSize:sample_dimension = "obs" profileVars.add(VariableSimpleImpl.makeScalar(profileTimeName, "nominal time of profile", timeUnit.getUdUnit(), DataType.DOUBLE) .add(new Attribute(CF.CALENDAR, timeUnit.getCalendar().toString()))); profileVars.add(VariableSimpleImpl.makeScalar(stationIndexName, "station index for this profile", null, DataType.INT) .add(new Attribute(CF.INSTANCE_DIMENSION, stationDimName))); for (StructureMembers.Member m : profileData.getMembers()) { VariableSimpleIF dv = getDataVar(m.getName()); if (dv != null) profileVars.add(dv); } if (isExtended) { profileStruct = (Structure) writer.addVariable(null, profileStructName, DataType.STRUCTURE, profileDimName); addCoordinatesExtended(profileStruct, profileVars); } else { addCoordinatesClassic(profileDim, profileVars, profileVarMap); } }
CalendarDate.parseISOformat(Calendar.uniform30day.toString(), "2038-01-01T03:00:00Z"), CalendarDate.parseISOformat(Calendar.uniform30day.toString(), "2038-01-01T06:00:00Z"), CalendarDate.parseISOformat(Calendar.uniform30day.toString(), "2038-01-01T09:00:00Z"), CalendarDate.parseISOformat(Calendar.uniform30day.toString(), "2038-01-01T12:00:00Z"), CalendarDate.parseISOformat(Calendar.uniform30day.toString(), "2038-01-01T15:00:00Z"), CalendarDate.parseISOformat(Calendar.uniform30day.toString(), "2038-01-01T18:00:00Z"), CalendarDate.parseISOformat(Calendar.uniform30day.toString(), "2038-01-01T21:00:00Z"), CalendarDate.parseISOformat(Calendar.uniform30day.toString(), "2038-01-02T00:00:00Z"), CalendarDate.parseISOformat(Calendar.uniform30day.toString(), "2038-01-02T03:00:00Z") }; List<CalendarDate> expectedCalendarDatesList = Arrays.asList(expectedCalendarDates);
private void makeTimeAuxReference(NetcdfFile ncfile, Group g, String timeName, String units, CoordinateTimeAbstract time) { if (time.getTime2runtime() == null) return; String tcName = "ref"+timeName; Variable v = ncfile.addVariable(g, new Variable(ncfile, g, null, tcName, DataType.DOUBLE, timeName)); v.addAttribute(new Attribute(CF.STANDARD_NAME, CF.TIME_REFERENCE)); v.addAttribute(new Attribute(CDM.LONG_NAME, Grib.GRIB_RUNTIME)); v.addAttribute(new Attribute(CF.CALENDAR, Calendar.proleptic_gregorian.toString())); v.addAttribute(new Attribute(CDM.UNITS, units)); // lazy evaluation v.setSPobject(new Time2Dinfo(Time2DinfoType.timeAuxRef, null, time)); }
private CoverageCoordAxis makeScalarTimeCoord(double val, CoverageCoordAxis1D runAxisSubset) { String name = "constantForecastTime"; String desc = "forecast time"; AttributeContainerHelper atts = new AttributeContainerHelper(name); atts.addAttribute(new Attribute(CDM.UNITS, runAxisSubset.getUnits())); atts.addAttribute(new Attribute(CF.STANDARD_NAME, CF.TIME)); atts.addAttribute(new Attribute(CDM.LONG_NAME, desc)); atts.addAttribute(new Attribute(CF.CALENDAR, runAxisSubset.getCalendar().toString())); CoverageCoordAxisBuilder builder = new CoverageCoordAxisBuilder(name, runAxisSubset.getUnits(), desc, DataType.DOUBLE, AxisType.Time, atts, CoverageCoordAxis.DependenceType.scalar, null, CoverageCoordAxis.Spacing.regularPoint, 1, val, val, 0.0, null, null); builder.setIsSubset(true); return new CoverageCoordAxis1D(builder); }
private CoverageCoordAxis makeScalarTimeCoord(double val, CoverageCoordAxis1D runAxisSubset) { String name = "constantForecastTime"; String desc = "forecast time"; AttributeContainerHelper atts = new AttributeContainerHelper(name); atts.addAttribute(new Attribute(CDM.UNITS, runAxisSubset.getUnits())); atts.addAttribute(new Attribute(CF.STANDARD_NAME, CF.TIME)); atts.addAttribute(new Attribute(CDM.LONG_NAME, desc)); atts.addAttribute(new Attribute(CF.CALENDAR, runAxisSubset.getCalendar().toString())); CoverageCoordAxisBuilder builder = new CoverageCoordAxisBuilder(name, runAxisSubset.getUnits(), desc, DataType.DOUBLE, AxisType.Time, atts, CoverageCoordAxis.DependenceType.scalar, null, CoverageCoordAxis.Spacing.regularPoint, 1, val, val, 0.0, null, null); builder.setIsSubset(true); return new CoverageCoordAxis1D(builder); }
private CoverageCoordAxis makeCoordAxis(CoordinateTime time) { trackDateRange(time.makeCalendarDateRange(null)); // default calendar List<Integer> offsets = time.getOffsetSorted(); int n = offsets.size(); double[] values = new double[n]; int count = 0; for (int offset : offsets) values[count++] = offset; AttributeContainerHelper atts = new AttributeContainerHelper(time.getName()); atts.addAttribute(new Attribute(CDM.UNITS, time.getUnit())); atts.addAttribute(new Attribute(CF.STANDARD_NAME, CF.TIME)); atts.addAttribute(new Attribute(CDM.LONG_NAME, Grib.GRIB_VALID_TIME)); atts.addAttribute(new Attribute(CF.CALENDAR, ucar.nc2.time.Calendar.proleptic_gregorian.toString())); CoverageCoordAxisBuilder builder = new CoverageCoordAxisBuilder(time.getName(), time.getTimeUdUnit(), Grib.GRIB_VALID_TIME, DataType.DOUBLE, AxisType.Time, atts, CoverageCoordAxis.DependenceType.independent, null, null, n, 0, 0, 0, values, this); builder.setSpacingFromValues(false); return new CoverageCoordAxis1D(builder); }
private CoverageCoordAxis1D makeRuntimeCoord(CoordinateRuntime runtime) { String units = runtime.getPeriodName() + " since " + gribCollection.getMasterFirstDate().toString(); List<Double> offsets = runtime.getOffsetsInTimeUnits(); int n = offsets.size(); // CoordinateRuntime master = gribCollection.getMasterRuntime(); boolean isScalar = (n == 1); // this is the case of runtime[1] CoverageCoordAxis.DependenceType dependence = isScalar ? CoverageCoordAxis.DependenceType.scalar : CoverageCoordAxis.DependenceType.independent; double[] values = new double[n]; int count = 0; for (Double offset : runtime.getOffsetsInTimeUnits()) values[count++] = offset; AttributeContainerHelper atts = new AttributeContainerHelper(runtime.getName()); atts.addAttribute(new Attribute(CDM.UNITS, units)); atts.addAttribute(new Attribute(CF.STANDARD_NAME, CF.TIME_REFERENCE)); atts.addAttribute(new Attribute(CDM.LONG_NAME, "GRIB reference time")); atts.addAttribute(new Attribute(CF.CALENDAR, ucar.nc2.time.Calendar.proleptic_gregorian.toString())); CoverageCoordAxisBuilder builder = new CoverageCoordAxisBuilder(runtime.getName(), units, "GRIB reference time", DataType.DOUBLE, AxisType.RunTime, atts, dependence, null, null, n, 0.0, 0.0, 0.0, values, this); builder.setSpacingFromValues(false); return new CoverageCoordAxis1D(builder); }
private CoverageCoordAxis makeCoordAxis(CoordinateTimeIntv time) { trackDateRange(time.makeCalendarDateRange(null)); // default calendar List<TimeCoord.Tinv> offsets = time.getTimeIntervals(); int n = offsets.size(); double[] values = new double[2 * n]; int count = 0; for (TimeCoord.Tinv offset : offsets) { values[count++] = offset.getBounds1(); values[count++] = offset.getBounds2(); } AttributeContainerHelper atts = new AttributeContainerHelper(time.getName()); atts.addAttribute(new Attribute(CDM.UNITS, time.getUnit())); atts.addAttribute(new Attribute(CF.STANDARD_NAME, CF.TIME)); atts.addAttribute(new Attribute(CDM.LONG_NAME, Grib.GRIB_VALID_TIME)); atts.addAttribute(new Attribute(CF.CALENDAR, ucar.nc2.time.Calendar.proleptic_gregorian.toString())); CoverageCoordAxisBuilder builder = new CoverageCoordAxisBuilder(time.getName(), time.getTimeUdUnit(), Grib.GRIB_VALID_TIME, DataType.DOUBLE, AxisType.Time, atts, CoverageCoordAxis.DependenceType.independent, null, null, n, 0, 0, 0, values, this); builder.setSpacingFromValues(true); return new CoverageCoordAxis1D(builder); }
private CoverageCoordAxis makeRuntimeAuxCoord(CoordinateTimeAbstract time) { if (time.getTime2runtime() == null) return null; String refName = "ref" + time.getName(); int length = time.getSize(); double[] data = new double[length]; for (int i = 0; i < length; i++) data[i] = Double.NaN; int count = 0; CoordinateRuntime master = gribCollection.getMasterRuntime(); List<Double> masterOffsets = master.getOffsetsInTimeUnits(); for (int masterIdx : time.getTime2runtime()) { data[count++] = masterOffsets.get(masterIdx - 1); } AttributeContainerHelper atts = new AttributeContainerHelper(time.getName()); atts.addAttribute(new Attribute(CDM.UNITS, time.getTimeUdUnit())); atts.addAttribute(new Attribute(CF.STANDARD_NAME, CF.TIME_REFERENCE)); atts.addAttribute(new Attribute(CDM.LONG_NAME, Grib.GRIB_RUNTIME)); atts.addAttribute(new Attribute(CF.CALENDAR, ucar.nc2.time.Calendar.proleptic_gregorian.toString())); CoverageCoordAxisBuilder builder = new CoverageCoordAxisBuilder(refName, master.getUnit(), Grib.GRIB_RUNTIME, DataType.DOUBLE, AxisType.RunTime, atts, CoverageCoordAxis.DependenceType.dependent, time.getName(), null, length, 0, 0, 0, data, this); builder.setSpacingFromValues(false); return new CoverageCoordAxis1D(builder); }
private CoverageCoordAxis makeRuntimeAuxCoord(CoordinateTime2D time2D, int ntimes) { CoordinateRuntime runtimeU = time2D.getRuntimeCoordinate(); List<Double> runOffsets = runtimeU.getOffsetsInTimeUnits(); double[] values = new double[ntimes]; int count = 0; for (int run = 0; run < time2D.getNruns(); run++) { CoordinateTimeAbstract timeCoord = time2D.getTimeCoordinate(run); for (int time = 0; time < timeCoord.getNCoords(); time++) values[count++] = runOffsets.get(run); } boolean isScalar = (time2D.getNruns() == 1); // this is the case of runtime[1] CoverageCoordAxis.DependenceType dependence = isScalar ? CoverageCoordAxis.DependenceType.scalar : CoverageCoordAxis.DependenceType.dependent; String refName = "ref" + time2D.getName(); AttributeContainerHelper atts = new AttributeContainerHelper(time2D.getName()); atts.addAttribute(new Attribute(CDM.UNITS, time2D.getTimeUdUnit())); atts.addAttribute(new Attribute(CF.STANDARD_NAME, CF.TIME_REFERENCE)); atts.addAttribute(new Attribute(CDM.LONG_NAME, Grib.GRIB_RUNTIME)); atts.addAttribute(new Attribute(CF.CALENDAR, ucar.nc2.time.Calendar.proleptic_gregorian.toString())); CoverageCoordAxisBuilder builder = new CoverageCoordAxisBuilder(refName, time2D.getTimeUdUnit(), Grib.GRIB_RUNTIME, DataType.DOUBLE, AxisType.RunTime, atts, dependence, time2D.getName(), null, ntimes, 0, 0, 0, values, this); builder.setSpacingFromValues(false); return new CoverageCoordAxis1D(builder); }
private void makeTimeCoordinate1D(NetcdfFile ncfile, Group g, CoordinateTime coordTime) { //}, CoordinateRuntime runtime) { int ntimes = coordTime.getSize(); String tcName = coordTime.getName(); String dims = coordTime.getName(); ncfile.addDimension(g, new Dimension(tcName, ntimes)); Variable v = ncfile.addVariable(g, new Variable(ncfile, g, null, tcName, DataType.DOUBLE, dims)); String units = coordTime.getTimeUdUnit(); v.addAttribute(new Attribute(CDM.UNITS, units)); v.addAttribute(new Attribute(CF.STANDARD_NAME, CF.TIME)); v.addAttribute(new Attribute(CDM.LONG_NAME, Grib.GRIB_VALID_TIME)); v.addAttribute(new Attribute(CF.CALENDAR, Calendar.proleptic_gregorian.toString())); double[] data = new double[ntimes]; int count = 0; // coordinate values for (int val : coordTime.getOffsetSorted()) data[count++] = val; v.setCachedData(Array.factory(DataType.DOUBLE, new int[]{ntimes}, data)); makeTimeAuxReference(ncfile, g, tcName, units, coordTime); }
private void makeRuntimeCoordinate(NetcdfFile ncfile, Group g, CoordinateRuntime rtc) { int n = rtc.getSize(); boolean isScalar = (n == 1); // this is the case of runtime[1] String tcName = rtc.getName(); String dims = isScalar ? null : rtc.getName(); // null means scalar if (!isScalar) ncfile.addDimension(g, new Dimension(tcName, n)); Variable v = ncfile.addVariable(g, new Variable(ncfile, g, null, tcName, DataType.DOUBLE, dims)); v.addAttribute(new Attribute(CDM.UNITS, rtc.getUnit())); v.addAttribute(new Attribute(CF.STANDARD_NAME, CF.TIME_REFERENCE)); v.addAttribute(new Attribute(CDM.LONG_NAME, Grib.GRIB_RUNTIME)); v.addAttribute(new Attribute(CF.CALENDAR, Calendar.proleptic_gregorian.toString())); /* String vsName = tcName + "_ISO"; Variable vs = ncfile.addVariable(g, new Variable(ncfile, g, null, vsName, DataType.STRING, dims)); vs.addAttribute(new Attribute(CDM.UNITS, "ISO8601")); v.addAttribute(new Attribute(CDM.LONG_NAME, "GRIB reference time")); v.addAttribute(new Attribute(CF.CALENDAR, Calendar.proleptic_gregorian.toString())); // coordinate values String[] dataS = new String[n]; int count = 0; for (CalendarDate val : rtc.getRuntimesSorted()) { dataS[count++] = val.toString(); } vs.setCachedData(Array.factory(DataType.STRING, isScalar ? new int[0] : new int[]{n}, dataS)); */ // lazy eval v.setSPobject(new Time2Dinfo(Time2DinfoType.reftime, null, rtc)); }
private void makeTimeCoordinate2D(NetcdfFile ncfile, Group g, CoordinateTime2D time2D, GribCollectionImmutable.Type gctype) { CoordinateRuntime runtime = time2D.getRuntimeCoordinate(); int nruns = time2D.getNruns(); int ntimes = time2D.getNtimes(); String tcName = time2D.getName(); //boolean singleRun = (nruns == 1); // dont use reftime dimension if time(1, ntimes) or time(nruns, 1)) // boolean uniqueTime = gctype.isUniqueTime(); String dims = runtime.getName() + " " + tcName; int dimLength = ntimes; ncfile.addDimension(g, new Dimension(tcName, dimLength)); Variable v = ncfile.addVariable(g, new Variable(ncfile, g, null, tcName, DataType.DOUBLE, dims)); String units = runtime.getUnit(); // + " since " + runtime.getFirstDate(); v.addAttribute(new Attribute(CDM.UNITS, units)); v.addAttribute(new Attribute(CF.STANDARD_NAME, CF.TIME)); v.addAttribute(new Attribute(CDM.LONG_NAME, Grib.GRIB_VALID_TIME)); v.addAttribute(new Attribute(CF.CALENDAR, Calendar.proleptic_gregorian.toString())); // the data is not generated until asked for to save space if (!time2D.isTimeInterval()) { v.setSPobject(new Time2Dinfo(Time2DinfoType.off, time2D, null)); } else { v.setSPobject(new Time2Dinfo(Time2DinfoType.intv, time2D, null)); // bounds for intervals String bounds_name = tcName + "_bounds"; Variable bounds = ncfile.addVariable(g, new Variable(ncfile, g, null, bounds_name, DataType.DOUBLE, dims + " 2")); v.addAttribute(new Attribute(CF.BOUNDS, bounds_name)); bounds.addAttribute(new Attribute(CDM.UNITS, units)); bounds.addAttribute(new Attribute(CDM.LONG_NAME, "bounds for " + tcName)); bounds.setSPobject(new Time2Dinfo(Time2DinfoType.bounds, time2D, null)); } }
v.addAttribute(new Attribute(CF.STANDARD_NAME, CF.TIME)); v.addAttribute(new Attribute(CDM.LONG_NAME, Grib.GRIB_VALID_TIME)); v.addAttribute(new Attribute(CF.CALENDAR, Calendar.proleptic_gregorian.toString()));