Refine search
NetcdfFile ncFile = null; try { ncFile = NetcdfFile.open(tis.getFile().getAbsolutePath()); metadata.set("File-Type-Description", ncFile.getFileTypeDescription()); for (Attribute attr : ncFile.getGlobalAttributes()) { Property property = resolveMetadataKey(attr.getFullName()); if (attr.getDataType().isString()) { metadata.add(property, attr.getStringValue()); } else if (attr.getDataType().isNumeric()) { int value = attr.getNumericValue().intValue(); xhtml.newline(); for (Dimension dim : ncFile.getDimensions()) { xhtml.element("li", dim.getFullName() + " = " + dim.getLength()); for (Variable var : ncFile.getVariables()) { xhtml.startElement("li"); xhtml.characters(var.getDataType() + " " + var.getNameAndDimensions()); xhtml.newline(); List<Attribute> attributes = var.getAttributes(); if (!attributes.isEmpty()) { xhtml.startElement("ul");
@Override public void hashCodeShow(Indent indent) { System.out.printf("%sDim hash = %d%n", indent, hashCode()); System.out.printf("%s shortName '%s' = %d%n", indent, getShortName(), getShortName() == null ? -1 : getShortName().hashCode()); System.out.printf("%s getLength %s%n", indent, getLength()); System.out.printf("%s isUnlimited %s%n", indent, isUnlimited()); System.out.printf("%s isVariableLength %s%n", indent, isVariableLength()); System.out.printf("%s isShared %s%n", indent, isShared()); if (getGroup() != null) System.out.printf("%s parentGroup %s = %d%n", indent, getGroup(), getGroup().hashCode()); }
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) {
NetcdfFile ncFile = NetcdfDataset.openFile(gribFile.getAbsolutePath(), null); for (Attribute attr : ncFile.getGlobalAttributes()) { Property property = resolveMetadataKey(attr.getFullName()); if (attr.getDataType().isString()) { metadata.add(property, attr.getStringValue()); } else if (attr.getDataType().isNumeric()) { int value = attr.getNumericValue().intValue(); xhtml.newline(); for (Dimension dim : ncFile.getDimensions()){ xhtml.element("li", dim.getFullName() + "=" + String.valueOf(dim.getLength()) + ";"); xhtml.newline(); xhtml.newline(); for (Variable var : ncFile.getVariables()){ xhtml.element("p", String.valueOf(var.getDataType()) + var.getNameAndDimensions() + ";"); for(Attribute element : var.getAttributes()){ xhtml.element("li", " :" + element + ";"); xhtml.newline();
private void testCoordVar(NetcdfFile ncfile, int n) { Variable lat = ncfile.findVariable("y"); assert null != lat; assert lat.getShortName().equals("y"); assert lat.getRank() == 1; assert lat.getSize() == n; assert lat.getShape()[0] == n; assert lat.getDataType() == DataType.DOUBLE || lat.getDataType() == DataType.FLOAT; assert !lat.isUnlimited(); assert lat.getDimension(0).equals(ncfile.findDimension("y")); Attribute att = lat.findAttribute("units"); assert null != att; assert !att.isArray(); assert att.isString(); assert att.getDataType() == DataType.STRING; assert att.getStringValue().equals("km"); assert att.getNumericValue() == null; assert att.getNumericValue(3) == null; try { Array data = lat.read(); assert data.getRank() == 1; assert data.getSize() == n; assert data.getShape()[0] == n; } catch (IOException io) {} }
public void testCoordVar(NetcdfFile ncfile) throws IOException { Variable lat = ncfile.findVariable("latitude"); assert lat.getDataType() == DataType.FLOAT; assert lat.getDimension(0).equals(ncfile.findDimension("latitude")); Attribute att = lat.findAttribute("units"); assert null != att; assert !att.isArray(); assert att.isString(); assert att.getDataType() == DataType.STRING; assert att.getStringValue().equals("degree_N"); Array data = lat.read(); assert data.getRank() == 1; assert data.getSize() == 630; assert data.getShape()[0] == 630; assert data.getElementType() == float.class; IndexIterator dataI = data.getIndexIterator(); Assert2.assertNearlyEquals(dataI.getFloatNext(), 43.0f); Assert2.assertNearlyEquals(dataI.getFloatNext(), 43.01045f); Assert2.assertNearlyEquals(dataI.getFloatNext(), 43.020893f); }
public void testCoordVar(NetcdfFile ncfile, String name, int n, DataType type) throws IOException { Variable lat = ncfile.findVariable(name); assert null != lat; assert lat.getShortName().equals(name); assert lat.getRank() == 1; assert lat.getSize() == n; assert lat.getShape()[0] == n; assert lat.getDataType() == type; assert !lat.isUnlimited(); assert lat.getDimension(0).equals(ncfile.findDimension(name)); Array data = lat.read(); assert data.getRank() == 1; assert data.getSize() == n; assert data.getShape()[0] == n; assert data.getElementType() == type.getPrimitiveClassType(); int count = 0; IndexIterator dataI = data.getIndexIterator(); while (dataI.hasNext()) Assert2.assertNearlyEquals(dataI.getDoubleNext(), (double) count++); }
private boolean makeCoordinateAxis( Variable ncvar, Dimension dim) { if (ncvar.getRank() != 1) return false; Dimension vdim = ncvar.getDimension(0); if (!vdim.equals(dim)) return false; if (!dim.getShortName().equals(ncvar.getShortName())) { ncvar.addAttribute( new Attribute(_Coordinate.AliasForDimension, dim.getShortName())); } /* if (dim.getCoordinateVariables().size() == 1) { dim.addCoordinateVariable( ncvar); ncvar.setIsCoordinateAxis( true); } */ return true; }
/** * Instances which have same content are equal. */ public boolean equals(Object oo) { if (this == oo) return true; if (!(oo instanceof Variable)) return false; Variable o = (Variable) oo; if (!getShortName().equals(o.getShortName())) return false; if (isScalar() != o.isScalar()) return false; if (getDataType() != o.getDataType()) return false; if (!getParentGroup().equals(o.getParentGroup())) return false; if ((getParentStructure() != null) && !getParentStructure().equals(o.getParentStructure())) return false; if (isVariableLength() != o.isVariableLength()) return false; if (dimensions.size() != o.getDimensions().size()) return false; for (int i=0; i<dimensions.size(); i++) if (!getDimension(i).equals(o.getDimension(i))) return false; return true; }
/** * Add a Dimension to the file * * @param dim copy this dimension * @return the new Dimension */ public Dimension writeDimension(Dimension dim) { String useName = N3iosp.makeValidNetcdfObjectName(dim.getShortName()); Dimension newDim = ncfile.addDimension(useName, dim.isUnlimited() ? 0 : dim.getLength(), dim.isShared(), dim.isUnlimited(), dim.isVariableLength()); dimHash.put(useName, newDim); if (debug) System.out.println("write dim= " + newDim); return newDim; }
public void testMetadata() { logger.debug("TestNested = \n{}", ncfile); Attribute att = ncfile.findGlobalAttribute("title"); assert null != att; assert !att.isArray(); assert att.isString(); assert att.getDataType() == DataType.STRING; assert att.getStringValue().equals("Example Data"); assert att.getNumericValue() == null; assert att.getNumericValue(3) == null; Dimension latDim = ncfile.findDimension("lat"); assert null != latDim; assert latDim.getShortName().equals("lat"); assert latDim.getLength() == 3; assert !latDim.isUnlimited(); Dimension timeDim = ncfile.findDimension("time"); assert null != timeDim; assert timeDim.getShortName().equals("time"); assert timeDim.getLength() == 2; assert timeDim.isUnlimited(); }
private static Map<Integer, Float> readGainInfo(NetcdfFile ncFile) throws IOException { Variable gainInfoVar = ncFile.getRootGroup().findVariable(ChrisConstants.VS_NAME_GAIN_INFO); if (gainInfoVar instanceof Structure) { Structure gainInfoStruct = (Structure) gainInfoVar; int recordCount = gainInfoStruct.getDimension(0).getLength(); Variable gainSetting = gainInfoStruct.findVariable(ChrisConstants.VS_NAME_GAIN_SETTING); Variable gainValue = gainInfoStruct.findVariable(ChrisConstants.VS_NAME_GAIN_VALUE); if (gainSetting != null && gainValue != null && recordCount > 0) { final Map<Integer, Float> gainInfoMap = new HashMap<Integer, Float>(recordCount); Array settingsArray = gainSetting.read(); Array valuesArray = gainValue.read(); for (int i = 0; i < recordCount; i++) { gainInfoMap.put(settingsArray.getInt(i), valuesArray.getFloat(i)); } return gainInfoMap; } } throw new IOException("Failed to read 'Gain Info' Structure."); }
private void makeEnsembleCoordinate(NetcdfFile ncfile, Group g, CoordinateEns ec) { int n = ec.getSize(); String ecName = ec.getName().toLowerCase(); ncfile.addDimension(g, new Dimension(ecName, n)); Variable v = new Variable(ncfile, g, null, ecName, DataType.INT, ecName); ncfile.addVariable(g, v); v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Ensemble.toString())); int[] data = new int[n]; int count = 0; for (EnsCoord.Coord ecc : ec.getEnsSorted()) data[count++] = ecc.getEnsMember(); v.setCachedData(Array.factory(DataType.INT, new int[]{n}, data)); }
@Test public void testHybridCoordinates() throws IOException { String filename = TestDir.cdmUnitTestDir + "formats/grib1/07010418_arw_d01.GrbF01500"; System.out.println("\n\nReading File " + filename); NetcdfFile ncfile = NetcdfFile.open(filename); Group best = ncfile.findGroup("Best"); Variable hybrid = ncfile.findVariable(best, "hybrid1"); assert hybrid != null; assert (hybrid.getDimensions().size() == 1); Dimension d = hybrid.getDimension(0); assert (d.getLength() == 2); ncfile.close(); }
private void initProductWidthAndHeight() { sceneRasterHeight = 0; for (Variable variable : netcdfFile.getVariables()) { Attribute gridMappingAttr = variable.findAttribute("grid_mapping_name"); if (gridMappingAttr != null) { if ("1D binned sinusoidal".equalsIgnoreCase(gridMappingAttr.getStringValue())) { Attribute numberOfLatitudeRows = variable.findAttribute("number_of_latitude_rows"); sceneRasterHeight = numberOfLatitudeRows.getNumericValue().intValue(); break; } } } if (sceneRasterHeight == 0) { final Dimension bin_index = netcdfFile.findDimension("bin_index"); if (bin_index != null) { sceneRasterHeight = bin_index.getLength(); } } if (sceneRasterHeight == 0) { sceneRasterHeight = 2160; } sceneRasterWidth = 2 * sceneRasterHeight; }
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 boolean computeIsInterval() { intervalWasComputed = true; Attribute boundsAtt = findAttributeIgnoreCase(CF.BOUNDS); if ((null == boundsAtt) || !boundsAtt.isString()) return false; String boundsVarName = boundsAtt.getStringValue(); VariableDS boundsVar = (VariableDS) ncd.findVariable(getParentGroup(), boundsVarName); if (null == boundsVar) return false; if (3 != boundsVar.getRank()) return false; if (getDimension(0) != boundsVar.getDimension(0)) return false; return 2 == boundsVar.getDimension(2).getLength(); }
private CoordinateAxis makeFakeCoordAxis(NetcdfDataset ds, String axisName, Dimension dim) { if (dim == null) return null; CoordinateAxis v = new CoordinateAxis1D(ds, null, axisName, DataType.SHORT, dim.getShortName(), "", "synthesized coordinate: only an index"); v.addAttribute(new Attribute(_Coordinate.AxisType, "GeoZ")); if (!axisName.equals(dim.getShortName())) v.addAttribute(new Attribute(_Coordinate.AliasForDimension, dim.getShortName())); ds.setValues(v, dim.getLength(), 0, 1); return v; }
/** * Find structure variable of rank 2 withe the nameed dimensions * @param ds in this dataset * @param dim0 first dimension * @param dim1 second dimension * @return structure variable or null */ static public Structure findStructureWithDimensions(NetcdfDataset ds, Dimension dim0, Dimension dim1) { for (Variable v : ds.getVariables()) { if ((v instanceof Structure) && (v.getRank() == 2)) { if (v.getDimension(0).equals(dim0) && v.getDimension(1).equals(dim1)) return (Structure) v; } } return null; }