public TableConfig getConfig(FeatureType wantFeatureType, NetcdfDataset ds, Formatter errlog) throws IOException { TableConfig topTable = new TableConfig(Table.Type.Top, "singleTrajectory"); CoordinateAxis coordAxis = CoordSysEvaluator.findCoordByType(ds, AxisType.Time); if (coordAxis == null) { errlog.format("Cant find a time coordinate"); return null; } final Dimension innerDim = coordAxis.getDimension(0); boolean obsIsStruct = Evaluator.hasNetcdf3RecordStructure(ds) && innerDim.isUnlimited(); TableConfig obsTable = new TableConfig(Table.Type.Structure, innerDim.getShortName()); obsTable.dimName = innerDim.getShortName(); obsTable.time = coordAxis.getFullName(); obsTable.structName = obsIsStruct ? "record" : innerDim.getShortName(); obsTable.structureType = obsIsStruct ? TableConfig.StructureType.Structure : TableConfig.StructureType.PsuedoStructure; CoordSysEvaluator.findCoords( obsTable, ds, new CoordSysEvaluator.Predicate() { public boolean match(CoordinateAxis axis) { return innerDim.equals(axis.getDimension(0)); } }); topTable.addChild(obsTable); return topTable; }
public static DateRange extractDateRange(GridDataset gridDataset) { DateRange maxDateRange = null; for (GridDataset.Gridset gridset : gridDataset.getGridsets()) { GridCoordSystem gsys = gridset.getGeoCoordSystem(); DateRange dateRange; CoordinateAxis1DTime time1D = gsys.getTimeAxis1D(); if (time1D != null) { dateRange = time1D.getDateRange(); } else { CoordinateAxis time = gsys.getTimeAxis(); if (time == null) continue; try { DateUnit du = new DateUnit(time.getUnitsString()); Date minDate = du.makeDate(time.getMinValue()); Date maxDate = du.makeDate(time.getMaxValue()); dateRange = new DateRange(minDate, maxDate); } catch (Exception e) { logger.warn("Illegal Date Unit " + time.getUnitsString()); continue; } } if (maxDateRange == null) maxDateRange = dateRange; else maxDateRange.extend(dateRange); } return maxDateRange; }
static void doOne( String dir, String filename, int ngrids, int ncoordSys, int ncoordAxes, int nVertCooordAxes) throws Exception { System.out.println("test read GridDataset = " + dir + filename); ucar.nc2.dt.grid.GridDataset gridDs = GridDataset.open(dir + filename); int countGrids = gridDs.getGrids().size(); int countCoordAxes = gridDs.getNetcdfDataset().getCoordinateAxes().size(); int countCoordSys = gridDs.getNetcdfDataset().getCoordinateSystems().size(); // count vertical axes int countVertCooordAxes = 0; List axes = gridDs.getNetcdfDataset().getCoordinateAxes(); for (int i = 0; i < axes.size(); i++) { CoordinateAxis axis = (CoordinateAxis) axes.get(i); AxisType t = axis.getAxisType(); if ((t == AxisType.GeoZ) || (t == AxisType.Height) || (t == AxisType.Pressure)) countVertCooordAxes++; } Iterator iter = gridDs.getGridsets().iterator(); while (iter.hasNext()) { GridDataset.Gridset gridset = (GridDataset.Gridset) iter.next(); GridCoordSys gcs = gridset.getGeoCoordSys(); // if (gcs.hasTimeAxis()) // System.out.println(" "+gcs.isDate()+" "+gcs.getName()); } if (showCount) { System.out.println(" grids=" + countGrids + ((ngrids < 0) ? " *" : "")); System.out.println(" coordSys=" + countCoordSys + ((ncoordSys < 0) ? " *" : "")); System.out.println(" coordAxes=" + countCoordAxes + ((ncoordAxes < 0) ? " *" : "")); System.out.println(" vertAxes=" + countVertCooordAxes + ((nVertCooordAxes < 0) ? " *" : "")); } if (ngrids >= 0) assert ngrids == countGrids : "Grids " + ngrids + " != " + countGrids; // if (ncoordSys >= 0) // assert ncoordSys == countCoordSys : "CoordSys " + ncoordSys + " != " + countCoordSys; // if (ncoordAxes >= 0) // assert ncoordAxes == countCoordAxes : "CoordAxes " + ncoordAxes + " != " + countCoordAxes; if (nVertCooordAxes >= 0) assert nVertCooordAxes == countVertCooordAxes : "VertAxes " + nVertCooordAxes + " != " + countVertCooordAxes; gridDs.close(); }
private void showValuesAsDates(CoordinateAxis axis) { String units = axis.getUnitsString(); String cal = getCalendarAttribute(axis); CalendarDateUnit cdu = CalendarDateUnit.of(cal, units); try { infoTA.appendLine(units); infoTA.appendLine(NCdumpW.printVariableData(axis, null)); if (axis.getDataType().isNumeric()) { if (axis instanceof CoordinateAxis2D) { showDates2D((CoordinateAxis2D) axis, cdu); } else if (axis instanceof CoordinateAxis1D) { // 1D showDates1D((CoordinateAxis1D) axis, cdu); } else { // > 2D Array data = axis.read(); IndexIterator ii = data.getIndexIterator(); while (ii.hasNext()) { double val = ii.getDoubleNext(); infoTA.appendLine(makeCalendarDateStringOrMissing(cdu, val)); } } } else { // must be iso dates Array data = axis.read(); Formatter f = new Formatter(); if (data instanceof ArrayChar) { ArrayChar dataS = (ArrayChar) data; ArrayChar.StringIterator iter = dataS.getStringIterator(); while (iter.hasNext()) f.format(" %s%n", iter.next()); infoTA.appendLine(f.toString()); } else if (data instanceof ArrayObject) { IndexIterator iter = data.getIndexIterator(); while (iter.hasNext()) f.format(" %s%n", iter.next()); infoTA.appendLine(f.toString()); } } } catch (Exception ex) { ex.printStackTrace(); infoTA.appendLine(ex.getMessage()); } }
private void showValues(CoordinateAxis axis) { try { if (axis instanceof CoordinateAxis1D && axis.isNumeric()) { CoordinateAxis1D axis1D = (CoordinateAxis1D) axis; printArray("midpoints=", axis1D.getCoordValues()); if (!axis1D.isInterval()) { printArray("edges=", axis1D.getCoordEdges()); } else { printArray("bound1=", axis1D.getBound1()); printArray("bound2=", axis1D.getBound2()); Formatter f = new Formatter(); double[] mid = axis1D.getCoordValues(); double[] b1 = axis1D.getBound1(); double[] b2 = axis1D.getBound2(); for (int i = 0; i < b1.length; i++) { f.format("%f (%f,%f) = %f%n", mid[i], b1[i], b2[i], b2[i] - b1[i]); } infoTA.appendLine(f.toString()); } } else if (axis instanceof CoordinateAxis2D && axis.isNumeric()) { infoTA.appendLine(NCdumpW.printVariableData(axis, null)); showValues2D((CoordinateAxis2D) axis); } else { infoTA.appendLine(NCdumpW.printVariableData(axis, null)); } } catch (IOException e1) { e1.printStackTrace(); infoTA.appendLine(e1.getMessage()); } }
public AxisBean(CoordinateAxis v) { this.axis = v; setName(v.getFullName()); setCoordVar(v.isCoordinateVariable()); setDescription(v.getDescription()); setUnits(v.getUnitsString()); // collect dimensions StringBuilder lens = new StringBuilder(); StringBuilder names = new StringBuilder(); java.util.List dims = v.getDimensions(); for (int j = 0; j < dims.size(); j++) { ucar.nc2.Dimension dim = (ucar.nc2.Dimension) dims.get(j); if (j > 0) { lens.append(","); names.append(","); } String name = dim.isShared() ? dim.getShortName() : "anon"; names.append(name); lens.append(dim.getLength()); } setDims(names.toString()); setShape(lens.toString()); AxisType at = v.getAxisType(); if (at != null) setAxisType(at.toString()); String p = v.getPositive(); if (p != null) setPositive(p); if (v instanceof CoordinateAxis1D) { CoordinateAxis1D v1 = (CoordinateAxis1D) v; if (v1.isRegular()) setRegular(Double.toString(v1.getIncrement())); } isLayer = (null != axis.findAttribute(_Coordinate.ZisLayer)); isInterval = axis.isInterval(); }
private void showValueDiffs(CoordinateAxis axis) { if (!axis.isNumeric()) return; try { if (axis instanceof CoordinateAxis1D) { CoordinateAxis1D axis1D = (CoordinateAxis1D) axis; double[] mids = axis1D.getCoordValues(); double[] diffs = new double[mids.length]; for (int i = 0; i < mids.length - 1; i++) diffs[i] = mids[i + 1] - mids[i]; printArrays("midpoint differences", mids, diffs); } else if (axis instanceof CoordinateAxis2D) { CoordinateAxis2D axis2D = (CoordinateAxis2D) axis; ArrayDouble.D2 mids = axis2D.getCoordValuesArray(); int[] shape = mids.getShape(); ArrayDouble.D2 diffx = (ArrayDouble.D2) Array.factory(DataType.DOUBLE, new int[] {shape[0], shape[1] - 1}); for (int j = 0; j < shape[0]; j++) { for (int i = 0; i < shape[1] - 1; i++) { double diff = mids.get(j, i + 1) - mids.get(j, i); diffx.set(j, i, diff); } } infoTA.appendLine(NCdumpW.toString(diffx, "diff in x", null)); ArrayDouble.D2 diffy = (ArrayDouble.D2) Array.factory(DataType.DOUBLE, new int[] {shape[0] - 1, shape[1]}); for (int j = 0; j < shape[0] - 1; j++) { for (int i = 0; i < shape[1]; i++) { double diff = mids.get(j + 1, i) - mids.get(j, i); diffy.set(j, i, diff); } } infoTA.appendLine("\n\n\n"); infoTA.appendLine(NCdumpW.toString(diffy, "diff in y", null)); } } catch (Exception e1) { e1.printStackTrace(); infoTA.appendLine(e1.getMessage()); } }
public boolean isContig() { return axis.isContiguous(); }