/** * testing */ public static void main(String arg[]) throws IOException { String defaultFilename = "C:/data/rap/fmrc.xml"; String filename = (arg.length > 0) ? arg[0] : defaultFilename; GridDataset gds = ucar.nc2.dt.grid.GridDataset.open(filename); GridDatatype gg = gds.findGridDatatype("T"); GridCoordSystem gsys = gg.getCoordinateSystem(); // gsys.getTimeAxisForRun(1); // generate error CoordinateAxis1DTime rtaxis = gsys.getRunTimeAxis(); CoordinateAxis taxis2D = gsys.getTimeAxis(); Array data = taxis2D.read(); NCdump.printArray(data, "2D time array", System.out, null); System.out.println("Run Time, Valid Times"); List<CalendarDate> runtimes = rtaxis.getCalendarDates(); for (int i = 0; i < runtimes.size(); i++) { System.out.println("\n" + runtimes.get(i)); CoordinateAxis1DTime taxis = gsys.getTimeAxisForRun(i); List<CalendarDate> times = taxis.getCalendarDates(); for (int j = 0; j < times.size(); j++) { System.out.println(" " + times.get(j)); } } }
Attribute att = gds.findGlobalAttributeIgnoreCase(CDM.FILE_FORMAT); boolean isGrib1 = (att != null) && att.getStringValue().startsWith("GRIB-1"); boolean isGrib2 = (att != null) && att.getStringValue().startsWith("GRIB-2"); String dataset = extractDatasetFromLocation(gds.getLocation()); if (dataset != null) { for (VariableRenamerBean r : mbean.newVars) { for (GridDatatype grid : gds.getGrids()) { String newMunged = munge(grid.getShortName()); if (newMunged.startsWith(oldMunged))
/** * Get the dataset named by the path. * called by DatasetHandler.getNetcdfFile() * * @param matchPath remaining path from match * @return requested dataset * @throws IOException if read error */ public NetcdfDataset getNetcdfDataset(String matchPath) throws IOException { int pos = matchPath.indexOf('/'); String type = (pos > -1) ? matchPath.substring(0, pos) : matchPath; String name = (pos > -1) ? matchPath.substring(pos + 1) : ""; // this assumes that these are files. also might be remote datasets from a catalog if (type.equals(FILES)) { if (topDirectory == null) return null; String filename = new StringBuilder(topDirectory) .append(topDirectory.endsWith("/") ? "" : "/") .append(name).toString(); return NetcdfDataset.acquireDataset(null, filename, null, -1, null, null); // no enhancement } GridDataset gds = getGridDataset(matchPath); // LOOK cant be right return (gds == null) ? null : (NetcdfDataset) gds.getNetcdfFile(); }
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(); } }
NetcdfDataset ncd = (NetcdfDataset) gridDs.getNetcdfFile(); int countGrids = gridDs.getGrids().size(); int countCoordAxes = ncd.getCoordinateAxes().size(); int countCoordSys = ncd.getCoordinateSystems().size(); for (ucar.nc2.dt.GridDataset.Gridset gridset : gridDs.getGridsets()) { gridset.getGeoCoordSystem(); Assert.assertEquals("Number of Grids", ngrids, countGrids); GridDatatype grid = gridDs.findGridDatatype(gridName); GridCoordSystem gcs = grid.getCoordinateSystem(); CoordinateAxis1DTime runtime = gcs.getRunTimeAxis(); Assert.assertEquals("Number of Best times for "+gridName, nbest, time.getDimension(0).getLength()); gridDs.close();
GridDatatype grid = gds.findGridDatatype(gridName); Variable newV = writer.findVariable(gridName); if (newV == null) { log.warn("NetcdfCFWriter cant find " + gridName + " in gds " + gds.getLocationURI()); continue; for (ucar.nc2.dt.GridDataset.Gridset gridSet : gds.getGridsets()) { ucar.nc2.dt.GridCoordSystem gcs = gridSet.getGeoCoordSystem(); ProjectionCT pct = gcs.getProjectionCT(); convertProjectionCTV((NetcdfDataset) gds.getNetcdfFile(), v); ctvList.add(v);
throws IOException, InvalidRangeException { NetcdfDataset ncd = (NetcdfDataset) gds.getNetcdfFile(); LatLonRect resultBB = null; GridDatatype grid = gds.findGridDatatype(gridName); GridCoordSystem gcsOrg = grid.getCoordinateSystem(); LatLonRect gridBB = gcsOrg.getLatLonBoundingBox();
private void extractGridDataset(PrintStream out, GridDataset gridDs) { out.println(" ngrids = " + gridDs.getGrids().size()); return; NetcdfDataset ds = (NetcdfDataset) gridDs.getNetcdfFile(); showAtts(out, ds.getGlobalAttributes()); out.println(); long nx = 0, ny = 0; for (GridDataset.Gridset gset : gridDs.getGridsets()) { GridCoordSystem gcs = gset.getGeoCoordSystem();
GridDatatype grid = gds.findGridDatatype(gridName); Variable newV = writer.findVariable(gridName); if (newV == null) { log.debug("NetcdfCFWriter cant find " + gridName + " in gds " + gds.getLocation()); continue; for (ucar.nc2.dt.GridDataset.Gridset gridSet : gds.getGridsets()) { ucar.nc2.dt.GridCoordSystem gcs = gridSet.getGeoCoordSystem(); ProjectionCT pct = gcs.getProjectionCT(); convertProjectionCTV((NetcdfDataset) gds.getNetcdfFile(), v); ctvList.add(v);
NetcdfFileWriter writer) throws IOException, InvalidRangeException { NetcdfDataset ncd = (NetcdfDataset) gds.getNetcdfFile(); for (GridDatatype grid : gds.getGrids()) gridList.add(grid.getName()); if (varNameList.contains(gridName)) // already contains continue; GridDatatype gridOrg = gds.findGridDatatype(gridName); if (gridOrg == null) { log.debug("writeOrTestSize cant find grid %s - skipping%n", gridName);
private List<CoordinateTransform> getCoordTransforms(ucar.nc2.dt.GridDataset gds) { Set<CoordinateTransform> ctHash = new HashSet<CoordinateTransform>(); for (ucar.nc2.dt.GridDataset.Gridset gridset : gds.getGridsets()) { GridCoordSystem gcs = gridset.getGeoCoordSystem(); for (CoordinateTransform axe : gcs.getCoordinateTransforms()) ctHash.add(axe); } List<CoordinateTransform> list = Arrays.asList((CoordinateTransform[]) ctHash.toArray( new CoordinateTransform[ ctHash.size()])); Collections.sort(list); return list; }
Element rootElem = new Element("gridForm"); Document doc = new Document(rootElem); rootElem.setAttribute("location", gds.getLocationURI()); if (null != path) rootElem.setAttribute("path", path); List<GridDatatype> grids = gds.getGrids(); Collections.sort(grids, new GridComparator()); // sort by time axis, vert axis, grid name LatLonRect bb = gds.getBoundingBox(); if (bb != null) rootElem.addContent(writeBoundingBox(bb)); CalendarDate start = gds.getCalendarDateStart(); CalendarDate end = gds.getCalendarDateEnd(); if ((start != null) && (end != null)) { Element dateRange = new Element("TimeSpan");
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(); } }
Element rootElem = new Element("gridDataset"); Document doc = new Document(rootElem); rootElem.setAttribute("location", gds.getLocationURI()); if (null != path) rootElem.setAttribute("path", path); List<GridDataset.Gridset> gridSets = gds.getGridsets(); Collections.sort(gridSets, new GridSetComparator()); for (GridDataset.Gridset gridset : gridSets) { LatLonRect bb = gds.getBoundingBox(); if (bb != null) rootElem.addContent(writeBoundingBox(bb)); CalendarDate start = gds.getCalendarDateStart(); CalendarDate end = gds.getCalendarDateEnd(); if ((start != null) && (end != null)) { Element dateRange = new Element("TimeSpan");
Element rootElem = new Element("gridForm"); Document doc = new Document(rootElem); rootElem.setAttribute("location", gds.getLocation()); if (null != path) rootElem.setAttribute("path", path); List<GridDatatype> grids = gds.getGrids(); Collections.sort(grids, new GridComparator()); // sort by time axis, vert axis, grid name LatLonRect bb = gds.getBoundingBox(); if (bb != null) rootElem.addContent(writeBoundingBox(bb)); CalendarDate start = gds.getCalendarDateStart(); CalendarDate end = gds.getCalendarDateEnd(); if ((start != null) && (end != null)) { Element dateRange = new Element("TimeSpan");
Element rootElem = new Element("gridDataset"); Document doc = new Document(rootElem); rootElem.setAttribute("location", gds.getLocation()); if (null != path) rootElem.setAttribute("path", path); List<GridDataset.Gridset> gridSets = gds.getGridsets(); Collections.sort(gridSets, new GridSetComparator()); for (GridDataset.Gridset gridset : gridSets) { LatLonRect bb = gds.getBoundingBox(); if (bb != null) rootElem.addContent(writeBoundingBox(bb)); CalendarDate start = gds.getCalendarDateStart(); CalendarDate end = gds.getCalendarDateEnd(); if ((start != null) && (end != null)) { Element dateRange = new Element("TimeSpan");
public void writeGrid(String gridDataset_filename, String gridName, int time, int level, boolean greyScale, LatLonRect pt) throws IOException { try (GridDataset dataset = ucar.nc2.dt.grid.GridDataset.open(gridDataset_filename)) { GridDatatype grid = dataset.findGridDatatype(gridName); if (grid == null) { throw new IllegalArgumentException("No grid named " + gridName + " in fileName"); Attribute att = dataset.findGlobalAttributeIgnoreCase("datasetId"); if (att != null && att.getStringValue().contains("DMSP")) { // LOOK!! writeSwathGrid(gridDataset_filename, gridName, time, level, greyScale, pt);
private ForecastModelRunInventory(ucar.nc2.dt.GridDataset gds, Date runDate) { name = gds.getTitle(); NetcdfFile ncfile = gds.getNetcdfFile(); if (runDate == null) { runTime = ncfile.findAttValueIgnoreCase(null, _Coordinate.ModelBaseDate, null); for (GridDatatype gg : gds.getGrids()) { GridCoordSystem gcs = gg.getCoordinateSystem(); Grid grid = new Grid(gg.getFullName());
private void writeGlobalAttributes(NetcdfFileWriter writer, ucar.nc2.dt.GridDataset gds, LatLonRect llbb) { // global attributes for (Attribute att : gds.getGlobalAttributes()) { if (att.getShortName().equals(CDM.FILE_FORMAT)) continue; if (att.getShortName().equals(_Coordinate._CoordSysBuilder)) continue; writer.addGroupAttribute(null, att); } Attribute att = gds.findGlobalAttributeIgnoreCase(CDM.CONVENTIONS); if (att == null || !att.getStringValue().startsWith("CF-")) // preserve previous version of CF Convention if it exists writer.addGroupAttribute(null, new Attribute(CDM.CONVENTIONS, "CF-1.0")); writer.addGroupAttribute(null, new Attribute("History", "Translated to CF-1.0 Conventions by Netcdf-Java CDM (CFGridWriter)\n" + "Original Dataset = " + gds.getLocation() + "; Translation Date = " + CalendarDate.present())); // this will replace any existing writer.addGroupAttribute(null, new Attribute(ACDD.LAT_MIN, llbb.getLatMin())); writer.addGroupAttribute(null, new Attribute(ACDD.LAT_MAX, llbb.getLatMax())); writer.addGroupAttribute(null, new Attribute(ACDD.LON_MIN, llbb.getLonMin())); writer.addGroupAttribute(null, new Attribute(ACDD.LON_MAX, llbb.getLonMax())); }
public WcsDataset( GridDataset dataset, String datasetPath ) { this.datasetPath = datasetPath; int pos = datasetPath.lastIndexOf( "/" ); this.datasetName = ( pos > 0 ) ? datasetPath.substring( pos + 1 ) : datasetPath; this.dataset = dataset; this.availableCoverages = new HashMap<String, WcsCoverage>(); // ToDo WCS 1.0PlusPlus - compartmentalize coverage to hide GridDatatype vs GridDataset.Gridset ??? // ToDo WCS 1.0Plus - change FROM coverage for each parameter TO coverage for each coordinate system // This is WCS 1.0 coverage for each parameter for ( GridDatatype curGridDatatype : this.dataset.getGrids() ) { GridCoordSystem gcs = curGridDatatype.getCoordinateSystem(); if ( !gcs.isRegularSpatial() ) continue; this.availableCoverages.put( curGridDatatype.getFullName(), new WcsCoverage( curGridDatatype, this) ); } // ToDo WCS 1.0Plus - change FROM coverage for each parameter TO coverage for each coordinate system // This is WCS 1.1 style coverage for each coordinate system // for ( GridDataset.Gridset curGridSet : this.dataset.getGridsets()) // { // GridCoordSystem gcs = curGridSet.getGeoCoordSystem(); // if ( !gcs.isRegularSpatial() ) // continue; // this.availableCoverages.put( gcs.getName(), curGridSet ); // } }