From 399e3d3f07f3598e214f1a06b1dae8e6aa12e552 Mon Sep 17 00:00:00 2001 From: Ben Steffensmeier Date: Tue, 18 Feb 2014 12:45:12 -0600 Subject: [PATCH] Issue #2672 Fix radar dataaccess from pure python. Former-commit-id: 3e0cba04c05f81d87508a0301d2a6b8734ffd0b8 [formerly 8beef8db2ffe599c9167dbd61aed8243d3a0af0e] Former-commit-id: e19b4518efd17e9b13e032de2eff4004df9d3d36 --- .../dataaccess/response/GridResponseData.java | 43 ++++++++++++++++--- .../radar/dataaccess/RadarGridFactory.java | 34 ++++++++++++++- 2 files changed, 69 insertions(+), 8 deletions(-) diff --git a/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/response/GridResponseData.java b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/response/GridResponseData.java index 36b4718378..24b7d1d2d1 100644 --- a/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/response/GridResponseData.java +++ b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/response/GridResponseData.java @@ -19,8 +19,12 @@ **/ package com.raytheon.uf.common.dataaccess.response; +import javax.measure.unit.Unit; + import com.raytheon.uf.common.dataaccess.grid.IGridData; +import com.raytheon.uf.common.geospatial.interpolation.data.DataDestination; import com.raytheon.uf.common.geospatial.interpolation.data.FloatArrayWrapper; +import com.raytheon.uf.common.geospatial.interpolation.data.UnitConvertingDataDestination; import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; @@ -31,9 +35,10 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; * * SOFTWARE HISTORY * - * Date Ticket# Engineer Description - * ------------ ---------- ----------- -------------------------- - * Jun 4, 2013 dgilling Initial creation + * Date Ticket# Engineer Description + * ------------- -------- ----------- -------------------------- + * Jun 04, 2013 dgilling Initial creation + * Feb 04, 2014 2672 bsteffen Better handling of odd units. * * * @@ -61,12 +66,36 @@ public class GridResponseData extends AbstractResponseData { super(data); parameter = data.getParameter(); - if (data.getUnit() != null) { - unit = data.getUnit().toString(); - } + + Unit dataUnit = data.getUnit(); FloatArrayWrapper dataGrid = new FloatArrayWrapper( data.getGridGeometry()); - dataGrid = data.populateData(dataGrid); + DataDestination dataDest = dataGrid; + if (data.getUnit() != null) { + try { + this.unit = dataUnit.toString(); + } catch (IllegalArgumentException e1) { + /* + * Not all units are representable as strings, convert to the + * standard unit so that the units can be preserved in string + * form. + */ + Unit stdUnit = dataUnit.getStandardUnit(); + try { + this.unit = stdUnit.toString(); + dataDest = new UnitConvertingDataDestination( + dataUnit.toStandardUnit(), dataDest); + } catch (IllegalArgumentException e2) { + /* + * The standard unit is also unstringable so treat the data + * as unitless. + */ + this.unit = null; + } + } + } + + data.populateData(dataDest); gridData = dataGrid.getArray(); } diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.radar/src/com/raytheon/uf/common/dataplugin/radar/dataaccess/RadarGridFactory.java b/edexOsgi/com.raytheon.uf.common.dataplugin.radar/src/com/raytheon/uf/common/dataplugin/radar/dataaccess/RadarGridFactory.java index 09c4ebb8e7..d306f0492c 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.radar/src/com/raytheon/uf/common/dataplugin/radar/dataaccess/RadarGridFactory.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.radar/src/com/raytheon/uf/common/dataplugin/radar/dataaccess/RadarGridFactory.java @@ -139,7 +139,7 @@ public class RadarGridFactory extends AbstractGridDataPluginFactory implements defaultGridData.setUnit(radarRecord.getDataUnit()); defaultGridData.setLevel(getTiltLevel(radarRecord .getPrimaryElevationAngle())); - defaultGridData.setLocationName(radarRecord.getIcao()); + defaultGridData.setLocationName(generateLocationName(radarRecord)); Map attributes = new HashMap(); attributes.put(ICAO, radarRecord.getIcao()); @@ -150,6 +150,38 @@ public class RadarGridFactory extends AbstractGridDataPluginFactory implements return defaultGridData; } + /** + * Get a unique name describing the location of the radar data. The name + * always includes icao, elevation angle, num bins and num radials. For + * radial data it also includes the first and last angle of the radial data. + * Theoretically two radial geometries could have the same name but + * internally different angleData but this is very unlikely and the points + * would be very nearly identical. + * + * + * @param radarRecord + * a record. + * @return A unique location name + */ + protected String generateLocationName(RadarRecord radarRecord){ + StringBuilder locationName = new StringBuilder(32); + locationName.append(radarRecord.getIcao()); + locationName.append("_"); + locationName.append(radarRecord.getTrueElevationAngle()); + locationName.append("_"); + locationName.append(radarRecord.getNumBins()); + locationName.append("_"); + locationName.append(radarRecord.getNumRadials()); + float[] angleData = radarRecord.getAngleData(); + if (angleData != null) { + locationName.append("_"); + locationName.append(angleData[0]); + locationName.append("_"); + locationName.append(angleData[angleData.length - 1]); + } + return locationName.toString(); + } + protected RadarRecord asRadarRecord(PluginDataObject pdo) { if (pdo instanceof RadarRecord == false) { throw new DataRetrievalException(this.getClass().getSimpleName()