/** * Adjust the mappingName if needed. This may happen for some projections where different * standard parallels may require _1SP or _2SP suffix. * * @param the input netCDF mappingName * @param var the gridMapping variable * @return */ private static String getProjectionName(String mappingName, Variable var) { String projectionName = mappingName; if (mappingName.equalsIgnoreCase(CF.LAMBERT_CONFORMAL_CONIC)) { Attribute standardParallel = var.findAttribute(CF.STANDARD_PARALLEL); // special Management for multiple standard parallels to use // the proper projection projectionName = CF.LAMBERT_CONFORMAL_CONIC + (standardParallel.getLength() == 1 ? "_1SP" : "_2SP"); } else if (mappingName.equalsIgnoreCase(CF.MERCATOR)) { Attribute standardParallel = var.findAttribute(CF.STANDARD_PARALLEL); projectionName = CF.MERCATOR + (standardParallel == null ? "_2SP" : "_1SP"); } return projectionName; }
/** * Get a proper {@link CRSParser} for the input Variable. * * @param var * @return */ public static NetCDFProjection.CRSParser getCRSParser(Variable var) { if (var != null) { Attribute attr = null; // check on crs related attributes which may contain a fully // defined WKT or a grid mapping reference if ((attr = var.findAttribute(NetCDFUtilities.CERP_ESRI_PE_STRING)) != null) { return new WKTCRSParser(attr); } else if ((attr = var.findAttribute(NetCDFUtilities.SPATIAL_REF)) != null) { return new WKTCRSParser(attr); } else if ((attr = var.findAttribute(NetCDFUtilities.GRID_MAPPING_NAME)) != null) { return new GridMappingCRSParser(attr); } } return null; }
Attribute coordinatesAttribute = var.findAttribute(NetCDFUtilities.COORDINATES); boolean hasXLon = false; boolean hasYLat = false;
Attribute semiMajorAxisAttribute = gridMappingVariable.findAttribute(CF.SEMI_MAJOR_AXIS); if (semiMajorAxisAttribute != null) { semiMajorAxis = semiMajorAxisAttribute.getNumericValue(); semiMajorAxisAttribute = gridMappingVariable.findAttribute(CF.EARTH_RADIUS); if (semiMajorAxisAttribute != null) { semiMajorAxis = semiMajorAxisAttribute.getNumericValue(); Attribute semiMinorAxisAttribute = gridMappingVariable.findAttribute(CF.SEMI_MINOR_AXIS); if (semiMinorAxisAttribute != null) { semiMinorAxis = semiMinorAxisAttribute.getNumericValue(); gridMappingVariable.findAttribute(CF.INVERSE_FLATTENING); if (inverseFlatteningAttribute != null) { inverseFlattening = inverseFlatteningAttribute.getNumericValue().doubleValue();
private static Variable getAuxiliaryCoordinate( NetcdfDataset dataset, Group group, Variable var, String dimName) { Variable coordinateVariable = null; Attribute attribute = var.findAttribute(NetCDFUtilities.COORDINATES); if (attribute != null) { String coordinates = attribute.getStringValue(); String[] coords = coordinates.split(" "); for (String coord : coords) { Variable coordVar = dataset.findVariable(group, coord); List<Dimension> varDimensions = coordVar.getDimensions(); if (varDimensions != null && varDimensions.size() == 1 && varDimensions.get(0).getFullName().equalsIgnoreCase(dimName)) { coordinateVariable = coordVar; break; } } } return coordinateVariable; }
private String getCoordinatesForVariable(String shortName) { Variable var = dataset.findVariable(null, shortName); if (var != null) { // Getting the coordinates attribute Attribute attribute = var.findAttribute(NetCDFUtilities.COORDINATES); if (attribute != null) { return attribute.getStringValue(); } else { return var.getDimensionsString(); } } return null; }
double max = Double.NaN; DataType dataType = null; Attribute rangeAttribute = var.findAttribute(ACTUAL_RANGE); if (rangeAttribute == null) { rangeAttribute = var.findAttribute(VALID_RANGE); max = rangeAttribute.getNumericValue(1).doubleValue(); } else { Attribute minAttribute = var.findAttribute(VALID_MIN); Attribute maxAttribute = var.findAttribute(VALID_MAX); if (minAttribute != null && maxAttribute != null) { dataType = minAttribute.getDataType();
Attribute attribute = var.findAttribute(netCDFattributeName); if (attribute != null) { final int numValues = attribute.getLength(); Attribute attribute = var.findAttribute(netCDFattributeName); if (attribute != null) {
Attribute gridMappingAttribute = var.findAttribute(NetCDFUtilities.GRID_MAPPING); String coordinates = manager.getCoordinateNames(var); if (coordinates != null && !boundingBoxes.containsKey(coordinates)) {
/** * Remove an Attribute by name. * * @param attName if exists, remove this attribute * @return true if was found and removed */ public boolean removeAttribute(String attName) { if (immutable) throw new IllegalStateException("Cant modify"); Attribute att = findAttribute(attName); return att != null && attributes.remove(att); }
/** * Remove an Attribute by name. * * @param attName if exists, remove this attribute * @return true if was found and removed */ public boolean removeAttribute(String attName) { if (immutable) throw new IllegalStateException("Cant modify"); Attribute att = findAttribute(attName); return att != null && attributes.remove(att); }
UF2Sweep(Variable v, int sweepno, int rays, int gates) { this.sweepVar = v; this.sweepno = sweepno; this.nrays = rays; this.ngates = gates; // ucar.unidata.util.Trace.call2("LevelII2Dataset:testRadialVariable mine"); Attribute att = sweepVar.findAttribute("abbrev"); abbrev = att.getStringValue(); }
UF2Sweep(Variable v, int sweepno, int rays, int gates) { this.sweepVar = v; this.sweepno = sweepno; this.nrays = rays; this.ngates = gates; // ucar.unidata.util.Trace.call2("LevelII2Dataset:testRadialVariable mine"); Attribute att = sweepVar.findAttribute("abbrev"); abbrev = att.getStringValue(); }
private Double getDoubleAttribute(Variable sourceVar, String attributeName) { Attribute attribute = sourceVar.findAttribute(attributeName); if (attribute != null) { return attribute.getNumericValue().doubleValue(); } else { return null; } }
/** * Copy attributes from src to target, skip ones that already exist (by name) * @param src copy from here * @param target copy to here */ static public void transferVariableAttributes(Variable src, Variable target) { for (Attribute a : src.getAttributes()) { if (null == target.findAttribute(a.getShortName())) target.addAttribute(a); } }
protected Attribute getChunkAttribute(Variable v) { Attribute att = v.findAttribute(CDM.CHUNK_SIZES); if (att != null && att.getDataType().isIntegral() && att.getLength() == v.getRank()) return att; return null; }
@Test public void code0_assume_spherical() throws IOException { String filename = dir + "grid174_scanmode_64_example.grb2"; try (NetcdfFile ncfile = NetcdfFile.open(filename, null)) { Variable v = ncfile.findVariable("LatLon_Projection"); Attribute axis = v.findAttribute("earth_radius"); Assert.assertEquals(6367470., axis.getNumericValue().doubleValue(), 0.1); } }
@Test public void code1_spherical_specified() throws IOException { String filename = dir + "LDUE18.grib2"; try (NetcdfFile ncfile = NetcdfFile.open(filename, null)) { Variable v = ncfile.findVariable("LambertConformal_Projection"); Attribute axis = v.findAttribute("earth_radius"); Assert.assertEquals(6371200., 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); } } }
@Test public void code6_assume_spherical() throws IOException { String filename = dir + "berkes.grb2"; try (NetcdfFile ncfile = NetcdfFile.open(filename, null)) { Group grp = ncfile.getRootGroup().getGroups().get(0); Variable v = grp.findVariable("LatLon_Projection"); Attribute axis = v.findAttribute("earth_radius"); Assert.assertEquals(6371229., axis.getNumericValue().doubleValue(), 0.1); } }