Java Code Examples for ucar.nc2.dataset.NetcdfDataset#findVariable()
The following examples show how to use
ucar.nc2.dataset.NetcdfDataset#findVariable() .
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: UnidataPointDatasetHelper.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Tries to find the coordinate variable of the specified type, which has the specified dimension as its firsst * dimension * * @param ds search in this dataset * @param a AxisType.LAT, LON, HEIGHT, or TIME * @param dim must use this dimension * @return coordinate variable, or null if not found. */ public static String getCoordinateName(NetcdfDataset ds, AxisType a, Dimension dim) { String name = getCoordinateName(ds, a); if (name == null) return null; Variable v = ds.findVariable(name); if (v == null) return null; if (v.isScalar()) return null; if (!v.getDimension(0).equals(dim)) return null; return name; }
Example 2
Source File: Table.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
TableParentIndex(NetcdfDataset ds, TableConfig config) { super(ds, config); this.parentIndexName = config.parentIndex; // construct the map try { Variable rpIndex = ds.findVariable(config.parentIndex); Array index = rpIndex.read(); int childIndex = 0; this.indexMap = new HashMap<>((int) (2 * index.getSize())); while (index.hasNext()) { int parent = index.nextInt(); List<Integer> list = indexMap.computeIfAbsent(parent, k -> new ArrayList<>()); list.add(childIndex); childIndex++; } } catch (IOException e) { throw new RuntimeException(e); } addNonDataVariable(config.parentIndex); }
Example 3
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 4
Source File: TestSequence.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void testSequence() { String url = "http://tsds.net/tsds/test/Scalar"; try { NetcdfDataset ds = NetcdfDatasets.openDataset(url); System.out.println(ds); Structure struct = (Structure) ds.findVariable("TimeSeries"); Variable var = struct.findVariable("time"); Array arr = var.read(); int n = (int) arr.getSize(); int i; for (i = 0; arr.hasNext() && i < n; i++) System.out.println(arr.nextDouble()); if (i != n) { System.err.println("short sequence"); System.exit(1); } } catch (Exception e) { e.printStackTrace(); } }
Example 5
Source File: BufrFeatureDatasetFactory.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private BufrStationDataset(NetcdfDataset ncfile, BufrCdmIndex index) { super(ncfile, FeatureType.STATION); this.index = index; // create the list of data variables munger = new Munge(); obs = (SequenceDS) ncfile.findVariable(BufrIosp2.obsRecordName); this.dataVariables = munger.makeDataVariables(index, obs); BufrStationCollection bufrCollection = new BufrStationCollection(ncfile.getLocation()); setPointFeatureCollection(bufrCollection); CalendarDateRange dateRange = CalendarDateRange.of(CalendarDate.of(index.start), CalendarDate.of(index.end)); setDateRange(dateRange); }
Example 6
Source File: Evaluator.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Find the variable pointed to by key * * @param ds in this dataset * @param key may be variable name or ":gatt" where gatt is local attribute whose value is the variable name * @param errlog error messages here * @return name of variable or null if not exist */ public static String getVariableName(NetcdfDataset ds, String key, Formatter errlog) { Variable v = null; String vs = getLiteral(ds, key, errlog); if (vs != null) { v = ds.findVariable(vs); if ((v == null) && (errlog != null)) errlog.format(" Cant find Variable %s from %s%n", vs, key); } return v == null ? null : v.getShortName(); }
Example 7
Source File: UnidataObsConvention.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private boolean addAxisType(NetcdfDataset ds, String vname, AxisType a) { if (vname == null) return false; Variable v = ds.findVariable(vname); if (v == null) return false; addAxisType(v, a); return true; }
Example 8
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 9
Source File: TestSimpleGeometryCSAll.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testSimpleGeometryBuildCS() throws IOException, InvalidRangeException { NetcdfDataset data = NetcdfDataset.openDataset(TestDir.cdmLocalTestDataDir + "dataset/SimpleGeos/hru_soil_moist_3hru_5timestep.nc"); List<CoordinateSystem> csl = data.getCoordinateSystems(); SimpleGeometryCSBuilder builder = new SimpleGeometryCSBuilder(data, csl.get(0), null); Variable hru_test = data.findVariable("hru_soil_moist"); SimpleGeometryFeature sgc = new SimpleGeometryFeature(hru_test.getFullNameEscaped(), hru_test.getDataType(), hru_test.attributes(), csl.get(0).getName(), hru_test.getUnitsString(), hru_test.getDescription(), null, GeometryType.POLYGON); sgc.setCoordSys(builder.makeCoordSys()); // Test retrieval of axis Assert.assertEquals("catchments_x", sgc.getXAxis().getFullNameEscaped()); Assert.assertEquals("catchments_y", sgc.getYAxis().getFullNameEscaped()); Assert.assertEquals("hruid", sgc.getIDAxis().getFullNameEscaped()); Assert.assertEquals(null, sgc.getZAxis()); // Now test reading a geometry. SimpleGeometry testGeometry = sgc.readGeometry(0); boolean testInstancePolygon = false; if (testGeometry instanceof Polygon) testInstancePolygon = true; Assert.assertEquals(true, testInstancePolygon); Polygon polygonTestGeometry = (Polygon) testGeometry; Assert.assertEquals(6233, polygonTestGeometry.getPoints().size()); }
Example 10
Source File: AWIPSConvention.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private CoordinateAxis makeTimeCoordAxisFromReference(NetcdfDataset ds, Variable timeVar, Array vals) { Variable refVar = ds.findVariable("reftime"); if (refVar == null) return null; double refValue; try { Array refArray = refVar.read(); refValue = refArray.getDouble(refArray.getIndex()); // get the first value } catch (IOException ioe) { return null; } if (refValue == N3iosp.NC_FILL_DOUBLE) return null; // construct the values array - make it a double to be safe Array dvals = Array.factory(DataType.DOUBLE, vals.getShape()); IndexIterator diter = dvals.getIndexIterator(); IndexIterator iiter = vals.getIndexIterator(); while (iiter.hasNext()) diter.setDoubleNext(iiter.getDoubleNext() + refValue); // add reftime to each of the values String units = ds.findAttValueIgnoreCase(refVar, CDM.UNITS, "seconds since 1970-1-1 00:00:00"); units = normalize(units); String desc = "synthesized time coordinate from reftime, valtimeMINUSreftime"; CoordinateAxis1D timeCoord = new CoordinateAxis1D(ds, null, "timeCoord", DataType.DOUBLE, "record", units, desc); timeCoord.setCachedData(dvals, true); parseInfo.format("Created Time Coordinate Axis From Reference = "); timeCoord.getNameAndDimensions(parseInfo, true, false); parseInfo.format("%n"); return timeCoord; }
Example 11
Source File: SequenceObsDataset.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Variable findVariable(NetcdfDataset ds, String name) { Variable result = ds.findVariable(name); if (result == null) { String aname = ds.findAttValueIgnoreCase(null, name + "_variable", null); if (aname == null) aname = ds.findAttValueIgnoreCase(null, name, null); if (aname != null) result = ds.findVariable(aname); } return result; }
Example 12
Source File: Madis.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public boolean isMine(FeatureType wantFeatureType, NetcdfDataset ds) { if ((wantFeatureType != FeatureType.ANY_POINT) && (wantFeatureType != FeatureType.STATION) && (wantFeatureType != FeatureType.POINT) && (wantFeatureType != FeatureType.STATION_PROFILE)) return false; if (!ds.hasUnlimitedDimension()) return false; if (ds.findDimension("recNum") == null) return false; if (ds.findVariable("staticIds") == null) return false; if (ds.findVariable("nStaticIds") == null) return false; if (ds.findVariable("lastRecord") == null) return false; if (ds.findVariable("prevRecord") == null) return false; VNames vn = getVariableNames(ds, null); if (ds.findVariable(vn.lat) == null) return false; if (ds.findVariable(vn.lon) == null) return false; return ds.findVariable(vn.obsTime) != null; }
Example 13
Source File: PointConfigXML.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private JoinArray readJoinArray(NetcdfDataset ds, Element joinElement) { JoinArray.Type type = JoinArray.Type.valueOf(joinElement.getAttributeValue("type")); Element paramElem = joinElement.getChild("param"); String paramS = paramElem.getText(); int param = Integer.parseInt(paramS); Element varElem = joinElement.getChild("variable"); String varName = varElem.getText(); VariableDS v = (VariableDS) ds.findVariable(varName); return new JoinArray(v, type, param); }
Example 14
Source File: RecordDatasetHelper.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Constructor. * * @param ncfile the netccdf file * @param typedDataVariables list of data variables; all record variables will be added to this list, except . You * can remove extra * @param obsTimeVName observation time variable name (required) * @param nomTimeVName nominal time variable name (may be null) * @throws IllegalArgumentException if ncfile has no unlimited dimension and recDimName is null. */ public RecordDatasetHelper(NetcdfDataset ncfile, String obsTimeVName, String nomTimeVName, List<VariableSimpleIF> typedDataVariables, String recDimName, Formatter errBuffer) { this.ncfile = ncfile; this.obsTimeVName = obsTimeVName; this.nomTimeVName = nomTimeVName; this.errs = errBuffer; // check if we already have a structure vs if we have to add it. if (this.ncfile.hasUnlimitedDimension()) { this.ncfile.sendIospMessage(NetcdfFile.IOSP_MESSAGE_ADD_RECORD_STRUCTURE); this.recordVar = (StructureDS) this.ncfile.getRootGroup().findVariableLocal("record"); this.obsDim = ncfile.getUnlimitedDimension(); } else { if (recDimName == null) throw new IllegalArgumentException("File <" + this.ncfile.getLocation() + "> has no unlimited dimension, specify psuedo record dimension with observationDimension global attribute."); this.obsDim = this.ncfile.getRootGroup().findDimension(recDimName); this.recordVar = new StructurePseudoDS(this.ncfile, null, "record", null, obsDim); } // create member variables List<Variable> recordMembers = ncfile.getVariables(); for (Variable v : recordMembers) { if (v == recordVar) continue; if (v.isScalar()) continue; if (v.getDimension(0) == this.obsDim) typedDataVariables.add(v); } // need the time units Variable timeVar = ncfile.findVariable(obsTimeVName); String timeUnitString = ncfile.findAttValueIgnoreCase(timeVar, CDM.UNITS, "seconds since 1970-01-01"); Calendar cal = TimeHelper.getCalendarFromAttribute(timeVar); try { timeUnit = CalendarDateUnit.withCalendar(cal, timeUnitString); } catch (Exception e) { if (null != errs) errs.format("Error on string = %s == %s%n", timeUnitString, e.getMessage()); timeUnit = CalendarDateUnit.unixDateUnit; } }
Example 15
Source File: UnidataStationObsDataset2.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
public UnidataStationObsDataset2(NetcdfDataset ds) throws IOException { super(ds); title = "Station Data from NWS"; desc = "Station Data from NWS distributed through the Unidata IDD realtime datastream. " + "Decoded into netCDF files by metar2nc (new). Usually 1 hour of data"; recordHelper = new RecordDatasetHelper(ds, "time_observation", "time_nominal", dataVariables, parseInfo); recordHelper.setStationInfo("station_index", "location"); removeDataVariable("time_observation"); removeDataVariable("time_nominal"); removeDataVariable("previousReport"); removeDataVariable("station_index"); recordVar = recordHelper.recordVar; timeUnit = recordHelper.timeUnit; // get the station info ArrayChar stationIdArray = (ArrayChar) ds.findVariable("id").read(); ArrayChar stationDescArray = (ArrayChar) ds.findVariable("location").read(); Array latArray = ds.findVariable("latitude").read(); Array lonArray = ds.findVariable("longitude").read(); Array elevArray = ds.findVariable("elevation").read(); Array lastRecordArray = ds.findVariable("lastReport").read(); Array numReportsArray = ds.findVariable("numberReports").read(); Index ima = lastRecordArray.getIndex(); int n = ds.findVariable("number_stations").readScalarInt(); recordHelper.stnHash = new HashMap(2 * n); for (int i = 0; i < n; i++) { ima.set(i); String stationName = stationIdArray.getString(i).trim(); String stationDesc = stationDescArray.getString(i).trim(); UnidataStationImpl bean = new UnidataStationImpl(stationName, stationDesc, latArray.getFloat(ima), lonArray.getFloat(ima), elevArray.getFloat(ima), lastRecordArray.getInt(ima), numReportsArray.getInt(ima)); stations.add(bean); recordHelper.stnHash.put(new Integer(i), bean); } setBoundingBox(); // get min, max date Variable minTimeVar = ds.findVariable("minimum_time_observation"); int minTimeValue = minTimeVar.readScalarInt(); startDate = timeUnit.makeDate(minTimeValue); Variable maxTimeVar = ds.findVariable("maximum_time_observation"); int maxTimeValue = maxTimeVar.readScalarInt(); endDate = timeUnit.makeDate(maxTimeValue); }
Example 16
Source File: MadisPointObsDataset.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
public MadisPointObsDataset(NetcdfDataset ds) throws IOException { super(ds); // dork around with the variable names altVName = "elevation"; String timeNames = ds.findAttValueIgnoreCase(null, "timeVariables", null); StringTokenizer stoker = new StringTokenizer(timeNames, ", "); obsTimeVName = stoker.nextToken(); if (ds.findVariable("timeNominal") != null) nomTimeVName = "timeNominal"; String idNames = ds.findAttValueIgnoreCase(null, "idVariables", null); stoker = new StringTokenizer(idNames, ", "); stnIdVName = stoker.nextToken(); if (stnIdVName.equals("stationName")) { // metars, sao, maritime if (ds.findVariable("locationName") != null) stnDescVName = "locationName"; if (debug) System.out.println("filetype 1 (metars)"); } else if (stnIdVName.equals("latitude")) { // acars LOOK this is not station - move to trajectory !! if (ds.findVariable("en_tailNumber") != null) stnIdVName = "en_tailNumber"; altVName = "altitude"; if (debug) System.out.println("filetype 3 (acars)"); } else { // coop, hydro, mesonet, radiometer if (ds.findVariable("stationId") != null) stnIdVName = "stationId"; if (ds.findVariable("stationName") != null) stnDescVName = "stationName"; if (debug) System.out.println("filetype 2 (mesonet)"); } if (debug) System.out.println("title= " + netcdfDataset.findAttValueIgnoreCase(null, "title", null)); recordHelper = new RecordDatasetHelper(ds, obsTimeVName, nomTimeVName, dataVariables, parseInfo); removeDataVariable("prevRecord"); timeUnit = recordHelper.timeUnit; // construct the stations Variable lastRecordVar = ds.findVariable("lastRecord"); ArrayInt.D1 lastRecord = (ArrayInt.D1) lastRecordVar.read(); Variable inventoryVar = ds.findVariable("inventory"); ArrayInt.D1 inventoryData = (ArrayInt.D1) inventoryVar.read(); Variable v = ds.findVariable("nStaticIds"); int n = v.readScalarInt(); recordHelper.stnHash = new HashMap(2 * n); recordVar = (Structure) ds.findVariable("record"); for (int stnIndex = 0; stnIndex < n; stnIndex++) { int lastValue = lastRecord.get(stnIndex); int inventory = inventoryData.get(stnIndex); if (lastValue < 0) continue; // get an obs record for this, and extract the station info StructureData sdata = null; try { sdata = recordVar.readStructure(lastValue); } catch (InvalidRangeException e) { parseInfo.append("Invalid lastValue=" + lastValue + " for station at index " + stnIndex + "\n"); continue; } String stationId = sdata.getScalarString(stnIdVName).trim(); String stationDesc = (stnDescVName == null) ? null : sdata.getScalarString(stnDescVName); } // if (debug) System.out.println("total stations " + stations.size()+" should be = "+n); // get min, max date Variable timeVar = ds.findVariable(obsTimeVName); Array timeData = timeVar.read(); MAMath.MinMax minmax = MAMath.getMinMax(timeData); startDate = timeUnit.makeDate(minmax.min); endDate = timeUnit.makeDate(minmax.max); setBoundingBox(); }
Example 17
Source File: CEDRICRadarConvention.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void augmentDataset(NetcdfDataset ncDataset, CancelTask cancelTask) throws IOException { /* * float lat = 40.45f; * float lon = -104.64f; * ProjectionImpl projection = new FlatEarth(lat, lon); * * Variable ct = new Variable( ncDataset, null, null, projection.getClassName()); * ct.setDataType( DataType.CHAR); * ct.setDimensions( ""); * * ct.addAttribute( new Attribute("grid_mapping_name", "flat_earth")); * ct.addAttribute( new Attribute(_Coordinate.TransformType, "Projection")); * ct.addAttribute( new Attribute(_Coordinate.Axes, "GeoX GeoY")); * ncDataset.addVariable(null, ct); */ NcMLReader.wrapNcMLresource(ncDataset, CoordSysBuilder.resourcesDir + "CEDRICRadar.ncml", cancelTask); Variable lat = ncDataset.findVariable("radar_latitude"); Variable lon = ncDataset.findVariable("radar_longitude"); float latv = (float) lat.readScalarDouble(); float lonv = (float) lon.readScalarDouble(); Variable pv = ncDataset.findVariable("Projection"); pv.addAttribute(new Attribute("longitude_of_projection_origin", lonv)); pv.addAttribute(new Attribute("latitude_of_projection_origin", latv)); Variable tvar = ncDataset.findVariable("time"); /* * Date dt = null; * Variable sdate = ncDataset.findVariable("start_date"); * Variable stime = ncDataset.findVariable("start_time"); * String dateStr = sdate.readScalarString(); * String timeStr = stime.readScalarString(); * try { * dt = DateUtil.parse(dateStr + " " + timeStr); * } catch (Exception e) {} */ int nt = 1; ArrayDouble.D1 data = new ArrayDouble.D1(nt); // fake data.setDouble(0, 0); // data.setDouble(0, dt.getTime()/1000); tvar.setCachedData(data, false); super.augmentDataset(ncDataset, cancelTask); }
Example 18
Source File: Nimbus.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) throws IOException { ds.addAttribute(null, new Attribute("cdm_data_type", ucar.nc2.constants.FeatureType.TRAJECTORY.name())); // deprecated ds.addAttribute(null, new Attribute(CF.FEATURE_TYPE, ucar.nc2.constants.FeatureType.TRAJECTORY.name())); if (!setAxisType(ds, "LATC", AxisType.Lat)) if (!setAxisType(ds, "LAT", AxisType.Lat)) setAxisType(ds, "GGLAT", AxisType.Lat); if (!setAxisType(ds, "LONC", AxisType.Lon)) if (!setAxisType(ds, "LON", AxisType.Lon)) setAxisType(ds, "GGLON", AxisType.Lon); if (!setAxisType(ds, "PALT", AxisType.Height)) setAxisType(ds, "GGALT", AxisType.Height); boolean hasTime = setAxisType(ds, "Time", AxisType.Time); if (!hasTime) hasTime = setAxisType(ds, "time", AxisType.Time); // do we need to version this ? // String version = ds.findAttValueIgnoreCase(null, "version", null); if (!hasTime) { Variable time = ds.findVariable("time_offset"); if (time != null) { Variable base = ds.findVariable("base_time"); int base_time = base.readScalarInt(); try { DateUnit dunit = new DateUnit("seconds since 1970-01-01 00:00"); String time_units = "seconds since " + dunit.makeStandardDateString(base_time); time.addAttribute(new Attribute(CDM.UNITS, time_units)); time.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Time.name())); } catch (Exception e) { e.printStackTrace(); } } } // look for coordinates String coordinates = ds.findAttValueIgnoreCase(null, "coordinates", null); if (coordinates != null) { String[] vars = coordinates.split(" "); for (String vname : vars) { Variable v = ds.findVariable(vname); if (v != null) { AxisType atype = getAxisType(ds, (VariableEnhanced) v); if (atype != null) v.addAttribute(new Attribute(_Coordinate.AxisType, atype.name())); } } } }
Example 19
Source File: Iridl.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
public TableConfig getConfig(FeatureType wantFeatureType, NetcdfDataset ds, Formatter errlog) { Dimension stationDim = CoordSysEvaluator.findDimensionByType(ds, AxisType.Lat); if (stationDim == null) { errlog.format("Must have a latitude coordinate"); return null; } Variable stationVar = ds.findVariable(stationDim.getShortName()); if (stationVar == null) { errlog.format("Must have a station coordinate variable"); return null; } Dimension obsDim = CoordSysEvaluator.findDimensionByType(ds, AxisType.Time); if (obsDim == null) { errlog.format("Must have a Time coordinate"); return null; } // station table TableConfig stationTable = new TableConfig(Table.Type.Structure, "station"); stationTable.structName = "station"; stationTable.structureType = TableConfig.StructureType.PsuedoStructure; stationTable.featureType = FeatureType.STATION; stationTable.dimName = stationDim.getShortName(); stationTable.stnId = stationVar.getShortName(); stationTable.lat = CoordSysEvaluator.findCoordNameByType(ds, AxisType.Lat); stationTable.lon = CoordSysEvaluator.findCoordNameByType(ds, AxisType.Lon); stationTable.stnAlt = CoordSysEvaluator.findCoordNameByType(ds, AxisType.Height); // obs table TableConfig obsTable; obsTable = new TableConfig(Table.Type.MultidimInner, "obs"); obsTable.time = CoordSysEvaluator.findCoordNameByType(ds, AxisType.Time); obsTable.outerName = stationDim.getShortName(); obsTable.dimName = obsDim.getShortName(); stationTable.addChild(obsTable); return stationTable; }
Example 20
Source File: CdmDirect.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
protected TableConfig getStationConfig(NetcdfDataset ds, Formatter errlog) { // find lat coord Variable lat = CoordSysEvaluator.findCoordByType(ds, AxisType.Lat); if (lat == null) { errlog.format("CdmDirect: Must have a Latitude coordinate%n"); return null; } // find lon coord Variable lon = CoordSysEvaluator.findCoordByType(ds, AxisType.Lon); if (lon == null) { errlog.format("CdmDirect: Must have a Longitude coordinate%n"); return null; } if (lat.getRank() != lon.getRank()) { errlog.format("CdmDirect: Lat and Lon coordinate must have same rank"); return null; } // should be a top level struct or sequence TableConfig stnTable = new TableConfig(Table.Type.Structure, "station"); stnTable.featureType = FeatureType.STATION; stnTable.structureType = TableConfig.StructureType.Structure; stnTable.lat = lat.getShortName(); stnTable.lon = lon.getShortName(); // optional alt coord Variable alt = CoordSysEvaluator.findCoordByType(ds, AxisType.Height); if (alt != null) stnTable.stnAlt = alt.getShortName(); // station id stnTable.stnId = Evaluator.findNameOfVariableWithAttributeValue(ds, CF.CF_ROLE, CF.STATION_ID); if (stnTable.stnId == null) stnTable.stnId = Evaluator.findNameOfVariableWithAttributeValue(ds, CF.STANDARD_NAME, CF.STATION_ID); // old way if (stnTable.stnId == null) { errlog.format("Must have a Station id variable with standard name station_id%n"); return null; } // other station stnTable.stnDesc = Evaluator.findNameOfVariableWithAttributeValue(ds, CF.STANDARD_NAME, CF.PLATFORM_NAME); if (stnTable.stnDesc == null) stnTable.stnDesc = Evaluator.findNameOfVariableWithAttributeValue(ds, CF.STANDARD_NAME, CF.STATION_DESC); stnTable.stnWmoId = Evaluator.findNameOfVariableWithAttributeValue(ds, CF.STANDARD_NAME, CF.STATION_WMOID); // obs table Structure stnv = (Structure) ds.findVariable("station"); Structure obsv = null; for (Variable v : stnv.getVariables()) { if (v.getDataType() == DataType.SEQUENCE) obsv = (Structure) v; } if (obsv == null) { errlog.format("Must have a SEQUENCE variable%n"); return null; } TableConfig obs = new TableConfig(Table.Type.NestedStructure, obsv.getFullName()); obs.nestedTableName = obsv.getShortName(); obs.time = CoordSysEvaluator.findCoordShortNameByType(ds, AxisType.Time); if (obs.time == null) { errlog.format("Must have a time coordinate%n"); return null; } stnTable.addChild(obs); return stnTable; }