/** * Get a set of sounding obs based on the choice * * @param dataChoice DataChoice for data * @param subset subselection criteria * @return corresponding sounding observations * @throws RemoteException Java RMI problem * @throws VisADException VisAD problem */ private Data getSoundingObs(DataChoice dataChoice, DataSelection subset) throws VisADException, RemoteException { Vector v = new Vector(); List choices = (dataChoice instanceof CompositeDataChoice) ? ((CompositeDataChoice) dataChoice).getDataChoices() : Arrays.asList(new DataChoice[] {dataChoice}); Object t = subset.getProperty(DataSelection.PROP_USESTIMEDRIVER); if ((t instanceof Boolean) && (useDriverTime == false)) { useDriverTime = ((Boolean) t).booleanValue(); } if (useDriverTime) { // getAllTimesForTimeDriver(dataChoice, subset, // subset.getTimeDriverTimes()); if (initTimes == null) { initTimes = subset.getTimeDriverTimes(); } if (initTimes != null) { // reset the time for data choice if useDriverTime List<SoundingOb> soundingObs = getTimeMatchingSoundingObs(initTimes); choices = getTimeMatchingDataChoices(soundingObs); } } for (Iterator iter = choices.iterator(); iter.hasNext(); ) { DataChoice dc = (DataChoice) iter.next(); Data ob = makeSoundingOb(dc, subset); if (ob != null) { v.add(ob); } } return (v.isEmpty()) ? null : new Tuple((Data[]) v.toArray(new Data[v.size()]), false); }
/** * set properties on dataselection * * @param dataSelection the dataselection */ public void applyToDataSelection(DataSelection dataSelection) { if (dataSelection != null) { StationModel plotModel = getPlotModel(); if (plotModel != null) { dataSelection.putProperty(PROP_STATIONMODELNAME, plotModel.getName()); } } }
/** * set properties on dataselection * * @param dataSelection the dataselection */ public void applyToDataSelection(DataSelection dataSelection) { if (dataSelection != null) { if (!useDefaultCbx.isSelected()) { dataSelection.putProperty(PROP_GRID_X, new Float(getGridX())); dataSelection.putProperty(PROP_GRID_Y, new Float(getGridY())); dataSelection.putProperty(PROP_GRID_UNIT, getGridUnit()); dataSelection.putProperty(PROP_GRID_NUMPASSES, new Integer(getNumGridPasses())); dataSelection.putProperty(PROP_GRID_GAIN, new Float(getGridGain())); dataSelection.putProperty(PROP_GRID_SEARCH_RADIUS, new Float(getGridSearchRadius())); } else { dataSelection.removeProperty(PROP_GRID_X); dataSelection.removeProperty(PROP_GRID_Y); dataSelection.removeProperty(PROP_GRID_UNIT); dataSelection.removeProperty(PROP_GRID_NUMPASSES); dataSelection.removeProperty(PROP_GRID_GAIN); dataSelection.removeProperty(PROP_GRID_SEARCH_RADIUS); } } }
/** * Get the data for the given DataChoice and selection criteria. * * @param dataChoice DataChoice for selection * @param category DataCategory for the DataChoice (not used) * @param subset subsetting criteria * @param requestProperties extra request properties * @return the Data object for the request * @throws RemoteException couldn't create a remote data object * @throws VisADException couldn't create the data */ protected Data getDataInner( final DataChoice dataChoice, DataCategory category, final DataSelection subset, final Hashtable requestProperties) throws VisADException, RemoteException { try { List times = null; if (subset != null) { times = getTimesFromDataSelection(subset, dataChoice); } if (times == null) { times = dataChoice.getSelectedDateTimes(); } List dtimes = subset.getTimeDriverTimes(); if (dtimes != null && useDriverTime == false) { useDriverTime = true; } List<RadarAdapter> adapters = getAdapters(); DateTime[] realDateTimes = new DateTime[adapters.size()]; for (int i = 0; i < adapters.size(); i++) { realDateTimes[i] = ((RadarAdapter) adapters.get(i)).getBaseTime(); } Arrays.sort(realDateTimes); // Flip it to get youngest date first boolean isRealTime = isRealTime(); if (isRealTime) { realDateTimes = (DateTime[]) Misc.reverseArray(realDateTimes, new DateTime[realDateTimes.length]); } // if use time driver if (useDriverTime) { List tests = resetTimesList(realDateTimes, times); if (!compareTimeLists(times, tests)) { reloadData(); adapters = getAdapters(); realDateTimes = new DateTime[adapters.size()]; for (int i = 0; i < adapters.size(); i++) { realDateTimes[i] = ((RadarAdapter) adapters.get(i)).getBaseTime(); } Arrays.sort(realDateTimes); // Flip it to get youngest date first isRealTime = isRealTime(); if (isRealTime) { realDateTimes = (DateTime[]) Misc.reverseArray(realDateTimes, new DateTime[realDateTimes.length]); } tests = resetTimesList(realDateTimes, times); } times = tests; } // if times are null, then that means all times DateTime[] dateTimes = null; if ((times == null) || (times.size() == 0)) { dateTimes = realDateTimes; } else { dateTimes = new DateTime[times.size()]; for (int i = 0; i < times.size(); i++) { Object time = times.get(i); if (time instanceof TwoFacedObject) { int index = ((Integer) ((TwoFacedObject) time).getId()).intValue(); dateTimes[i] = realDateTimes[index]; } else if (time instanceof DateTime) { dateTimes[i] = (DateTime) time; } } } Arrays.sort(dateTimes); final Data[] datas = new Data[dateTimes.length]; int timeIndex = 0; final MathType[] mt = {null}; // create a new field of (Time -> (radar data)). // fill in the times array and data array with dates/data // only from those adapters which match the selected times. // if a data object is null, stick it in the list. // if all are null, then the MathType (mt) will never get set, // so return null. // System.err.println ("Reading " + adapters.size() + " radar files"); int cnt = 0; ThreadManager threadManager = new visad.util.ThreadManager("radar data reading"); for (Iterator iter = adapters.iterator(); iter.hasNext(); ) { final RadarAdapter adapter = (RadarAdapter) iter.next(); timeIndex = Arrays.binarySearch(dateTimes, adapter.getBaseTime()); // System.err.println ("timeIndex:" + timeIndex); if (timeIndex < 0) { continue; } cnt++; LogUtil.message("Time: " + (cnt) + "/" + dateTimes.length + " From:" + toString()); final int theTimeIndex = timeIndex; threadManager.addRunnable( new visad.util.ThreadManager.MyRunnable() { public void run() throws Exception { Trace.call1("RDS.getData"); Data d = adapter.getData(dataChoice, subset, requestProperties); Trace.call2("RDS.getData"); datas[theTimeIndex] = d; if (d != null) { mt[0] = d.getType(); } else { } } }); } try { // threadManager.debug = true; threadManager.runInParallel(getDataContext().getIdv().getMaxDataThreadCount()); } catch (VisADException ve) { LogUtil.printMessage(ve.toString()); } if (mt[0] == null) { return null; } FunctionType ft = new FunctionType(RealType.Time, mt[0]); SampledSet domainSet = (dateTimes.length == 1) ? (SampledSet) new SingletonSet(new RealTuple(dateTimes)) : (SampledSet) DateTime.makeTimeSet(dateTimes); FieldImpl fi = new FieldImpl(ft, domainSet); fi.setSamples(datas, false); return fi; } catch (Exception exc) { logException("Creating obs", exc); } return null; }
/** * Get the data represented by this class. Calls makeObs, real work needs to be implemented there. * * @param dataChoice choice for data * @param category category of data * @param dataSelection subselection properties * @param requestProperties additional selection properties (not used here) * @return Data object representative of the choice * @throws RemoteException Java RMI error * @throws VisADException VisAD Error */ protected Data getDataInner( DataChoice dataChoice, DataCategory category, DataSelection dataSelection, Hashtable requestProperties) throws VisADException, RemoteException { Object id = dataChoice.getId(); // CompositeDataChoice // If it is a list then we are doing a grid field boolean doGriddedData = false; if (id instanceof List) { if (((List) id).get(0) instanceof Integer) { doGriddedData = true; } } if (doGriddedData) { List idList = (List) id; // Integer i = (Integer) idList.get(0); RealType type = (RealType) idList.get(1); Hashtable properties = dataChoice.getProperties(); if (properties == null) { properties = new Hashtable(); } Data firstGuessData = null; boolean doFirstGuessField = false; if (idList.size() > 2) { doFirstGuessField = ((Boolean) idList.get(2)).booleanValue(); } if (doFirstGuessField) { DataChoice firstGuessDataChoice = (DataChoice) dataChoice.getProperty(PROP_FIRSTGUESS); if (firstGuessDataChoice == null) { List operands = new ArrayList(); List categories = DataCategory.parseCategories("GRID-2D-TIME;GRID-3D-TIME", false); operands.add( new DataOperand("First Guess Field", "First Guess Field", categories, false)); List userValues = getDataContext().selectDataChoices(operands); if (userValues == null) { return null; } firstGuessDataChoice = (DataChoice) userValues.get(0); dataChoice.setObjectProperty(PROP_FIRSTGUESS, firstGuessDataChoice); } if (firstGuessDataChoice != null) { firstGuessData = firstGuessDataChoice.getData(null); if (firstGuessData == null) { return null; } } } // Merge the point obs properties.put(PROP_GRID_PARAM, type); FieldImpl pointObs = null; List datas = new ArrayList(); for (int i = 0; i < sources.size(); i++) { DataChoice choice = new DirectDataChoice( this, new Integer(i), "", "", dataChoice.getCategories(), properties); pointObs = (FieldImpl) getDataInner(choice, category, dataSelection, requestProperties); if (pointObs != null) { datas.add(pointObs); } } if (datas.size() == 0) { return null; } pointObs = PointObFactory.mergeData(datas); if (pointObs == null) { return null; } // { minY, minX, maxY, maxX }; float spacingX = this.gridX; float spacingY = this.gridY; int passes = this.numGridPasses; float gain = this.gridGain; float searchRadius = this.gridSearchRadius; Number tmp; tmp = (Float) dataSelection.getProperty(PROP_GRID_X); if (tmp != null) { spacingX = tmp.floatValue(); } tmp = (Float) dataSelection.getProperty(PROP_GRID_Y); if (tmp != null) { spacingY = tmp.floatValue(); } tmp = (Integer) dataSelection.getProperty(PROP_GRID_NUMPASSES); if (tmp != null) { passes = tmp.intValue(); } String theUnit = (String) dataSelection.getProperty(PROP_GRID_UNIT); if (theUnit == null) { theUnit = this.gridUnit; } tmp = (Float) dataSelection.getProperty(PROP_GRID_GAIN); if (tmp != null) { gain = tmp.floatValue(); } tmp = (Float) dataSelection.getProperty(PROP_GRID_SEARCH_RADIUS); if (tmp != null) { searchRadius = tmp.floatValue(); } float degreesX = 0, degreesY = 0; pointObs = PointObFactory.makeTimeSequenceOfPointObs(pointObs); if (theUnit.equals(SPACING_COMPUTE) || (spacingX <= 0) || (spacingY <= 0)) { degreesX = PointObFactory.OA_GRID_DEFAULT; degreesY = PointObFactory.OA_GRID_DEFAULT; if ((searchRadius == DEFAULT_RADIUS) && (firstGuessData == null)) { searchRadius = PointObFactory.OA_GRID_DEFAULT; } } else if (theUnit.equals(SPACING_POINTS)) { double[] bbox = PointObFactory.getBoundingBox(pointObs); float spanX = (float) Math.abs(bbox[1] - bbox[3]); float spanY = (float) Math.abs(bbox[0] - bbox[2]); degreesX = spanX / (int) spacingX; degreesY = spanY / (int) spacingY; } else if (theUnit.equals(SPACING_DEGREES)) { degreesX = spacingX; degreesY = spacingY; } Barnes.AnalysisParameters ap = new Barnes.AnalysisParameters(degreesX, degreesY, searchRadius, 0.0d); log_.debug( "X = " + degreesX + " Y = " + degreesY + " unit = " + theUnit + " gain = " + gain + " search = " + searchRadius); LogUtil.message("Doing Barnes Analysis"); FieldImpl fi = PointObFactory.barnes( pointObs, type, degreesX, degreesY, passes, gain, searchRadius, ap, (FieldImpl) firstGuessData); if (ap.getGridXArray() != null) { log_.debug( "Analysis params: X = " + ap.getGridXArray().length + " Y = " + ap.getGridYArray().length + " search = " + ap.getScaleLengthGU() + " random = " + ap.getRandomDataSpacing()); } return fi; } GeoSelection geoSelection = ((dataSelection != null) ? dataSelection.getGeoSelection() : null); GeoLocationInfo bbox = ((geoSelection == null) ? null : geoSelection.getBoundingBox()); LatLonRect llr = ((bbox != null) ? bbox.getLatLonRect() : null); FieldImpl retField = null; try { // List choices = (List) dataChoice.getId(); List choices = (dataChoice instanceof CompositeDataChoice) ? ((CompositeDataChoice) dataChoice).getDataChoices() : Misc.toList(new DataChoice[] {dataChoice}); List datas = new ArrayList(choices.size()); for (int i = 0; i < choices.size(); i++) { DataChoice subDataChoice = (DataChoice) choices.get(i); FieldImpl obs = makeObs(subDataChoice, dataSelection, llr); if (obs == null) { continue; } // if (true) { // return obs; // } datas.add(obs); if (fieldsDescription == null) { makeFieldDescription(obs); } } if (datas.isEmpty()) { return null; } retField = PointObFactory.mergeData(datas); } catch (Exception exc) { logException("Creating obs", exc); } return retField; }