public boolean addVariableAttribute(String varName, Attribute att) { return addVariableAttribute(findVariable(varName), att); } /**
/** * Add the gridMapping attribute * * @param writer * @param crs * @param transform * @param var * @param gridMapping */ private void setGeoreferencingAttributes(NetcdfFileWriter writer, CoordinateReferenceSystem crs, MathTransform transform, Variable var) { // Adding GDAL Attributes spatial_ref and GeoTransform writer.addVariableAttribute(var, getSpatialRefAttribute(crs)); writer.addVariableAttribute(var, getGeoTransformAttribute(transform)); }
/** * Add the gridMapping attribute * * @param writer * @param crs * @param transform * @param var * @param gridMapping */ private void setGeoreferencingAttributes( NetcdfFileWriter writer, CoordinateReferenceSystem crs, MathTransform transform, Variable var) { // Adding GDAL Attributes spatial_ref and GeoTransform writer.addVariableAttribute(var, getSpatialRefAttribute(crs)); writer.addVariableAttribute(var, getGeoTransformAttribute(transform)); }
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)); }
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)); }
public boolean addVariableAttribute(String varName, String name, String value) { return addVariableAttribute(findVariable(varName), new Attribute(name, value)); }
public boolean addVariableAttribute(String varName, String name, Number value) { return addVariableAttribute(findVariable(varName), new Attribute(name, value)); }
private void createCoordinates(DateUnit timeUnit) throws IOException { writer.addUnlimitedDimension(recordDimName); // 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")); // add the station Variables using the station dimension lat = writer.addVariable(null, latName, DataType.DOUBLE, recordDimName); writer.addVariableAttribute(lat, new Attribute(CDM.UNITS, CDM.LAT_UNITS)); writer.addVariableAttribute(lat, new Attribute(CDM.LONG_NAME, "station latitude")); lon = writer.addVariable(null, lonName, DataType.DOUBLE, recordDimName); writer.addVariableAttribute(lon, new Attribute(CDM.UNITS, CDM.LON_UNITS)); writer.addVariableAttribute(lon, new Attribute(CDM.LONG_NAME, "station longitude")); if (altUnits != null) { alt = writer.addVariable(null, altName, DataType.DOUBLE, recordDimName); writer.addVariableAttribute(alt, new Attribute(CDM.UNITS, altUnits)); // ncfile.addVariableAttribute(v, new Attribute("positive", "up")); writer.addVariableAttribute(alt, new Attribute(CDM.LONG_NAME, "altitude")); } }
private void createProfiles(List<String> profileNames) throws IOException { int nprofiles = profileNames.size(); // find string lengths for (String name : profileNames) { name_strlen = Math.max(name_strlen, name.length()); } // add the dimensions writer.addUnlimitedDimension(recordDimName); List<Dimension> profileDims = new ArrayList<Dimension>(1); Dimension profileDim = writer.addDimension(null, profileDimName, nprofiles); profileDims.add(profileDim); // add the profile Variables using the profile dimension id = writer.addStringVariable(null, idName, profileDims, name_strlen); writer.addVariableAttribute(id, new Attribute(CDM.LONG_NAME, "profile identifier")); writer.addVariableAttribute(id, new Attribute(CF.CF_ROLE, CF.PROFILE_ID)); Variable lat = writer.addVariable(null, latName, DataType.DOUBLE, profileDimName); writer.addVariableAttribute(lat, new Attribute(CDM.UNITS, CDM.LAT_UNITS)); writer.addVariableAttribute(lat, new Attribute(CDM.LONG_NAME, "profile latitude")); Variable lon = writer.addVariable(null, lonName, DataType.DOUBLE, profileDimName); writer.addVariableAttribute(lon, new Attribute(CDM.UNITS, CDM.LON_UNITS)); writer.addVariableAttribute(lon, new Attribute(CDM.LONG_NAME, "profile longitude")); if (altUnits != null) { Variable alt = writer.addVariable(null, altName, DataType.DOUBLE, profileDimName); writer.addVariableAttribute(alt, new Attribute(CDM.UNITS, altUnits)); writer.addVariableAttribute(alt, new Attribute(CDM.LONG_NAME, "profile altitude")); } }
private void defineHeader(NetcdfFileWriter writeableFile, String timeDim, String latDim, String lonDim, String dim3) { writeableFile.addVariable(latVar, DataType.FLOAT, latDim); writeableFile.addVariableAttribute(latVar, unitsAttName, "degrees_north"); writeableFile.addVariableAttribute(latVar, axisAttName, "Y"); writeableFile.addVariableAttribute(latVar, standardNameAttName, "latitude"); // could add bounds, but not familiar how it works writeableFile.addVariable(lonVar, DataType.FLOAT, lonDim); writeableFile.addVariableAttribute(lonVar, unitsAttName, "degrees_east"); writeableFile.addVariableAttribute(lonVar, axisAttName, "X"); writeableFile.addVariableAttribute(lonVar, standardNameAttName, "longitude"); // could add bounds, but not familiar how it works writeableFile.addVariable(variableName, DataType.FLOAT, dim3); writeableFile.addVariableAttribute(variableName, longNameAttName, variableName); writeableFile.addVariableAttribute(variableName, unitsAttName, units); writeableFile.addVariable("cellId", DataType.CHAR, "lat lon"); // STRING illegal change to CHAR writeableFile.addVariableAttribute("cellId", longNameAttName, "Cell ID"); writeableFile.addVariable(timeVar, DataType.INT, timeDim); writeableFile.addVariableAttribute(timeVar, axisAttName, "T"); writeableFile.addVariableAttribute(timeVar, standardNameAttName, timeVar); writeableFile.addVariableAttribute(timeVar, longNameAttName, timeVar); writeableFile.setFill(true); // could add bounds, but not familiar how it works }
private void addValidMinMax( Variable sourceVar, Variable var, DataPacking.DataPacker dataPacker, NetcdfFileWriter writer, String attributeName) { Attribute attribute = sourceVar.findAttribute(attributeName); if (attribute != null) { double value = attribute.getNumericValue().doubleValue(); int packedValue = dataPacker.pack(value); writer.addVariableAttribute(var, new Attribute(attributeName, packedValue)); } }
private void defineHeader(NetcdfFileWriter writeableFile, String timeDim, String latDim, String lonDim) { Variable latVar = writeableFile.addVariable(latVarName, DataType.FLOAT, latDim); writeableFile.addVariableAttribute(latVar, new Attribute( unitsAttName, "degrees_north")); writeableFile.addVariableAttribute(latVar, new Attribute(axisAttName, "Y")); writeableFile.addVariableAttribute(latVar, new Attribute(standardNameAttName, "latitude")); // could add bounds, but not familiar how it works Variable lonVar = writeableFile.addVariable(lonVarName, DataType.FLOAT, lonDim); writeableFile.addVariableAttribute(lonVar, new Attribute(unitsAttName, "degrees_east")); writeableFile.addVariableAttribute(lonVar, new Attribute(axisAttName, "X")); writeableFile.addVariableAttribute(lonVar, new Attribute(standardNameAttName, "longitude")); // could add bounds, but not familiar how it works Variable var = writeableFile.addVariable(variableName, DataType.FLOAT, latDim+" "+lonDim+" "+timeDim); writeableFile.addVariableAttribute(var, new Attribute(longNameAttName, variableName)); writeableFile.addVariableAttribute(var, new Attribute(unitsAttName, units)); writeableFile.addVariableAttribute(var, new Attribute(missingValueAttName, fillValue)); writeableFile.addVariableAttribute(var, new Attribute(fillValueAttName, fillValue)); Variable cellVar = writeableFile.addVariable("cellId", DataType.INT, latDim+" "+lonDim); writeableFile.addVariableAttribute(cellVar, new Attribute(longNameAttName, "Cell ID")); Variable timeVar = writeableFile.addVariable(timeVarName, DataType.INT, timeDim); writeableFile.addVariableAttribute(timeVar, new Attribute(unitsAttName, "days since 1889-01-01")); writeableFile.addVariableAttribute(timeVar, new Attribute(axisAttName, "T")); writeableFile.addVariableAttribute(timeVar, new Attribute(standardNameAttName, timeVarName)); writeableFile.addVariableAttribute(timeVar, new Attribute(longNameAttName, timeVarName)); // writeableFile.setFill(true); // could add bounds, but not familiar how it works }
/** * Specify which variable will get written * * @param oldVar add this variable, and all parent groups * @return new Variable. */ public Variable addVariable(Variable oldVar) { List<Dimension> newDims = getNewDimensions(oldVar); Variable newVar; if ((oldVar.getDataType().equals(DataType.STRING)) && (!version.isNetdf4format())) { newVar = writer.addStringVariable(null, oldVar, newDims); } else { newVar = writer.addVariable(null, oldVar.getShortName(), oldVar.getDataType(), newDims); } varMap.put(oldVar, newVar); varList.add(oldVar); for (Attribute att : oldVar.getAttributes()) writer.addVariableAttribute(newVar, att); // atts are immutable return newVar; }
/** * Add gridMapping variable for projected datasets. * * @param var the {@link Variable} where the mapping attribute needs to be appended */ void initializeGridMapping(Variable var) { NetCDFProjection projection = netcdfCrsType.getNetCDFProjection(); // CRS may be standard WGS84 or a projected one. // Add GridMapping name if projected if (projection != null) { String mappingName = projection.getName(); if (var != null) { writer.addVariableAttribute(var, new Attribute(NetCDFUtilities.GRID_MAPPING, mappingName)); } // Add the mapping variable writer.addVariable(null, mappingName, DataType.CHAR, (String) null); } // update CRS information updateProjectionInformation(netcdfCrsType, writer, crs, transform); }
/** * Specify which variable will get written * * @param oldVar add this variable, and all parent groups * @return new Variable. */ public Variable addVariable(Variable oldVar) { List<Dimension> newDims = getNewDimensions(oldVar); Variable newVar; if ((oldVar.getDataType().equals(DataType.STRING)) && (!version.isExtendedModel())) { newVar = writer.addStringVariable(null, oldVar, newDims); } else { newVar = writer.addVariable(null, oldVar.getShortName(), oldVar.getDataType(), newDims); } varMap.put(oldVar, newVar); varList.add(oldVar); for (Attribute att : oldVar.getAttributes()) writer.addVariableAttribute(newVar, att); // atts are immutable return newVar; }
/** * Add gridMapping variable for projected datasets. * * @param var the {@link Variable} where the mapping attribute needs to be appended */ void initializeGridMapping(Variable var) { NetCDFProjection projection = netcdfCrsType.getNetCDFProjection(); // CRS may be standard WGS84 or a projected one. // Add GridMapping name if projected if (projection != null) { String mappingName = projection.getName(); if (var != null) { writer.addVariableAttribute( var, new Attribute(NetCDFUtilities.GRID_MAPPING, mappingName)); } // Add the mapping variable writer.addVariable(null, mappingName, DataType.CHAR, (String) null); } // update CRS information updateProjectionInformation(netcdfCrsType, writer, crs, transform); }
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; }
/** * Specify which variable will get written * * @param oldVar add this variable, and all parent groups * @return new Variable. */ public Variable addVariable(Variable oldVar) { List<Dimension> newDims = getNewDimensions(oldVar); Variable newVar; if ((oldVar.getDataType().equals(DataType.STRING)) && (!version.isExtendedModel())) { newVar = writer.addStringVariable(null, oldVar, newDims); } else { newVar = writer.addVariable(null, oldVar.getShortName(), oldVar.getDataType(), newDims); } varMap.put(oldVar, newVar); varList.add(oldVar); for (Attribute orgAtt : oldVar.getAttributes()) writer.addVariableAttribute(newVar, convertAttribute(orgAtt)); return newVar; }
public void makeNetCDF() throws IOException, InvalidRangeException { String helloGreek = makeString(helloGreekCode, true); helloGreek = ""; //Normalizer.normalize(helloGreek, Normalizer.Form.NFC); System.out.println("normalized= "+showString(helloGreek)); String filename = "C:/data/unicode/helloNorm.nc"; NetcdfFileWriter ncfile = NetcdfFileWriter.createNew(filename, true); ucar.nc2.Dimension dim = ncfile.addDimension(helloGreek, 20); ncfile.addVariable(helloGreek, DataType.CHAR, helloGreek); ncfile.addVariableAttribute(helloGreek, "units", helloGreek); ncfile.create(); ArrayChar.D1 data = new ArrayChar.D1(dim.getLength()); data.setString(helloGreek); ncfile.write(helloGreek, data); ncfile.close(); NetcdfFile nc = NetcdfFile.open(filename); Variable v = ncfile.findVariable(helloGreek); assert v != null; assert v.getShortName().equals(helloGreek); Attribute att = v.findAttribute("units"); assert att != null; assert att.isString(); assert(helloGreek.equals(att.getStringValue())); nc.close(); }
Dimension timeDim = ncWriteable.addUnlimitedDimension("time"); ncWriteable.addVariable("time", DataType.INT, "time"); ncWriteable.addVariableAttribute("time", "units", "hours since 1990-01-01"); ncWriteable.create();