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); }
private Element writeGrid(GridDatatype grid) { Element varElem = new Element("grid"); varElem.setAttribute("name", grid.getFullName()); String desc = grid.getDescription() != null ? grid.getDescription() : "No description"; varElem.setAttribute("desc", desc); StringBuilder buff = new StringBuilder(); List dims = grid.getDimensions(); for (int i = 0; i < dims.size(); i++) { Dimension dim = (Dimension) dims.get(i); if (i > 0) buff.append(" "); if (dim.isShared()) buff.append(dim.getShortName()); else buff.append(dim.getLength()); } if (buff.length() > 0) varElem.setAttribute("shape", buff.toString()); DataType dt = grid.getDataType(); if (dt != null) varElem.setAttribute("type", dt.toString()); //GridCoordSystem cs = grid.getCoordinateSystem(); //varElem.setAttribute("coordSys", cs.getName()); // attributes for (ucar.nc2.Attribute att : grid.getAttributes()) { varElem.addContent(ucar.nc2.ncml.NcMLWriter.writeAttribute(att, "attribute", null)); } return varElem; }
private void makeGrib1Vocabulary(List<GridDatatype> grids, PrintStream out) { String stdName; out.println("\n<variables vocabulary='GRIB-1'>"); for (GridDatatype grid : grids) { Attribute att = grid.findAttributeIgnoreCase("GRIB_param_number"); stdName = (att != null) ? att.getNumericValue().toString() : null; out.print(" <variable name='"); out.print(grid.getFullName()); out.print("' vocabulary_name='"); out.print(stdName != null ? stdName : "dunno"); out.print("' units='"); out.print(grid.getUnitsString()); out.println("'/>"); } out.println("</variables>"); }
public WcsRangeField( GridDatatype gridDatatype ) { if ( gridDatatype == null) throw new IllegalArgumentException( "Range field must be non-null."); this.gridDatatype = gridDatatype; this.name = this.gridDatatype.getFullName(); this.label = this.gridDatatype.getInfo(); this.description = this.gridDatatype.getDescription(); this.datatypeString = this.gridDatatype.getDataType().toString(); this.unitsString = this.gridDatatype.getUnitsString(); this.validMin = this.gridDatatype.getVariable().getValidMin(); this.validMax = this.gridDatatype.getVariable().getValidMax(); // ToDo GeoGrids only handle scalar range fields. (???) axes = Collections.emptyList(); }
public int compare(GridDatatype grid1, GridDatatype grid2) { GridCoordSystem gcs1 = grid1.getCoordinateSystem(); GridCoordSystem gcs2 = grid2.getCoordinateSystem(); CoordinateAxis time1 = gcs1.getTimeAxis(); CoordinateAxis time2 = gcs2.getTimeAxis(); int ret = compareAxis(time1, time2); if (ret != 0) return ret; CoordinateAxis vert1 = gcs1.getVerticalAxis(); CoordinateAxis vert2 = gcs2.getVerticalAxis(); ret = compareAxis(vert1, vert2); if (ret != 0) return ret; return grid1.getFullName().compareTo(grid2.getFullName()); }
private long processTransformationVars(ArrayList<Variable> varList, ArrayList<String> varNameList , NetcdfDataset ncd, ucar.nc2.dt.GridDataset gds, GridDatatype grid, Range timeRange, Range zRangeUse, Range yRange, Range xRange, int z_stride, int y_stride, int x_stride) throws InvalidRangeException { List<CoordinateTransform> cctt = grid.getCoordinateSystem().getCoordinateTransforms(); for(CoordinateTransform ct : cctt){ Parameter param = ct.findParameterIgnoreCase( CF.FORMULA_TERMS ); complementaryGrid = complementaryGrid.makeSubset(null, null, timeRange, zRangeUse, yRange, xRange); paramVar = complementaryGrid.getVariable();
for (GridDatatype grid : gridDataset.getGrids()) { ThreddsMetadata.Variable v = new ThreddsMetadata.Variable(); v.setName(grid.getFullName()); v.setDescription(grid.getDescription()); v.setUnits(grid.getUnitsString()); Attribute att = grid.findAttributeIgnoreCase("Grib_Variable_Id"); if (att != null) { v.setVocabularyId(att.getStringValue()); v.setVocabularyName(att.getStringValue()); } else { att = grid.findAttributeIgnoreCase("Grib_Parameter"); v.setVocabularyId(att); vars.addVariable(v); v.setName(grid.getFullName()); v.setDescription(grid.getDescription()); v.setUnits(grid.getUnitsString()); ucar.nc2.Attribute att = grid.findAttributeIgnoreCase("standard_name"); if (att != null) v.setVocabularyName(att.getStringValue());
public GridAsPointDataset( List<GridDatatype> grids) { this.grids = grids; //HashSet<Date> dateHash = new HashSet<Date>(); ???? HashSet<CalendarDate> dateHash = new HashSet<CalendarDate>(); List<CoordinateAxis1DTime> timeAxes = new ArrayList<CoordinateAxis1DTime>(); for (GridDatatype grid : grids) { GridCoordSystem gcs = grid.getCoordinateSystem(); CoordinateAxis1DTime timeAxis = gcs.getTimeAxis1D(); if ((timeAxis != null) && !timeAxes.contains(timeAxis)) { timeAxes.add(timeAxis); //Date[] timeDates = timeAxis.getTimeDates(); List<CalendarDate> timeDates = timeAxis.getCalendarDates(); //for (Date timeDate : timeDates) for (CalendarDate timeDate : timeDates) //dateHash.add( CalendarDate.of( timeDate) ); dateHash.add( timeDate ); } } // -->if dateHash is HashSet<Date> hashSet.toArray returns Date[], not CalendarDate[] ??? dates = Arrays.asList( dateHash.toArray(new CalendarDate[dateHash.size()])); Collections.sort(dates); }
gridList = new ArrayList<>(); for (GridDatatype grid : gds.getGrids()) gridList.add(grid.getName()); GridCoordSystem gcsOrg = grid.getCoordinateSystem(); boolean isGlobal = gcsOrg.isGlobalLon(); varNameList.add(gridName); if (projRect != null) { makeHorizRange(gcsOrg, projRect, horizStride, yxRanges); grid = grid.makeSubset(null, null, timeRange, zRangeUse, yxRanges.get(0), yxRanges.get(1)); yxRanges.add(null); } else { yxRanges = grid.getCoordinateSystem().getRangesFromLatLonRect(llbb); grid = grid.makeSubset(timeRange, zRangeUse, llbb, 1, horizStride, horizStride); LatLonRect gridBB = grid.getCoordinateSystem().getLatLonBoundingBox(); if (resultBB == null) resultBB = gridBB; Variable gridV = grid.getVariable(); varList.add(gridV); total_size += gridV.getSize() * gridV.getElementSize(); GridCoordSystem gcs = grid.getCoordinateSystem(); addCoordinateAxis(gcs, varNameList, varList, axisList);
@Test public void testReadData() throws IOException { GridDatatype g = gds.findGridDatatype("IR_WV"); assert null != g; assert g.getFullName().equals("IR_WV"); assert g.getRank() == 3; assert g.getShape()[0] == ntimes; assert g.getShape()[1] == 1008; assert g.getShape()[2] == 1536; assert g.getDataType() == DataType.USHORT : g.getDataType(); GridCoordSystem gsys = g.getCoordinateSystem(); assert gsys.getXHorizAxis() != null; assert gsys.getYHorizAxis() != null; assert gsys.getTimeAxis() != null; assert gsys.getVerticalAxis() == null; assert gsys.getProjection() != null; Array data = g.readVolumeData(0); assert data.getRank() == 2; assert data.getShape()[0] == 1008; assert data.getShape()[1] == 1536; assert data.getElementType() == short.class; } }
@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); } }
GridCoordSystem gcs = grid.getCoordinateSystem(); MAMath.MinMax dataMinMax = grid.getMinMaxSkipMissingData(data); if (greyScale) { ArrayByte result = replaceMissingValuesAndScale(grid, data, dataMinMax);
GridCoordSystem gcs = gg.getCoordinateSystem(); Grid grid = new Grid(gg.getFullName()); VariableEnhanced ve = gg.getVariable();
String name = grid.getShortName(); String desc = grid.getDescription(); String units = grid.getUnitsString(); String vname = null; String id = null; Attribute att = grid.findAttributeIgnoreCase(Grib.VARIABLE_ID_ATTNAME); if (att != null) { id = att.getStringValue(); vocab = "CF-1.0"; for (GridDatatype grid : gridDataset.getGrids()) { String name = grid.getShortName(); String desc = grid.getDescription(); String units = grid.getUnitsString(); String vname = null; String id = null; ucar.nc2.Attribute att = grid.findAttributeIgnoreCase("standard_name"); if (att != null) vname = att.getStringValue();
public String getWcs1_0CrsId( GridDatatype gridDatatype, GridDataset gridDataset ) throws IllegalArgumentException { gridDataset.getTitle(); gridDatatype.getFullName(); StringBuilder buf = new StringBuilder(); Attribute gridMappingAtt = gridDatatype.findAttributeIgnoreCase( CF.GRID_MAPPING ); String gridMapping = gridMappingAtt.getStringValue(); Variable gridMapVar = gridDataset.getNetcdfFile().getRootGroup().findVariable(gridMapping); Attribute gridMappingNameAtt = gridMapVar.findAttributeIgnoreCase( CF.GRID_MAPPING_NAME ); String gridMappingName = gridMappingNameAtt.getStringValue(); buf.append( "EPSG:" ).append( ProjectionStandardsInfo.getProjectionByCfName( gridMappingName)); return buf.toString(); } }
assertNotNull(gridDatatype); Dimension rtDimension = gridDatatype.getRunTimeDimension(); Dimension ensDimension = gridDatatype.getEnsembleDimension(); Dimension timeDimension = gridDatatype.getTimeDimension(); Dimension xDimension = gridDatatype.getXDimension(); Dimension yDimension = gridDatatype.getYDimension(); Dimension zDimension = gridDatatype.getZDimension(); int rtIndex = gridDatatype.getRunTimeDimensionIndex(); int ensIndex = gridDatatype.getEnsembleDimensionIndex(); int timeIndex = gridDatatype.getTimeDimensionIndex(); int yIndex = gridDatatype.getYDimensionIndex(); int xIndex = gridDatatype.getXDimensionIndex(); int zIndex = gridDatatype.getZDimensionIndex(); assertEquals(-1, zIndex); Dimension ensDim = gridDatatype.getDimension(ensIndex); //ensIndex = 0 assertEquals(1, ensDim.getLength()); assertEquals("ens", ensDim.getShortName()); Variable variable = gridDatatype.getVariable().getOriginalVariable();
log.error( "writeCoverageDataToFile(): Failed to subset coverage <" + this.coverage.getFullName() + "> along vertical range <" + verticalRange + ">: " + e.getMessage() ); throw new WcsException( WcsException.Code.CoverageNotDefined, "Vertical", "Failed to subset coverage [" + this.coverage.getFullName() + "] along vertical range." ); log.error( "writeCoverageDataToFile(): Failed to subset coverage [" + this.coverage.getFullName() + "] along time axis [" + timeRange + "]: " + e.getMessage() ); throw new WcsException( WcsException.Code.CoverageNotDefined, "Time", "Failed to subset coverage [" + this.coverage.getFullName() + "] along time axis [" + timeRange + "]." ); GridDatatype subset = this.coverage.makeSubset( tRange, zRange, bboxLatLonRect, 1, 1, 1 ); Array data = subset.readDataSlice( 0, 0, -1, -1 ); log.error( "writeCoverageDataToFile(): Failed to subset coverage <" + this.coverage.getFullName() + "> along time axis <" + timeRange + ">: " + e.getMessage() ); throw new WcsException( WcsException.Code.CoverageNotDefined, "", "Failed to subset coverage [" + this.coverage.getFullName() + "]." ); log.error( "writeCoverageDataToFile(): Failed to write file for requested coverage <" + this.coverage.getFullName() + ">: " + e.getMessage() ); throw new WcsException( WcsException.Code.UNKNOWN, "", "Problem creating coverage [" + this.coverage.getFullName() + "]." ); Collections.singletonList( this.coverage.getFullName() ), bboxLatLonRect, 1, zRange, log.error( "writeCoverageDataToFile(): Failed to subset coverage <" + this.coverage.getFullName() + ">: " + e.getMessage() ); throw new WcsException( WcsException.Code.CoverageNotDefined, "", "Failed to subset coverage [" + this.coverage.getFullName() + "]." ); log.error( "writeCoverageDataToFile(): Failed to create or write temporary file for requested coverage <" + this.coverage.getFullName() + ">: " + e.getMessage() ); throw new WcsException( WcsException.Code.UNKNOWN, "", "Problem creating coverage [" + this.coverage.getFullName() + "]." );
public void testStride() throws java.io.IOException, InvalidRangeException { String filename= TestDir.cdmUnitTestDir + "/conventions/wrf/wrfout_d01_2006-03-08_21-00-00"; GridDataset gds = ucar.nc2.dt.grid.GridDataset.open( filename); GridDatatype grid = gds.findGridDatatype("T"); assert grid != null; grid = grid.makeSubset(null,null,null,1,2,4); GridCoordSystem gcs = grid.getCoordinateSystem(); assert gcs != null; VerticalTransform vt = gcs.getVerticalTransform(); assert vt != null; ArrayDouble.D3 ca = vt.getCoordinateArray(0); assert ca != null; assert ca.getRank() == 3 : ca.getRank(); int[] shape = ca.getShape(); for (int i = 0; i < 3; i++) System.out.println(" shape " + i + " = " + shape[i]); assert shape[0] == 44; assert shape[1] == 399/2 + 1; assert shape[2] == 399/4 + 1; gds.close(); } }
@Ignore("takes too long") @Test public void testGridCoverageDataset() throws IOException { System.out.printf("Test Dataset %s%n", endpoint); try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(endpoint)) { Assert.assertNotNull(endpoint, cc); CoverageCollection gcs = cc.findCoverageDataset(expectType); Assert.assertNotNull(expectType.toString(), gcs); // check DtCoverageCS try (GridDataset ds = GridDataset.open(endpoint)) { for (GridDatatype dt : ds.getGrids()) { if (expectType == FeatureType.FMRC && !dt.getFullName().startsWith("TwoD")) continue; if (expectType == FeatureType.GRID && dt.getFullName().startsWith("TwoD")) continue; GridCoordSystem csys = dt.getCoordinateSystem(); CoordinateAxis1DTime rtAxis = csys.getRunTimeAxis(); CoordinateAxis1D ensAxis = csys.getEnsembleAxis(); CoordinateAxis1D vertAxis = csys.getVerticalAxis(); Coverage cover = gcs.findCoverage(dt.getShortName()); if (cover == null) { System.out.printf("Cant find %s%n", dt.getFullName()); continue; } System.out.printf(" Grid %s%n", dt.getFullName()); readAllRuntimes(cover, dt, rtAxis, ensAxis, vertAxis); } } } }
data = grid.readDataSlice( this.time, 0, -1, -1); return ImageArrayAdapter.makeGrayscaleImage( data, grid); } catch (IOException e) {