protected void setTimeUnits() throws Exception { CoordinateAxis axis = ds.findCoordinateAxis(AxisType.Time); if (axis == null) { parseInfo.append("*** Time Units not Found\n"); } else { String units = axis.getUnitsString(); dateUnits = new DateUnit(units); } }
protected void setTimeUnits() throws Exception { CoordinateAxis axis = ds.findCoordinateAxis(AxisType.Time); if (axis == null) { parseInfo.append("*** Time Units not Found\n"); } else { String units = axis.getUnitsString(); dateUnits = new DateUnit(units); calDateUnits = CalendarDateUnit.of(null, units); } }
protected void setTimeUnits() throws Exception { CoordinateAxis axis = ds.findCoordinateAxis(AxisType.Time); if (axis == null) { parseInfo.append("*** Time Units not Found\n"); } else { String units = axis.getUnitsString(); dateUnits = new DateUnit(units); calDateUnits = CalendarDateUnit.of(null, units); } }
protected void setStartDate() { String start_datetime = ds.findAttValueIgnoreCase(null, "time_coverage_start", null); if (start_datetime != null) { startDate = DateUnit.getStandardOrISO(start_datetime); return; } else { CoordinateAxis axis = ds.findCoordinateAxis(AxisType.Time); if (axis != null) { double val = axis.getMinValue(); startDate = dateUnits.makeDate(val); return; } } parseInfo.append("*** start_datetime not Found\n"); }
protected void setStartDate() { String start_datetime = ds.findAttValueIgnoreCase(null, "time_coverage_start", null); if (start_datetime != null) { startDate = DateUnit.getStandardOrISO(start_datetime); return; } else { CoordinateAxis axis = ds.findCoordinateAxis(AxisType.Time); if (axis != null) { double val = axis.getMinValue(); startDate = dateUnits.makeDate(val); return; } } parseInfo.append("*** start_datetime not Found\n"); }
protected void setEndDate() { String end_datetime = ds.findAttValueIgnoreCase(null, "time_coverage_end", null); if (end_datetime != null) { endDate = DateUnit.getStandardOrISO(end_datetime); } else { CoordinateAxis axis = ds.findCoordinateAxis(AxisType.Time); if (axis != null) { double val = axis.getMaxValue(); endDate = dateUnits.makeDate(val); return; } } parseInfo.append("*** end_datetime not Found\n"); }
protected void setStartDate() { String start_datetime = ds.findAttValueIgnoreCase(null, "time_coverage_start", null); if (start_datetime != null) { startDate = DateUnit.getStandardOrISO(start_datetime); return; } else { CoordinateAxis axis = ds.findCoordinateAxis(AxisType.Time); if (axis != null) { double val = axis.getMinValue(); startDate = dateUnits.makeDate(val); return; } } parseInfo.append("*** start_datetime not Found\n"); }
protected void setEndDate() { String end_datetime = ds.findAttValueIgnoreCase(null, "time_coverage_end", null); if (end_datetime != null) { endDate = DateUnit.getStandardOrISO(end_datetime); } else { CoordinateAxis axis = ds.findCoordinateAxis(AxisType.Time); if (axis != null) { double val = axis.getMaxValue(); endDate = dateUnits.makeDate(val); return; } } parseInfo.append("*** end_datetime not Found\n"); }
protected void setEndDate() { String end_datetime = ds.findAttValueIgnoreCase(null, "time_coverage_end", null); if (end_datetime != null) { endDate = DateUnit.getStandardOrISO(end_datetime); } else { CoordinateAxis axis = ds.findCoordinateAxis(AxisType.Time); if (axis != null) { double val = axis.getMaxValue(); endDate = dateUnits.makeDate(val); return; } } parseInfo.append("*** end_datetime not Found\n"); }
private CoordinateSystem findReplacementCs(CoordinateSystem protoCs, String timeDim, NetcdfDataset result) { CoordinateSystem replace = result.findCoordinateSystem(protoCs.getName()); if (replace != null) return replace; List<CoordinateAxis> axes = new ArrayList<>(); for (CoordinateAxis axis : protoCs.getCoordinateAxes()) { CoordinateAxis ra = result.findCoordinateAxis(axis.getFullNameEscaped()); axes.add(ra); } // coord transforms are immutable and can be shared CoordinateSystem cs = new CoordinateSystem(result, axes, protoCs.getCoordinateTransforms()); result.addCoordinateSystem(cs); return cs; }
/** * Add a CoordinateAxis to the dataset, by turning the VariableDS into a CoordinateAxis (if needed). * Also adds it to the list of variables. Replaces any existing Variable and CoordinateAxis with the same name. * * @param v make this VariableDS into a CoordinateAxis * @return the CoordinateAxis */ public CoordinateAxis addCoordinateAxis(VariableDS v) { if (v == null) return null; CoordinateAxis oldVar = findCoordinateAxis(v.getFullName()); if (oldVar != null) coordAxes.remove(oldVar); CoordinateAxis ca = (v instanceof CoordinateAxis) ? (CoordinateAxis) v : CoordinateAxis.factory(this, v); coordAxes.add(ca); if (v.isMemberOfStructure()) { Structure parentOrg = v.getParentStructure(); // gotta be careful to get the wrapping parent Structure parent = (Structure) findVariable(parentOrg.getFullNameEscaped()); parent.replaceMemberVariable(ca); } else { removeVariable(v.getParentGroup(), v.getShortName()); // remove by short name if it exists addVariable(ca.getParentGroup(), ca); } return ca; }
/** * Add a CoordinateAxis to the dataset, by turning the VariableDS into a CoordinateAxis (if needed). * Also adds it to the list of variables. Replaces any existing Variable and CoordinateAxis with the same name. * * @param v make this VariableDS into a CoordinateAxis * @return the CoordinateAxis */ public CoordinateAxis addCoordinateAxis(VariableDS v) { if (v == null) return null; CoordinateAxis oldVar = findCoordinateAxis(v.getFullName()); if (oldVar != null) coordAxes.remove(oldVar); CoordinateAxis ca = (v instanceof CoordinateAxis) ? (CoordinateAxis) v : CoordinateAxis.factory(this, v); coordAxes.add(ca); if (v.isMemberOfStructure()) { Structure parentOrg = v.getParentStructure(); // gotta be careful to get the wrapping parent Structure parent = (Structure) findVariable(parentOrg.getFullNameEscaped()); parent.replaceMemberVariable(ca); } else { removeVariable(v.getParentGroup(), v.getShortName()); // remove by short name if it exists addVariable(ca.getParentGroup(), ca); } return ca; }
/** * Add a CoordinateAxis to the dataset, by turning the VariableDS into a CoordinateAxis (if needed). * Also adds it to the list of variables. Replaces any existing Variable and CoordinateAxis with the same name. * * @param v make this VariableDS into a CoordinateAxis * @return the CoordinateAxis */ public CoordinateAxis addCoordinateAxis(VariableDS v) { if (v == null) return null; CoordinateAxis oldVar = findCoordinateAxis(v.getFullName()); if (oldVar != null) coordAxes.remove(oldVar); CoordinateAxis ca = (v instanceof CoordinateAxis) ? (CoordinateAxis) v : CoordinateAxis.factory(this, v); coordAxes.add(ca); if (v.isMemberOfStructure()) { Structure parentOrg = v.getParentStructure(); // gotta be careful to get the wrapping parent Structure parent = (Structure) findVariable(parentOrg.getFullNameEscaped()); parent.replaceMemberVariable(ca); } else { removeVariable(v.getParentGroup(), v.getShortName()); // remove by short name if it exists addVariable(ca.getParentGroup(), ca); } return ca; }
private CoordinateSystem findReplacementCs(CoordinateSystem protoCs, String timeDim, NetcdfDataset result) { CoordinateSystem replace = result.findCoordinateSystem(protoCs.getName()); if (replace != null) return replace; List<CoordinateAxis> axes = new ArrayList<CoordinateAxis>(); for (CoordinateAxis axis : protoCs.getCoordinateAxes()) { Variable v = result.findCoordinateAxis(axis.getFullNameEscaped()); CoordinateAxis ra; if (v instanceof CoordinateAxis) ra = (CoordinateAxis) v; else { // if not a CoordinateAxis, will turn into one ra = result.addCoordinateAxis((VariableDS) v); if (axis.getAxisType() != null) { ra.setAxisType(axis.getAxisType()); ra.addAttribute(new Attribute(_Coordinate.AxisType, axis.getAxisType().toString())); } } axes.add(ra); } // coord transforms are immutable and can be shared CoordinateSystem cs = new CoordinateSystem(result, axes, protoCs.getCoordinateTransforms()); result.addCoordinateSystem(cs); return cs; }
private CoordinateSystem findReplacementCs(CoordinateSystem protoCs, String timeDim, NetcdfDataset result) { CoordinateSystem replace = result.findCoordinateSystem(protoCs.getName()); if (replace != null) return replace; List<CoordinateAxis> axes = new ArrayList<CoordinateAxis>(); for (CoordinateAxis axis : protoCs.getCoordinateAxes()) { Variable v = result.findCoordinateAxis(axis.getFullNameEscaped()); CoordinateAxis ra; if (v instanceof CoordinateAxis) ra = (CoordinateAxis) v; else { // if not a CoordinateAxis, will turn into one ra = result.addCoordinateAxis((VariableDS) v); if (axis.getAxisType() != null) { ra.setAxisType(axis.getAxisType()); ra.addAttribute(new Attribute(_Coordinate.AxisType, axis.getAxisType().toString())); } } axes.add(ra); } // coord transforms are immutable and can be shared CoordinateSystem cs = new CoordinateSystem(result, axes, protoCs.getCoordinateTransforms()); result.addCoordinateSystem(cs); return cs; }
@Category(NeedsCdmUnitTest.class) public void testWrapOnce() throws IOException { String filename = TestDir.cdmUnitTestDir + "ncml/coords/testCoordScaling.ncml"; System.out.printf("%s%n", filename); NetcdfDataset ncd = ucar.nc2.dataset.NetcdfDataset.openDataset(filename); Variable v = ncd.findCoordinateAxis("Longitude"); assert v != null; assert v instanceof CoordinateAxis1D; // if offset is applied twice, the result is not in +-180 range Array data = v.read(); logger.debug(NCdumpW.toString(data)); IndexIterator ii = data.getIndexIterator(); while (ii.hasNext()) { assert Math.abs(ii.getDoubleNext()) < 180 : ii.getDoubleCurrent(); } ncd.close(); }
@Override public double[] readCoordValues(CoverageCoordAxis coordAxis) throws IOException { ucar.nc2.dataset.CoordinateAxis dtCoordAxis = proxy.getNetcdfDataset().findCoordinateAxis(coordAxis.getName()); if (dtCoordAxis == null) throw new IllegalStateException("Cants find Coordinate Axis " + coordAxis.getName());
@Category(NeedsCdmUnitTest.class) public void testAlias() throws IOException { String filename = TestDir.cdmUnitTestDir + "ft/grid/ensemble/demeter/MM_cnrm_129_red.ncml"; NetcdfDataset ncd = ucar.nc2.dataset.NetcdfDataset.openDataset(filename); Variable v = ncd.findCoordinateAxis("number"); assert v != null; //assert v.isCoordinateVariable(); assert v instanceof CoordinateAxis1D; assert null != ncd.findDimension("ensemble"); assert v.getDimension(0) == ncd.findDimension("ensemble"); ncd.close(); }
@Test public void testWrfTimeUnderscore() throws IOException { String tstFile = TestDir.cdmLocalTestDataDir +"wrf/WrfTimesStrUnderscore.nc"; System.out.println(tstFile); String wrfConvention = new WRFConvention().getConventionUsed(); NetcdfDataset ncd = NetcdfDataset.openDataset(tstFile); // make sure this file went through the WrfConvention assert ncd.getConventionUsed().equals(wrfConvention); CoordinateAxis tca = ncd.findCoordinateAxis(AxisType.Time); Array times = tca.read(); ncd.close(); // if the date/time string cannot be parsed (in this case, 2008-06-27_00:00:00) // the the time will come back as 0 seconds after going through the WRFConvention // coordinate system builder class. assert times.getInt(0) != 0; // first date in this file is 1214524800 [seconds since 1970-01-01T00:00:00], // which is 2008-06-27 00:00:00 assert times.getInt(0) == 1214524800; }
NetcdfDataset ds = new NetcdfDataset(nf); CoordinateAxis1DTime tAxis = CoordinateAxis1DTime.factory(ds, ds.findCoordinateAxis("time"), null); List<CalendarDate> dates = tAxis.getCalendarDates(); assert dates != null;