/** * Utility method for getting NoData from an input {@link Variable} * * @param var Variable instance * @return a Number representing NoData */ public static Number getNodata(Variable var) { if (var != null) { // Getting all the Variable attributes List<Attribute> attributes = var.getAttributes(); String fullName; // Searching for FILL_VALUE or MISSING_VALUE attributes for (Attribute attribute : attributes) { fullName = attribute.getFullName(); if (fullName.equalsIgnoreCase(FILL_VALUE) || fullName.equalsIgnoreCase(MISSING_VALUE)) { return attribute.getNumericValue(); } } } return null; }
semiMajorAxis = semiMajorAxisAttribute.getNumericValue(); ellipsoidParams.put(NetCDFUtilities.SEMI_MAJOR, semiMajorAxis); semiMajorAxisAttribute = gridMappingVariable.findAttribute(CF.EARTH_RADIUS); if (semiMajorAxisAttribute != null) { semiMajorAxis = semiMajorAxisAttribute.getNumericValue(); ellipsoidParams.put(NetCDFUtilities.SEMI_MAJOR, semiMajorAxis); semiMinorAxis = semiMinorAxisAttribute.getNumericValue(); ellipsoidParams.put(NetCDFUtilities.SEMI_MINOR, semiMinorAxis); gridMappingVariable.findAttribute(CF.INVERSE_FLATTENING); if (inverseFlatteningAttribute != null) { inverseFlattening = inverseFlatteningAttribute.getNumericValue().doubleValue();
min = rangeAttribute.getNumericValue(0).doubleValue(); max = rangeAttribute.getNumericValue(1).doubleValue(); } else { Attribute minAttribute = var.findAttribute(VALID_MIN); if (minAttribute != null && maxAttribute != null) { dataType = minAttribute.getDataType(); min = minAttribute.getNumericValue().doubleValue(); max = maxAttribute.getNumericValue().doubleValue();
/** * @param binding * @param coordinateAxis */ public NumericCoordinateVariable(Class<T> binding, CoordinateAxis coordinateAxis) { super(binding, coordinateAxis); // If the axis is not numeric, we can't process any further. if (!coordinateAxis.isNumeric()) { throw new IllegalArgumentException( "Unable to process non numeric coordinate variable: " + coordinateAxis.toString()); } // scale and offset Attribute scaleFactor = coordinateAxis.findAttribute("scale_factor"); if (scaleFactor != null) { this.scaleFactor = scaleFactor.getNumericValue().doubleValue(); } Attribute offsetFactor = coordinateAxis.findAttribute("offset"); if (offsetFactor != null) { this.offsetFactor = offsetFactor.getNumericValue().doubleValue(); } // converter from double to binding this.converter = CONVERTER_FACTORY.createConverter(Double.class, this.binding, null); init(); }
value = number.doubleValue(); } else { value = attribute.getNumericValue().doubleValue(); value = attribute.getNumericValue().doubleValue(); if (netCDFattributeName.contains("meridian") || netCDFattributeName.contains("longitude")) {
protected void unravelStringMet(NetcdfFile ncFile, Group group, Metadata met) { if (group == null) { group = ncFile.getRootGroup(); } // get file type met.set("File-Type-Description", ncFile.getFileTypeDescription()); // unravel its string attrs for (Attribute attribute : group.getAttributes()) { if (attribute.isString()) { met.add(attribute.getFullName(), attribute.getStringValue()); } else { // try and cast its value to a string met.add(attribute.getFullName(), String.valueOf(attribute .getNumericValue())); } } for (Group g : group.getGroups()) { unravelStringMet(ncFile, g, met); } }
private ProjectionCT makeSinusoidalProjection(String name, Attribute projParams) { double radius = projParams.getNumericValue(0).doubleValue(); double centMer = projParams.getNumericValue(4).doubleValue(); double falseEast = projParams.getNumericValue(6).doubleValue(); double falseNorth = projParams.getNumericValue(7).doubleValue(); Sinusoidal proj = new Sinusoidal(centMer, falseEast * .001, falseNorth * .001, radius * .001); return new ProjectionCT(name, "FGDC", proj); }
private double findAttributeDouble(NetcdfDataset ds, String attname) { Attribute att = ds.findGlobalAttributeIgnoreCase(attname); if (att == null) { parseInfo.format("ERROR cant find attribute= %s\n", attname); return Double.NaN; } return att.getNumericValue().doubleValue(); }
static private int intAttribute_( NetcdfFile ncFile, String name ) { int result = 0; Attribute attribute = ncFile.findGlobalAttribute( name ); if ( attribute != null ) { result = attribute.getNumericValue().intValue(); } return result; }
public float getRangeToFirstGate() { Attribute firstGate = ds.findGlobalAttributeIgnoreCase("RangeToFirstGate"); double gateStart = firstGate.getNumericValue().doubleValue(); return (float) gateStart; }
private double findAttributeDouble(NetcdfDataset ds, String attname) { Attribute att = ds.findGlobalAttributeIgnoreCase(attname); if (att == null) return Double.NaN; return att.getNumericValue().doubleValue(); }
metadata.add(property, attr.getStringValue()); } else if (attr.getDataType().isNumeric()) { int value = attr.getNumericValue().intValue(); metadata.add(property, String.valueOf(value));
static private boolean hasIntAttribute_( NetcdfFile ncFile, String name, int min, int max ) { boolean result = false; Attribute a = ncFile.findGlobalAttribute( name ); if ( a != null ) { if ( a.getDataType() == DataType.INT ) { final int v = a.getNumericValue().intValue(); result = v >= min && v <= max; } } return result; }
private double findAttributeDouble(NetcdfDataset ds, String attname) { Attribute att = ds.findGlobalAttributeIgnoreCase(attname); if ((att == null) || (att.isString())) return Double.NaN; return att.getNumericValue().doubleValue(); }
static private double getAttAsDouble( NetcdfDataset ds, String attname) { Attribute att = ds.findGlobalAttributeIgnoreCase(attname); if (null == att) throw new IllegalArgumentException("Must have a "+attname+" global attribute"); if (att.getDataType() == DataType.STRING) { return Double.parseDouble( att.getStringValue()); } else { return att.getNumericValue().doubleValue(); } }
metadata.add(property, attr.getStringValue()); } else if (attr.getDataType().isNumeric()) { int value = attr.getNumericValue().intValue(); metadata.add(property, String.valueOf(value));
private void convertAttribute(Variable ctv, Attribute att, double scalef) { if (att == null) return; double val = scalef * att.getNumericValue().doubleValue(); ctv.addAttribute(new Attribute(att.getShortName(), val)); }
public double readAttributeDouble(Variable v, String attName, double defValue) { Attribute att; if (v == null) att = rootGroup.findAttributeIgnoreCase(attName); else att = v.findAttributeIgnoreCase(attName); if (att == null) return defValue; if (att.isString()) return Double.parseDouble(att.getStringValue()); else return att.getNumericValue().doubleValue(); }
@Test public void code5_assume_WGS84() throws IOException { String filename = dir + "Albers_viirs_s.grb2"; try (NetcdfFile ncfile = NetcdfFile.open(filename, null)) { Variable v = ncfile.findVariable("AlbersEqualArea_Projection"); Attribute axis = v.findAttribute("semi_major_axis"); Assert.assertEquals(6378137., axis.getNumericValue().doubleValue(), 0.1); } }
@Test public void code7_oblate_specified_m() throws IOException { String filename = dir + "TT_FC_INCA.grb2"; try (NetcdfFile ncfile = NetcdfFile.open(filename, null)) { Variable v = ncfile.findVariable("LambertConformal_Projection"); Attribute axis = v.findAttribute("semi_major_axis"); Assert.assertEquals(6377397., axis.getNumericValue().doubleValue(), 0.1); } } }