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; }
public static NetcdfDataset acquireFeatureCollection(String path) throws IOException { Formatter formatter = new Formatter(System.err); FeatureCollectionConfigBuilder builder = new FeatureCollectionConfigBuilder(formatter); FeatureCollectionConfig config = builder.readConfigFromFile( path.toString()); // this is the path to the feature collection XML Fmrc fmrc = Fmrc.open(config, formatter); NetcdfDataset dataset = new NetcdfDataset(); fmrc.getDataset2D(dataset); dataset.setLocation(path); return dataset; }
/** Construtor when theres a NetcdfFile underneath * @param ncfile adapt this NetcdfDataset */ public TypedDatasetImpl(NetcdfDataset ncfile) { this.ncfile = ncfile; this.location = ncfile.getLocation(); this.title = ncfile.getTitle(); if (title == null) title = ncfile.findAttValueIgnoreCase(null, "title", null); if (desc == null) desc = ncfile.findAttValueIgnoreCase(null, "description", null); }
Set<String> unsupported = NetCDFUtilities.getUnsupportedDimensions(); Set<String> ignored = NetCDFUtilities.getIgnoredDimensions(); for (CoordinateAxis axis : dataset.getCoordinateAxes()) { final int axisDimensions = axis.getDimensions().size(); if (axisDimensions > 0 && axisDimensions < 3) { + axis + " in input: " + dataset.getLocation() + " has been found");
public void check(Formatter f) { for (Variable v : getVariables()) { VariableDS vds = (VariableDS) v; if (vds.getOriginalDataType() != vds.getDataType()) { f.format("Variable %s has type %s, org = %s%n", vds.getFullName(), vds.getOriginalDataType(), vds.getDataType()); } if (vds.getOriginalVariable() != null) { Variable orgVar = vds.getOriginalVariable(); if (orgVar.getRank() != vds.getRank()) f.format("Variable %s has rank %d, org = %d%n", vds.getFullName(), vds.getRank(), orgVar.getRank()); } } }
/** * Find the variable pointed to by key * * @param ds in this dataset * @param key may be variable name or ":gatt" where gatt is local attribute whose value is the variable name * @param errlog error messages here * @return name of variable or null if not exist */ static public String getVariableName(NetcdfDataset ds, String key, Formatter errlog) { Variable v = null; String vs = getLiteral(ds, key, errlog); if (vs != null) { v = ds.findVariable(vs); if ((v == null) && (errlog != null)) errlog.format(" Cant find Variable %s from %s%n", vs, key); } return v == null ? null : v.getShortName(); }
protected String getFormula(NetcdfDataset ds, Variable ctv) { String formula = ds.findAttValueIgnoreCase(ctv, "formula_terms", null); if (null == formula) { if (null != errBuffer) errBuffer.format("CoordTransBuilder %s: needs attribute 'formula_terms' on Variable %s%n", getTransformName(), ctv.getFullName()); return null; } return formula; }
static void doit(PointDatasetStandardFactory fac, String filename) throws IOException { System.out.println(filename); Formatter errlog = new Formatter(System.out); NetcdfDataset ncd = ucar.nc2.dataset.NetcdfDataset.openDataset(filename); TableAnalyzer analysis = (TableAnalyzer) fac.isMine(FeatureType.ANY_POINT, ncd, errlog); fac.open(FeatureType.ANY_POINT, ncd, analysis, null, errlog); analysis.getDetailInfo(errlog); System.out.printf("\n-----------------"); ncd.close(); }
static void test(String location, String timeVarName) throws IOException { FmrcImpl fmrc = new FmrcImpl(location); System.out.println("Fmrc for dataset= " + location); NetcdfDataset fmrcd = fmrc.getFmrcDataset(); Variable time = fmrcd.findVariable(timeVarName); Array data = time.read(); NCdumpW.printArray(data, "2D time", new PrintWriter( System.out), null); fmrc.dump(new Formatter(System.out)); }
static void doit(String filename) throws IOException { System.out.println(filename); NetcdfDataset ncd = ucar.nc2.dataset.NetcdfDataset.openDataset(filename); TableAnalyzer csa = TableAnalyzer.factory(null, null, ncd); csa.getDetailInfo(new Formatter(System.out)); System.out.println("%n-----------------"); }
NetcdfFile ncFile = NetcdfDataset.openFile(gribFile.getAbsolutePath(), null); 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.element("li", dim.getFullName() + "=" + String.valueOf(dim.getLength()) + ";"); xhtml.newline(); xhtml.element("p", String.valueOf(var.getDataType()) + var.getNameAndDimensions() + ";"); for(Attribute element : var.getAttributes()){ xhtml.element("li", " :" + element + ";"); xhtml.newline();
public float getT(String tName, int swpNumber, int ray) throws IOException { Array timeData = ds.findVariable(tName).read(); Index timeIndex = timeData.getIndex(); return timeData.getFloat(timeIndex.set(swpNumber, ray)); }
private NetcdfDataset createDataset(InventoryGetter invGetter, String type, String name) throws IOException { NetcdfDataset newds = new NetcdfDataset(); newds.setLocation(makeLocation(type, name)); Group src = ncd_2dtime.getRootGroup(); Group target = newds.getRootGroup(); for (Attribute a : src.getAttributes()) { target.addAttribute(a); String oldHistory = ncd_2dtime.findAttValueIgnoreCase(null, CDM.HISTORY, null); String newHistory = "Synthetic dataset from TDS fmrc (" + type + ") aggregation, original data from " + ncd_2dtime.getLocation(); String history = (oldHistory != null) ? oldHistory + "; " + newHistory : newHistory; target.addAttribute(new Attribute(CDM.HISTORY, history)); target.addAttribute(new Attribute(_Coordinate.ModelBaseDate, df.toDateTimeStringISO(baseDate))); Variable orgVar = ncd_2dtime.findVariable(grid.getVariable().getFullNameEscaped()); for (Variable v : src.getVariables()) { if ((null == gridHash.get(v.getFullName()) && !coordSet.contains(v.getFullName()))) { VariableDS vds = new VariableDS(newds.getRootGroup(), v, false); // reparent LOOK fishy !!!! vds.clearCoordinateSystems(); vds.remove(vds.findAttribute("coordinates")); newds.finish(); newds.enhance(EnumSet.of(NetcdfDataset.Enhance.CoordSystems));
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(); }
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 void addLongName(NetcdfDataset ds, String varName, String longName) { Variable v = ds.findVariable(varName); if (v != null) v.addAttribute(new Attribute(CDM.LONG_NAME, longName)); }
@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()); } }
protected Variable findVariableWithStandardNameAndNotDimension(NetcdfDataset ds, String standard_name, Dimension outer, Formatter errlog) { for (Variable v : ds.getVariables()) { String stdName = ds.findAttValueIgnoreCase(v, CF.STANDARD_NAME, null); if ((stdName != null) && stdName.equals(standard_name) && v.getRank() > 0 && !v.getDimension(0).equals(outer)) return v; } return null; }
private boolean addTimeCoordinate(NetcdfDataset ds) { // add time coordinate CalendarDate cd = parseFilenameForDate(ds.getLocation()); if (cd == null) return false; ds.addAttribute(ds.getRootGroup(), new Attribute("_MODIS_Date", cd.toString())); // add the time dimension int nTimesDim = 1; Dimension newDim = new Dimension(TIME_NAME, nTimesDim); ds.addDimension( null, newDim); // add the coordinate variable String units = "seconds since "+cd.toString(); String desc = "time coordinate"; Array data = Array.makeArray(DataType.DOUBLE, 1, 0.0, 0.0) ; CoordinateAxis1D timeCoord = new CoordinateAxis1D( ds, null, TIME_NAME, DataType.DOUBLE, "", units, desc); timeCoord.setCachedData(data, true); timeCoord.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Time.toString())); ds.addCoordinateAxis(timeCoord); return true; }
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; }