Java Code Examples for ucar.nc2.dataset.NetcdfDataset#finish()
The following examples show how to use
ucar.nc2.dataset.NetcdfDataset#finish() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Suomi.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) { String start_date = ds.findAttValueIgnoreCase(null, "start_date", null); if (start_date == null) return; SimpleDateFormat df = new SimpleDateFormat("yyyy.DDD.HH.mm.ss"); // "2006.105.00.00.00" DateFormatter dfo = new DateFormatter(); Date start; try { start = df.parse(start_date); } catch (ParseException e) { throw new RuntimeException("Cant read start_date=" + start_date); } Variable v = ds.findVariable("time_offset"); v.addAttribute(new Attribute(CDM.UNITS, "seconds since " + dfo.toDateTimeString(start))); Group root = ds.getRootGroup(); root.addAttribute(new Attribute(CDM.CONVENTIONS, "Suomi-Station-CDM")); ds.finish(); }
Example 2
Source File: FslWindProfiler.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) { for (Variable v : ds.getVariables()) { switch (v.getShortName()) { case "staName": v.addAttribute(new Attribute("standard_name", "station_name")); break; case "staLat": v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lat.toString())); break; case "staLon": v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lon.toString())); break; case "staElev": case "levels": v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Height.toString())); break; case "timeObs": v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Time.toString())); break; } } ds.finish(); }
Example 3
Source File: HdfEosOmiConvention.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * */ private void augmentDataset3(NetcdfDataset ds) { Group grids = ds.findGroup("/HDFEOS/GRIDS"); if (grids == null) { return; } for (Group g2 : grids.getGroups()) { Attribute gctp = g2.findAttribute("GCTPProjectionCode"); if (gctp == null || !gctp.getNumericValue().equals(0)) { continue; } Attribute nlon = g2.findAttribute("NumberOfLongitudesInGrid"); Attribute nlat = g2.findAttribute("NumberOfLatitudesInGrid"); if (nlon == null || nlon.isString()) { continue; } if (nlat == null || nlat.isString()) { continue; } ds.addCoordinateAxis(makeLonCoordAxis(ds, g2, nlon.getNumericValue().intValue(), "XDim")); ds.addCoordinateAxis(makeLatCoordAxis(ds, g2, nlat.getNumericValue().intValue(), "YDim")); for (Group g3 : g2.getGroups()) { for (Variable v : g3.getVariables()) { v.addAttribute(new Attribute(_Coordinate.Axes, "lat lon")); } } } ds.finish(); }
Example 4
Source File: IFPSConvention.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) throws IOException { if (null != ds.findVariable("xCoord")) return; // check if its already been done - aggregating enhanced datasets. parseInfo.format("IFPS augmentDataset %n"); // Figure out projection info. Assume the same for all variables VariableDS lonVar = (VariableDS) ds.findVariable("longitude"); lonVar.setUnitsString(CDM.LON_UNITS); lonVar.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lon.toString())); VariableDS latVar = (VariableDS) ds.findVariable("latitude"); latVar.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lat.toString())); latVar.setUnitsString(CDM.LAT_UNITS); projVar = latVar; String projName = ds.findAttValueIgnoreCase(projVar, "projectionType", null); if ("LAMBERT_CONFORMAL".equals(projName)) { Projection proj = makeLCProjection(ds); makeXYcoords(ds, proj, latVar, lonVar); } // figure out the time coordinate for each data variable // LOOK : always seperate; could try to discover if they are the same List<Variable> vars = ds.getVariables(); for (Variable ncvar : vars) { // variables that are used but not displayable or have no data have DIM_0, also don't want history, since those // are just how the person edited the grids if ((!ncvar.getDimension(0).getShortName().equals("DIM_0")) && !ncvar.getShortName().endsWith("History") && (ncvar.getRank() > 2) && !ncvar.getShortName().startsWith("Tool")) { createTimeCoordinate(ds, ncvar); } else if (ncvar.getShortName().equals("Topo")) { // Deal with Topography variable ncvar.addAttribute(new Attribute(CDM.LONG_NAME, "Topography")); ncvar.addAttribute(new Attribute(CDM.UNITS, "ft")); } } ds.finish(); }
Example 5
Source File: ThreddsDataFactory.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Add information from the InvDataset to the NetcdfDataset. * * @param ds get info from here * @param ncDataset add to here */ public static void annotate(InvDataset ds, NetcdfDataset ncDataset) { ncDataset.setTitle(ds.getName()); ncDataset.setId(ds.getID()); // add properties as global attributes for (InvProperty p : ds.getProperties()) { String name = p.getName(); if (null == ncDataset.findGlobalAttribute(name)) { ncDataset.addAttribute(null, new Attribute(name, p.getValue())); } } /* * ThreddsMetadata.GeospatialCoverage geoCoverage = ds.getGeospatialCoverage(); * if (geoCoverage != null) { * if ( null != geoCoverage.getNorthSouthRange()) { * ncDataset.addAttribute(null, new Attribute("geospatial_lat_min", new Double(geoCoverage.getLatSouth()))); * ncDataset.addAttribute(null, new Attribute("geospatial_lat_max", new Double(geoCoverage.getLatNorth()))); * } * if ( null != geoCoverage.getEastWestRange()) { * ncDataset.addAttribute(null, new Attribute("geospatial_lon_min", new Double(geoCoverage.getLonWest()))); * ncDataset.addAttribute(null, new Attribute("geospatial_lon_max", new Double(geoCoverage.getLonEast()))); * } * if ( null != geoCoverage.getUpDownRange()) { * ncDataset.addAttribute(null, new Attribute("geospatial_vertical_min", new Double(geoCoverage.getHeightStart()))); * ncDataset.addAttribute(null, new Attribute("geospatial_vertical_max", new Double(geoCoverage.getHeightStart() + * geoCoverage.getHeightExtent()))); * } * } * * DateRange timeCoverage = ds.getTimeCoverage(); * if (timeCoverage != null) { * ncDataset.addAttribute(null, new Attribute("time_coverage_start", * timeCoverage.getStart().toDateTimeStringISO())); * ncDataset.addAttribute(null, new Attribute("time_coverage_end", timeCoverage.getEnd().toDateTimeStringISO())); * } */ ncDataset.finish(); }
Example 6
Source File: DataFactory.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Add information from the Dataset to the NetcdfDataset. * * @param ds get info from here * @param ncDataset add to here */ public static void annotate(Dataset ds, NetcdfDataset ncDataset) { ncDataset.setTitle(ds.getName()); ncDataset.setId(ds.getId()); // add properties as global attributes for (Property p : ds.getProperties()) { String name = p.getName(); if (null == ncDataset.findGlobalAttribute(name)) { ncDataset.addAttribute(null, new Attribute(name, p.getValue())); } } /* * ThreddsMetadata.GeospatialCoverage geoCoverage = ds.getGeospatialCoverage(); * if (geoCoverage != null) { * if ( null != geoCoverage.getNorthSouthRange()) { * ncDataset.addAttribute(null, new Attribute("geospatial_lat_min", new Double(geoCoverage.getLatSouth()))); * ncDataset.addAttribute(null, new Attribute("geospatial_lat_max", new Double(geoCoverage.getLatNorth()))); * } * if ( null != geoCoverage.getEastWestRange()) { * ncDataset.addAttribute(null, new Attribute("geospatial_lon_min", new Double(geoCoverage.getLonWest()))); * ncDataset.addAttribute(null, new Attribute("geospatial_lon_max", new Double(geoCoverage.getLonEast()))); * } * if ( null != geoCoverage.getUpDownRange()) { * ncDataset.addAttribute(null, new Attribute("geospatial_vertical_min", new Double(geoCoverage.getHeightStart()))); * ncDataset.addAttribute(null, new Attribute("geospatial_vertical_max", new Double(geoCoverage.getHeightStart() + * geoCoverage.getHeightExtent()))); * } * } * * DateRange timeCoverage = ds.getTimeCoverage(); * if (timeCoverage != null) { * ncDataset.addAttribute(null, new Attribute("time_coverage_start", * timeCoverage.getStart().toDateTimeStringISO())); * ncDataset.addAttribute(null, new Attribute("time_coverage_end", timeCoverage.getEnd().toDateTimeStringISO())); * } */ ncDataset.finish(); }
Example 7
Source File: GempakCdm.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
protected TableConfig getStationAsPointConfig(NetcdfDataset ds, Formatter errlog) { boolean needFinish = false; // find lat coord Variable lat = CoordSysEvaluator.findCoordByType(ds, AxisType.Lat); if (lat == null) { errlog.format("GempakCdm: Must have a Latitude coordinate"); return null; } // find lon coord Variable lon = CoordSysEvaluator.findCoordByType(ds, AxisType.Lon); if (lon == null) { errlog.format("GempakCdm: Must have a Longitude coordinate"); return null; } if (lat.getRank() != lon.getRank()) { errlog.format("GempakCdm: Lat and Lon coordinate must have same rank"); return null; } // check dimensions boolean stnIsScalar = (lat.getRank() == 0); boolean stnIsSingle = (lat.getRank() == 1) && (lat.getSize() == 1); Dimension stationDim = null; if (!stnIsScalar) { if (lat.getDimension(0) != lon.getDimension(0)) { errlog.format("Lat and Lon coordinate must have same size"); return null; } stationDim = lat.getDimension(0); } // optional alt coord Variable alt = CoordSysEvaluator.findCoordByType(ds, AxisType.Height); // obs table VariableDS time = CoordSysEvaluator.findCoordByType(ds, AxisType.Time); if (time == null) { errlog.format("GempakCdm: Must have a Time coordinate"); return null; } Dimension obsDim = time.getDimension(time.getRank() - 1); // may be time(time) or time(stn, obs) Table.Type obsTableType = Table.Type.Structure; Structure multidimStruct = Evaluator.findStructureWithDimensions(ds, stationDim, obsDim); if (multidimStruct == null) { errlog.format("GempakCdm: Cannot figure out StationAsPoint table structure"); return null; } TableConfig obs = new TableConfig(obsTableType, obsDim.getShortName()); obs.dimName = obsDim.getShortName(); obs.structName = multidimStruct.getFullName(); obs.structureType = TableConfig.StructureType.Structure; obs.featureType = FeatureType.POINT; obs.lat = lat.getFullName(); obs.lon = lon.getFullName(); obs.time = time.getFullName(); if (alt != null) obs.elev = alt.getFullName(); List<String> vars = new ArrayList<>(30); for (Variable v : ds.getVariables()) { if ((v.getDimension(0) == stationDim) && ((v.getRank() == 1) || ((v.getRank() == 2) && (v.getDataType() == DataType.CHAR)))) vars.add(v.getShortName()); } StructureDS s = new StructurePseudoDS(ds, null, "stnStruct", vars, stationDim); obs.addJoin(new JoinMuiltdimStructure(s, obsDim.getLength())); obs.addJoin(new JoinArray(time, JoinArray.Type.modulo, obsDim.getLength())); if (needFinish) ds.finish(); return obs; }