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 void augmentGroup(NetcdfDataset ds, Group g) { Variable crs = g.findVariable(HdfEos.HDFEOS_CRS); if (crs != null) augmentGroupWithProjectionInfo(ds, g); for (Group ng : g.getGroups()) augmentGroup(ds, ng); }
public Variable findVariableByAttribute(Group g, String attName, String attValue) { if (g == null) g = getRootGroup(); for (Variable v : variables) { for (Attribute att : v.getAttributes()) if (attName.equals(att.getShortName()) && attValue.equals(att.getStringValue())) return v; } for (Group nested : g.getGroups()) { Variable v = findVariableByAttribute(nested, attName, attValue); if (v != null) return v; } return null; }
private void augmentGroup(NetcdfDataset ds, Group g) { Variable crs = g.findVariable(HdfEos.HDFEOS_CRS); if (crs != null) augmentGroupWithProjectionInfo(ds, g); for (Group ng : g.getGroups()) augmentGroup(ds, ng); }
private void augmentGroup(NetcdfDataset ds, Group g) { Variable crs = g.findVariable(HdfEos.HDFEOS_CRS); if (crs != null) augmentGroupWithProjectionInfo(ds, g); for (Group ng : g.getGroups()) augmentGroup(ds, ng); }
public Variable findVariableByAttribute(Group g, String attName, String attValue) { if (g == null) g = getRootGroup(); for (Variable v : g.getVariables()) { for (Attribute att : v.getAttributes()) if (attName.equals(att.getShortName()) && attValue.equals(att.getStringValue())) return v; } for (Group nested : g.getGroups()) { Variable v = findVariableByAttribute(nested, attName, attValue); if (v != null) return v; } return null; }
public Variable findVariableByAttribute(Group g, String attName, String attValue) { if (g == null) g = getRootGroup(); for (Variable v : g.getVariables()) { for (Attribute att : v.getAttributes()) if (attName.equals(att.getShortName()) && attValue.equals(att.getStringValue())) return v; } for (Group nested : g.getGroups()) { Variable v = findVariableByAttribute(nested, attName, attValue); if (v != null) return v; } return null; }
private void setImmutable(Group g) { for (Variable v : g.variables) v.setImmutable(); for (Dimension d : g.dimensions) d.setImmutable(); for (Group nested : g.getGroups()) setImmutable(nested); g.setImmutable(); }
private void setImmutable(Group g) { for (Variable v : g.variables) v.setImmutable(); for (Dimension d : g.dimensions) d.setImmutable(); for (Group nested : g.getGroups()) setImmutable(nested); g.setImmutable(); }
private void setImmutable(Group g) { for (Variable v : g.variables) v.setImmutable(); for (Dimension d : g.dimensions) d.setImmutable(); for (Group nested : g.getGroups()) setImmutable(nested); g.setImmutable(); }
private void fixAttributes(Group g) { for (Variable v : g.getVariables()) { for (Attribute a : v.getAttributes()) { if (a.getShortName().equalsIgnoreCase("UNIT") || a.getShortName().equalsIgnoreCase("UNITS")) a.setShortName(CDM.UNITS); if (a.getShortName().equalsIgnoreCase("SCALE_FACTOR")) a.setShortName(CDM.SCALE_FACTOR); if (a.getShortName().equalsIgnoreCase("OFFSET")) a.setShortName(CDM.ADD_OFFSET); } } for (Group ng : g.getGroups()) { fixAttributes(ng); } }
private static boolean checkGroup(Group g) { Variable crs = g.findVariable(HdfEos.HDFEOS_CRS); Group dataG = g.findGroup(DATA_GROUP); if (crs != null && dataG != null) { Attribute att = crs.findAttribute(HdfEos.HDFEOS_CRS_Projection); if (att == null) return false; if (!att.getStringValue().equals("GCTP_SNSOID") && !att.getStringValue().equals("GCTP_GEO")) return false; return !(dataG.findDimensionLocal(DIMX_NAME) == null || dataG.findDimensionLocal(DIMY_NAME) == null); } for (Group ng : g.getGroups()) { if (checkGroup(ng)) return true; } return false; }
public static void addGroups(final MetadataElement parentElem, final Group parentGroup) { final List<Group> groupList = parentGroup.getGroups(); for (Group grp : groupList) { final MetadataElement newElem = new MetadataElement(grp.getShortName()); parentElem.addElement(newElem); // recurse addGroups(newElem, grp); } addAttributes(parentElem, parentGroup); }
void transferData(Group oldGroup) throws IOException, InvalidRangeException { for (Variable v : oldGroup.getVariables()) { if (!isRadial && v.getRank() >= 3) { invertOneVar(v); } else { System.out.printf("write %s%n",v.getNameAndDimensions()); Array data = v.read(); Variable nv = ncOut.findVariable(v.getFullName()); ncOut.write(nv, data); } } // recurse for (Group g : oldGroup.getGroups()) transferData( g); }
@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); } }
private void convertGroup(Group g, Group from) { for (EnumTypedef et : from.getEnumTypedefs()) g.addEnumeration(et); for (Dimension d : from.getDimensions()) g.addDimension(new Dimension(d.getShortName(), d)); for (Attribute a : from.getAttributes()) g.addAttribute(a); for (Variable v : from.getVariables()) g.addVariable(convertVariable(g, v)); for (Group nested : from.getGroups()) { Group nnested = new Group(this, g, nested.getShortName()); g.addGroup(nnested); convertGroup(nnested, nested); } }