public static void main(String[] args) throws IOException { GridDataset gds = ucar.nc2.dt.grid.GridDataset.open("Q:/cdmUnitTest/transforms/Eumetsat.VerticalPerspective.grb"); GridDatatype grid = gds.findGridDatatype( "Pixel_scene_type"); GridCoordSystem gcs = grid.getCoordinateSystem(); double lat = 8.0; double lon = 21.0; // find the x,y point for a specific lat/lon position int[] xy = gcs.findXYindexFromLatLon(lat, lon, null); // xy[0] = x, xy[1] = y // read the data at that lat, lon a specific t and z value Array data = grid.readDataSlice(0, 0, xy[1], xy[0]); // note t, z, y, x double val = data.getDouble(0); System.out.printf("Value at %f %f == %f%n", lat, lon, val); }
public static void main(String[] args) throws IOException { GridDataset gds = ucar.nc2.dt.grid.GridDataset.open("Q:/cdmUnitTest/transforms/Eumetsat.VerticalPerspective.grb"); GridDatatype grid = gds.findGridDatatype( "Pixel_scene_type"); GridCoordSystem gcs = grid.getCoordinateSystem(); double lat = 8.0; double lon = 21.0; // find the x,y point for a specific lat/lon position int[] xy = gcs.findXYindexFromLatLon(lat, lon, null); // xy[0] = x, xy[1] = y // read the data at that lat, lon a specific t and z value Array data = grid.readDataSlice(0, 0, xy[1], xy[0]); // note t, z, y, x double val = data.getDouble(0); System.out.printf("Value at %f %f == %f%n", lat, lon, val); }
public static void main(String[] args) throws IOException { GridDataset gds = ucar.nc2.dt.grid.GridDataset.open("Q:/cdmUnitTest/transforms/Eumetsat.VerticalPerspective.grb"); GridDatatype grid = gds.findGridDatatype( "Pixel_scene_type"); GridCoordSystem gcs = grid.getCoordinateSystem(); double lat = 8.0; double lon = 21.0; // find the x,y point for a specific lat/lon position int[] xy = gcs.findXYindexFromLatLon(lat, lon, null); // xy[0] = x, xy[1] = y // read the data at that lat, lon a specific t and z value Array data = grid.readDataSlice(0, 0, xy[1], xy[0]); // note t, z, y, x double val = data.getDouble(0); System.out.printf("Value at %f %f == %f%n", lat, lon, val); }
public BufferedImage openDataset( GridDatatype grid) throws java.io.IOException { this.grid = grid; this.time = 0; GridCoordSystem gcsys = grid.getCoordinateSystem(); if (gcsys.getTimeAxis() != null) ntimes = (int) gcsys.getTimeAxis().getSize(); Array data = grid.readDataSlice( this.time, 0, -1, -1); return ImageArrayAdapter.makeGrayscaleImage( data, grid); }
public BufferedImage openDataset( GridDatatype grid) throws java.io.IOException { this.grid = grid; this.time = 0; GridCoordSystem gcsys = grid.getCoordinateSystem(); if (gcsys.getTimeAxis() != null) ntimes = (int) gcsys.getTimeAxis().getSize(); Array data = grid.readDataSlice( this.time, 0, -1, -1); return ImageArrayAdapter.makeGrayscaleImage( data); }
public void openFileProblem() throws IOException { long start = System.currentTimeMillis(); // String filename = "B:/rdavm/ds083.2/grib1/ds083.2_Aggregation-grib1.ncx4"; String filename = TestDir.cdmUnitTestDir + "gribCollections/gfs_2p5deg/gfs_2p5deg.ncx4"; try (GridDataset gds = GridDataset.open(filename)) { GridDatatype gdt = gds.findGridByName("TwoD/Latent_heat_net_flux_surface_Mixed_intervals_Average"); assert gdt != null; int n = 5; int first = 17; double sum = 0; for (int time = first; time < first + n; time++) { Array data = gdt.readDataSlice(0, -0, time, 0, -1, -1); sum += MAMath.sumDouble(data); } System.out.printf("sum = %s%n", sum); long took = System.currentTimeMillis() - start; float r = ((float) took) / n; System.out.printf("%n that took %d secs total, %d records %f msecs per record%n", took / 1000, n, r); } }
@Test public void testTiling() throws IOException { // Global Heap 1t 13059 runs out with no heap id = 0 String filename = TestN4reading.testDir+"tiling.nc4"; try( GridDataset gridDataset = GridDataset.open(filename)) { GridDatatype grid = gridDataset.findGridByName("Turbulence_SIGMET_AIRMET"); System.out.printf("grid=%s%n", grid); Array data = grid.readDataSlice(4, 13, 176, 216); // FAILS assert data != null; } }
public void problem() throws IOException { long start = System.currentTimeMillis(); // String filename = "B:/rdavm/ds083.2/grib1/ds083.2_Aggregation-grib1.ncx4"; String filename = TestDir.cdmUnitTestDir + "gribCollections/gfs_2p5deg/gfs_2p5deg.ncx4"; try (GridDataset gds = GridDataset.open(filename)) { GridDatatype gdt = gds.findGridByName("TwoD/Latent_heat_net_flux_surface_Mixed_intervals_Average"); assert gdt != null; int n = 22; int first = 23; double sum = 0; for (int time=first; time < first+n; time++) { Array data = gdt.readDataSlice(0, -0, time, 0, -1, -1); sum += MAMath.sumDouble(data); } System.out.printf("sum = %s%n", sum); long took = System.currentTimeMillis() - start; float r = ((float) took) / n; System.out.printf("%n that took %d secs total, %d records %f msecs per record%n", took / 1000, n, r); } }
public void openDatasetAndView(String url) throws IOException { Array temp_data; try (GridDataset dataset = GridDataset.open(url)) { for (GridDatatype grid : dataset.getGrids()) { temp_data = grid.readDataSlice(0, 0, -1, -1); assert grid.getMinMaxSkipMissingData(temp_data).min == 0.0; // min assert grid.getMinMaxSkipMissingData(temp_data).max == 42.0; // max } } }
void tryAgain(SubsetParams coords) { try { if (cover != null) cover.readData(coords); if (grid != null) { int rtIndex = (Integer) dtCoords.get("rtIndex"); int tIndex = (Integer) dtCoords.get("tIndex"); int zIndex = (Integer) dtCoords.get("zIndex"); grid.readDataSlice(rtIndex, -1, tIndex, zIndex, -1, -1); } } catch (InvalidRangeException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
dt_array = dt.readDataSlice(rt_idx, ens_idx, time_idx, vert_idx, -1, -1); } catch (IOException e) { e.printStackTrace(); } catch (Throwable t) { try { dt.readDataSlice(rt_idx, ens_idx, time_idx, vert_idx, -1, -1); } catch (IOException e) { e.printStackTrace();
public Point readData(GridDatatype grid, CalendarDate date, double lat, double lon) throws java.io.IOException { GridCoordSystem gcs = grid.getCoordinateSystem(); //CoordinateAxis1DTime timeAxis = gcs.getTimeAxis1D(); //int tidx = timeAxis.findTimeIndexFromCalendarDate(date); int tidx =-1; //Date may be null if the grid does not have time axis if(date != null) tidx = findTimeIndexForCalendarDate(gcs, date); //int[] xy = gcs.findXYindexFromLatLonBounded(lat, lon, null); int[] xy = gcs.findXYindexFromLatLon(lat, lon, null); Array data = grid.readDataSlice(tidx, -1, xy[1], xy[0]); // use actual grid midpoint LatLonPoint latlon = gcs.getLatLon(xy[0], xy[1]); Point p = new Point(); p.lat = latlon.getLatitude(); p.lon = latlon.getLongitude(); p.dataValue = data.getDouble( data.getIndex()); return p; }
private static void read(GridDatatype gdt, Count count, int rtIndex, int tIndex, int zIndex) throws IOException { Array data = gdt.readDataSlice(rtIndex, -1, tIndex, zIndex, -1, -1);
public Point readData(GridDatatype grid, CalendarDate date, double lat, double lon) throws java.io.IOException { GridCoordSystem gcs = grid.getCoordinateSystem(); //CoordinateAxis1DTime timeAxis = gcs.getTimeAxis1D(); //int tidx = timeAxis.findTimeIndexFromCalendarDate(date); int tidx =-1; //Date may be null if the grid does not have time axis if(date != null) tidx = findTimeIndexForCalendarDate(gcs, date); //int[] xy = gcs.findXYindexFromLatLonBounded(lat, lon, null); int[] xy = gcs.findXYindexFromLatLon(lat, lon, null); Array data = grid.readDataSlice(tidx, -1, xy[1], xy[0]); // use actual grid midpoint LatLonPoint latlon = gcs.getLatLon(xy[0], xy[1]); Point p = new Point(); p.lat = latlon.getLatitude(); p.lon = latlon.getLongitude(); p.dataValue = data.getDouble( data.getIndex()); return p; }
public Point readData(GridDatatype grid, CalendarDate date, double lat, double lon) throws java.io.IOException { GridCoordSystem gcs = grid.getCoordinateSystem(); //CoordinateAxis1DTime timeAxis = gcs.getTimeAxis1D(); //int tidx = timeAxis.findTimeIndexFromCalendarDate(date); int tidx =-1; //Date may be null if the grid does not have time axis if(date != null) tidx = findTimeIndexForCalendarDate(gcs, date); //int[] xy = gcs.findXYindexFromLatLonBounded(lat, lon, null); int[] xy = gcs.findXYindexFromLatLon(lat, lon, null); Array data = grid.readDataSlice(tidx, -1, xy[1], xy[0]); // use actual grid midpoint LatLonPoint latlon = gcs.getLatLon(xy[0], xy[1]); Point p = new Point(); p.lat = latlon.getLatitude(); p.lon = latlon.getLongitude(); p.dataValue = data.getDouble( data.getIndex()); return p; }
public Point readData(GridDatatype grid, CalendarDate date, double zCoord, double lat, double lon) throws java.io.IOException { GridCoordSystem gcs = grid.getCoordinateSystem(); //CoordinateAxis1DTime timeAxis = gcs.getTimeAxis1D(); //int tidx = timeAxis.findTimeIndexFromCalendarDate(date); int tidx = -1; //Date may be null if the grid does not have time axis if(date != null) tidx= findTimeIndexForCalendarDate(gcs, date); CoordinateAxis1D zAxis = gcs.getVerticalAxis(); int zidx = zAxis.findCoordElement( zCoord); int[] xy = gcs.findXYindexFromLatLon(lat, lon, null); Array data = grid.readDataSlice(tidx, zidx, xy[1], xy[0]); // use actual grid midpoint LatLonPoint latlon = gcs.getLatLon(xy[0], xy[1]); Point p = new Point(); p.lat = latlon.getLatitude(); p.lon = latlon.getLongitude(); p.z = zAxis.getCoordValue( zidx); p.dataValue = data.getDouble( data.getIndex()); return p; }
public Point readData(GridDatatype grid, CalendarDate date, double zCoord, double lat, double lon) throws java.io.IOException { GridCoordSystem gcs = grid.getCoordinateSystem(); //CoordinateAxis1DTime timeAxis = gcs.getTimeAxis1D(); //int tidx = timeAxis.findTimeIndexFromCalendarDate(date); int tidx = -1; //Date may be null if the grid does not have time axis if(date != null) tidx= findTimeIndexForCalendarDate(gcs, date); CoordinateAxis1D zAxis = gcs.getVerticalAxis(); int zidx = zAxis.findCoordElement( zCoord); int[] xy = gcs.findXYindexFromLatLon(lat, lon, null); Array data = grid.readDataSlice(tidx, zidx, xy[1], xy[0]); // use actual grid midpoint LatLonPoint latlon = gcs.getLatLon(xy[0], xy[1]); Point p = new Point(); p.lat = latlon.getLatitude(); p.lon = latlon.getLongitude(); p.z = zAxis.getCoordValue( zidx); p.dataValue = data.getDouble( data.getIndex()); return p; }
public Point readData(GridDatatype grid, CalendarDate date, double zCoord, double lat, double lon) throws java.io.IOException { GridCoordSystem gcs = grid.getCoordinateSystem(); //CoordinateAxis1DTime timeAxis = gcs.getTimeAxis1D(); //int tidx = timeAxis.findTimeIndexFromCalendarDate(date); int tidx = -1; //Date may be null if the grid does not have time axis if(date != null) tidx= findTimeIndexForCalendarDate(gcs, date); CoordinateAxis1D zAxis = gcs.getVerticalAxis(); int zidx = zAxis.findCoordElement( zCoord); int[] xy = gcs.findXYindexFromLatLon(lat, lon, null); Array data = grid.readDataSlice(tidx, zidx, xy[1], xy[0]); // use actual grid midpoint LatLonPoint latlon = gcs.getLatLon(xy[0], xy[1]); Point p = new Point(); p.lat = latlon.getLatitude(); p.lon = latlon.getLongitude(); p.z = zAxis.getCoordValue( zidx); p.dataValue = data.getDouble( data.getIndex()); return p; }
private void readAndTestGrib(GridDatatype gdt, int rtIndex, int tIndex, int zIndex) throws IOException { countReadsForVariable++; if (MAX_READS > 0 && countReadsForVariable > MAX_READS) return; GribDataReader.currentDataRecord = null; gdt.readDataSlice(rtIndex, -1, tIndex, zIndex, -1, -1); dtCoords.set("rtIndex", rtIndex); dtCoords.set("tIndex", tIndex); dtCoords.set("zIndex", zIndex); if (isGrib1) readAndTestGrib1(gdt.getName(), dtCoords); else readAndTestGrib2(gdt.getName(), dtCoords); grid = null; }
Array data = grid.readDataSlice(tidx, zidx, xy[1], xy[0]); p.dataValue = data.getDouble( data.getIndex());