private int findTimeIndexForCalendarDate(GridCoordSystem gcs, CalendarDate date){ CoordinateAxis1DTime timeAxis = gcs.getTimeAxis1D(); return timeAxis.findTimeIndexFromCalendarDate(date); }
private int findTimeIndexForCalendarDate(GridCoordSystem gcs, CalendarDate date){ CoordinateAxis1DTime timeAxis = gcs.getTimeAxis1D(); return timeAxis.findTimeIndexFromCalendarDate(date); }
private int findTimeIndexForCalendarDate(GridCoordSystem gcs, CalendarDate date){ CoordinateAxis1DTime timeAxis = gcs.getTimeAxis1D(); return timeAxis.findTimeIndexFromCalendarDate(date); }
public boolean hasTime( GridDatatype grid, CalendarDate date) { GridCoordSystem gcs = grid.getCoordinateSystem(); CoordinateAxis1DTime timeAxis = gcs.getTimeAxis1D(); return (timeAxis != null) && timeAxis.hasCalendarDate( date); }
public boolean hasTime( GridDatatype grid, CalendarDate date) { GridCoordSystem gcs = grid.getCoordinateSystem(); CoordinateAxis1DTime timeAxis = gcs.getTimeAxis1D(); return (timeAxis != null) && timeAxis.hasCalendarDate( date); }
public boolean hasTime( GridDatatype grid, CalendarDate date) { GridCoordSystem gcs = grid.getCoordinateSystem(); CoordinateAxis1DTime timeAxis = gcs.getTimeAxis1D(); return (timeAxis != null) && timeAxis.hasCalendarDate( date); }
private Element genDomainSetElem( WcsCoverage coverage) { // ../domainSet Element domainSetElem = new Element( "domainSet", wcsNS); // ../domainSet/spatialDomain [0..1] AND/OR temporalDomain [0..1] domainSetElem.addContent( genSpatialDomainElem( coverage) ); if ( coverage.getCoordinateSystem().hasTimeAxis() ) { domainSetElem.addContent( genTemporalDomainElem( coverage.getCoordinateSystem().getTimeAxis1D() ) ); } return domainSetElem; }
private Element genDomainSetElem( WcsCoverage coverage) { // ../domainSet Element domainSetElem = new Element( "domainSet", wcsNS); // ../domainSet/spatialDomain [0..1] AND/OR temporalDomain [0..1] domainSetElem.addContent( genSpatialDomainElem( coverage) ); if ( coverage.getCoordinateSystem().hasTimeAxis() ) { domainSetElem.addContent( genTemporalDomainElem( coverage.getCoordinateSystem().getTimeAxis1D() ) ); } return domainSetElem; }
public static void main(String[] args) throws IOException { GridDataset gds = ucar.nc2.dt.grid.GridDataset.open(args[0]); ucar.nc2.dt.GridDatatype grid = gds.findGridDatatype( args[1]); ucar.nc2.dt.GridCoordSystem gcs = grid.getCoordinateSystem(); CoordinateAxis xAxis = gcs.getXHorizAxis(); CoordinateAxis yAxis = gcs.getXHorizAxis(); CoordinateAxis1D zAxis = gcs.getVerticalAxis(); // may be null if (gcs.hasTimeAxis1D()) { CoordinateAxis1D tAxis = gcs.getTimeAxis1D(); } else if (gcs.hasTimeAxis()) { CoordinateAxis tAxis = gcs.getTimeAxis(); } } }
public void testConventionsMultiple() throws IOException { //String filename = TestDir.cdmUnitTestDir + "ft/grid/ensemble/demeter/MM_cnrm_129_red.ncml"; String filename = "G:/work/lmoxey/PF5_SST_Climatology_Monthly_1982_2008.ncml"; GridDataset ncd = GridDataset.open(filename); Attribute convAtt = ncd.findGlobalAttributeIgnoreCase("Conventions"); assert convAtt != null; System.out.printf("%s%n", convAtt); GeoGrid grid = ncd.findGridByName("sst"); GridCoordSystem gcs = grid.getCoordinateSystem(); CoordinateAxis1DTime time = gcs.getTimeAxis1D(); assert time != null; /* Variable v = ncd.getDetailInfo("TIME"); assert v != null; //assert v.isCoordinateVariable(); assert v instanceof CoordinateAxis1DTime; CoordinateAxis1DTime axis = (CoordinateAxis1DTime) v; List<CalendarDate> dates = axis.getCalendarDates(); for (CalendarDate d : dates) System.out.printf("%s%n", d); */ ncd.close(); }
@Test public void testFloatingPointCompare() throws Exception { String spec = TestDir.cdmUnitTestDir+"ft/fmrc/fp_precision/sediment_thickness_#yyMMddHHmm#.*\\.nc$"; System.out.printf("%n====================FMRC dataset %s%n", spec); Formatter errlog = new Formatter(); Fmrc fmrc = Fmrc.open(spec, errlog); assert (fmrc != null) : errlog; try (ucar.nc2.dt.GridDataset gridDs = fmrc.getDatasetBest()) { GridDatatype v = gridDs.findGridByShortName("thickness_of_sediment"); assert v != null; GridCoordSystem gcs = v.getCoordinateSystem(); CoordinateAxis1DTime time = gcs.getTimeAxis1D(); Assert.assertEquals("hours since 2015-03-08 12:51:00.000 UTC", time.getUnitsString()); Assert.assertEquals(74, time.getSize()); Array data = time.read(); logger.debug("{}", NCdumpW.toString(data)); for (CalendarDate cd : time.getCalendarDates()) { assert cd.getFieldValue(CalendarPeriod.Field.Minute) == 0 : System.out.printf("%s%n", cd); } } } }
private void doRead4Volume( GridDataset ds, String varName) throws IOException { GeoGrid gg = ds.findGridByName( varName); CoordinateAxis1D timeAxis = gg.getCoordinateSystem().getTimeAxis1D(); for (int t=0; t<timeAxis.getSize(); t++) { Array aa = gg.readVolumeData(t); int[] shape = aa.getShape(); Index ima = aa.getIndex(); for (int i=0; i<shape[0]; i++) { for (int j=0; j<shape[1]; j++) { for (int k=0; k<shape[2]; k++) { double got = aa.getDouble( ima.set(i,j,k)); double want = ((double) (t*1000 + i*100 + j*10 + k)); assert (got == want) : "got "+got+ " want "+want; } } } } System.out.println("*** ok reading doRead4Volume for "+varName); }
private void doRead4Volume( GridDataset ds, String varName) throws IOException { GeoGrid gg = ds.findGridByName( varName); CoordinateAxis1D timeAxis = gg.getCoordinateSystem().getTimeAxis1D(); for (int t=0; t<timeAxis.getSize(); t++) { Array aa = gg.readVolumeData(t); int[] shape = aa.getShape(); Index ima = aa.getIndex(); for (int i=0; i<shape[0]; i++) { for (int j=0; j<shape[1]; j++) { for (int k=0; k<shape[2]; k++) { double got = aa.getDouble( ima.set(i,j,k)); double want = ((double) (t*1000 + i*100 + j*10 + k)); assert (got == want) : "got "+got+ " want "+want; } } } } System.out.println("*** ok reading doRead4Volume for "+varName); }
private void doRead4Volume( GridDataset ds, String varName) throws IOException { GeoGrid gg = ds.findGridByName( varName); CoordinateAxis1D timeAxis = gg.getCoordinateSystem().getTimeAxis1D(); for (int t=0; t<timeAxis.getSize(); t++) { Array aa = gg.readVolumeData(t); int[] shape = aa.getShape(); Index ima = aa.getIndex(); for (int i=0; i<shape[0]; i++) { for (int j=0; j<shape[1]; j++) { for (int k=0; k<shape[2]; k++) { double got = aa.getDouble( ima.set(i,j,k)); double want = ((double) (t*1000 + i*100 + j*10 + k)); assert (got == want) : "got "+got+ " want "+want; } } } } System.out.println("*** ok reading doRead4Volume for "+varName); }
private void doRead3Volume( GridDataset ds, String varName) throws IOException { GeoGrid gg = ds.findGridByName( varName); CoordinateAxis1D timeAxis = gg.getCoordinateSystem().getTimeAxis1D(); int[] w = getWeights( gg); for (int t=0; t<timeAxis.getSize(); t++) { Array aa = gg.readVolumeData(t); int[] shape = aa.getShape(); Index ima = aa.getIndex(); for (int i=0; i<shape[0]; i++) { for (int j=0; j<shape[1]; j++) { double got = aa.getDouble( ima.set(i,j)); double want = ((double) (t*1000 + i*w[1] + j*w[2])); assert (got == want) : "got "+got+ " want "+want; } } } System.out.println("*** ok reading doRead3Volume for "+varName); }
private void doRead3Volume( GridDataset ds, String varName) throws IOException { GeoGrid gg = ds.findGridByName( varName); CoordinateAxis1D timeAxis = gg.getCoordinateSystem().getTimeAxis1D(); int[] w = getWeights( gg); for (int t=0; t<timeAxis.getSize(); t++) { Array aa = gg.readVolumeData(t); int[] shape = aa.getShape(); Index ima = aa.getIndex(); for (int i=0; i<shape[0]; i++) { for (int j=0; j<shape[1]; j++) { double got = aa.getDouble( ima.set(i,j)); double want = ((double) (t*1000 + i*w[1] + j*w[2])); assert (got == want) : "got "+got+ " want "+want; } } } System.out.println("*** ok reading doRead3Volume for "+varName); }
private void doRead3Volume( GridDataset ds, String varName) throws IOException { GeoGrid gg = ds.findGridByName( varName); CoordinateAxis1D timeAxis = gg.getCoordinateSystem().getTimeAxis1D(); int[] w = getWeights( gg); for (int t=0; t<timeAxis.getSize(); t++) { Array aa = gg.readVolumeData(t); int[] shape = aa.getShape(); Index ima = aa.getIndex(); for (int i=0; i<shape[0]; i++) { for (int j=0; j<shape[1]; j++) { double got = aa.getDouble( ima.set(i,j)); double want = ((double) (t*1000 + i*w[1] + j*w[2])); assert (got == want) : "got "+got+ " want "+want; } } } System.out.println("*** ok reading doRead3Volume for "+varName); }
@Test public void testGrid() { GridDatatype grid = gds.findGridDatatype("T"); assert null != grid; assert grid.getFullName().equals("T"); assert grid.getRank() == 3; assert grid.getDataType() == DataType.DOUBLE; GridCoordSystem gcsys = grid.getCoordinateSystem(); assert gcsys.getYHorizAxis() != null; assert gcsys.getXHorizAxis() != null; assert gcsys.getTimeAxis() != null; CoordinateAxis1DTime taxis = gcsys.getTimeAxis1D(); assert taxis.getDataType() == DataType.STRING : taxis.getDataType(); List names = taxis.getNames(); java.util.Date[] dates = taxis.getTimeDates(); assert dates != null; for (int i = 0; i < dates.length; i++) { Date d = dates[i]; ucar.nc2.util.NamedObject name = (ucar.nc2.util.NamedObject) names.get(i); logger.debug("{} == {}", name.getName(), d); } }
/** * Test GridCoordSystem.findXYindexFromLatLonBounded() * @throws IOException */ @Test public void checkGridCoordSystem_findXYindexFromLatLonBounded() throws IOException { GridDataset gd = GridDataset.open( datasetLocation ); GridDatatype hsGrid = gd.findGridDatatype( "hs" ); GridCoordSystem coordSys = hsGrid.getCoordinateSystem(); CalendarDate date = coordSys.getTimeAxis1D().getCalendarDate(0); int[] xy = coordSys.findXYindexFromLatLonBounded( lat, lon, null ); assertEquals( i, xy[0] ); assertEquals( j, xy[1] ); GridAsPointDataset hsGridAsPoint = new GridAsPointDataset( Collections.singletonList( hsGrid )); GridAsPointDataset.Point point = hsGridAsPoint.readData( hsGrid, date, lat, lon ); assertEquals( lat, point.lat, 0.001 ); assertEquals( lon, point.lon, 0.001 ); } }
@Test public void testCOARDSdefaultCalendar() throws IOException { try (GridDataset ds = GridDataset.open(TestDir.cdmUnitTestDir + "conventions/coards/olr.day.mean.nc")) { GeoGrid grid = ds.findGridByName("olr"); assert grid != null; GridCoordSystem gcs = grid.getCoordinateSystem(); CoordinateAxis1DTime time = gcs.getTimeAxis1D(); assert time != null; CalendarDate first = time.getCalendarDate(0); CalendarDate cd = CalendarDateFormatter.isoStringToCalendarDate(Calendar.gregorian, "2002-01-01T00:00:00Z"); assert first.equals(cd) : first + " != " + cd; CalendarDate last = time.getCalendarDate((int) time.getSize() - 1); CalendarDate cd2 = CalendarDateFormatter.isoStringToCalendarDate(Calendar.gregorian, "2012-12-02T00:00:00Z"); assert last.equals(cd2) : last + " != " + cd2; } }