Omaha #3052 Improved TopoQuery error handling to throw exceptions with useful error messages.
Change-Id: Ic181682611801ea244b986e8a2ce1400c4dc15d1 Former-commit-id:49d4eba710
[formerlybd50ae9854
] [formerly3f169399b8
] [formerly49d4eba710
[formerlybd50ae9854
] [formerly3f169399b8
] [formerly304364e356
[formerly3f169399b8
[formerly 0d42d4fdc56122c3df912c93e5e09b0ab28c1b37]]]] Former-commit-id:304364e356
Former-commit-id:9b0c3f2355
[formerly060b0221fa
] [formerly bba329f4d5727f79bd95b57a11fd41ca3994a509 [formerly3ff441f9da
]] Former-commit-id: 0d5de25d2e6c39b305e848012322ce2570f429ed [formerly7171bc6f0a
] Former-commit-id:b98936356f
This commit is contained in:
parent
9f379f0573
commit
492d3fce39
5 changed files with 74 additions and 42 deletions
|
@ -30,6 +30,9 @@ import java.util.List;
|
|||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.topo.TopoException;
|
||||
import com.raytheon.uf.common.topo.TopoQuery;
|
||||
import com.raytheon.uf.viz.core.exception.VizException;
|
||||
|
||||
|
@ -55,6 +58,9 @@ import com.raytheon.uf.viz.core.exception.VizException;
|
|||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
public class GribNSharpResourceData extends D2DNSharpResourceData {
|
||||
|
||||
private static final transient IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(GribNSharpResourceData.class);
|
||||
|
||||
private float surfaceElevation = NcSoundingProfile.MISSING;
|
||||
|
||||
public GribNSharpResourceData() {
|
||||
|
@ -79,16 +85,18 @@ public class GribNSharpResourceData extends D2DNSharpResourceData {
|
|||
NcSoundingCube cube = NcSoundingQuery.mdlSoundingQueryByLatLon(
|
||||
refTimeStr, validTimeStr, latLon, "grid", getSoundingType(),
|
||||
false, "-1");
|
||||
if (cube != null && !cube.getSoundingProfileList().isEmpty()) {
|
||||
if ((cube != null) && !cube.getSoundingProfileList().isEmpty()) {
|
||||
NcSoundingProfile profileList = cube.getSoundingProfileList()
|
||||
.get(0);
|
||||
// If stationElevation is not set, set it to the topo value.
|
||||
if (profileList.getStationElevation() == NcSoundingProfile.MISSING) {
|
||||
if (surfaceElevation == NcSoundingProfile.MISSING) {
|
||||
TopoQuery topoQuery = TopoQuery.getInstance();
|
||||
if (topoQuery != null) {
|
||||
try {
|
||||
TopoQuery topoQuery = TopoQuery.getInstance();
|
||||
surfaceElevation = (float) topoQuery
|
||||
.getHeight(coordinate);
|
||||
} catch (TopoException e) {
|
||||
statusHandler.error("Unable to retrieve topo", e);
|
||||
}
|
||||
}
|
||||
profileList.setStationElevation(surfaceElevation);
|
||||
|
@ -108,7 +116,7 @@ public class GribNSharpResourceData extends D2DNSharpResourceData {
|
|||
float h1 = layers.get(i - 1).getGeoHeight();
|
||||
float h2 = layers.get(i).getGeoHeight();
|
||||
float h = sfcLayer.getGeoHeight();
|
||||
float p = p1 + (h - h1) * (p1 - p2) / (h1 - h2);
|
||||
float p = p1 + (((h - h1) * (p1 - p2)) / (h1 - h2));
|
||||
sfcLayer.setPressure(p);
|
||||
}
|
||||
layers.add(i, sfcLayer);
|
||||
|
|
|
@ -36,6 +36,7 @@ import com.raytheon.uf.common.status.IUFStatusHandler;
|
|||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
import com.raytheon.uf.common.style.level.Level.LevelType;
|
||||
import com.raytheon.uf.common.topo.TopoException;
|
||||
import com.raytheon.uf.common.topo.TopoQuery;
|
||||
import com.raytheon.uf.common.wxmath.Hgt2Pres;
|
||||
import com.raytheon.uf.viz.core.DrawableString;
|
||||
|
@ -167,7 +168,7 @@ public class CrossSectionGraph extends AbstractGraph {
|
|||
@Override
|
||||
public void paint(IGraphicsTarget target, PaintProperties paintProps)
|
||||
throws VizException {
|
||||
if (1 / paintProps.getZoomLevel() != zoomLevel) {
|
||||
if ((1 / paintProps.getZoomLevel()) != zoomLevel) {
|
||||
zoomLevel = (int) (1 / paintProps.getZoomLevel());
|
||||
createAxes();
|
||||
redraw = true;
|
||||
|
@ -208,7 +209,7 @@ public class CrossSectionGraph extends AbstractGraph {
|
|||
testString.magnification = currentMagnification;
|
||||
double unitsHeight = target.getStringsBounds(testString).getHeight();
|
||||
// Leave 4.5 lines for the cities labels and the distance labels
|
||||
double y = graphExtent.getMaxY() + unitsHeight / ratio * 4.5;
|
||||
double y = graphExtent.getMaxY() + ((unitsHeight / ratio) * 4.5);
|
||||
if (y > paintProps.getView().getExtent().getMaxY()) {
|
||||
y = paintProps.getView().getExtent().getMaxY();
|
||||
}
|
||||
|
@ -300,16 +301,16 @@ public class CrossSectionGraph extends AbstractGraph {
|
|||
|
||||
double y = graphExtent.getMaxY() + height;
|
||||
// Leave space for the distance labels below this
|
||||
if (y > paintProps.getView().getExtent().getMaxY() - height * 3.5) {
|
||||
y = paintProps.getView().getExtent().getMaxY() - height * 3.5;
|
||||
if (y > (paintProps.getView().getExtent().getMaxY() - (height * 3.5))) {
|
||||
y = paintProps.getView().getExtent().getMaxY() - (height * 3.5);
|
||||
}
|
||||
List<DrawableString> labels = new ArrayList<DrawableString>();
|
||||
for (int i = 0; i < cities.length; i++) {
|
||||
if (cities[i] == null) {
|
||||
continue;
|
||||
}
|
||||
double x = graphExtent.getMinX() + graphExtent.getWidth()
|
||||
/ (cities.length - 1) * i;
|
||||
double x = graphExtent.getMinX()
|
||||
+ ((graphExtent.getWidth() / (cities.length - 1)) * i);
|
||||
DrawableString caret = new DrawableString("^", graphColor);
|
||||
DrawableString city = new DrawableString(cities[i], graphColor);
|
||||
caret.setCoordinates(x, y);
|
||||
|
@ -340,9 +341,9 @@ public class CrossSectionGraph extends AbstractGraph {
|
|||
.getColor();
|
||||
double inc = determineIncrement(yAxisPlacer.getDataWidth());
|
||||
// Leave space for the cities labels above and the Distance label below
|
||||
double y = graphExtent.getMaxY() + height * 2;
|
||||
if (y > paintProps.getView().getExtent().getMaxY() - height * 2.5) {
|
||||
y = paintProps.getView().getExtent().getMaxY() - height * 2.5;
|
||||
double y = graphExtent.getMaxY() + (height * 2);
|
||||
if (y > (paintProps.getView().getExtent().getMaxY() - (height * 2.5))) {
|
||||
y = paintProps.getView().getExtent().getMaxY() - (height * 2.5);
|
||||
}
|
||||
List<DrawableString> labels = new ArrayList<DrawableString>();
|
||||
for (double d = yAxisPlacer.getMinDataValue(); d <= yAxisPlacer
|
||||
|
@ -386,12 +387,12 @@ public class CrossSectionGraph extends AbstractGraph {
|
|||
shape = target.createWireframeShape(false, descriptor);
|
||||
double[][] lineSegment = new double[topoData.length][2];
|
||||
for (int i = 0; i < topoData.length; i++) {
|
||||
lineSegment[i][0] = graphExtent.getMinX() + i
|
||||
* graphExtent.getWidth() / (topoData.length - 1);
|
||||
lineSegment[i][0] = graphExtent.getMinX()
|
||||
+ ((i * graphExtent.getWidth()) / (topoData.length - 1));
|
||||
lineSegment[i][1] = topoData[i];
|
||||
lineSegment[i][1] = Math.min(lineSegment[i][1],
|
||||
graphExtent.getMaxY());
|
||||
if (i % 2 == 0) {
|
||||
if ((i % 2) == 0) {
|
||||
double[][] bar = new double[2][2];
|
||||
bar[0] = lineSegment[i];
|
||||
bar[1][0] = lineSegment[i][0];
|
||||
|
@ -407,7 +408,7 @@ public class CrossSectionGraph extends AbstractGraph {
|
|||
|
||||
public double[] getTopoData(LineString line, int numPoints) {
|
||||
if (topoData.containsKey(line)
|
||||
&& topoData.get(line).length == numPoints) {
|
||||
&& (topoData.get(line).length == numPoints)) {
|
||||
return topoData.get(line);
|
||||
}
|
||||
|
||||
|
@ -420,11 +421,12 @@ public class CrossSectionGraph extends AbstractGraph {
|
|||
Coordinate[] lineData;
|
||||
lineData = GeoUtil.splitLine(numPoints, line.getCoordinates());
|
||||
|
||||
heights = TopoQuery.getInstance().getHeight(lineData);
|
||||
if (heights == null) {
|
||||
try {
|
||||
heights = TopoQuery.getInstance().getHeight(lineData);
|
||||
} catch (TopoException e) {
|
||||
statusHandler
|
||||
.handle(Priority.PROBLEM,
|
||||
"Error occured requesting Topo data, topo will be unavailable.");
|
||||
.error("Error occured requesting Topo data, topo will be unavailable.",
|
||||
e);
|
||||
return new double[numPoints];
|
||||
}
|
||||
if (csDesc.getHeightScale().getHeightType() == LevelType.PRESSURE) {
|
||||
|
|
|
@ -27,15 +27,16 @@ import javax.measure.unit.SI;
|
|||
import org.geotools.coverage.grid.GridGeometry2D;
|
||||
|
||||
import com.raytheon.uf.common.comm.CommunicationException;
|
||||
import com.raytheon.uf.common.inventory.data.AbstractRequestableData;
|
||||
import com.raytheon.uf.common.inventory.exception.DataCubeException;
|
||||
import com.raytheon.uf.common.dataplugin.level.LevelFactory;
|
||||
import com.raytheon.uf.common.datastorage.Request;
|
||||
import com.raytheon.uf.common.datastorage.records.FloatDataRecord;
|
||||
import com.raytheon.uf.common.gridcoverage.GridCoverage;
|
||||
import com.raytheon.uf.common.inventory.data.AbstractRequestableData;
|
||||
import com.raytheon.uf.common.inventory.exception.DataCubeException;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
import com.raytheon.uf.common.topo.TopoException;
|
||||
import com.raytheon.uf.common.topo.TopoQuery;
|
||||
import com.raytheon.viz.grid.util.SliceUtil;
|
||||
|
||||
|
@ -90,12 +91,13 @@ public class TopoRequestableData extends AbstractRequestableData {
|
|||
if (rval == null) {
|
||||
// retrieve topo data and assign record to FloatDataRecord
|
||||
GridGeometry2D gridGeom = coverage.getGridGeometry();
|
||||
float[] heights = TopoQuery.getInstance().getHeight(gridGeom);
|
||||
|
||||
if (heights != null) {
|
||||
try {
|
||||
float[] heights = TopoQuery.getInstance().getHeight(gridGeom);
|
||||
rval = new FloatDataRecord(null, null, heights, 2, new long[] {
|
||||
coverage.getNx(), coverage.getNy() });
|
||||
topoCache.put(coverage, rval);
|
||||
} catch (TopoException e) {
|
||||
throw new DataCubeException("Unable to retrieve topo data", e);
|
||||
}
|
||||
}
|
||||
if (arg instanceof Request) {
|
||||
|
|
|
@ -231,12 +231,15 @@ public class TopoDatabase extends VGridDatabase {
|
|||
TR);
|
||||
ServerResponse<ScalarGridSlice> srRetrieve = topoMgr
|
||||
.getTopoData(gloc);
|
||||
sr.addMessages(srRetrieve);
|
||||
ScalarGridSlice tempgs = srRetrieve.getPayload();
|
||||
IGridSlice gs = new ScalarGridSlice(TR, gpi,
|
||||
new GridDataHistory[] { gdh }, tempgs.getScalarGrid());
|
||||
data.add(gs);
|
||||
sr.setPayload(data);
|
||||
if (srRetrieve.isOkay()) {
|
||||
ScalarGridSlice tempgs = srRetrieve.getPayload();
|
||||
IGridSlice gs = new ScalarGridSlice(TR, gpi,
|
||||
new GridDataHistory[] { gdh }, tempgs.getScalarGrid());
|
||||
data.add(gs);
|
||||
sr.setPayload(data);
|
||||
} else {
|
||||
sr.addMessages(srRetrieve);
|
||||
}
|
||||
}
|
||||
|
||||
return sr;
|
||||
|
|
|
@ -57,6 +57,7 @@ import com.raytheon.uf.common.status.IUFStatusHandler;
|
|||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
import com.raytheon.uf.common.time.TimeRange;
|
||||
import com.raytheon.uf.common.topo.TopoException;
|
||||
import com.raytheon.uf.common.topo.TopoQuery;
|
||||
|
||||
/**
|
||||
|
@ -139,7 +140,7 @@ public class TopoDatabaseManager {
|
|||
public ServerResponse<ScalarGridSlice> getTopoData(final GridLocation gloc) {
|
||||
ServerResponse<ScalarGridSlice> sr = new ServerResponse<ScalarGridSlice>();
|
||||
ScalarGridSlice data = new ScalarGridSlice();
|
||||
Grid2DFloat grid;
|
||||
Grid2DFloat grid = null;
|
||||
String cacheGroupName = calcGroupName(gloc);
|
||||
|
||||
try {
|
||||
|
@ -154,20 +155,27 @@ public class TopoDatabaseManager {
|
|||
// create new cache since file doesn't exist
|
||||
statusHandler.handle(Priority.DEBUG, "Calculating Topography for "
|
||||
+ gloc);
|
||||
grid = processTopography(gloc, config.isTopoAllowedBelowZero());
|
||||
if (grid.isValid()) {
|
||||
writeTopoData(gloc, grid);
|
||||
|
||||
try {
|
||||
grid = processTopography(gloc, config.isTopoAllowedBelowZero());
|
||||
if (grid.isValid()) {
|
||||
writeTopoData(gloc, grid);
|
||||
} else {
|
||||
sr.addMessage("Error calculating topography for " + gloc);
|
||||
}
|
||||
} catch (TopoException e1) {
|
||||
sr.addMessage("Unable to calculate topography for " + gloc);
|
||||
}
|
||||
}
|
||||
|
||||
// convert to IGridSlice
|
||||
if (sr.isOkay()) {
|
||||
data = makeGridSlice(gloc, grid);
|
||||
sr.setPayload(data);
|
||||
} else {
|
||||
sr.addMessage("Unable to provide topography grid");
|
||||
}
|
||||
|
||||
sr.setPayload(data);
|
||||
return sr;
|
||||
}
|
||||
|
||||
|
@ -225,9 +233,10 @@ public class TopoDatabaseManager {
|
|||
* If set to false, values less than zero in the grid will be set
|
||||
* to 0.
|
||||
* @return The topography grid.
|
||||
* @throws TopoException
|
||||
*/
|
||||
private Grid2DFloat processTopography(final GridLocation gloc,
|
||||
boolean allowValuesBelowZero) {
|
||||
boolean allowValuesBelowZero) throws TopoException {
|
||||
float[] heights = TopoQuery.getInstance().getHeight(
|
||||
MapUtil.getGridGeometry(gloc));
|
||||
UnitConverter cvt = SI.METER.getConverterTo(NonSI.FOOT);
|
||||
|
@ -263,10 +272,18 @@ public class TopoDatabaseManager {
|
|||
if (!cachedFiles.contains(calcGroupName(gloc))) {
|
||||
// if not in list, then we need to make one
|
||||
statusHandler.debug("Calculating Topography for " + gloc);
|
||||
Grid2DFloat grid = processTopography(gloc,
|
||||
config.isTopoAllowedBelowZero());
|
||||
if (grid.isValid()) {
|
||||
writeTopoData(gloc, grid);
|
||||
try {
|
||||
Grid2DFloat grid = processTopography(gloc,
|
||||
config.isTopoAllowedBelowZero());
|
||||
if (grid.isValid()) {
|
||||
writeTopoData(gloc, grid);
|
||||
} else {
|
||||
statusHandler.error("Error calculating topography for "
|
||||
+ gloc);
|
||||
}
|
||||
} catch (TopoException e1) {
|
||||
statusHandler.error("Unable to calculate topography for "
|
||||
+ gloc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue