private void createObsVariables(DateUnit timeUnit) throws IOException { // time variable time = writer.addVariable(null, timeName, DataType.DOUBLE, recordDimName); writer.addVariableAttribute(time, new Attribute(CDM.UNITS, timeUnit.getUnitsString())); writer.addVariableAttribute(time, new Attribute(CDM.LONG_NAME, "time of measurement")); stationIndex = writer.addVariable(null, stationIndexName, DataType.INT, recordDimName); writer.addVariableAttribute(stationIndex, new Attribute(CDM.LONG_NAME, "station index for this observation record")); writer.addVariableAttribute(stationIndex, new Attribute(CF.INSTANCE_DIMENSION, stationDimName)); }
/** * Add a variable to the file. Must be in define mode. * * @param g the group to add to. if null, use root group * @param shortName name of Variable, must be unique with the file. * @param dataType type of underlying element * @param dimString names of Dimensions for the variable, blank separated. * Must already have been added. Use an empty string for a scalar variable. * @return the Variable that has been added */ public Variable addVariable(Group g, String shortName, DataType dataType, String dimString) { Group parent = (g == null) ? ncfile.getRootGroup() : g; return addVariable(g, null, shortName, dataType, Dimension.makeDimensionsList(parent, dimString)); }
private void addCoordTransforms(CoverageCollection subsetDataset, NetcdfFileWriter writer) { for (CoverageTransform ct : subsetDataset.getCoordTransforms()) { // scalar coordinate transform variable - container for transform info Variable ctv = writer.addVariable(null, ct.getName(), DataType.INT, ""); for (Attribute att : ct.getAttributes()) ctv.addAttribute(att); } }
private void createObsVariables(DateUnit timeUnit) throws IOException { // time variable LOOK could also be time(profile) time = writer.addVariable(null, timeName, DataType.DOUBLE, recordDimName); writer.addVariableAttribute(time, new Attribute(CDM.UNITS, timeUnit.getUnitsString())); writer.addVariableAttribute(time, new Attribute(CDM.LONG_NAME, "time of measurement")); /*Variable zVar = ncfile.addVariable(zName, DataType.DOUBLE, recordDimName); ncfile.addVariableAttribute(timeVar, new Attribute(CDM.UNITS, zUnit)); ncfile.addVariableAttribute(timeVar, new Attribute(CDM.LONG_NAME, "time of measurement")); */ index = writer.addVariable(null, profileIndexName, DataType.INT, recordDimName); writer.addVariableAttribute(index, new Attribute(CDM.LONG_NAME, "profile index for this observation record")); writer.addVariableAttribute(index, new Attribute(CF.INSTANCE_DIMENSION, profileDimName)); }
protected void addExtraVariables() throws IOException { if (extra == null) return; if (extraMap == null) extraMap = new HashMap<>(); addDimensionsClassic(extra, dimMap); for (VariableSimpleIF vs : extra) { List<Dimension> dims = makeDimensionList(dimMap, vs.getDimensions()); Variable mv = writer.addVariable(null, vs.getShortName(), vs.getDataType(), dims); for (Attribute att : vs.getAttributes()) mv.addAttribute(att); extraMap.put(mv.getShortName(), mv); } }
private static Dimension setDimension(NetcdfFileWriter ncFile, String name, String units, int length) { Dimension dimension = ncFile.addDimension(null, name, length); Variable v = ncFile.addVariable(null, name, DataType.FLOAT, name); ncFile.addVariableAttribute(v, new Attribute("units", units)); return dimension; }
protected void addExtraVariables() throws IOException { if (extra == null) return; if (extraMap == null) extraMap = new HashMap<>(); addDimensionsClassic(extra, dimMap); for (VariableSimpleIF vs : extra) { List<Dimension> dims = makeDimensionList(dimMap, vs.getDimensions()); Variable mv = writer.addVariable(null, vs.getShortName(), vs.getDataType(), dims); for (Attribute att : vs.getAttributes()) mv.addAttribute(att); extraMap.put(mv.getShortName(), mv); } }
private void serializeTime(ITemporalExtent time, List<Dimension> dims) throws KlabException { if (time.getMultiplicity() > 1) { defineMode(true); Dimension tDim = _ncfile.addUnlimitedDimension("time"); _time = _ncfile.addVariable(null, "time", DataType.DOUBLE, "time"); // TODO should probably use natural step in scale when appropriate, assuming // we carry over the // unit and resolution. _time.addAttribute(new Attribute("units", "milliseconds since EPOCH")); defineMode(false); dims.add(tDim); } }
private void addCoverages(CoverageCollection subsetDataset, NetcdfFileWriter writer) { for (Coverage grid : subsetDataset.getCoverages()) { Variable v = writer.addVariable(null, grid.getName(), grid.getDataType(), grid.getIndependentAxisNamesOrdered()); addVariableAttributes(v, grid.getAttributes()); } }
@Before public void setUp() throws IOException { filePath = tempFolder.newFile().getAbsolutePath(); try (NetcdfFileWriter file = NetcdfFileWriter.createNew(NetcdfFileWriter.Version.netcdf3, filePath)) { file.addDimension(null, "t", DIM_T); file.addDimension(null, "alt", DIM_ALT); file.addDimension(null, "lat", DIM_LAT); file.addDimension(null, "lon", DIM_LON); file.addVariable(DATA_VARIABLE, DataType.FLOAT, "t alt lat lon"); file.create(); } }
protected Variable addVariableTime(NetcdfFileWriter writer, List<Dimension> dims) { Variable v = writer.addVariable(null, getVariableDimensionCaseName(CFStandardNames.TIME.getName()), DataType.DOUBLE, dims); v.addAttribute(new Attribute(CFConstants.STANDARD_NAME, CFStandardNames.TIME.getName())); v.addAttribute(new Attribute(CFConstants.LONG_NAME, getLongName(CFStandardNames.TIME.getName()))); v.addAttribute(new Attribute(CFConstants.UNITS, getTimeUnits())); v.addAttribute(new Attribute(CFConstants.AXIS, CFConstants.AXIS_T)); v.addAttribute(new Attribute(CFConstants.FILL_VALUE, getNetcdfHelper().getFillValue())); return v; }
protected Variable addVariableLatitude(NetcdfFileWriter writer, List<Dimension> dims) { Variable v = writer.addVariable(null, getVariableDimensionCaseName(CFStandardNames.LATITUDE.getName()), getDataType(), dims); v.addAttribute(new Attribute(CFConstants.STANDARD_NAME, CFStandardNames.LATITUDE.getName())); v.addAttribute(new Attribute(CFConstants.LONG_NAME, getLongName(CFStandardNames.LATITUDE.getName()))); v.addAttribute(new Attribute(CFConstants.UNITS, CFConstants.UNITS_DEGREES_NORTH)); v.addAttribute(new Attribute(CFConstants.AXIS, CFConstants.AXIS_Y)); v.addAttribute(new Attribute(CFConstants.FILL_VALUE, getNetcdfHelper().getFillValue())); return v; }
protected Variable addVariableLatitude(NetcdfFileWriter writer, List<Dimension> dims) { Variable v = writer.addVariable(null, getVariableDimensionCaseName(CFStandardNames.LATITUDE.getName()), getDataType(), dims); v.addAttribute(new Attribute(CFConstants.STANDARD_NAME, CFStandardNames.LATITUDE.getName())); v.addAttribute(new Attribute(CFConstants.LONG_NAME, getLongName(CFStandardNames.LATITUDE.getName()))); v.addAttribute(new Attribute(CFConstants.UNITS, CFConstants.UNITS_DEGREES_NORTH)); v.addAttribute(new Attribute(CFConstants.AXIS, CFConstants.AXIS_Y)); v.addAttribute(new Attribute(CFConstants.FILL_VALUE, getNetcdfHelper().getFillValue())); return v; }
protected Variable addVariableTime(NetcdfFileWriter writer, List<Dimension> dims) { Variable v = writer.addVariable(null, getVariableDimensionCaseName(CFStandardNames.TIME.getName()), DataType.DOUBLE, dims); v.addAttribute(new Attribute(CFConstants.STANDARD_NAME, CFStandardNames.TIME.getName())); v.addAttribute(new Attribute(CFConstants.LONG_NAME, getLongName(CFStandardNames.TIME.getName()))); v.addAttribute(new Attribute(CFConstants.UNITS, getTimeUnits())); v.addAttribute(new Attribute(CFConstants.AXIS, CFConstants.AXIS_T)); v.addAttribute(new Attribute(CFConstants.FILL_VALUE, getNetcdfHelper().getFillValue())); return v; }
protected Variable addVariableLongitude(NetcdfFileWriter writer, List<Dimension> dims) { Variable v = writer.addVariable(null, getVariableDimensionCaseName(CFStandardNames.LONGITUDE.getName()), getDataType(), dims); v.addAttribute(new Attribute(CFConstants.STANDARD_NAME, CFStandardNames.LONGITUDE.getName())); v.addAttribute(new Attribute(CFConstants.LONG_NAME, getLongName(CFStandardNames.LONGITUDE.getName()))); v.addAttribute(new Attribute(CFConstants.UNITS, CFConstants.UNITS_DEGREES_EAST)); v.addAttribute(new Attribute(CFConstants.AXIS, CFConstants.AXIS_X)); v.addAttribute(new Attribute(CFConstants.FILL_VALUE, getNetcdfHelper().getFillValue())); return v; }
protected Variable addVariableLongitude(NetcdfFileWriter writer, List<Dimension> dims) { Variable v = writer.addVariable(null, getVariableDimensionCaseName(CFStandardNames.LONGITUDE.getName()), getDataType(), dims); v.addAttribute(new Attribute(CFConstants.STANDARD_NAME, CFStandardNames.LONGITUDE.getName())); v.addAttribute(new Attribute(CFConstants.LONG_NAME, getLongName(CFStandardNames.LONGITUDE.getName()))); v.addAttribute(new Attribute(CFConstants.UNITS, CFConstants.UNITS_DEGREES_EAST)); v.addAttribute(new Attribute(CFConstants.AXIS, CFConstants.AXIS_X)); v.addAttribute(new Attribute(CFConstants.FILL_VALUE, getNetcdfHelper().getFillValue())); return v; }
protected Variable addVariableHeight(NetcdfFileWriter writer, List<Dimension> dims) { Variable v = writer.addVariable(null, getVariableDimensionCaseName(CFStandardNames.HEIGHT.getName()), getDataType(), dims); v.addAttribute(new Attribute(CFConstants.STANDARD_NAME, CFStandardNames.HEIGHT.getName())); v.addAttribute(new Attribute(CFConstants.LONG_NAME, getLongName(CFStandardNames.HEIGHT.getName()))); v.addAttribute(new Attribute(CFConstants.UNITS, CFConstants.UNITS_METERS)); v.addAttribute(new Attribute(CFConstants.AXIS, CFConstants.AXIS_Z)); v.addAttribute(new Attribute(CFConstants.POSITIVE, CFConstants.POSITIVE_UP)); v.addAttribute(new Attribute(CFConstants.FILL_VALUE, getNetcdfHelper().getFillValue())); return v; }
protected Variable addVariableHeight(NetcdfFileWriter writer, List<Dimension> dims) { Variable v = writer.addVariable(null, getVariableDimensionCaseName(CFStandardNames.HEIGHT.getName()), getDataType(), dims); v.addAttribute(new Attribute(CFConstants.STANDARD_NAME, CFStandardNames.HEIGHT.getName())); v.addAttribute(new Attribute(CFConstants.LONG_NAME, getLongName(CFStandardNames.HEIGHT.getName()))); v.addAttribute(new Attribute(CFConstants.UNITS, CFConstants.UNITS_METERS)); v.addAttribute(new Attribute(CFConstants.AXIS, CFConstants.AXIS_Z)); v.addAttribute(new Attribute(CFConstants.POSITIVE, CFConstants.POSITIVE_UP)); v.addAttribute(new Attribute(CFConstants.FILL_VALUE, getNetcdfHelper().getFillValue())); return v; }
protected Variable addVariableDepth(NetcdfFileWriter writer, List<Dimension> dims) { Variable v = writer.addVariable(null, getVariableDimensionCaseName(CFStandardNames.DEPTH.getName()), getDataType(), dims); v.addAttribute(new Attribute(CFConstants.STANDARD_NAME, CFStandardNames.DEPTH.getName())); v.addAttribute(new Attribute(CFConstants.LONG_NAME, getLongName(CFStandardNames.DEPTH.getName()))); v.addAttribute(new Attribute(CFConstants.UNITS, CFConstants.UNITS_METERS)); v.addAttribute(new Attribute(CFConstants.AXIS, CFConstants.AXIS_Z)); v.addAttribute(new Attribute(CFConstants.POSITIVE, CFConstants.POSITIVE_DOWN)); v.addAttribute(new Attribute(CFConstants.FILL_VALUE, getNetcdfHelper().getFillValue())); return v; }
protected Variable addVariableDepth(NetcdfFileWriter writer, List<Dimension> dims) { Variable v = writer.addVariable(null, getVariableDimensionCaseName(CFStandardNames.DEPTH.getName()), getDataType(), dims); v.addAttribute(new Attribute(CFConstants.STANDARD_NAME, CFStandardNames.DEPTH.getName())); v.addAttribute(new Attribute(CFConstants.LONG_NAME, getLongName(CFStandardNames.DEPTH.getName()))); v.addAttribute(new Attribute(CFConstants.UNITS, CFConstants.UNITS_METERS)); v.addAttribute(new Attribute(CFConstants.AXIS, CFConstants.AXIS_Z)); v.addAttribute(new Attribute(CFConstants.POSITIVE, CFConstants.POSITIVE_DOWN)); v.addAttribute(new Attribute(CFConstants.FILL_VALUE, getNetcdfHelper().getFillValue())); return v; }