Refine search
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; }
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); } }
@Override protected DecodeQualification getDecodeQualification(NetcdfFile netcdfFile) { Attribute attribute = netcdfFile.getRootGroup().findAttribute("metadata_profile"); if (attribute != null) { String value = attribute.getStringValue(); if (value != null && value.equals("beam")) { return DecodeQualification.INTENDED; } } return DecodeQualification.UNABLE; }
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); } }
protected Group makeRootGroup() { Group root = new Group(this, null, ""); root.setParentGroup(null); return root; }
private void addGroupToGroup(Group parent, Group g, Tag tag) { Group groupExisting = parent.findGroup(g.getShortName()); if (groupExisting != null) { g.setName(g.getShortName() + tag.refno); } parent.addGroup(g); }
private void augmentGroupWithProjectionInfo(NetcdfDataset ds, Group g) { Dimension dimX = null, dimY = null; Group dataG = g.findGroup(DATA_GROUP); if (dataG != null) { dimX = dataG.findDimensionLocal(DIMX_NAME); dimY = dataG.findDimensionLocal(DIMY_NAME); Variable crs = g.findVariable(HdfEos.HDFEOS_CRS); Attribute projAtt = crs.findAttribute(HdfEos.HDFEOS_CRS_Projection); if (projAtt != null) { Attribute upperLeft = crs.findAttribute(HdfEos.HDFEOS_CRS_UpperLeft); Attribute lowerRight = crs.findAttribute(HdfEos.HDFEOS_CRS_LowerRight); Attribute projParams = crs.findAttribute(HdfEos.HDFEOS_CRS_ProjParams); double minX = upperLeft.getNumericValue(0).doubleValue(); double minY = upperLeft.getNumericValue(1).doubleValue(); double maxX = lowerRight.getNumericValue(0).doubleValue(); double maxY = lowerRight.getNumericValue(1).doubleValue(); VariableDS crss = makeCoordinateTransformVariable(ds, ct); crss.addAttribute(new Attribute(_Coordinate.AxisTypes, "GeoX GeoY")); ds.addVariable(dataG, crss); } else if (projAtt.getStringValue().equals("GCTP_GEO")) { for (Variable v : dataG.getVariables()) { if (v.getRank() != 2) continue; if (!v.getDimension(0).equals(dimY)) continue;
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 augmentDataset3(NetcdfDataset ds) throws IOException { Group grids = ds.findGroup("/HDFEOS/GRIDS"); if (grids == null) return; for (Group g2 : grids.getGroups()) { Attribute gctp = g2.findAttribute("GCTPProjectionCode"); if (gctp == null || !gctp.getNumericValue().equals(0)) continue; Attribute nlon = g2.findAttribute("NumberOfLongitudesInGrid"); Attribute nlat = g2.findAttribute("NumberOfLatitudesInGrid"); if (nlon == null || nlon.isString()) continue; if (nlat == null || nlat.isString()) continue; ds.addCoordinateAxis(makeLonCoordAxis(ds, g2, nlon.getNumericValue().intValue(), "XDim")); ds.addCoordinateAxis(makeLatCoordAxis(ds, g2, nlat.getNumericValue().intValue(), "YDim")); for (Group g3 : g2.getGroups()) { for (Variable v : g3.getVariables()) { v.addAttribute(new Attribute(_Coordinate.Axes, "lat lon")); } } } ds.finish(); }
private void finishGroup(Group g) { variables.addAll(g.variables); // LOOK should group atts be promoted to global atts? for (Attribute oldAtt : g.getAttributes()) { if (g == rootGroup) { gattributes.add(oldAtt); } else { String newName = makeFullNameWithString(g, oldAtt.getShortName()); // LOOK fishy gattributes.add(new Attribute(newName, oldAtt)); } } // LOOK this wont match the variables' dimensions if there are groups: what happens if we remove this ?? for (Dimension oldDim : g.dimensions) { if (oldDim.isShared()) { if (g == rootGroup) { dimensions.add(oldDim); } else { String newName = makeFullNameWithString(g, oldDim.getShortName()); // LOOK fishy dimensions.add(new Dimension(newName, oldDim)); } } } List<Group> groups = g.getGroups(); for (Group nested : groups) { finishGroup(nested); } }
static public Dimension getBoundsDimension(NetcdfFile ncfile) { Group g = ncfile.getRootGroup(); Dimension d = g.findDimension(boundsDimName); if (d == null) d = ncfile.addDimension(g, new Dimension(boundsDimName, 2, true)); return d; }
public Array getData( Range range, String parameterName ) throws IOException, InvalidRangeException { Variable variable = ncfile.getRootGroup().findVariable( parameterName ); int varRank = variable.getRank(); int [] varShape = variable.getShape(); List section = new ArrayList( varRank); section.add( range); section.add( trajPointRange ); for ( int i = 2; i < varRank; i++) { section.add( new Range( 0, varShape[i]-1 ) ); } Array array = variable.read( section); array = array.reduce(1); // Reduce the trajectory dimension. if ( array.getShape()[0] == 1) return( array.reduce( 0)); // Reduce the time dimension, if a point was requested. else return( array); }
static Variable decodeVar(NetcdfFile ncfile, Group g, Structure parent, NcStreamProto.Variable var) { Variable ncvar = new Variable(ncfile, g, parent, var.getName()); DataType varType = decodeDataType(var.getDataType()); ncvar.setDataType(decodeDataType(var.getDataType())); EnumTypedef enumType = g.findEnumeration(enumName); if (enumType != null) ncvar.setEnumTypedef(enumType); for (ucar.nc2.stream.NcStreamProto.Dimension dim : var.getShapeList()) { Dimension ncdim = decodeDim(dim); if (!ncdim.isShared()) dims.add(ncdim); else { Dimension d = g.findDimension(ncdim.getShortName()); if (d == null) throw new IllegalStateException("Can find shared dimension " + dim.getName()); ncvar.addAttribute(new Attribute(CDM.UNSIGNED, "true"));
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) throws IOException { String start_date = ds.findAttValueIgnoreCase(null, "start_date", null); SimpleDateFormat df = new SimpleDateFormat("yyyy.DDD.HH.mm.ss"); // "2006.105.00.00.00" DateFormatter dfo = new DateFormatter(); Date start = null; try { start = df.parse(start_date); } catch (ParseException e) { throw new RuntimeException("Cant read start_date="+start_date); } Variable v = ds.findVariable("time_offset"); v.addAttribute(new Attribute( CDM.UNITS, "seconds since "+dfo.toDateTimeString(start))); Group root = ds.getRootGroup(); root.addAttribute(new Attribute( CDM.CONVENTIONS, "Suomi-Station-CDM")); ds.finish(); }
void dumpClasses(Group g, PrintStream out) { out.println("Dimensions:"); for (Dimension ds : g.getDimensions()) { out.println(" " + ds.getShortName() + " " + ds.getClass().getName()); } out.println("Atributes:"); for (Attribute a : g.getAttributes()) { out.println(" " + a.getShortName() + " " + a.getClass().getName()); } out.println("Variables:"); dumpVariables(g.getVariables(), out); out.println("Groups:"); for (Group nested : g.getGroups()) { out.println(" " + nested.getFullName() + " " + nested.getClass().getName()); dumpClasses(nested, out); } }
static Variable decodeVar(NetcdfFile ncfile, Group g, Structure parent, NcStreamProto.Variable var) { Variable ncvar = new Variable(ncfile, g, parent, var.getName()); DataType varType = decodeDataType(var.getDataType()); ncvar.setDataType(decodeDataType(var.getDataType())); EnumTypedef enumType = g.findEnumeration(enumName); if (enumType != null) ncvar.setEnumTypedef(enumType); for (ucar.nc2.stream.NcStreamProto.Dimension dim : var.getShapeList()) { if (dim.getIsPrivate()) dims.add(new Dimension(dim.getName(), (int) dim.getLength(), false, dim.getIsUnlimited(), dim.getIsVlen())); else { Dimension d = g.findDimension(dim.getName()); if (d == null) throw new IllegalStateException("Can find shared dimension " + dim.getName()); ncvar.addAttribute(new Attribute(CDM.UNSIGNED, "true"));
return false; } else if (checkType == CheckType.NOSCALARS) { List<Dimension> dimensions = var.getDimensions(); if (dimensions.size() < 2) { return false; DataType dataType = var.getDataType(); if (dataType == DataType.CHAR) { return false; return isVariableAccepted(var.getFullName(), CheckType.NONE); } else if (checkType == CheckType.ONLYGEOGRIDS) { List<Dimension> dimensions = var.getDimensions(); String dimName = dimension.getFullName(); Group group = dimension.getGroup(); continue; Variable dimVariable = group.findVariable(dimName); if (dimVariable == null && dataset != null) {
@Test public void test_true_degrees() throws IOException { // Make sure we return grib units of "degree true" as "degree_true" String filename = "tds/ncep/NDFD_CONUS_5km_20140805_1200.grib2"; try (NetcdfDataset ds = NetcdfDataset.openDataset(TestDir.cdmUnitTestDir + filename)) { Group grp = ds.getRootGroup(); Assert.assertNotNull(grp); Variable var = grp.findVariable("Wind_direction_from_which_blowing_height_above_ground"); Assert.assertNotNull(var); Attribute att = var.findAttribute("units"); Assert.assertNotNull(att); Assert.assertEquals("degree_true", att.getStringValue()); } }
@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 makeCoordinateVariable(Group parentGroup, Variable v, Array data) { String name = v.getShortName(); // replace in Variable Dimension oldDimension = v.getDimension(0); Dimension newDimension = new Dimension(name, oldDimension.getLength()); // newDimension.setCoordinateAxis( v); calcCoordinateVaribale will do this v.setDimension(0, newDimension); // replace old (if it exists) in Group with shared dimension Dimension old = parentGroup.findDimension(name); parentGroup.remove(old); parentGroup.addDimension(newDimension); // might as well cache the data if (data != null) { v.setCachedData(data); if (debugCached) System.out.println(" cache for <" + name + "> length =" + data.getSize()); } }