private LatLonRect getBoundingBox(List stnList) { ucar.unidata.geoloc.Station s = (ucar.unidata.geoloc.Station) stnList.get(0); LatLonPointImpl llpt = new LatLonPointImpl(); llpt.set(s.getLatitude(), s.getLongitude()); LatLonRect rect = new LatLonRect(llpt, .001, .001); for (int i = 1; i < stnList.size(); i++) { s = (ucar.unidata.geoloc.Station) stnList.get(i); llpt.set(s.getLatitude(), s.getLongitude()); rect.extend(llpt); } return rect; }
private void hideNestedTable(int level) { int n = nestedTableList.size(); for (int i = n - 1; i >= level; i--) { NestedTable ntable = nestedTableList.get(i); ntable.hide(); } }
/** * Create a new GridVertCoord with the appropriate params * * @param records list of GridRecords that make up this coord * @param levelName the name of the level * @param lookup the lookup table * @param hcs Horizontal coordinate */ GridVertCoord( List<GridRecord> records, String levelName, GridTableLookup lookup, GridHorizCoordSys hcs) { this.typicalRecord = records.get(0); this.levelName = levelName; this.lookup = lookup; dontUseVertical = !lookup.isVerticalCoordinate(typicalRecord); positive = lookup.isPositiveUp(typicalRecord) ? "up" : "down"; units = lookup.getLevelUnit(typicalRecord); usesBounds = lookup.isLayer(this.typicalRecord); addLevels(records); if (typicalRecord.getLevelType1() == 109 && lookup instanceof Grib1GridTableLookup) checkForPressureLevels(records, hcs); if (GridServiceProvider.debugVert) { System.out.println( "GribVertCoord: " + getVariableName() + "(" + typicalRecord.getLevelType1() + ") useVertical= " + (!dontUseVertical) + " positive=" + positive + " units=" + units); } }
public void setDataset(NetcdfFile ds) { this.ds = ds; NestedTable nt = nestedTableList.get(0); nt.table.setBeans(getVariableBeans(ds)); hideNestedTable(1); datasetTree.setFile(ds); }
/** get the shape */ public int[] getShape() { int[] shape = new int[mydims.size()]; for (int i = 0; i < mydims.size(); i++) { Dimension d = mydims.get(i); shape[i] = d.getLength(); } return shape; }
private void makeSelectStations(StringBuffer sbuff, List stations) { // ID id1,id2,id3,...idn // However, it will depend on the dataset as to the variable for the station ID. // For synoptic data it's IDN (e.g. 72469) // for METAR it's ID. // For profiler data, there are two variables IDA and IDB where IDA is the first 4 chars and IDB // is the second 4. sbuff.append("ID "); for (int i = 0; i < stations.size(); i++) { Station s = (Station) stations.get(i); if (i > 0) sbuff.append(","); sbuff.append(s.getName()); } }
private NestedTable setNestedTable(int level, Structure s) { NestedTable ntable; if (nestedTableList.size() < level + 1) { ntable = new NestedTable(level); nestedTableList.add(ntable); } else { ntable = nestedTableList.get(level); } if (s != null) // variables inside of records ntable.table.setBeans(getStructureVariables(s)); ntable.show(); return ntable; }
/** check for Sigma Pressure Levels */ boolean checkForPressureLevels(List<GridRecord> records, GridHorizCoordSys hcs) { GridDefRecord gdr = hcs.getGds(); Grib1GDSVariables g1dr = (Grib1GDSVariables) gdr.getGdsv(); if (g1dr == null || !g1dr.hasVerticalPressureLevels()) return false; // add hybrid numbers coordValues = new double[levels.size()]; for (int i = 0; i < levels.size(); i++) { LevelCoord lc = levels.get(i); coordValues[i] = lc.value1; } int NV = g1dr.getNV(); // add new variables if (NV > 2 && NV < 255) { // Some data doesn't add Pressure Level values factors = g1dr.getVerticalPressureLevels(); } return true; }
/** * Add this as a variable to the netCDF file * * @param ncfile the netCDF file * @param g the group in the file */ void addToNetcdfFile(NetcdfFile ncfile, Group g) { Variable v = new Variable(ncfile, g, null, getName()); v.setDimensions(v.getShortName()); v.setDataType(DataType.STRING); v.addAttribute(new Attribute("long_name", "ensemble")); v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Ensemble.toString())); String[] data = new String[getNEnsembles()]; for (int i = 0; i < getNEnsembles(); i++) { EnsCoord ec = ensCoords.get(i); data[i] = Grib2Tables.codeTable4_6(ec.type) + " " + ec.number; } Array dataArray = Array.factory(DataType.STRING, new int[] {getNEnsembles()}, data); v.setCachedData(dataArray, false); ncfile.addVariable(g, v); }
private void setSelected(Variable v) { eventsOK = false; List<Variable> vchain = new ArrayList<Variable>(); vchain.add(v); Variable vp = v; while (vp.isMemberOfStructure()) { vp = vp.getParentStructure(); vchain.add(0, vp); // reverse } for (int i = 0; i < vchain.size(); i++) { vp = vchain.get(i); NestedTable ntable = setNestedTable(i, vp.getParentStructure()); ntable.setSelected(vp); } eventsOK = true; }
private void writeStationData(List<ucar.unidata.geoloc.Station> stnList) throws IOException { this.stnList = stnList; int nstns = stnList.size(); stationMap = new HashMap<String, StationTracker>(2 * nstns); if (debug) System.out.println("stationMap created"); // now write the station data ArrayDouble.D1 latArray = new ArrayDouble.D1(nstns); ArrayDouble.D1 lonArray = new ArrayDouble.D1(nstns); ArrayDouble.D1 altArray = new ArrayDouble.D1(nstns); ArrayObject.D1 idArray = new ArrayObject.D1(String.class, nstns); ArrayObject.D1 descArray = new ArrayObject.D1(String.class, nstns); ArrayObject.D1 wmoArray = new ArrayObject.D1(String.class, nstns); for (int i = 0; i < stnList.size(); i++) { ucar.unidata.geoloc.Station stn = stnList.get(i); stationMap.put(stn.getName(), new StationTracker(i)); latArray.set(i, stn.getLatitude()); lonArray.set(i, stn.getLongitude()); if (useAlt) altArray.set(i, stn.getAltitude()); idArray.set(i, stn.getName()); descArray.set(i, stn.getDescription()); if (useWmoId) wmoArray.set(i, stn.getWmoId()); } try { ncfile.write(latName, latArray); ncfile.write(lonName, lonArray); if (useAlt) ncfile.write(altName, altArray); ncfile.writeStringData(idName, idArray); ncfile.writeStringData(descName, descArray); if (useWmoId) ncfile.writeStringData(wmoName, wmoArray); } catch (InvalidRangeException e) { e.printStackTrace(); throw new IllegalStateException(e); } }
private void compareDataset(CompareDialog.Data data) { if (data.name == null) return; NetcdfFile compareFile = null; try { compareFile = NetcdfDataset.openFile(data.name, null); Formatter f = new Formatter(); CompareNetcdf2 cn = new CompareNetcdf2(f, data.showCompare, data.showDetails, data.readData); if (data.howMuch == CompareDialog.HowMuch.All) cn.compare(ds, compareFile); else { NestedTable nested = nestedTableList.get(0); Variable org = getCurrentVariable(nested.table); if (org == null) return; Variable ov = compareFile.findVariable(org.getFullNameEscaped()); if (ov != null) cn.compareVariable(org, ov); } infoTA.setText(f.toString()); infoTA.gotoTop(); infoWindow.setTitle("Compare"); infoWindow.show(); } catch (Throwable ioe) { ByteArrayOutputStream bos = new ByteArrayOutputStream(10000); ioe.printStackTrace(new PrintStream(bos)); infoTA.setText(bos.toString()); infoTA.gotoTop(); infoWindow.show(); } finally { if (compareFile != null) try { compareFile.close(); } catch (Exception eek) { } } }
/** * Get the coordinate index for the record * * @param record record in question * @return index or -1 if not found */ private int coordIndex(GridRecord record) { double val = record.getLevel1(); double val2 = record.getLevel2(); if (usesBounds && (val > val2)) { val = record.getLevel2(); val2 = record.getLevel1(); } for (int i = 0; i < levels.size(); i++) { LevelCoord lc = (LevelCoord) levels.get(i); if (usesBounds) { if (ucar.nc2.util.Misc.closeEnough(lc.value1, val) && ucar.nc2.util.Misc.closeEnough(lc.value2, val2)) { return i; } } else { if (ucar.nc2.util.Misc.closeEnough(lc.value1, val)) { return i; } } } return -1; }
// Constructor for when you already have the StructureData, and need to find Station and times protected RecordStationObs(StructureData sdata, int recno, boolean useId) { super(recno); this.recno = recno; this.sdata = sdata; this.timeUnit = RecordDatasetHelper.this.timeUnit; StructureMembers members = sdata.getStructureMembers(); obsTime = getTime(members.findMember(obsTimeVName), sdata); nomTime = (nomTimeVName == null) ? obsTime : getTime(members.findMember(nomTimeVName), sdata); if (useId) { // this assumes the station id/name is stored in the obs record String stationId; if (stationIdType == DataType.INT) { stationId = Integer.toString(sdata.getScalarInt(stnIdVName)); } else stationId = sdata.getScalarString(stnIdVName).trim(); station = stationHelper.getStation(stationId); if (null != errs) errs.format(" cant find station id = <%s> when reading record %d%n", stationId, recno); log.error(" cant find station id = <" + stationId + "> when reading record " + recno); } else { // use a station index List<Station> stations = stationHelper.getStations(); int stationIndex = sdata.getScalarInt(stnIndexVName); if (stationIndex < 0 || stationIndex >= stations.size()) { if (null != errs) errs.format( " cant find station at index =%d when reading record %d%n", stationIndex, recno); log.error( "cant find station at index = " + stationIndex + " when reading record " + recno); } else station = stations.get(stationIndex); } location = station; }
/** * Create a new GeoGrid that is a logical subset of this GeoGrid. * * @param t_range subset the time dimension, or null if you want all of it * @param z_range subset the vertical dimension, or null if you want all of it * @param bbox a lat/lon bounding box, or null if you want all x,y * @param z_stride use only if z_range is null, then take all z with this stride (1 means all) * @param y_stride use this stride on the y coordinate (1 means all) * @param x_stride use this stride on the x coordinate (1 means all) * @return subsetted GeoGrid * @throws InvalidRangeException if bbox does not intersect GeoGrid */ public GeoGrid subset( Range t_range, Range z_range, LatLonRect bbox, int z_stride, int y_stride, int x_stride) throws InvalidRangeException { if ((z_range == null) && (z_stride > 1)) { Dimension zdim = getZDimension(); if (zdim != null) z_range = new Range(0, zdim.getLength() - 1, z_stride); } Range y_range = null, x_range = null; if (bbox != null) { List yx_ranges = gcs.getRangesFromLatLonRect(bbox); y_range = (Range) yx_ranges.get(0); x_range = (Range) yx_ranges.get(1); } if (y_stride > 1) { if (y_range == null) { Dimension ydim = getYDimension(); y_range = new Range(0, ydim.getLength() - 1, y_stride); } else { y_range = new Range(y_range.first(), y_range.last(), y_stride); } } if (x_stride > 1) { if (x_range == null) { Dimension xdim = getXDimension(); x_range = new Range(0, xdim.getLength() - 1, x_stride); } else { x_range = new Range(x_range.first(), x_range.last(), x_stride); } } return subset(t_range, z_range, y_range, x_range); }
/** * Add levels * * @param records GridRecords, one for each level */ void addLevels(List<GridRecord> records) { for (int i = 0; i < records.size(); i++) { GridRecord record = records.get(i); if (coordIndex(record) < 0) { levels.add(new LevelCoord(record.getLevel1(), record.getLevel2())); if (dontUseVertical && (levels.size() > 1)) { if (GridServiceProvider.debugVert) { logger.warn( "GribCoordSys: unused level coordinate has > 1 levels = " + levelName + " " + record.getLevelType1() + " " + levels.size()); } } } } Collections.sort(levels); if (positive.equals("down")) { Collections.reverse(levels); } }
public static boolean isValidFile(NetcdfDataset ds) { // Check that has a time dimension and a trajectory dimension. List list = ds.getRootGroup().getDimensions(); if (list.size() != 2) return (false); Dimension d; for (int i = 0; i < 2; i++) { d = (Dimension) list.get(i); if (!d.getShortName().equals(timeDimNameDefault) && !d.getShortName().equals(trajDimNameDefault)) return (false); } // Check that has a trajectory coordinate variable. Variable var = ds.getRootGroup().findVariable(trajVarNameDefault); if (var == null) return (false); list = var.getDimensions(); if (list.size() != 1) return (false); d = (Dimension) list.get(0); if (!d.getShortName().equals(trajDimNameDefault)) return (false); // Check that has a time coordinate variable with units that are udunits time var = ds.getRootGroup().findVariable(timeVarNameDefault); if (var == null) return (false); list = var.getDimensions(); if (list.size() != 1) return (false); d = (Dimension) list.get(0); if (!d.getShortName().equals(timeDimNameDefault)) return (false); String units = var.findAttribute("units").getStringValue(); Date date = DateUnit.getStandardDate("0 " + units); if (date == null) return (false); // Check for variable latitude(time) with units of "deg". var = ds.getRootGroup().findVariable(latVarNameDefault); if (var == null) return (false); list = var.getDimensions(); if (list.size() != 2) return (false); for (int i = 0; i < 2; i++) { d = (Dimension) list.get(i); if (!d.getShortName().equals(timeDimNameDefault) && !d.getShortName().equals(trajDimNameDefault)) return (false); } // units = var.findAttribute( "units").getStringValue(); // if ( ! SimpleUnit.isCompatible( units, "degrees_north")) return( false); // Check for variable longitude(time) with units of "deg". var = ds.getRootGroup().findVariable(lonVarNameDefault); if (var == null) return (false); list = var.getDimensions(); if (list.size() != 2) return (false); for (int i = 0; i < 2; i++) { d = (Dimension) list.get(i); if (!d.getShortName().equals(timeDimNameDefault) && !d.getShortName().equals(trajDimNameDefault)) return (false); } // units = var.findAttribute( "units").getStringValue(); // if ( ! SimpleUnit.isCompatible( units, "degrees_east")) return( false); // Check for variable altitude(time) with units of "m". var = ds.getRootGroup().findVariable(elevVarNameDefault); if (var == null) return (false); list = var.getDimensions(); if (list.size() != 2) return (false); for (int i = 0; i < 2; i++) { d = (Dimension) list.get(i); if (!d.getShortName().equals(timeDimNameDefault) && !d.getShortName().equals(trajDimNameDefault)) return (false); } units = var.findAttribute("units").getStringValue(); if (!SimpleUnit.isCompatible(units, "m")) return (false); return (true); }
private void writeDataFinish() throws IOException { // finish global variables ArrayInt.D0 totalArray = new ArrayInt.D0(); totalArray.set(profileIndex); try { ncfile.write(numProfilesTotalName, totalArray); } catch (InvalidRangeException e) { e.printStackTrace(); throw new IllegalStateException(e); } // finish the station data int nstns = stnList.size(); ArrayInt.D1 firstProfileArray = new ArrayInt.D1(nstns); ArrayInt.D1 numProfileArray = new ArrayInt.D1(nstns); ArrayInt.D1 nextProfileArray = new ArrayInt.D1(nprofiles); for (int i = 0; i < stnList.size(); i++) { ucar.unidata.geoloc.Station stn = stnList.get(i); StationTracker tracker = stationMap.get(stn.getName()); numProfileArray.set(i, tracker.numChildren); int first = (tracker.link.size() > 0) ? tracker.link.get(0) : -1; firstProfileArray.set(i, first); if (tracker.link.size() > 0) { // construct forward link List<Integer> nextList = tracker.link; for (int j = 0; j < nextList.size() - 1; j++) { Integer curr = nextList.get(j); Integer next = nextList.get(j + 1); nextProfileArray.set(curr, next); } Integer curr = nextList.get(nextList.size() - 1); nextProfileArray.set(curr, -1); } } try { ncfile.write(firstProfileName, firstProfileArray); ncfile.write(numProfilesName, numProfileArray); ncfile.write(nextProfileName, nextProfileArray); } catch (InvalidRangeException e) { e.printStackTrace(); throw new IllegalStateException(e); } // finish the profile data ArrayInt.D1 nextObsArray = new ArrayInt.D1(recno); ArrayInt.D1 firstObsArray = new ArrayInt.D1(nprofiles); ArrayInt.D1 numObsArray = new ArrayInt.D1(nprofiles); for (int i = 0; i < stnList.size(); i++) { ucar.unidata.geoloc.Station stn = stnList.get(i); StationTracker stnTracker = stationMap.get(stn.getName()); Set<Date> dates = stnTracker.profileMap.keySet(); for (Date date : dates) { ProfileTracker proTracker = stnTracker.profileMap.get(date); int trackerIndex = proTracker.parent_index; numObsArray.set(trackerIndex, proTracker.numChildren); int first = (proTracker.link.size() > 0) ? proTracker.link.get(0) : -1; firstObsArray.set(trackerIndex, first); if (proTracker.link.size() > 0) { // construct forward link List<Integer> nextList = proTracker.link; for (int j = 0; j < nextList.size() - 1; j++) { Integer curr = nextList.get(j); Integer next = nextList.get(j + 1); nextObsArray.set(curr, next); } Integer curr = nextList.get(nextList.size() - 1); nextObsArray.set(curr, -1); } } } try { ncfile.write(firstObsName, firstObsArray); ncfile.write(numObsName, numObsArray); ncfile.write(nextObsName, nextObsArray); } catch (InvalidRangeException e) { e.printStackTrace(); throw new IllegalStateException(e); } // finish the obs data ncfile.updateAttribute( null, new Attribute("time_coverage_start", dateFormatter.toDateTimeStringISO(minDate))); ncfile.updateAttribute( null, new Attribute("time_coverage_end", dateFormatter.toDateTimeStringISO(maxDate))); }
private void createStations(List<ucar.unidata.geoloc.Station> stnList) throws IOException { int nstns = stnList.size(); // see if there's altitude, wmoId for any stations for (int i = 0; i < nstns; i++) { ucar.unidata.geoloc.Station stn = stnList.get(i); // if (!Double.isNaN(stn.getAltitude())) // useAlt = true; if ((stn.getWmoId() != null) && (stn.getWmoId().trim().length() > 0)) useWmoId = true; } /* if (useAlt) ncfile.addGlobalAttribute("altitude_coordinate", altName); */ // find string lengths for (int i = 0; i < nstns; i++) { ucar.unidata.geoloc.Station station = stnList.get(i); name_strlen = Math.max(name_strlen, station.getName().length()); desc_strlen = Math.max(desc_strlen, station.getDescription().length()); if (useWmoId) wmo_strlen = Math.max(wmo_strlen, station.getName().length()); } LatLonRect llbb = getBoundingBox(stnList); ncfile.addGlobalAttribute( "geospatial_lat_min", Double.toString(llbb.getLowerLeftPoint().getLatitude())); ncfile.addGlobalAttribute( "geospatial_lat_max", Double.toString(llbb.getUpperRightPoint().getLatitude())); ncfile.addGlobalAttribute( "geospatial_lon_min", Double.toString(llbb.getLowerLeftPoint().getLongitude())); ncfile.addGlobalAttribute( "geospatial_lon_max", Double.toString(llbb.getUpperRightPoint().getLongitude())); // add the dimensions Dimension recordDim = ncfile.addUnlimitedDimension(recordDimName); recordDims.add(recordDim); Dimension stationDim = ncfile.addDimension(stationDimName, nstns); stationDims.add(stationDim); // add the station Variables using the station dimension Variable v = ncfile.addVariable(latName, DataType.DOUBLE, stationDimName); ncfile.addVariableAttribute(v, new Attribute("units", "degrees_north")); ncfile.addVariableAttribute(v, new Attribute("long_name", "station latitude")); v = ncfile.addVariable(lonName, DataType.DOUBLE, stationDimName); ncfile.addVariableAttribute(v, new Attribute("units", "degrees_east")); ncfile.addVariableAttribute(v, new Attribute("long_name", "station longitude")); if (useAlt) { v = ncfile.addVariable(altName, DataType.DOUBLE, stationDimName); ncfile.addVariableAttribute(v, new Attribute("units", "meters")); ncfile.addVariableAttribute(v, new Attribute("long_name", "station altitude")); } v = ncfile.addStringVariable(idName, stationDims, name_strlen); ncfile.addVariableAttribute(v, new Attribute("long_name", "station identifier")); v = ncfile.addStringVariable(descName, stationDims, desc_strlen); ncfile.addVariableAttribute(v, new Attribute("long_name", "station description")); if (useWmoId) { v = ncfile.addStringVariable(wmoName, stationDims, wmo_strlen); ncfile.addVariableAttribute(v, new Attribute("long_name", "station WMO id")); } v = ncfile.addVariable(numProfilesName, DataType.INT, stationDimName); ncfile.addVariableAttribute( v, new Attribute("long_name", "number of profiles in linked list for this station")); v = ncfile.addVariable(firstProfileName, DataType.INT, stationDimName); ncfile.addVariableAttribute( v, new Attribute("long_name", "index of first profile in linked list for this station")); }
public Variable makeVariable( NetcdfFile ncfile, int datatype, String shortName, String longName, String abbrev, List groups) throws IOException { int nscans = groups.size(); if (nscans == 0) { throw new IllegalStateException("No data for " + shortName); } // get representative record List firstGroup = (List) groups.get(0); Cinrad2Record firstRecord = (Cinrad2Record) firstGroup.get(0); int ngates = firstRecord.getGateCount(datatype); String scanDimName = "scan" + abbrev; String gateDimName = "gate" + abbrev; Dimension scanDim = new Dimension(scanDimName, nscans); Dimension gateDim = new Dimension(gateDimName, ngates); ncfile.addDimension(null, scanDim); ncfile.addDimension(null, gateDim); ArrayList dims = new ArrayList(); dims.add(scanDim); dims.add(radialDim); dims.add(gateDim); Variable v = new Variable(ncfile, null, null, shortName); v.setDataType(DataType.BYTE); v.setDimensions(dims); ncfile.addVariable(null, v); v.addAttribute(new Attribute(CDM.UNITS, Cinrad2Record.getDatatypeUnits(datatype))); v.addAttribute(new Attribute(CDM.LONG_NAME, longName)); byte[] b = new byte[2]; b[0] = Cinrad2Record.MISSING_DATA; b[1] = Cinrad2Record.BELOW_THRESHOLD; Array missingArray = Array.factory(DataType.BYTE.getPrimitiveClassType(), new int[] {2}, b); v.addAttribute(new Attribute(CDM.MISSING_VALUE, missingArray)); v.addAttribute( new Attribute("signal_below_threshold", new Byte(Cinrad2Record.BELOW_THRESHOLD))); v.addAttribute( new Attribute(CDM.SCALE_FACTOR, new Float(Cinrad2Record.getDatatypeScaleFactor(datatype)))); v.addAttribute( new Attribute(CDM.ADD_OFFSET, new Float(Cinrad2Record.getDatatypeAddOffset(datatype)))); v.addAttribute(new Attribute(CDM.UNSIGNED, "true")); ArrayList dim2 = new ArrayList(); dim2.add(scanDim); dim2.add(radialDim); // add time coordinate variable String timeCoordName = "time" + abbrev; Variable timeVar = new Variable(ncfile, null, null, timeCoordName); timeVar.setDataType(DataType.INT); timeVar.setDimensions(dim2); ncfile.addVariable(null, timeVar); // int julianDays = volScan.getTitleJulianDays(); // Date d = Cinrad2Record.getDate( julianDays, 0); // Date d = Cinrad2Record.getDate(volScan.getTitleJulianDays(), volScan.getTitleMsecs()); Date d = volScan.getStartDate(); String units = "msecs since " + formatter.toDateTimeStringISO(d); timeVar.addAttribute(new Attribute(CDM.LONG_NAME, "time since base date")); timeVar.addAttribute(new Attribute(CDM.UNITS, units)); timeVar.addAttribute(new Attribute(CDM.MISSING_VALUE, new Integer(MISSING_INT))); timeVar.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Time.toString())); // add elevation coordinate variable String elevCoordName = "elevation" + abbrev; Variable elevVar = new Variable(ncfile, null, null, elevCoordName); elevVar.setDataType(DataType.FLOAT); elevVar.setDimensions(dim2); ncfile.addVariable(null, elevVar); elevVar.addAttribute(new Attribute(CDM.UNITS, "degrees")); elevVar.addAttribute( new Attribute( CDM.LONG_NAME, "elevation angle in degres: 0 = parallel to pedestal base, 90 = perpendicular")); elevVar.addAttribute(new Attribute(CDM.MISSING_VALUE, new Float(MISSING_FLOAT))); elevVar.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.RadialElevation.toString())); // add azimuth coordinate variable String aziCoordName = "azimuth" + abbrev; Variable aziVar = new Variable(ncfile, null, null, aziCoordName); aziVar.setDataType(DataType.FLOAT); aziVar.setDimensions(dim2); ncfile.addVariable(null, aziVar); aziVar.addAttribute(new Attribute(CDM.UNITS, "degrees")); aziVar.addAttribute( new Attribute(CDM.LONG_NAME, "azimuth angle in degrees: 0 = true north, 90 = east")); aziVar.addAttribute(new Attribute(CDM.MISSING_VALUE, new Float(MISSING_FLOAT))); aziVar.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.RadialAzimuth.toString())); // add gate coordinate variable String gateCoordName = "distance" + abbrev; Variable gateVar = new Variable(ncfile, null, null, gateCoordName); gateVar.setDataType(DataType.FLOAT); gateVar.setDimensions(gateDimName); Array data = Array.makeArray( DataType.FLOAT, ngates, (double) firstRecord.getGateStart(datatype), (double) firstRecord.getGateSize(datatype)); gateVar.setCachedData(data, false); ncfile.addVariable(null, gateVar); radarRadius = firstRecord.getGateStart(datatype) + ngates * firstRecord.getGateSize(datatype); gateVar.addAttribute(new Attribute(CDM.UNITS, "m")); gateVar.addAttribute(new Attribute(CDM.LONG_NAME, "radial distance to start of gate")); gateVar.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.RadialDistance.toString())); // add number of radials variable String nradialsName = "numRadials" + abbrev; Variable nradialsVar = new Variable(ncfile, null, null, nradialsName); nradialsVar.setDataType(DataType.INT); nradialsVar.setDimensions(scanDim.getName()); nradialsVar.addAttribute(new Attribute(CDM.LONG_NAME, "number of valid radials in this scan")); ncfile.addVariable(null, nradialsVar); // add number of gates variable String ngateName = "numGates" + abbrev; Variable ngateVar = new Variable(ncfile, null, null, ngateName); ngateVar.setDataType(DataType.INT); ngateVar.setDimensions(scanDim.getName()); ngateVar.addAttribute(new Attribute(CDM.LONG_NAME, "number of valid gates in this scan")); ncfile.addVariable(null, ngateVar); makeCoordinateDataWithMissing( datatype, timeVar, elevVar, aziVar, nradialsVar, ngateVar, groups); // back to the data variable String coordinates = timeCoordName + " " + elevCoordName + " " + aziCoordName + " " + gateCoordName; v.addAttribute(new Attribute(_Coordinate.Axes, coordinates)); // make the record map int nradials = radialDim.getLength(); Cinrad2Record[][] map = new Cinrad2Record[nscans][nradials]; for (int i = 0; i < groups.size(); i++) { Cinrad2Record[] mapScan = map[i]; List group = (List) groups.get(i); for (int j = 0; j < group.size(); j++) { Cinrad2Record r = (Cinrad2Record) group.get(j); int radial = r.radial_num - 1; mapScan[radial] = r; } } Vgroup vg = new Vgroup(datatype, map); v.setSPobject(vg); return v; }
private void makeCoordinateData( int datatype, Variable time, Variable elev, Variable azi, Variable nradialsVar, Variable ngatesVar, List groups) { Array timeData = Array.factory(time.getDataType().getPrimitiveClassType(), time.getShape()); IndexIterator timeDataIter = timeData.getIndexIterator(); Array elevData = Array.factory(elev.getDataType().getPrimitiveClassType(), elev.getShape()); IndexIterator elevDataIter = elevData.getIndexIterator(); Array aziData = Array.factory(azi.getDataType().getPrimitiveClassType(), azi.getShape()); IndexIterator aziDataIter = aziData.getIndexIterator(); Array nradialsData = Array.factory(nradialsVar.getDataType().getPrimitiveClassType(), nradialsVar.getShape()); IndexIterator nradialsIter = nradialsData.getIndexIterator(); Array ngatesData = Array.factory(ngatesVar.getDataType().getPrimitiveClassType(), ngatesVar.getShape()); IndexIterator ngatesIter = ngatesData.getIndexIterator(); int last_msecs = Integer.MIN_VALUE; int nscans = groups.size(); int maxRadials = volScan.getMaxRadials(); for (int i = 0; i < nscans; i++) { List scanGroup = (List) groups.get(i); int nradials = scanGroup.size(); Cinrad2Record first = null; for (int j = 0; j < nradials; j++) { Cinrad2Record r = (Cinrad2Record) scanGroup.get(j); if (first == null) first = r; timeDataIter.setIntNext(r.data_msecs); elevDataIter.setFloatNext(r.getElevation()); aziDataIter.setFloatNext(r.getAzimuth()); if (r.data_msecs < last_msecs) logger.warn("makeCoordinateData time out of order " + r.data_msecs); last_msecs = r.data_msecs; } for (int j = nradials; j < maxRadials; j++) { timeDataIter.setIntNext(MISSING_INT); elevDataIter.setFloatNext(MISSING_FLOAT); aziDataIter.setFloatNext(MISSING_FLOAT); } nradialsIter.setIntNext(nradials); ngatesIter.setIntNext(first.getGateCount(datatype)); } time.setCachedData(timeData, false); elev.setCachedData(elevData, false); azi.setCachedData(aziData, false); nradialsVar.setCachedData(nradialsData, false); ngatesVar.setCachedData(ngatesData, false); }
/** * get the ith dimension * * @param i : which dimension * @return ith Dimension */ public Dimension getDimension(int i) { if ((i < 0) || (i >= mydims.size())) return null; return mydims.get(i); }
/** * Add this coord as a variable in the netCDF file * * @param ncfile netCDF file to add to * @param g group in file */ void addToNetcdfFile(NetcdfFile ncfile, Group g) { if (dontUseVertical) { typicalRecord = null; return; } if (g == null) { g = ncfile.getRootGroup(); } // coordinate axis Variable v = new Variable(ncfile, g, null, getVariableName()); v.setDataType(DataType.DOUBLE); String desc = lookup.getLevelDescription(typicalRecord); if (lookup instanceof Grib2GridTableLookup && usesBounds) { desc = "Layer between " + desc; } v.addAttribute(new Attribute("long_name", desc)); v.addAttribute(new Attribute("units", lookup.getLevelUnit(typicalRecord))); // positive attribute needed for CF-1 Height and Pressure if (positive != null) { v.addAttribute(new Attribute("positive", positive)); } if (units != null) { AxisType axisType; if (SimpleUnit.isCompatible("millibar", units)) { axisType = AxisType.Pressure; } else if (SimpleUnit.isCompatible("m", units)) { axisType = AxisType.Height; } else { axisType = AxisType.GeoZ; } if (lookup instanceof Grib2GridTableLookup || lookup instanceof Grib1GridTableLookup) { v.addAttribute( new Attribute("GRIB_level_type", Integer.toString(typicalRecord.getLevelType1()))); } else { v.addAttribute( new Attribute("level_type", Integer.toString(typicalRecord.getLevelType1()))); } v.addAttribute(new Attribute(_Coordinate.AxisType, axisType.toString())); } if (coordValues == null) { coordValues = new double[levels.size()]; for (int i = 0; i < levels.size(); i++) { LevelCoord lc = (LevelCoord) levels.get(i); coordValues[i] = lc.mid; } } Array dataArray = Array.factory(DataType.DOUBLE, new int[] {coordValues.length}, coordValues); v.setDimensions(getVariableName()); v.setCachedData(dataArray, true); ncfile.addVariable(g, v); if (usesBounds) { String boundsDimName = "bounds_dim"; if (g.findDimension(boundsDimName) == null) { ncfile.addDimension(g, new Dimension(boundsDimName, 2, true)); } String bname = getVariableName() + "_bounds"; v.addAttribute(new Attribute("bounds", bname)); v.addAttribute(new Attribute(_Coordinate.ZisLayer, "true")); Variable b = new Variable(ncfile, g, null, bname); b.setDataType(DataType.DOUBLE); b.setDimensions(getVariableName() + " " + boundsDimName); b.addAttribute(new Attribute("long_name", "bounds for " + v.getName())); b.addAttribute(new Attribute("units", lookup.getLevelUnit(typicalRecord))); Array boundsArray = Array.factory(DataType.DOUBLE, new int[] {coordValues.length, 2}); ucar.ma2.Index ima = boundsArray.getIndex(); for (int i = 0; i < coordValues.length; i++) { LevelCoord lc = (LevelCoord) levels.get(i); boundsArray.setDouble(ima.set(i, 0), lc.value1); boundsArray.setDouble(ima.set(i, 1), lc.value2); } b.setCachedData(boundsArray, true); ncfile.addVariable(g, b); } if (factors != null) { // check if already created if (g == null) { g = ncfile.getRootGroup(); } if (g.findVariable("hybrida") != null) return; v.addAttribute(new Attribute("standard_name", "atmosphere_hybrid_sigma_pressure_coordinate")); v.addAttribute(new Attribute("formula_terms", "ap: hybrida b: hybridb ps: Pressure")); // create hybrid factor variables // add hybrida variable Variable ha = new Variable(ncfile, g, null, "hybrida"); ha.setDataType(DataType.DOUBLE); ha.addAttribute(new Attribute("long_name", "level_a_factor")); ha.addAttribute(new Attribute("units", "")); ha.setDimensions(getVariableName()); // add data int middle = factors.length / 2; double[] adata; double[] bdata; if (levels.size() < middle) { // only partial data wanted adata = new double[levels.size()]; bdata = new double[levels.size()]; } else { adata = new double[middle]; bdata = new double[middle]; } for (int i = 0; i < middle && i < levels.size(); i++) adata[i] = factors[i]; Array haArray = Array.factory(DataType.DOUBLE, new int[] {adata.length}, adata); ha.setCachedData(haArray, true); ncfile.addVariable(g, ha); // add hybridb variable Variable hb = new Variable(ncfile, g, null, "hybridb"); hb.setDataType(DataType.DOUBLE); hb.addAttribute(new Attribute("long_name", "level_b_factor")); hb.addAttribute(new Attribute("units", "")); hb.setDimensions(getVariableName()); // add data for (int i = 0; i < middle && i < levels.size(); i++) bdata[i] = factors[i + middle]; Array hbArray = Array.factory(DataType.DOUBLE, new int[] {bdata.length}, bdata); hb.setCachedData(hbArray, true); ncfile.addVariable(g, hb); /* // TODO: delete next time modifying code double[] adata = new double[ middle ]; for( int i = 0; i < middle; i++ ) adata[ i ] = factors[ i ]; Array haArray = Array.factory(DataType.DOUBLE, new int[]{adata.length}, adata); ha.setCachedData(haArray, true); ncfile.addVariable(g, ha); // add hybridb variable Variable hb = new Variable(ncfile, g, null, "hybridb"); hb.setDataType(DataType.DOUBLE); hb.addAttribute(new Attribute("long_name", "level_b_factor" )); //hb.addAttribute(new Attribute("standard_name", "atmosphere_hybrid_sigma_pressure_coordinate" )); hb.addAttribute(new Attribute("units", "")); hb.setDimensions(getVariableName()); // add data double[] bdata = new double[ middle ]; for( int i = 0; i < middle; i++ ) bdata[ i ] = factors[ i + middle ]; Array hbArray = Array.factory(DataType.DOUBLE, new int[]{bdata.length}, bdata); hb.setCachedData(hbArray, true); ncfile.addVariable(g, hb); */ } }
private void makeCoordinateDataWithMissing( int datatype, Variable time, Variable elev, Variable azi, Variable nradialsVar, Variable ngatesVar, List groups) { Array timeData = Array.factory(time.getDataType().getPrimitiveClassType(), time.getShape()); Index timeIndex = timeData.getIndex(); Array elevData = Array.factory(elev.getDataType().getPrimitiveClassType(), elev.getShape()); Index elevIndex = elevData.getIndex(); Array aziData = Array.factory(azi.getDataType().getPrimitiveClassType(), azi.getShape()); Index aziIndex = aziData.getIndex(); Array nradialsData = Array.factory(nradialsVar.getDataType().getPrimitiveClassType(), nradialsVar.getShape()); IndexIterator nradialsIter = nradialsData.getIndexIterator(); Array ngatesData = Array.factory(ngatesVar.getDataType().getPrimitiveClassType(), ngatesVar.getShape()); IndexIterator ngatesIter = ngatesData.getIndexIterator(); // first fill with missing data IndexIterator ii = timeData.getIndexIterator(); while (ii.hasNext()) ii.setIntNext(MISSING_INT); ii = elevData.getIndexIterator(); while (ii.hasNext()) ii.setFloatNext(MISSING_FLOAT); ii = aziData.getIndexIterator(); while (ii.hasNext()) ii.setFloatNext(MISSING_FLOAT); // now set the coordinate variables from the Cinrad2Record radial int last_msecs = Integer.MIN_VALUE; int nscans = groups.size(); try { for (int scan = 0; scan < nscans; scan++) { List scanGroup = (List) groups.get(scan); int nradials = scanGroup.size(); Cinrad2Record first = null; for (int j = 0; j < nradials; j++) { Cinrad2Record r = (Cinrad2Record) scanGroup.get(j); if (first == null) first = r; int radial = r.radial_num - 1; timeData.setInt(timeIndex.set(scan, radial), r.data_msecs); elevData.setFloat(elevIndex.set(scan, radial), r.getElevation()); aziData.setFloat(aziIndex.set(scan, radial), r.getAzimuth()); if (r.data_msecs < last_msecs) logger.warn("makeCoordinateData time out of order " + r.data_msecs); last_msecs = r.data_msecs; } nradialsIter.setIntNext(nradials); ngatesIter.setIntNext(first.getGateCount(datatype)); } } catch (java.lang.ArrayIndexOutOfBoundsException ae) { logger.debug("Cinrad2IOSP.uncompress ", ae); } time.setCachedData(timeData, false); elev.setCachedData(elevData, false); azi.setCachedData(aziData, false); nradialsVar.setCachedData(nradialsData, false); ngatesVar.setCachedData(ngatesData, false); }