This is a 19.2.1 change being added to unidata_18.2.1 to allow string variables for satellite data in the product legend
This commit is contained in:
parent
494e06c812
commit
03eea9ac7a
2 changed files with 70 additions and 83 deletions
|
@ -26,7 +26,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8",
|
|||
com.raytheon.uf.common.numeric;bundle-version="1.14",
|
||||
com.raytheon.viz.alerts,
|
||||
com.raytheon.uf.viz.core.rsc;bundle-version="1.14",
|
||||
javax.measure
|
||||
javax.measure,
|
||||
com.raytheon.uf.common.util;bundle-version="1.16.0"
|
||||
Import-Package: com.raytheon.viz.awipstools,
|
||||
com.raytheon.viz.core.rsc.hdf5
|
||||
Export-Package: com.raytheon.viz.satellite,
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.viz.satellite.rsc;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -27,17 +27,14 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.measure.Measure;
|
||||
import javax.measure.converter.UnitConverter;
|
||||
import javax.measure.quantity.Temperature;
|
||||
import javax.measure.unit.Unit;
|
||||
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.opengis.referencing.FactoryException;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
import org.opengis.referencing.operation.TransformException;
|
||||
|
||||
import com.raytheon.uf.common.colormap.ColorMapException;
|
||||
import com.raytheon.uf.common.colormap.ColorMapLoader;
|
||||
import com.raytheon.uf.common.colormap.IColorMap;
|
||||
|
@ -67,6 +64,7 @@ import com.raytheon.uf.common.style.image.SamplePreferences;
|
|||
import com.raytheon.uf.common.style.level.Level;
|
||||
import com.raytheon.uf.common.style.level.SingleLevel;
|
||||
import com.raytheon.uf.common.time.DataTime;
|
||||
import com.raytheon.uf.common.util.VariableSubstitutor;
|
||||
import com.raytheon.uf.viz.core.DrawableImage;
|
||||
import com.raytheon.uf.viz.core.IExtent;
|
||||
import com.raytheon.uf.viz.core.IGraphicsTarget;
|
||||
|
@ -95,7 +93,6 @@ import com.raytheon.viz.satellite.inventory.DerivedSatelliteRecord;
|
|||
import com.raytheon.viz.satellite.tileset.SatDataRetriever;
|
||||
import com.raytheon.viz.satellite.tileset.SatRenderable;
|
||||
import com.raytheon.viz.satellite.tileset.SatRenderable.InterrogationResult;
|
||||
|
||||
/**
|
||||
* Provides satellite raster rendering support
|
||||
*
|
||||
|
@ -140,10 +137,13 @@ import com.raytheon.viz.satellite.tileset.SatRenderable.InterrogationResult;
|
|||
* Jul 28, 2015 4633 bsteffen Create tileset in resource so it can be
|
||||
* overridden for daylight transition.
|
||||
* Oct 08, 2015 4937 bsteffen Move SatRenderable to new class.
|
||||
* Jul 13, 2016 DCS 18781 jburks Added ability to mask incomplete frames.
|
||||
* Jul 13, 2016 18781 jburks Added ability to mask incomplete frames.
|
||||
* Aug 03, 2016 5786 bsteffen Schedule the loading of all frames on
|
||||
* initialization
|
||||
* Jun 26, 2017 mjames Set default viz colormap to linear.
|
||||
* Mar 22, 2018 6846 bsteffen Perform substitution of style units in
|
||||
* legend strings.
|
||||
* Apr 04, 2018 6889 njensen Use brightness from ImagePreferences if
|
||||
* present but missing in ImagingCapability
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -152,7 +152,6 @@ import com.raytheon.viz.satellite.tileset.SatRenderable.InterrogationResult;
|
|||
public class SatResource extends
|
||||
AbstractPluginDataObjectResource<SatResourceData, IMapDescriptor>
|
||||
implements ImageProvider, Interrogatable, IToolChangedListener {
|
||||
|
||||
/**
|
||||
* String id to look for satellite-provided data values
|
||||
*
|
||||
|
@ -161,18 +160,12 @@ public class SatResource extends
|
|||
*/
|
||||
@Deprecated
|
||||
public static final String SATELLITE_DATA_INTERROGATE_ID = "satelliteDataValue";
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static final InterrogationKey<Measure<? extends Number, ?>> SATELLITE_DATA_INTERROGATE_KEY = new StringInterrogationKey<>(
|
||||
SATELLITE_DATA_INTERROGATE_ID,
|
||||
(Class<Measure<? extends Number, ?>>) ((Class<?>) Measure.class));
|
||||
|
||||
SATELLITE_DATA_INTERROGATE_ID, Interrogator.getTypedMeasureClass());
|
||||
private static final InterrogationKey<SatelliteRecord> SATELLITE_RECORD_INTERROGATE_KEY = new ClassInterrogationKey<>(
|
||||
SatelliteRecord.class);
|
||||
|
||||
private static final InterrogationKey<GeographicDataSource> DATA_SOURCE_INTERROGATE_KEY = new ClassInterrogationKey<>(
|
||||
GeographicDataSource.class);
|
||||
|
||||
/**
|
||||
* Property that controls whether all frames of satellite data will be
|
||||
* loaded in the background when the resource is initialized. When the data
|
||||
|
@ -183,26 +176,19 @@ public class SatResource extends
|
|||
* {@link Boolean#getBoolean(String)} is not used because it defaults to
|
||||
* false and the default value for this property is true.
|
||||
*/
|
||||
private static final boolean BACKGROUND_LOAD = !System.getProperty(
|
||||
"d2d.sat.background.load", "true").equalsIgnoreCase("false");
|
||||
|
||||
private static final boolean BACKGROUND_LOAD = !"false".equalsIgnoreCase(
|
||||
System.getProperty("d2d.sat.background.load", "true"));
|
||||
protected String legend;
|
||||
|
||||
protected SamplePreferences sampleRange;
|
||||
|
||||
/** Flag to avoid reinitializing ColorMapParameters from style rules */
|
||||
private boolean initialized = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @throws VizException
|
||||
*/
|
||||
public SatResource(SatResourceData data, LoadProperties props) {
|
||||
super(data, props);
|
||||
addDataObject(data.getRecords());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initInternal(IGraphicsTarget target) throws VizException {
|
||||
super.initInternal(target);
|
||||
|
@ -213,15 +199,13 @@ public class SatResource extends
|
|||
if (display == null) {
|
||||
return;
|
||||
}
|
||||
IExtent extent = new PixelExtent(descriptor.getGridGeometry()
|
||||
.getGridRange());
|
||||
IExtent extent = new PixelExtent(
|
||||
descriptor.getGridGeometry().getGridRange());
|
||||
Rectangle canvasBounds = display.getBounds();
|
||||
|
||||
List<DataTime> times = new ArrayList<>(Arrays.asList(getDataTimes()));
|
||||
/* Make current time first */
|
||||
DataTime currentTime = getTimeForResource();
|
||||
times.add(0, currentTime);
|
||||
|
||||
for (DataTime time : times) {
|
||||
IRenderable renderable = getOrCreateRenderable(time);
|
||||
if (renderable instanceof SatRenderable) {
|
||||
|
@ -230,10 +214,9 @@ public class SatResource extends
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DataTime getDataObjectTime(PluginDataObject pdo) {
|
||||
if (initialized == false) {
|
||||
if (!initialized) {
|
||||
try {
|
||||
initializeFirstFrame((SatelliteRecord) pdo);
|
||||
} catch (VizException e) {
|
||||
|
@ -248,7 +231,6 @@ public class SatResource extends
|
|||
}
|
||||
return pdoTime;
|
||||
}
|
||||
|
||||
private void initializeFirstFrame(SatelliteRecord record)
|
||||
throws VizException {
|
||||
getCapability(ImagingCapability.class).setProvider(this);
|
||||
|
@ -256,7 +238,6 @@ public class SatResource extends
|
|||
IColorMap colorMap = null;
|
||||
String cmName = null;
|
||||
PersistedParameters persisted = null;
|
||||
|
||||
if (hasCapability(ColorMapCapability.class)) {
|
||||
colorMapParameters = getCapability(ColorMapCapability.class)
|
||||
.getColorMapParameters();
|
||||
|
@ -267,7 +248,6 @@ public class SatResource extends
|
|||
}
|
||||
}
|
||||
Unit<?> unit = SatDataRetriever.getRecordUnit(record);
|
||||
|
||||
/*
|
||||
* TODO default to NaN instead of 0. 0 is the default to support older
|
||||
* data(before the gini decoder set a fill value), when all decoders and
|
||||
|
@ -317,29 +297,27 @@ public class SatResource extends
|
|||
statusHandler.handle(Priority.WARN,
|
||||
"Unable to request sample record", e);
|
||||
}
|
||||
|
||||
SingleLevel level = new SingleLevel(Level.LevelType.SURFACE);
|
||||
String physicalElement = record.getPhysicalElement();
|
||||
|
||||
// Grab the sampleRange from the preferences
|
||||
ParamLevelMatchCriteria match = new ParamLevelMatchCriteria();
|
||||
match.setParameterName(Arrays.asList(physicalElement));
|
||||
match.setLevels(Arrays.asList((Level) level));
|
||||
match.setCreatingEntityNames(Arrays.asList(record.getCreatingEntity()));
|
||||
String lg = null;
|
||||
StyleRule sr = null;
|
||||
try {
|
||||
StyleRule sr = StyleManager.getInstance()
|
||||
sr = StyleManager.getInstance()
|
||||
.getStyleRule(StyleManager.StyleType.IMAGERY, match);
|
||||
|
||||
ImagePreferences preferences = null;
|
||||
if (sr == null || sr
|
||||
.getPreferences() instanceof ImagePreferences == false) {
|
||||
if (sr == null
|
||||
|| !(sr.getPreferences() instanceof ImagePreferences)) {
|
||||
// No style rule, this is a best guess at what might look good.
|
||||
preferences = new ImagePreferences();
|
||||
if (unit != null && unit.isCompatible(Temperature.UNIT)) {
|
||||
preferences.setDefaultColormap("Sat/IR/CIRA (IR Default)");
|
||||
} else {
|
||||
preferences.setDefaultColormap("Sat/VIS/Linear");
|
||||
preferences.setDefaultColormap("Sat/VIS/ZA (Vis Default)");
|
||||
}
|
||||
DataScale range = new DataScale();
|
||||
range.setScaleType(DataScale.Type.LINEAR);
|
||||
|
@ -351,17 +329,16 @@ public class SatResource extends
|
|||
}
|
||||
colorMapParameters = ColorMapParameterFactory.build(preferences,
|
||||
unit);
|
||||
|
||||
sampleRange = preferences.getSamplePrefs();
|
||||
lg = preferences.getLegend();
|
||||
// test, so legend is not over written with empty string
|
||||
if (lg != null && lg.trim().isEmpty()) {
|
||||
lg = null;
|
||||
}
|
||||
|
||||
} catch (StyleException e) {
|
||||
throw new VizException(e.getLocalizedMessage(), e);
|
||||
}
|
||||
|
||||
// If null, set from style rules
|
||||
if (cmName == null) {
|
||||
cmName = colorMapParameters.getColorMapName();
|
||||
|
@ -369,11 +346,10 @@ public class SatResource extends
|
|||
if (colorMap == null) {
|
||||
colorMap = colorMapParameters.getColorMap();
|
||||
}
|
||||
|
||||
// Load colormap into parameters
|
||||
if (colorMap == null) {
|
||||
if (cmName == null) {
|
||||
cmName = "Sat/VIS/Linear";
|
||||
cmName = "Sat/VIS/ZA (Vis Default)";
|
||||
}
|
||||
try {
|
||||
colorMap = ColorMapLoader.loadColorMap(cmName);
|
||||
|
@ -381,29 +357,22 @@ public class SatResource extends
|
|||
throw new VizException("Unable to load clormap: " + cmName, e);
|
||||
}
|
||||
}
|
||||
|
||||
if (colorMap != null) {
|
||||
colorMapParameters.setColorMap(colorMap);
|
||||
}
|
||||
|
||||
if (persisted != null) {
|
||||
colorMapParameters.applyPersistedParameters(persisted);
|
||||
}
|
||||
|
||||
if (colorMapParameters.getDataMapping() == null) {
|
||||
colorMapParameters.setNoDataValue(fillValue);
|
||||
}
|
||||
|
||||
getCapability(ColorMapCapability.class)
|
||||
.setColorMapParameters(colorMapParameters);
|
||||
|
||||
if (lg != null) {
|
||||
this.legend = lg;
|
||||
} else {
|
||||
this.legend = getLegend(record);
|
||||
if (lg == null) {
|
||||
lg = getLegend(record);
|
||||
}
|
||||
this.legend = performLegendSubstitution(record, sr, lg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (this.legend != null) {
|
||||
|
@ -411,14 +380,12 @@ public class SatResource extends
|
|||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> interrogate(ReferencedCoordinate coord)
|
||||
throws VizException {
|
||||
DataTime displayedDate = descriptor.getFramesInfo()
|
||||
.getTimeForResource(this);
|
||||
Map<String, Object> dataMap = new HashMap<String, Object>();
|
||||
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
SatRenderable renderable = (SatRenderable) getRenderable(displayedDate);
|
||||
ColorMapParameters parameters = getCapability(ColorMapCapability.class)
|
||||
.getColorMapParameters();
|
||||
|
@ -437,17 +404,13 @@ public class SatResource extends
|
|||
throw new VizException("Error interrogating raw data", e);
|
||||
}
|
||||
}
|
||||
|
||||
dataMap.put(SATELLITE_DATA_INTERROGATE_ID,
|
||||
Measure.valueOf(dataValue, dataUnit));
|
||||
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String inspect(ReferencedCoordinate coord) throws VizException {
|
||||
Map<String, Object> dataMap = interrogate(coord);
|
||||
|
||||
Measure<?, ?> value = (Measure<?, ?>) dataMap
|
||||
.get(SATELLITE_DATA_INTERROGATE_ID);
|
||||
double measuredValue = Double.NaN;
|
||||
|
@ -459,7 +422,6 @@ public class SatResource extends
|
|||
}
|
||||
ColorMapParameters cmp = getCapability(ColorMapCapability.class)
|
||||
.getColorMapParameters();
|
||||
|
||||
// check if data mapping preferences exist
|
||||
DataMappingPreferences dataMapping = cmp.getDataMapping();
|
||||
if (dataMapping != null) {
|
||||
|
@ -471,7 +433,6 @@ public class SatResource extends
|
|||
return label;
|
||||
}
|
||||
}
|
||||
|
||||
Unit<?> unit = cmp.getDisplayUnit();
|
||||
Unit<?> measuredUnit = value.getUnit();
|
||||
if (unit != null && measuredUnit != null) {
|
||||
|
@ -480,11 +441,10 @@ public class SatResource extends
|
|||
measuredValue = dataToDisplay.convert(measuredValue);
|
||||
}
|
||||
}
|
||||
|
||||
// Had to use 'bit' as the display unit because
|
||||
// counts was not an acceptable unit.
|
||||
String unitString = unit == null ? ""
|
||||
: unit.toString().equals("bit") ? "counts" : unit.toString();
|
||||
: "bit".equals(unit.toString()) ? "counts" : unit.toString();
|
||||
double f1 = Double.NEGATIVE_INFINITY;
|
||||
double f2 = Double.POSITIVE_INFINITY;
|
||||
if (sampleRange != null) {
|
||||
|
@ -499,7 +459,6 @@ public class SatResource extends
|
|||
}
|
||||
return String.format("%.1f%s", measuredValue, unitString);
|
||||
}
|
||||
|
||||
private String getLegend(SatelliteRecord record) {
|
||||
String productName = record.getPhysicalElement();
|
||||
if (record instanceof DerivedSatelliteRecord) {
|
||||
|
@ -508,37 +467,73 @@ public class SatResource extends
|
|||
return SatelliteConstants.getLegend(productName,
|
||||
record.getCreatingEntity());
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the {@link VariableSubstitutor} to replace any variables in the
|
||||
* legend with real values from the record or style rule
|
||||
*
|
||||
* @param record
|
||||
* an example satellite record whose fields are used to populate
|
||||
* the substitution
|
||||
* @param styleRule
|
||||
* an optional style rule for units information, this may be
|
||||
* null.
|
||||
* @param legend
|
||||
* the legend string retrieved form style rules, constants, or
|
||||
* elsewhere.
|
||||
* @return A new legend with any variables replaced.
|
||||
* @throws VizException
|
||||
* if an error occurs parsing variables.
|
||||
*/
|
||||
private String performLegendSubstitution(SatelliteRecord record,
|
||||
StyleRule styleRule, String legend) throws VizException {
|
||||
if (legend.indexOf('$') >= 0) {
|
||||
Map<String, String> subs = new HashMap<>();
|
||||
subs.put("creatingEntity", record.getCreatingEntity());
|
||||
subs.put("physicalElement", record.getPhysicalElement());
|
||||
subs.put("sectorID", record.getSectorID());
|
||||
subs.put("source", record.getSource());
|
||||
subs.put("units", record.getUnits());
|
||||
if (styleRule != null) {
|
||||
String unitLabel = styleRule.getPreferences()
|
||||
.getDisplayUnitLabel();
|
||||
if (unitLabel != null) {
|
||||
subs.put("units", unitLabel);
|
||||
}
|
||||
}
|
||||
try {
|
||||
legend = VariableSubstitutor.processVariables(legend, subs);
|
||||
} catch (ParseException e) {
|
||||
throw new VizException("Error building product legend", e);
|
||||
}
|
||||
}
|
||||
return legend;
|
||||
}
|
||||
@Override
|
||||
public List<DrawableImage> getImages(IGraphicsTarget target,
|
||||
PaintProperties paintProps) throws VizException {
|
||||
SatRenderable renderable = (SatRenderable) getOrCreateRenderable(
|
||||
paintProps.getDataTime());
|
||||
if (renderable != null) {
|
||||
return new ArrayList<DrawableImage>(
|
||||
return new ArrayList<>(
|
||||
renderable.getImagesToRender(target, paintProps));
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void capabilityChanged(IRenderable renderable,
|
||||
AbstractCapability capability) {
|
||||
issueRefresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void disposeRenderable(IRenderable renderable) {
|
||||
((SatRenderable) renderable).dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean projectRenderable(IRenderable renderable,
|
||||
CoordinateReferenceSystem crs) throws VizException {
|
||||
((SatRenderable) renderable).project();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IRenderable constructRenderable(DataTime time,
|
||||
List<PluginDataObject> records) throws VizException {
|
||||
|
@ -547,7 +542,6 @@ public class SatResource extends
|
|||
renderable.project();
|
||||
return renderable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean updateRenderable(IRenderable renderable,
|
||||
PluginDataObject... pdos) {
|
||||
|
@ -555,14 +549,10 @@ public class SatResource extends
|
|||
for (PluginDataObject object : pdos) {
|
||||
if (object instanceof SatelliteRecord) {
|
||||
sr.addRecord((SatelliteRecord) object);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<InterrogationKey<?>> getInterrogationKeys() {
|
||||
Set<InterrogationKey<?>> result = new HashSet<>();
|
||||
|
@ -572,7 +562,6 @@ public class SatResource extends
|
|||
result.add(DATA_SOURCE_INTERROGATE_KEY);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterrogateMap interrogate(ReferencedCoordinate coordinate,
|
||||
DataTime time, InterrogationKey<?>... keys) {
|
||||
|
@ -614,15 +603,12 @@ public class SatResource extends
|
|||
renderableResult.getDataSource());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toolChanged() {
|
||||
issueRefresh();
|
||||
}
|
||||
|
||||
public void redoMainTimeMatch() {
|
||||
try {
|
||||
descriptor.getTimeMatcher().redoTimeMatching(this);
|
||||
|
@ -632,4 +618,4 @@ public class SatResource extends
|
|||
"Unable to redo the time matching " + getSafeName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue