Issue #2508 Added DiscreteGridSlice.getKeys(), deprecated getKey()

Change-Id: I5d47498c2056de1c217927102770092bb57a372c

Former-commit-id: 42e924e021 [formerly 38e33092a2 [formerly 19246ae601e292bd26ba8ba6b9446ef8d82ee663]]
Former-commit-id: 38e33092a2
Former-commit-id: b61ccc1609
This commit is contained in:
Ron Anderson 2013-10-31 11:40:00 -05:00
parent 7648e116ad
commit f0529e0eee
17 changed files with 404 additions and 369 deletions

View file

@ -51,6 +51,7 @@
# (e.g. grid[mask] = value) # (e.g. grid[mask] = value)
# Oct 07, 2013 2424 randerso remove use of pytz # Oct 07, 2013 2424 randerso remove use of pytz
# Oct 29, 2013 2476 njensen Improved getting wx/discrete keys in _getGridResults # Oct 29, 2013 2476 njensen Improved getting wx/discrete keys in _getGridResults
# Oct 31, 2013 2508 randerso Change to use DiscreteGridSlice.getKeys()
# #
######################################################################## ########################################################################
import types, string, time, sys import types, string, time, sys
@ -484,7 +485,7 @@ class SmartScript(BaseTool.BaseTool):
if result[0].dtype != numpy.int8: if result[0].dtype != numpy.int8:
# scalar # scalar
result = result[0] result = result[0]
else: else:
# discrete or weather # discrete or weather
keys = JUtil.javaObjToPyVal(slice.getKeyList()) keys = JUtil.javaObjToPyVal(slice.getKeyList())
result.append(keys) result.append(keys)
@ -650,7 +651,7 @@ class SmartScript(BaseTool.BaseTool):
slice = DiscreteGridSlice() slice = DiscreteGridSlice()
bits = self.__dataMgr.getIscDataAccess().getCompositeGrid(gid, exactMatch, slice) bits = self.__dataMgr.getIscDataAccess().getCompositeGrid(gid, exactMatch, slice)
keys = [] keys = []
for k in slice.getKey(): for k in slice.getKeys():
keys.append(str(k)) keys.append(str(k))
args = (bits.__numpy__[0], slice.getDiscreteGrid().__numpy__[0], keys) args = (bits.__numpy__[0], slice.getDiscreteGrid().__numpy__[0], keys)
return args return args

View file

@ -72,6 +72,7 @@ import com.vividsolutions.jts.geom.MultiPolygon;
* 30Jan2013 #15719 jdynina Fixed allowed field size to accept more * 30Jan2013 #15719 jdynina Fixed allowed field size to accept more
* than 128 characters * than 128 characters
* 02/19/2013 1637 randerso Added throws declarations to translateDataFrom * 02/19/2013 1637 randerso Added throws declarations to translateDataFrom
* 10/31/2013 2508 randerso Change to use DiscreteGridSlice.getKeys()
* *
* </pre> * </pre>
* *
@ -102,8 +103,8 @@ public class DiscreteGridData extends AbstractGridData implements INumpyable {
DiscreteGridSlice thisSlice = getDiscreteSlice(); DiscreteGridSlice thisSlice = getDiscreteSlice();
Grid2DByte grid = thisSlice.getDiscreteGrid(); Grid2DByte grid = thisSlice.getDiscreteGrid();
if (grid.getXdim() != pointsToSmooth.getXdim() if ((grid.getXdim() != pointsToSmooth.getXdim())
|| grid.getYdim() != pointsToSmooth.getYdim()) { || (grid.getYdim() != pointsToSmooth.getYdim())) {
statusHandler.handle( statusHandler.handle(
Priority.ERROR, Priority.ERROR,
"Dimension mismatch in doSmooth: " + getGrid().getXdim() "Dimension mismatch in doSmooth: " + getGrid().getXdim()
@ -121,7 +122,7 @@ public class DiscreteGridData extends AbstractGridData implements INumpyable {
getISCGrid(time, slice); getISCGrid(time, slice);
} }
originalGrid = slice.getDiscreteGrid(); originalGrid = slice.getDiscreteGrid();
originalKey = slice.getKey(); originalKey = slice.getKeys();
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
originalGrid = new Grid2DByte(); originalGrid = new Grid2DByte();
originalKey = new DiscreteKey[0]; originalKey = new DiscreteKey[0];
@ -155,8 +156,8 @@ public class DiscreteGridData extends AbstractGridData implements INumpyable {
// uses fewer than nine points if near grid edge, // uses fewer than nine points if near grid edge,
// but always has at least four values to average. // but always has at least four values to average.
Arrays.fill(histo, (short) 0); Arrays.fill(histo, (short) 0);
for (int newx = i - ss; newx <= i + ss; newx++) { for (int newx = i - ss; newx <= (i + ss); newx++) {
for (int newy = j - ss; newy <= j + ss; newy++) { for (int newy = j - ss; newy <= (j + ss); newy++) {
// if inside grid limits, make a smoothed value // if inside grid limits, make a smoothed value
if (originalGrid.isValid(newx, newy)) { if (originalGrid.isValid(newx, newy)) {
histo[0xFF & originalGrid.get(newx, newy)]++; histo[0xFF & originalGrid.get(newx, newy)]++;
@ -234,7 +235,7 @@ public class DiscreteGridData extends AbstractGridData implements INumpyable {
// complex case - translation is necessary // complex case - translation is necessary
else { else {
// copy the key from the source to the destination // copy the key from the source to the destination
setKey(((DiscreteGridSlice) sourceGrid.getGridSlice()).getKey()); setKey(((DiscreteGridSlice) sourceGrid.getGridSlice()).getKeys());
// find no discrete key, which is always the 1st one // find no discrete key, which is always the 1st one
int nowx = 0; int nowx = 0;
@ -340,8 +341,8 @@ public class DiscreteGridData extends AbstractGridData implements INumpyable {
protected Grid2DBit doPencilStretch(Date time, WxValue value, protected Grid2DBit doPencilStretch(Date time, WxValue value,
Coordinate[] path, Grid2DBit editArea) { Coordinate[] path, Grid2DBit editArea) {
Grid2DByte grid = getGrid(); Grid2DByte grid = getGrid();
if (grid.getXdim() != editArea.getXdim() if ((grid.getXdim() != editArea.getXdim())
|| grid.getYdim() != editArea.getYdim()) { || (grid.getYdim() != editArea.getYdim())) {
statusHandler.handle(Priority.ERROR, statusHandler.handle(Priority.ERROR,
"Dimension mismatch in doPencilStretch: " + grid.getXdim() "Dimension mismatch in doPencilStretch: " + grid.getXdim()
+ ',' + grid.getYdim() + ' ' + editArea.getXdim() + ',' + grid.getYdim() + ' ' + editArea.getXdim()
@ -675,8 +676,8 @@ public class DiscreteGridData extends AbstractGridData implements INumpyable {
protected Grid2DBit doCopy(Date time, Grid2DBit pointsToCopy, Point delta) { protected Grid2DBit doCopy(Date time, Grid2DBit pointsToCopy, Point delta) {
DiscreteGridSlice thisSlice = getDiscreteSlice(); DiscreteGridSlice thisSlice = getDiscreteSlice();
Grid2DByte sliceGrid = thisSlice.getDiscreteGrid(); Grid2DByte sliceGrid = thisSlice.getDiscreteGrid();
if (sliceGrid.getXdim() != pointsToCopy.getXdim() if ((sliceGrid.getXdim() != pointsToCopy.getXdim())
|| sliceGrid.getYdim() != pointsToCopy.getYdim()) { || (sliceGrid.getYdim() != pointsToCopy.getYdim())) {
throw new IllegalArgumentException("Dimension mismatch in doCopy: " throw new IllegalArgumentException("Dimension mismatch in doCopy: "
+ sliceGrid.getXdim() + ',' + sliceGrid.getYdim() + ' ' + sliceGrid.getXdim() + ',' + sliceGrid.getYdim() + ' '
+ pointsToCopy.getXdim() + ',' + pointsToCopy.getYdim()); + pointsToCopy.getXdim() + ',' + pointsToCopy.getYdim());
@ -695,7 +696,7 @@ public class DiscreteGridData extends AbstractGridData implements INumpyable {
getISCGrid(time, slice); getISCGrid(time, slice);
} }
originalGrid = slice.getDiscreteGrid(); originalGrid = slice.getDiscreteGrid();
originalKey = slice.getKey(); originalKey = slice.getKeys();
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
originalGrid = new Grid2DByte(); originalGrid = new Grid2DByte();
originalKey = new DiscreteKey[0]; originalKey = new DiscreteKey[0];
@ -751,8 +752,8 @@ public class DiscreteGridData extends AbstractGridData implements INumpyable {
@Override @Override
protected Grid2DBit doFillIn(Date time, Grid2DBit pointsToFillIn) { protected Grid2DBit doFillIn(Date time, Grid2DBit pointsToFillIn) {
Grid2DByte grid = getGrid(); Grid2DByte grid = getGrid();
if (grid.getXdim() != pointsToFillIn.getXdim() if ((grid.getXdim() != pointsToFillIn.getXdim())
|| grid.getYdim() != pointsToFillIn.getYdim()) { || (grid.getYdim() != pointsToFillIn.getYdim())) {
statusHandler.handle(Priority.ERROR, statusHandler.handle(Priority.ERROR,
"Dimension mismatch in doFillIn: " + grid.getXdim() + ',' "Dimension mismatch in doFillIn: " + grid.getXdim() + ','
+ grid.getYdim() + ' ' + pointsToFillIn.getXdim() + grid.getYdim() + ' ' + pointsToFillIn.getXdim()
@ -814,8 +815,8 @@ public class DiscreteGridData extends AbstractGridData implements INumpyable {
boolean done = false; boolean done = false;
while (!done) { while (!done) {
// Check for bounds // Check for bounds
if (coord.x < 0 || coord.x >= gridCells.getXdim() if ((coord.x < 0) || (coord.x >= gridCells.getXdim())
|| coord.y < 0 || coord.y >= gridCells.getYdim()) { || (coord.y < 0) || (coord.y >= gridCells.getYdim())) {
done = true; done = true;
} }
// Check for bit set // Check for bit set
@ -882,8 +883,8 @@ public class DiscreteGridData extends AbstractGridData implements INumpyable {
Grid2DBit points) { Grid2DBit points) {
Grid2DByte grid = getGrid(); Grid2DByte grid = getGrid();
Point dim = new Point(grid.getXdim(), grid.getYdim()); Point dim = new Point(grid.getXdim(), grid.getYdim());
if (values.getXdim() != dim.x || values.getYdim() != dim.y if ((values.getXdim() != dim.x) || (values.getYdim() != dim.y)
|| points.getXdim() != dim.x || points.getYdim() != dim.y) { || (points.getXdim() != dim.x) || (points.getYdim() != dim.y)) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"bad values/points dimensions for grid for: " "bad values/points dimensions for grid for: "
+ this.getParm().getParmID() + " gridDim=" + this.getParm().getParmID() + " gridDim="
@ -903,7 +904,7 @@ public class DiscreteGridData extends AbstractGridData implements INumpyable {
int numValues = values.getXdim() * values.getYdim(); int numValues = values.getXdim() * values.getYdim();
byte[] bp = values.getBuffer().array(); byte[] bp = values.getBuffer().array();
for (int i = 0; i < numValues; i++) { for (int i = 0; i < numValues; i++) {
if ((0xFF & bp[i]) > key.size() - 1) { if ((0xFF & bp[i]) > (key.size() - 1)) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Illegal discrete grid (bad values) in gridSet()"); "Illegal discrete grid (bad values) in gridSet()");
} }
@ -915,7 +916,7 @@ public class DiscreteGridData extends AbstractGridData implements INumpyable {
parmId.getCompositeName()); parmId.getCompositeName());
// REPLACE mode is easy // REPLACE mode is easy
if (parm.getParmState().getCombineMode() == ParmState.CombineMode.REPLACE if ((parm.getParmState().getCombineMode() == ParmState.CombineMode.REPLACE)
|| !overlapping) { || !overlapping) {
// create remap array // create remap array
byte[] remap = new byte[256]; byte[] remap = new byte[256];
@ -1019,7 +1020,7 @@ public class DiscreteGridData extends AbstractGridData implements INumpyable {
} }
private DiscreteKey[] getKey() { private DiscreteKey[] getKey() {
return ((DiscreteGridSlice) getGridSlice()).getKey(); return ((DiscreteGridSlice) getGridSlice()).getKeys();
} }
private void setKey(DiscreteKey[] key) { private void setKey(DiscreteKey[] key) {
@ -1034,8 +1035,8 @@ public class DiscreteGridData extends AbstractGridData implements INumpyable {
protected boolean doValid() { protected boolean doValid() {
String emsg = "Grid contains data which exceeds limits for this parm. "; String emsg = "Grid contains data which exceeds limits for this parm. ";
if (!getGridTime().isValid() || getParm() == null if (!getGridTime().isValid() || (getParm() == null)
|| getGridSlice() == null) { || (getGridSlice() == null)) {
statusHandler.handle(Priority.PROBLEM, statusHandler.handle(Priority.PROBLEM,
"Invalid grid time, bad parm or data slice"); "Invalid grid time, bad parm or data slice");
return false; // time, parm, or data slice not valid return false; // time, parm, or data slice not valid

View file

@ -74,6 +74,7 @@ import com.vividsolutions.jts.geom.Coordinate;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* 07/14/09 1995 bphillip Initial release * 07/14/09 1995 bphillip Initial release
* 10/31/2013 2508 randerso Change to use DiscreteGridSlice.getKeys()
* *
* </pre> * </pre>
* *
@ -105,6 +106,7 @@ public class ISCDataAccess implements IISCDataAccess {
} }
// returns corresponding ISC gridid, parm, grid // returns corresponding ISC gridid, parm, grid
@Override
public GridID getISCGridID(GridID id, boolean exactMatch) { public GridID getISCGridID(GridID id, boolean exactMatch) {
Parm p = this.getISCParm(id.getParm()); Parm p = this.getISCParm(id.getParm());
@ -150,10 +152,12 @@ public class ISCDataAccess implements IISCDataAccess {
} }
} }
@Override
public ParmID getISCParmID(ParmID parmID) { public ParmID getISCParmID(ParmID parmID) {
return dataMgr.getParmManager().getISCParmID(parmID); return dataMgr.getParmManager().getISCParmID(parmID);
} }
@Override
public Parm getISCParm(Parm p) { public Parm getISCParm(Parm p) {
if (p == null) { if (p == null) {
@ -185,6 +189,7 @@ public class ISCDataAccess implements IISCDataAccess {
return iscP; return iscP;
} }
@Override
public String getISCSite(Point loc, GridID gid) { public String getISCSite(Point loc, GridID gid) {
String empty = ""; String empty = "";
String officeType = gid.getParm().getOfficeType(); String officeType = gid.getParm().getOfficeType();
@ -202,6 +207,7 @@ public class ISCDataAccess implements IISCDataAccess {
} }
} }
@Override
public boolean inOurSite(Point loc, GridID gid) { public boolean inOurSite(Point loc, GridID gid) {
// must be our office type to be inOurSite // must be our office type to be inOurSite
if (!dataMgr.getOfficeType().equals(gid.getParm().getOfficeType())) { if (!dataMgr.getOfficeType().equals(gid.getParm().getOfficeType())) {
@ -216,12 +222,14 @@ public class ISCDataAccess implements IISCDataAccess {
} }
@Override
public WxValue getDataPoint(GridID gridID, Coordinate worldLoc) public WxValue getDataPoint(GridID gridID, Coordinate worldLoc)
throws GFEServerException { throws GFEServerException {
Coordinate gloc = new Coordinate(); Coordinate gloc = new Coordinate();
return getDataPoint(gridID, worldLoc, gloc); return getDataPoint(gridID, worldLoc, gloc);
} }
@Override
public WxValue getDataPoint(GridID gridID, Coordinate worldLoc, public WxValue getDataPoint(GridID gridID, Coordinate worldLoc,
Coordinate gloc) throws GFEServerException { Coordinate gloc) throws GFEServerException {
if (gridID.getParm() == null) { if (gridID.getParm() == null) {
@ -233,8 +241,8 @@ public class ISCDataAccess implements IISCDataAccess {
boolean inGrid = false; boolean inGrid = false;
gloc = MapUtil.latLonToGridCoordinate(worldLoc, gloc = MapUtil.latLonToGridCoordinate(worldLoc,
PixelOrientation.UPPER_RIGHT, location); PixelOrientation.UPPER_RIGHT, location);
inGrid = gloc.x >= 0 && gloc.x < location.getNx() && gloc.y >= 0 inGrid = (gloc.x >= 0) && (gloc.x < location.getNx()) && (gloc.y >= 0)
&& gloc.y < location.getNy(); && (gloc.y < location.getNy());
if (!inGrid) { if (!inGrid) {
return WxValue.defaultValue(gridID.getParm()); return WxValue.defaultValue(gridID.getParm());
} }
@ -263,6 +271,7 @@ public class ISCDataAccess implements IISCDataAccess {
} }
@Override
public Grid2DBit getCompositeGrid(GridID gid, boolean exactMatch, public Grid2DBit getCompositeGrid(GridID gid, boolean exactMatch,
ScalarGridSlice slice) { ScalarGridSlice slice) {
@ -333,6 +342,7 @@ public class ISCDataAccess implements IISCDataAccess {
return getCompositeGrid(gid, exactMatch, slice); return getCompositeGrid(gid, exactMatch, slice);
} }
@Override
public Grid2DBit getCompositeGrid(GridID gid, boolean exactMatch, public Grid2DBit getCompositeGrid(GridID gid, boolean exactMatch,
VectorGridSlice slice) { VectorGridSlice slice) {
@ -397,6 +407,7 @@ public class ISCDataAccess implements IISCDataAccess {
} }
@Override
public Grid2DBit getCompositeGrid(GridID gid, boolean exactMatch, public Grid2DBit getCompositeGrid(GridID gid, boolean exactMatch,
WeatherGridSlice slice) { WeatherGridSlice slice) {
@ -484,6 +495,7 @@ public class ISCDataAccess implements IISCDataAccess {
return siteMask.or(ourSiteMask); return siteMask.or(ourSiteMask);
} }
@Override
public Grid2DBit getCompositeGrid(GridID gid, boolean exactMatch, public Grid2DBit getCompositeGrid(GridID gid, boolean exactMatch,
DiscreteGridSlice slice) { DiscreteGridSlice slice) {
@ -519,9 +531,9 @@ public class ISCDataAccess implements IISCDataAccess {
slice.setDiscreteGrid(primary.getDiscreteSlice().getDiscreteGrid() slice.setDiscreteGrid(primary.getDiscreteSlice().getDiscreteGrid()
.clone()); .clone());
DiscreteKey[] keys = new DiscreteKey[primary.getDiscreteSlice() DiscreteKey[] keys = new DiscreteKey[primary.getDiscreteSlice()
.getKey().length]; .getKeys().length];
for (int i = 0; i < keys.length; i++) { for (int i = 0; i < keys.length; i++) {
keys[i] = new DiscreteKey(primary.getDiscreteSlice().getKey()[i]); keys[i] = new DiscreteKey(primary.getDiscreteSlice().getKeys()[i]);
} }
slice.setKey(keys); slice.setKey(keys);
@ -544,9 +556,9 @@ public class ISCDataAccess implements IISCDataAccess {
// blend the isc grid into the grid/key for those points set // blend the isc grid into the grid/key for those points set
Grid2DByte iscGrid = iscGridData.getDiscreteSlice().getDiscreteGrid(); Grid2DByte iscGrid = iscGridData.getDiscreteSlice().getDiscreteGrid();
DiscreteKey[] iscKey = iscGridData.getDiscreteSlice().getKey(); DiscreteKey[] iscKey = iscGridData.getDiscreteSlice().getKeys();
DiscreteKey[] keyList = slice.getKey(); DiscreteKey[] keyList = slice.getKeys();
Map<DiscreteKey, Integer> keyIndexMap = new HashMap<DiscreteKey, Integer>( Map<DiscreteKey, Integer> keyIndexMap = new HashMap<DiscreteKey, Integer>(
keyList.length); keyList.length);
for (int i = 0; i < keyList.length; i++) { for (int i = 0; i < keyList.length; i++) {
@ -595,7 +607,7 @@ public class ISCDataAccess implements IISCDataAccess {
for (int i = 0; i < available.size(); i++) { for (int i = 0; i < available.size(); i++) {
String name = available.get(i).getName(); String name = available.get(i).getName();
if (name.length() >= 5 && name.startsWith("ISC_") if ((name.length() >= 5) && name.startsWith("ISC_")
&& (name.indexOf('_', 4) == -1)) { && (name.indexOf('_', 4) == -1)) {
String site = name.substring(4); String site = name.substring(4);
if (knownSites.contains(site)) { if (knownSites.contains(site)) {

View file

@ -184,6 +184,7 @@ import com.vividsolutions.jts.geom.Coordinate;
* ant time weighted average. * ant time weighted average.
* Apr 02, 2013 #1774 randerso Fixed a possible deadlock issue. * Apr 02, 2013 #1774 randerso Fixed a possible deadlock issue.
* Aug 27, 2013 #2302 randerso Fix simultaneous save issue * Aug 27, 2013 #2302 randerso Fix simultaneous save issue
* Oct 31, 2013 #2508 randerso Change to use DiscreteGridSlice.getKeys()
* *
* </pre> * </pre>
* *
@ -593,7 +594,8 @@ public abstract class Parm implements Comparable<Parm> {
this.grids.acquireReadLock(); this.grids.acquireReadLock();
try { try {
if (this.grids.size() > 0 && !getGridInfo().isTimeIndependentParm()) { if ((this.grids.size() > 0)
&& !getGridInfo().isTimeIndependentParm()) {
return new TimeRange( return new TimeRange(
this.grids.get(0).getGridTime().getStart(), this.grids this.grids.get(0).getGridTime().getStart(), this.grids
.get(this.grids.size() - 1).getGridTime() .get(this.grids.size() - 1).getGridTime()
@ -965,7 +967,7 @@ public abstract class Parm implements Comparable<Parm> {
Date[] dateArray = { absTime }; Date[] dateArray = { absTime };
IGridData[] gridData = startParmEdit(dateArray); IGridData[] gridData = startParmEdit(dateArray);
if (gridData != null && gridData.length == 1) { if ((gridData != null) && (gridData.length == 1)) {
return gridData[0]; return gridData[0];
} }
@ -1029,7 +1031,7 @@ public abstract class Parm implements Comparable<Parm> {
IGridData grid = null; IGridData grid = null;
grid = overlappingGrid(absTime); grid = overlappingGrid(absTime);
if (grid != null && isOkToEdit(grid.getGridTime())) { if ((grid != null) && isOkToEdit(grid.getGridTime())) {
retGrids.add(grid); retGrids.add(grid);
affectedTimes.add(grid.getGridTime()); affectedTimes.add(grid.getGridTime());
saveUndoTimes.add(grid.getGridTime()); saveUndoTimes.add(grid.getGridTime());
@ -1245,7 +1247,7 @@ public abstract class Parm implements Comparable<Parm> {
boolean invChanged = false; boolean invChanged = false;
IGridData leftGrid = overlappingGrid(splitTimeRange.getStart()); IGridData leftGrid = overlappingGrid(splitTimeRange.getStart());
if (leftGrid != null if ((leftGrid != null)
&& !leftGrid.getGridTime().getStart() && !leftGrid.getGridTime().getStart()
.equals(splitTimeRange.getStart())) { .equals(splitTimeRange.getStart())) {
IGridData newGrid = null; IGridData newGrid = null;
@ -1266,7 +1268,7 @@ public abstract class Parm implements Comparable<Parm> {
IGridData rightGrid = overlappingGrid(new Date(splitTimeRange.getEnd() IGridData rightGrid = overlappingGrid(new Date(splitTimeRange.getEnd()
.getTime() - 1000)); .getTime() - 1000));
if (rightGrid != null if ((rightGrid != null)
&& !rightGrid.getGridTime().getEnd() && !rightGrid.getGridTime().getEnd()
.equals(splitTimeRange.getEnd())) { .equals(splitTimeRange.getEnd())) {
IGridData newGrid; IGridData newGrid;
@ -1355,10 +1357,10 @@ public abstract class Parm implements Comparable<Parm> {
// in some cases, you can end up with an invalid TR // in some cases, you can end up with an invalid TR
if (!expTR.isValid() if (!expTR.isValid()
|| orgTR.getStart().getTime() < replaceRange.getStart() || (orgTR.getStart().getTime() < replaceRange.getStart()
.getTime() .getTime())
|| orgTR.getEnd().getTime() > replaceRange.getEnd() || (orgTR.getEnd().getTime() > replaceRange.getEnd()
.getTime()) { .getTime())) {
continue; continue;
} }
@ -1461,8 +1463,8 @@ public abstract class Parm implements Comparable<Parm> {
// add proportional value to existing grid // add proportional value to existing grid
float timeRatio = (float) intersect.getDuration() float timeRatio = (float) intersect.getDuration()
/ (float) orgTR.getDuration(); / (float) orgTR.getDuration();
if (grids.get(j).getGridSlice() instanceof IContinuousSlice if ((grids.get(j).getGridSlice() instanceof IContinuousSlice)
&& grid.getGridSlice() instanceof IContinuousSlice) { && (grid.getGridSlice() instanceof IContinuousSlice)) {
IGridSlice copy; IGridSlice copy;
try { try {
@ -1656,8 +1658,8 @@ public abstract class Parm implements Comparable<Parm> {
e); e);
} }
if (copy instanceof IContinuousSlice if ((copy instanceof IContinuousSlice)
&& newgrid.getGridSlice() instanceof IContinuousSlice) { && (newgrid.getGridSlice() instanceof IContinuousSlice)) {
((IContinuousSlice) copy).operateEquals(Op.MULTIPLY, timeRatio, ((IContinuousSlice) copy).operateEquals(Op.MULTIPLY, timeRatio,
dataManager.getRefManager().fullRefSet().getGrid()); dataManager.getRefManager().fullRefSet().getGrid());
((IContinuousSlice) newgrid.getGridSlice()).operateEquals( ((IContinuousSlice) newgrid.getGridSlice()).operateEquals(
@ -2068,8 +2070,8 @@ public abstract class Parm implements Comparable<Parm> {
ParmID parmId = getParmID(); ParmID parmId = getParmID();
String siteId = parmId.getDbId().getSiteId(); String siteId = parmId.getDbId().getSiteId();
if (grids.length == 1 if ((grids.length == 1)
&& getGridInfo().getGridType() != GridType.WEATHER) { && (getGridInfo().getGridType() != GridType.WEATHER)) {
// nothing to average so we're done, except in the weather case // nothing to average so we're done, except in the weather case
try { try {
gridSlice = grids[0].getGridSlice().clone(); gridSlice = grids[0].getGridSlice().clone();
@ -2119,8 +2121,8 @@ public abstract class Parm implements Comparable<Parm> {
float dur = gridTR.get(k).getDuration(); float dur = gridTR.get(k).getDuration();
for (int i = 0; i < ge.getSpan(0); i++) { for (int i = 0; i < ge.getSpan(0); i++) {
for (int j = 0; j < ge.getSpan(1); j++) { for (int j = 0; j < ge.getSpan(1); j++) {
uSum.set(i, j, uSum.get(i, j) + uGrid.get(i, j) * dur); uSum.set(i, j, uSum.get(i, j) + (uGrid.get(i, j) * dur));
vSum.set(i, j, vSum.get(i, j) + vGrid.get(i, j) * dur); vSum.set(i, j, vSum.get(i, j) + (vGrid.get(i, j) * dur));
} }
} }
} }
@ -2184,7 +2186,7 @@ public abstract class Parm implements Comparable<Parm> {
// values that exceed the configured percentage // values that exceed the configured percentage
ArrayList<WeatherSubKey> weightedKeys = new ArrayList<WeatherSubKey>(); ArrayList<WeatherSubKey> weightedKeys = new ArrayList<WeatherSubKey>();
for (int k = 0; k < subKeys.size(); k++) { for (int k = 0; k < subKeys.size(); k++) {
if ((float) wcount.get(k) / totalDuration > significantPercent) { if (((float) wcount.get(k) / totalDuration) > significantPercent) {
weightedKeys.add(subKeys.get(k)); weightedKeys.add(subKeys.get(k));
} }
} }
@ -2237,7 +2239,7 @@ public abstract class Parm implements Comparable<Parm> {
Map<DiscreteKey, MutableInteger> values = new HashMap<DiscreteKey, MutableInteger>(); Map<DiscreteKey, MutableInteger> values = new HashMap<DiscreteKey, MutableInteger>();
for (int k = 0; k < gridCount; k++) { for (int k = 0; k < gridCount; k++) {
DiscreteKey key1[] = ((DiscreteGridSlice) grids[k] DiscreteKey key1[] = ((DiscreteGridSlice) grids[k]
.getGridSlice()).getKey(); .getGridSlice()).getKeys();
Grid2DByte grid1 = ((DiscreteGridSlice) grids[k] Grid2DByte grid1 = ((DiscreteGridSlice) grids[k]
.getGridSlice()).getDiscreteGrid(); .getGridSlice()).getDiscreteGrid();
// TextString kv = key1[grid1(i, j)].keyAsString(); // TextString kv = key1[grid1(i, j)].keyAsString();
@ -2323,8 +2325,8 @@ public abstract class Parm implements Comparable<Parm> {
public void adjust(float deltaValue, final Date time, public void adjust(float deltaValue, final Date time,
final ReferenceData refData) { final ReferenceData refData) {
// Can't adjust weather or discrete // Can't adjust weather or discrete
if (getGridInfo().getGridType() == GridType.WEATHER if ((getGridInfo().getGridType() == GridType.WEATHER)
|| getGridInfo().getGridType() == GridType.DISCRETE) { || (getGridInfo().getGridType() == GridType.DISCRETE)) {
return; return;
} }
@ -2348,7 +2350,7 @@ public abstract class Parm implements Comparable<Parm> {
Date[] dateArray = { absTime }; Date[] dateArray = { absTime };
IGridData[] gridData = extendParmEdit(dateArray); IGridData[] gridData = extendParmEdit(dateArray);
if (gridData != null && gridData.length == 1) { if ((gridData != null) && (gridData.length == 1)) {
return gridData[0]; return gridData[0];
} }
@ -2434,8 +2436,8 @@ public abstract class Parm implements Comparable<Parm> {
*/ */
public boolean timeShiftTR(TimeRange tr, int secondsToShift, public boolean timeShiftTR(TimeRange tr, int secondsToShift,
boolean copyOnly) { boolean copyOnly) {
if (Math.abs(secondsToShift) if ((Math.abs(secondsToShift) % this.gridInfo.getTimeConstraints()
% this.gridInfo.getTimeConstraints().getRepeatInterval() != 0) { .getRepeatInterval()) != 0) {
throw new IllegalArgumentException("timeShiftSelectedTR of " throw new IllegalArgumentException("timeShiftSelectedTR of "
+ secondsToShift + " not an interval of " + secondsToShift + " not an interval of "
+ this.gridInfo.getTimeConstraints().getRepeatInterval() + this.gridInfo.getTimeConstraints().getRepeatInterval()
@ -2443,15 +2445,15 @@ public abstract class Parm implements Comparable<Parm> {
} }
// Make sure the given timeRange is valid and there is something to do // Make sure the given timeRange is valid and there is something to do
if (!tr.isValid() || secondsToShift == 0) { if (!tr.isValid() || (secondsToShift == 0)) {
return false; return false;
} }
// calculate source and destination timeRanges // calculate source and destination timeRanges
TimeRange sourceTR = new TimeRange(tr.getStart(), tr.getEnd()); TimeRange sourceTR = new TimeRange(tr.getStart(), tr.getEnd());
TimeRange destinationTR = new TimeRange(tr.getStart().getTime() TimeRange destinationTR = new TimeRange(tr.getStart().getTime()
+ secondsToShift * 1000, tr.getEnd().getTime() + secondsToShift + (secondsToShift * 1000), tr.getEnd().getTime()
* 1000); + (secondsToShift * 1000));
// Create a combinedTR that includes the all blocks it touches // Create a combinedTR that includes the all blocks it touches
TimeRange combinedTR = destinationTR; TimeRange combinedTR = destinationTR;
@ -2502,27 +2504,28 @@ public abstract class Parm implements Comparable<Parm> {
for (int i = 0; i < destGrids.length; i++) { for (int i = 0; i < destGrids.length; i++) {
TimeRange tr2 = destGrids[i].getGridTime(); TimeRange tr2 = destGrids[i].getGridTime();
tr2 = new TimeRange(tr2.getStart().getTime() + secondsToShift tr2 = new TimeRange(tr2.getStart().getTime()
* 1000, tr2.getEnd().getTime() + secondsToShift * 1000); + (secondsToShift * 1000), tr2.getEnd().getTime()
+ (secondsToShift * 1000));
destGrids[i].changeValidTime(tr2, true); destGrids[i].changeValidTime(tr2, true);
destGrids[i].updateHistoryToModified(this.dataManager.getWsId()); destGrids[i].updateHistoryToModified(this.dataManager.getWsId());
} }
// Trim the start of the first copied grid, if necessary // Trim the start of the first copied grid, if necessary
if (destGrids[0].getGridTime().getStart().getTime() < sourceTR if (destGrids[0].getGridTime().getStart().getTime() < (sourceTR
.getStart().getTime() + secondsToShift * 1000) { .getStart().getTime() + (secondsToShift * 1000))) {
TimeRange newTR = new TimeRange(sourceTR.getStart().getTime() TimeRange newTR = new TimeRange(sourceTR.getStart().getTime()
+ secondsToShift * 1000, destGrids[0].getGridTime() + (secondsToShift * 1000), destGrids[0].getGridTime()
.getEnd().getTime()); .getEnd().getTime());
destGrids[0].changeValidTime(newTR, true); destGrids[0].changeValidTime(newTR, true);
} }
// Trim the end of the last copied grid, if necessary // Trim the end of the last copied grid, if necessary
if (destGrids[destGrids.length - 1].getGridTime().getEnd().getTime() > sourceTR if (destGrids[destGrids.length - 1].getGridTime().getEnd().getTime() > (sourceTR
.getEnd().getTime() + secondsToShift * 1000) { .getEnd().getTime() + (secondsToShift * 1000))) {
TimeRange newTR = new TimeRange(destGrids[destGrids.length - 1] TimeRange newTR = new TimeRange(destGrids[destGrids.length - 1]
.getGridTime().getStart().getTime(), sourceTR.getEnd() .getGridTime().getStart().getTime(), sourceTR.getEnd()
.getTime() + secondsToShift * 1000); .getTime() + (secondsToShift * 1000));
destGrids[destGrids.length - 1].changeValidTime(newTR, true); destGrids[destGrids.length - 1].changeValidTime(newTR, true);
} }
@ -2730,9 +2733,9 @@ public abstract class Parm implements Comparable<Parm> {
IGridData leftGrid = overlappingGrid(timeRange.getStart()); IGridData leftGrid = overlappingGrid(timeRange.getStart());
IGridData rightGrid = overlappingGrid(new Date(timeRange.getEnd() IGridData rightGrid = overlappingGrid(new Date(timeRange.getEnd()
.getTime() - 1000)); .getTime() - 1000));
if ((leftGrid == null || leftGrid.getGridTime().getStart() if (((leftGrid == null) || leftGrid.getGridTime().getStart()
.equals(timeRange.getStart())) .equals(timeRange.getStart()))
&& (rightGrid == null || rightGrid.getGridTime().getEnd() && ((rightGrid == null) || rightGrid.getGridTime().getEnd()
.equals(timeRange.getEnd()))) { .equals(timeRange.getEnd()))) {
return false; // nothing to split return false; // nothing to split
} }
@ -3180,8 +3183,8 @@ public abstract class Parm implements Comparable<Parm> {
ParmState.CombineMode cCombineMode = this.parmState.getCombineMode(); ParmState.CombineMode cCombineMode = this.parmState.getCombineMode();
if (this.gridInfo.getGridType() == GFERecord.GridType.VECTOR) { if (this.gridInfo.getGridType() == GFERecord.GridType.VECTOR) {
this.parmState.setVectorMode(ParmState.VectorMode.BOTH); this.parmState.setVectorMode(ParmState.VectorMode.BOTH);
} else if (this.gridInfo.getGridType() == GFERecord.GridType.WEATHER } else if ((this.gridInfo.getGridType() == GFERecord.GridType.WEATHER)
|| this.gridInfo.getGridType() == GFERecord.GridType.DISCRETE) { || (this.gridInfo.getGridType() == GFERecord.GridType.DISCRETE)) {
this.parmState.setCombineMode(ParmState.CombineMode.REPLACE); this.parmState.setCombineMode(ParmState.CombineMode.REPLACE);
} }
@ -3198,8 +3201,8 @@ public abstract class Parm implements Comparable<Parm> {
// restore the edit modes // restore the edit modes
if (this.gridInfo.getGridType() == GFERecord.GridType.VECTOR) { if (this.gridInfo.getGridType() == GFERecord.GridType.VECTOR) {
this.parmState.setVectorMode(cVectorMode); this.parmState.setVectorMode(cVectorMode);
} else if (this.gridInfo.getGridType() == GFERecord.GridType.WEATHER } else if ((this.gridInfo.getGridType() == GFERecord.GridType.WEATHER)
|| this.gridInfo.getGridType() == GFERecord.GridType.DISCRETE) { || (this.gridInfo.getGridType() == GFERecord.GridType.DISCRETE)) {
this.parmState.setCombineMode(cCombineMode); this.parmState.setCombineMode(cCombineMode);
} }
@ -3367,13 +3370,13 @@ public abstract class Parm implements Comparable<Parm> {
if (interval < tc.getRepeatInterval()) { if (interval < tc.getRepeatInterval()) {
interval = tc.getRepeatInterval(); interval = tc.getRepeatInterval();
} }
if (interval % tc.getRepeatInterval() != 0) { if ((interval % tc.getRepeatInterval()) != 0) {
interval = (interval / tc.getRepeatInterval() + 1) interval = ((interval / tc.getRepeatInterval()) + 1)
* tc.getRepeatInterval(); * tc.getRepeatInterval();
} }
} }
if (interval == 0 || duration == 0) { if ((interval == 0) || (duration == 0)) {
gridTimes.add(tr); gridTimes.add(tr);
} }
@ -3415,8 +3418,8 @@ public abstract class Parm implements Comparable<Parm> {
*/ */
public Parm min(TimeRange timeRange) { public Parm min(TimeRange timeRange) {
// Can't take the minimum of a weather or discrete type // Can't take the minimum of a weather or discrete type
if (this.gridInfo.getGridType() == GridType.WEATHER if ((this.gridInfo.getGridType() == GridType.WEATHER)
|| this.gridInfo.getGridType() == GridType.DISCRETE) { || (this.gridInfo.getGridType() == GridType.DISCRETE)) {
return null; return null;
} }
@ -3478,8 +3481,8 @@ public abstract class Parm implements Comparable<Parm> {
*/ */
public Parm max(TimeRange timeRange) { public Parm max(TimeRange timeRange) {
// Can't take the minimum of a weather or discrete type // Can't take the minimum of a weather or discrete type
if (this.gridInfo.getGridType() == GridType.WEATHER if ((this.gridInfo.getGridType() == GridType.WEATHER)
|| this.gridInfo.getGridType() == GridType.DISCRETE) { || (this.gridInfo.getGridType() == GridType.DISCRETE)) {
return null; return null;
} }
@ -3541,8 +3544,8 @@ public abstract class Parm implements Comparable<Parm> {
*/ */
public Parm sum(TimeRange timeRange) { public Parm sum(TimeRange timeRange) {
// Can't take the minimum of a weather or discrete type // Can't take the minimum of a weather or discrete type
if (this.gridInfo.getGridType() == GridType.WEATHER if ((this.gridInfo.getGridType() == GridType.WEATHER)
|| this.gridInfo.getGridType() == GridType.DISCRETE) { || (this.gridInfo.getGridType() == GridType.DISCRETE)) {
return null; return null;
} }
@ -3769,7 +3772,7 @@ public abstract class Parm implements Comparable<Parm> {
for (k = 0; k < gridCount; k++) { for (k = 0; k < gridCount; k++) {
DiscreteKey[] key1 = ((DiscreteGridSlice) grids[k] DiscreteKey[] key1 = ((DiscreteGridSlice) grids[k]
.getGridSlice()).getKey(); .getGridSlice()).getKeys();
Grid2DByte grid1 = ((DiscreteGridSlice) grids[k] Grid2DByte grid1 = ((DiscreteGridSlice) grids[k]
.getGridSlice()).getDiscreteGrid(); .getGridSlice()).getDiscreteGrid();
DiscreteKey dkv = key1[grid1.get(i, j)]; DiscreteKey dkv = key1[grid1.get(i, j)];
@ -3919,16 +3922,16 @@ public abstract class Parm implements Comparable<Parm> {
// left // left
{ {
end = mid - 1; end = mid - 1;
mid = (end - begin) / 2 + begin; mid = ((end - begin) / 2) + begin;
} else // on the right } else // on the right
{ {
begin = mid + 1; begin = mid + 1;
mid = (end - begin) / 2 + begin; mid = ((end - begin) / 2) + begin;
} }
} }
// Did we find it? Last chance... // Did we find it? Last chance...
if (mid >= 0 && mid < this.grids.size() if ((mid >= 0) && (mid < this.grids.size())
&& this.grids.get(mid).getGridTime().contains(time)) { && this.grids.get(mid).getGridTime().contains(time)) {
return this.grids.get(mid); return this.grids.get(mid);
} }
@ -4042,7 +4045,7 @@ public abstract class Parm implements Comparable<Parm> {
} }
// set duration to interval if needed // set duration to interval if needed
if (interval != 0 && duration == 0) { if ((interval != 0) && (duration == 0)) {
duration = interval; duration = interval;
} }
@ -4120,7 +4123,7 @@ public abstract class Parm implements Comparable<Parm> {
// eliminate all of the earlier and the later grids from // eliminate all of the earlier and the later grids from
// basegrids // basegrids
if (endIndex != -1 && endIndex < baseGrids.size() - 1) { if ((endIndex != -1) && (endIndex < (baseGrids.size() - 1))) {
baseGrids.subList(endIndex + 1, baseGrids.size()).clear(); baseGrids.subList(endIndex + 1, baseGrids.size()).clear();
} }
if (startIndex >= 1) { if (startIndex >= 1) {
@ -4160,7 +4163,7 @@ public abstract class Parm implements Comparable<Parm> {
break; break;
} }
} }
st.setTime(st.getTime() + interval * 1000); st.setTime(st.getTime() + (interval * 1000));
} }
// now split grids if necessary due to interference with base grids // now split grids if necessary due to interference with base grids
@ -4173,12 +4176,12 @@ public abstract class Parm implements Comparable<Parm> {
if (bgTime.contains(t)) { if (bgTime.contains(t)) {
break; // can't salvage this one break; // can't salvage this one
} }
if (bgTime.getStart().compareTo(t.getStart()) <= 0 if ((bgTime.getStart().compareTo(t.getStart()) <= 0)
&& bgTime.getEnd().compareTo(t.getEnd()) < 0) { && (bgTime.getEnd().compareTo(t.getEnd()) < 0)) {
newDSTR.add(new TimeRange(bgTime.getEnd(), t.getEnd())); newDSTR.add(new TimeRange(bgTime.getEnd(), t.getEnd()));
overlaps = true; overlaps = true;
} else if (bgTime.getStart().compareTo(t.getStart()) > 0 } else if ((bgTime.getStart().compareTo(t.getStart()) > 0)
&& bgTime.getEnd().compareTo(t.getEnd()) >= 0) { && (bgTime.getEnd().compareTo(t.getEnd()) >= 0)) {
newDSTR.add(new TimeRange(t.getStart(), bgTime newDSTR.add(new TimeRange(t.getStart(), bgTime
.getStart())); .getStart()));
overlaps = true; overlaps = true;
@ -4227,13 +4230,13 @@ public abstract class Parm implements Comparable<Parm> {
interptimes.add(bs.getValidTime()); interptimes.add(bs.getValidTime());
// if a gap's time range fits in here, append to arrays. // if a gap's time range fits in here, append to arrays.
if (i < baseGrids.size() - 1) { if (i < (baseGrids.size() - 1)) {
IGridSlice nbs = baseGrids.get(i + 1).getGridSlice(); IGridSlice nbs = baseGrids.get(i + 1).getGridSlice();
for (j = 0; j < newDSTR.size(); j++) { for (j = 0; j < newDSTR.size(); j++) {
TimeRange ntr = newDSTR.get(j); TimeRange ntr = newDSTR.get(j);
if (ntr.getStart().compareTo(bs.getValidTime().getEnd()) >= 0 if ((ntr.getStart().compareTo(bs.getValidTime().getEnd()) >= 0)
&& ntr.getEnd().compareTo( && (ntr.getEnd().compareTo(
nbs.getValidTime().getStart()) <= 0) { nbs.getValidTime().getStart()) <= 0)) {
// make an empty NONE type GridSlice for the // make an empty NONE type GridSlice for the
// ones to // ones to
// be interpolated, and append the time for it. // be interpolated, and append the time for it.
@ -4469,11 +4472,11 @@ public abstract class Parm implements Comparable<Parm> {
int idx2 = strings.indexOf(parm2); int idx2 = strings.indexOf(parm2);
// parms in strings come before those that aren't // parms in strings come before those that aren't
if (idx1 != -1 && idx2 == -1) { if ((idx1 != -1) && (idx2 == -1)) {
cmp = -1; cmp = -1;
} else if (idx1 == -1 && idx2 != -1) { } else if ((idx1 == -1) && (idx2 != -1)) {
cmp = 1; cmp = 1;
} else if (idx1 != -1 && idx2 != -1 && idx1 != idx2) { } else if ((idx1 != -1) && (idx2 != -1) && (idx1 != idx2)) {
// both are in strings at different indices. // both are in strings at different indices.
// compare their position in strings. // compare their position in strings.
if (idx1 > idx2) { if (idx1 > idx2) {

View file

@ -49,6 +49,7 @@ import com.raytheon.viz.gfe.core.griddata.WeatherGridData;
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Jan 12, 2012 dgilling Initial creation * Jan 12, 2012 dgilling Initial creation
* Oct 29, 2013 2476 njensen Renamed numeric methods to numpy * Oct 29, 2013 2476 njensen Renamed numeric methods to numpy
* Oct 31, 2013 #2508 randerso Change to use DiscreteGridSlice.getKeys()
* *
* </pre> * </pre>
* *
@ -96,7 +97,7 @@ public class CalcVcModGridArg implements IVcModuleArgument {
tempNames.addAll(encodeGridAndMask(gd, mask, i, sb, instance)); tempNames.addAll(encodeGridAndMask(gd, mask, i, sb, instance));
sb.append(')'); sb.append(')');
if (i < argTuples.size() - 1) { if (i < (argTuples.size() - 1)) {
sb.append(','); sb.append(',');
} }
} }
@ -165,7 +166,7 @@ public class CalcVcModGridArg implements IVcModuleArgument {
jepString.append('('); jepString.append('(');
jepString.append(name); jepString.append(name);
jepString.append(','); jepString.append(',');
DiscreteKey[] keys = grid.getDiscreteSlice().getKey(); DiscreteKey[] keys = grid.getDiscreteSlice().getKeys();
ArrayList<String> stringKeys = new ArrayList<String>(keys.length); ArrayList<String> stringKeys = new ArrayList<String>(keys.length);
for (DiscreteKey k : keys) { for (DiscreteKey k : keys) {
stringKeys.add(k.toString()); stringKeys.add(k.toString());

View file

@ -124,6 +124,7 @@ import com.raytheon.viz.gfe.Activator;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Jun 2, 2008 #1161 randerso Initial creation * Jun 2, 2008 #1161 randerso Initial creation
* Oct 31, 2013 #2508 randerso Change to use DiscreteGridSlice.getKeys()
* *
* </pre> * </pre>
* *
@ -380,7 +381,7 @@ public class DiscreteInterp extends Interp {
findWxTypeGroups(joint, single); findWxTypeGroups(joint, single);
// do joint interpolation if needed. // do joint interpolation if needed.
if (joint.size() > 0 && joint.get(0) != 0 && joint.get(1) != 0) { if ((joint.size() > 0) && (joint.get(0) != 0) && (joint.get(1) != 0)) {
jointInterpControl(joint, workGrid1, workGrid2, groupGrid1, jointInterpControl(joint, workGrid1, workGrid2, groupGrid1,
groupGrid2, newGrid, fraction, interpResult); groupGrid2, newGrid, fraction, interpResult);
} }
@ -441,8 +442,8 @@ public class DiscreteInterp extends Interp {
Grid2DByte grid2 = baseData2.getDiscreteGrid(); Grid2DByte grid2 = baseData2.getDiscreteGrid();
// extract the lists of weatherKeys associated with each index grid // extract the lists of weatherKeys associated with each index grid
DiscreteKey[] keys1 = baseData1.getKey(); DiscreteKey[] keys1 = baseData1.getKeys();
DiscreteKey[] keys2 = baseData2.getKey(); DiscreteKey[] keys2 = baseData2.getKeys();
// Make a list of DiscreteKeys that spans both keys1 and keys2. // Make a list of DiscreteKeys that spans both keys1 and keys2.
@ -711,18 +712,18 @@ public class DiscreteInterp extends Interp {
if (x < 0) { if (x < 0) {
x = 0; x = 0;
} }
if (x > _xDim - 1) { if (x > (_xDim - 1)) {
x = _xDim - 1; x = _xDim - 1;
} }
if (y < 0) { if (y < 0) {
y = 0; y = 0;
} }
if (y > _yDim - 1) { if (y > (_yDim - 1)) {
y = _yDim - 1; y = _yDim - 1;
} }
// if the point has a different and non-zero value // if the point has a different and non-zero value
if (grid.get(x, y) != 0 && grid.get(x, y) != wxValue) { if ((grid.get(x, y) != 0) && (grid.get(x, y) != wxValue)) {
// have found a contiguous point of differing value // have found a contiguous point of differing value
// set flag for contiguous point // set flag for contiguous point
@ -848,8 +849,8 @@ public class DiscreteInterp extends Interp {
for (j = 1; j < _wxTypeInfoMatrix.getYDim(); j++) { for (j = 1; j < _wxTypeInfoMatrix.getYDim(); j++) {
// if types match, and // if types match, and
// if it contiguous to other types // if it contiguous to other types
if (_wxTypeList1.get(i).wxType == _wxTypeInfoMatrix.get(0, if ((_wxTypeList1.get(i).wxType == _wxTypeInfoMatrix.get(0,
j) && _wxTypeList1.get(i).isContig) { j)) && _wxTypeList1.get(i).isContig) {
// now there is a list of the types this one // now there is a list of the types this one
// is contiguous to, but they may not be in // is contiguous to, but they may not be in
// same order as first column in matrix. // same order as first column in matrix.
@ -858,10 +859,10 @@ public class DiscreteInterp extends Interp {
// when find it, flag in matrix, but only in // when find it, flag in matrix, but only in
// upper left half: where j>m // upper left half: where j>m
for (m = 1; m < _wxTypeInfoMatrix.getXDim(); m++) { for (m = 1; m < _wxTypeInfoMatrix.getXDim(); m++) {
if (j > m if ((j > m)
&& _wxTypeInfoMatrix.get(m, 0) == _wxTypeList1 && (_wxTypeInfoMatrix.get(m, 0) == _wxTypeList1
.get(i).contigWxType.get(k) .get(i).contigWxType.get(k)
.intValue()) { .intValue())) {
_wxTypeInfoMatrix.set(m, j, 1); // done! _wxTypeInfoMatrix.set(m, j, 1); // done!
} }
} }
@ -876,14 +877,14 @@ public class DiscreteInterp extends Interp {
for (i = 0; i < _wxTypeList2.size(); i++) { for (i = 0; i < _wxTypeList2.size(); i++) {
if (_wxTypeList2.get(i).wxType != 0) { if (_wxTypeList2.get(i).wxType != 0) {
for (m = 1; m < _wxTypeInfoMatrix.getXDim(); m++) { for (m = 1; m < _wxTypeInfoMatrix.getXDim(); m++) {
if (_wxTypeList2.get(i).wxType == _wxTypeInfoMatrix.get(m, if ((_wxTypeList2.get(i).wxType == _wxTypeInfoMatrix.get(m,
0) && _wxTypeList2.get(i).isContig) { 0)) && _wxTypeList2.get(i).isContig) {
for (k = 0; k < _wxTypeList2.get(i).contigWxType.size(); k++) { for (k = 0; k < _wxTypeList2.get(i).contigWxType.size(); k++) {
for (j = 1; j < _wxTypeInfoMatrix.getXDim(); j++) { for (j = 1; j < _wxTypeInfoMatrix.getXDim(); j++) {
if (m > j if ((m > j)
&& _wxTypeInfoMatrix.get(0, j) == _wxTypeList2 && (_wxTypeInfoMatrix.get(0, j) == _wxTypeList2
.get(i).contigWxType.get(k) .get(i).contigWxType.get(k)
.intValue()) { .intValue())) {
_wxTypeInfoMatrix.set(m, j, 1); // done! _wxTypeInfoMatrix.set(m, j, 1); // done!
} }
} }
@ -945,9 +946,10 @@ public class DiscreteInterp extends Interp {
// loop over left col // loop over left col
for (n = 1; n < _wxTypeInfoMatrix.getYDim(); n++) { for (n = 1; n < _wxTypeInfoMatrix.getYDim(); n++) {
if (n != m // not on diagonal if ((n != m // not on diagonal
&& _wxTypeInfoMatrix.get(m, n) == 1 )
&& _wxTypeInfoMatrix.get(n, m) == 1) { && (_wxTypeInfoMatrix.get(m, n) == 1)
&& (_wxTypeInfoMatrix.get(n, m) == 1)) {
jointInterp = true; jointInterp = true;
// add _wxTypeInfoMatrix(m,0) to joint if not already // add _wxTypeInfoMatrix(m,0) to joint if not already
@ -1080,7 +1082,7 @@ public class DiscreteInterp extends Interp {
for (i = 0; i < joint.size(); i++) { for (i = 0; i < joint.size(); i++) {
if (size[i] != 0) { if (size[i] != 0) {
for (j = i + 1; j < joint.size(); j++) { for (j = i + 1; j < joint.size(); j++) {
if (size[j] > size[i] && size[j] > 0) { if ((size[j] > size[i]) && (size[j] > 0)) {
tempwx = joint.get(i); tempwx = joint.get(i);
tempsize = size[i]; tempsize = size[i];
joint.set(i, joint.get(j)); joint.set(i, joint.get(j));
@ -1178,11 +1180,11 @@ public class DiscreteInterp extends Interp {
// kind of weather wxValue were found in that grid. Reset the // kind of weather wxValue were found in that grid. Reset the
// 0,0 to the other center x,y so the area does not move to the // 0,0 to the other center x,y so the area does not move to the
// corner. It will grow or shrink in the same place. // corner. It will grow or shrink in the same place.
if (center1.x == 0 && center1.y == 0) { if ((center1.x == 0) && (center1.y == 0)) {
center1.x = center2.x; center1.x = center2.x;
center1.y = center2.y; center1.y = center2.y;
} }
if (center2.x == 0 && center2.y == 0) { if ((center2.x == 0) && (center2.y == 0)) {
center2.x = center1.x; center2.x = center1.x;
center2.y = center1.y; center2.y = center1.y;
} }
@ -1208,26 +1210,26 @@ public class DiscreteInterp extends Interp {
y = j + _dy; y = j + _dy;
// if the translated point is still on visible grid // if the translated point is still on visible grid
if (x >= 0 && x < _xDim && y >= 0 && y < _yDim) { if ((x >= 0) && (x < _xDim) && (y >= 0) && (y < _yDim)) {
// if this point is part of BOTH the original area, // if this point is part of BOTH the original area,
// and part of the final area when translated, // and part of the final area when translated,
// it is a point in the "core area." // it is a point in the "core area."
if (_featureStart.get(i, j) == wxValue if ((_featureStart.get(i, j) == wxValue)
&& _featureEnd.get(x, y) == wxValue) { && (_featureEnd.get(x, y) == wxValue)) {
_coreArea.set(i, j, 1); _coreArea.set(i, j, 1);
} }
// if it appears in original grid but not in final grid, // if it appears in original grid but not in final grid,
// it will "fade away", so note in _fadeArea. // it will "fade away", so note in _fadeArea.
if (_featureStart.get(i, j) == wxValue if ((_featureStart.get(i, j) == wxValue)
&& _featureEnd.get(x, y) != wxValue) { && (_featureEnd.get(x, y) != wxValue)) {
_fadeArea.set(i + _xDim / 2, j + _yDim / 2, 1); _fadeArea.set(i + (_xDim / 2), j + (_yDim / 2), 1);
// compute distance "dist" from center of // compute distance "dist" from center of
// weather area to this _fadeArea point // weather area to this _fadeArea point
dist = (float) Math.sqrt((i - center1.x) dist = (float) Math
* (i - center1.x) + (j - center1.y) .sqrt(((i - center1.x) * (i - center1.x))
* (j - center1.y)); + ((j - center1.y) * (j - center1.y)));
// compute which angle sector this point lies in // compute which angle sector this point lies in
deltax = i - center1.x; deltax = i - center1.x;
@ -1240,8 +1242,8 @@ public class DiscreteInterp extends Interp {
_faControl.set(sector, 1, dist); _faControl.set(sector, 1, dist);
} }
// set min distance to edge of _fadeArea in this sector // set min distance to edge of _fadeArea in this sector
if (dist < _faControl.get(sector, 0) if ((dist < _faControl.get(sector, 0))
|| _faControl.get(sector, 0) == 0.0f) { || (_faControl.get(sector, 0) == 0.0f)) {
_faControl.set(sector, 0, dist); _faControl.set(sector, 0, dist);
} }
} }
@ -1250,11 +1252,12 @@ public class DiscreteInterp extends Interp {
// for original grid points which land // for original grid points which land
// outside data grid when projected: // outside data grid when projected:
// keep 'em as _fadeArea points. // keep 'em as _fadeArea points.
if (_featureStart.get(i, j) == wxValue if ((_featureStart.get(i, j) == wxValue)
&& (x < 0 || x >= _xDim || y < 0 || y >= _yDim)) { && ((x < 0) || (x >= _xDim) || (y < 0) || (y >= _yDim))) {
_fadeArea.set(i + _xDim / 2, j + _yDim / 2, 1); _fadeArea.set(i + (_xDim / 2), j + (_yDim / 2), 1);
dist = (float) Math.sqrt((i - center1.x) * (i - center1.x) dist = (float) Math
+ (j - center1.y) * (j - center1.y)); .sqrt(((i - center1.x) * (i - center1.x))
+ ((j - center1.y) * (j - center1.y)));
// compute which angle sector this point lies in // compute which angle sector this point lies in
deltax = i - center1.x; deltax = i - center1.x;
@ -1267,8 +1270,8 @@ public class DiscreteInterp extends Interp {
_faControl.set(sector, 1, dist); _faControl.set(sector, 1, dist);
} }
// set min distance to edge of _fadeArea in this sector // set min distance to edge of _fadeArea in this sector
if (dist < _faControl.get(sector, 0) if ((dist < _faControl.get(sector, 0))
|| _faControl.get(sector, 0) == 0.0f) { || (_faControl.get(sector, 0) == 0.0f)) {
_faControl.set(sector, 0, dist); _faControl.set(sector, 0, dist);
} }
} }
@ -1306,16 +1309,17 @@ public class DiscreteInterp extends Interp {
mainy = y - _dy; mainy = y - _dy;
// indices in the _growArea grid: // indices in the _growArea grid:
m = mainx + _xDim / 2; m = mainx + (_xDim / 2);
n = mainy + _yDim / 2; n = mainy + (_yDim / 2);
// (make sure (n,m) inside the _growArea grid) // (make sure (n,m) inside the _growArea grid)
if (m >= 0 && m < 2 * _xDim && n >= 0 && n < 2 * _yDim) { if ((m >= 0) && (m < (2 * _xDim)) && (n >= 0)
&& (n < (2 * _yDim))) {
_growArea.set(m, n, 1); _growArea.set(m, n, 1);
// compute distance "dist" from center of // compute distance "dist" from center of
// weather area to this _growArea point // weather area to this _growArea point
arg = (mainx - center1.x) * (mainx - center1.x) arg = ((mainx - center1.x) * (mainx - center1.x))
+ (mainy - center1.y) * (mainy - center1.y); + ((mainy - center1.y) * (mainy - center1.y));
dist = (float) Math.sqrt(arg); dist = (float) Math.sqrt(arg);
// compute which angle sector this point lies in // compute which angle sector this point lies in
@ -1330,8 +1334,8 @@ public class DiscreteInterp extends Interp {
} }
// set min distance to edge of _growArea in this sector // set min distance to edge of _growArea in this sector
if (dist < _gaControl.get(sector, 0) if ((dist < _gaControl.get(sector, 0))
|| _gaControl.get(sector, 0) == 0.0f) { || (_gaControl.get(sector, 0) == 0.0f)) {
_gaControl.set(sector, 0, dist); _gaControl.set(sector, 0, dist);
} }
} }
@ -1373,14 +1377,14 @@ public class DiscreteInterp extends Interp {
// (A) number of radians per sector = 2 * pi /(how many sectors in // (A) number of radians per sector = 2 * pi /(how many sectors in
// circle) // circle)
double step = 2.0 * Math.PI / _numSectors; double step = (2.0 * Math.PI) / _numSectors;
// compartimentalize into sectors: // compartimentalize into sectors:
sector = (int) (0.5 + (angle + Math.PI) / step) - 1; sector = (int) (0.5 + ((angle + Math.PI) / step)) - 1;
// (A) // (A)
// bad value clamp (should not occur) // bad value clamp (should not occur)
if (sector < 0 || sector >= _numSectors) { if ((sector < 0) || (sector >= _numSectors)) {
sector = 0; sector = 0;
} }
@ -1418,8 +1422,8 @@ public class DiscreteInterp extends Interp {
Point center = new Point(); Point center = new Point();
if (num != 0) { if (num != 0) {
center.x = (int) (0.5 + sumX / num); center.x = (int) (0.5 + (sumX / num));
center.y = (int) (0.5 + sumY / num); center.y = (int) (0.5 + (sumY / num));
} else { } else {
center.x = 0; center.x = 0;
center.y = 0; center.y = 0;
@ -1505,18 +1509,18 @@ public class DiscreteInterp extends Interp {
// Add in points from grow and fade Areas where appropriate. // Add in points from grow and fade Areas where appropriate.
// loop over coordinates for _growArea and _fadeArea grids // loop over coordinates for _growArea and _fadeArea grids
for (int i = 0; i < 2 * _xDim; i++) { for (int i = 0; i < (2 * _xDim); i++) {
for (int j = 0; j < 2 * _yDim; j++) { for (int j = 0; j < (2 * _yDim); j++) {
// "i,j" positions for grow or fade area // "i,j" positions for grow or fade area
// as if on on main grid coordinates (there may not actually // as if on on main grid coordinates (there may not actually
// be any main grid points with these indexes). // be any main grid points with these indexes).
mainx = i - _xDim / 2; mainx = i - (_xDim / 2);
mainy = j - _yDim / 2; mainy = j - (_yDim / 2);
// distance from center of initial area to this g or f area // distance from center of initial area to this g or f area
// point. // point.
dist = Math.sqrt((mainx - center1.x) * (mainx - center1.x) dist = Math.sqrt(((mainx - center1.x) * (mainx - center1.x))
+ (mainy - center1.y) * (mainy - center1.y)); + ((mainy - center1.y) * (mainy - center1.y)));
// translated position for this step: // translated position for this step:
// (coordinates in _growArea and _fadeArea grid system) // (coordinates in _growArea and _fadeArea grid system)
@ -1524,8 +1528,8 @@ public class DiscreteInterp extends Interp {
int jj = j + (int) ((_dy * zeta) + 0.5); int jj = j + (int) ((_dy * zeta) + 0.5);
// translated position on main grid // translated position on main grid
tmainy = jj - _yDim / 2; tmainy = jj - (_yDim / 2);
tmainx = ii - _xDim / 2; tmainx = ii - (_xDim / 2);
// get angle sector for this point // get angle sector for this point
sector = findAngleSector(mainx - center1.x, mainy - center1.y); sector = findAngleSector(mainx - center1.x, mainy - center1.y);
@ -1568,8 +1572,9 @@ public class DiscreteInterp extends Interp {
// from center of moving area, addthis point to the weather // from center of moving area, addthis point to the weather
// area. // area.
// (also make sure it's on the main grid!) // (also make sure it's on the main grid!)
if (dist < testGAdist && tmainy >= 0 && tmainx < _xDim if ((dist < testGAdist) && (tmainy >= 0)
&& tmainx >= 0 && tmainy < _yDim) { && (tmainx < _xDim) && (tmainx >= 0)
&& (tmainy < _yDim)) {
newGrid.set(tmainx, tmainy, wxValue); newGrid.set(tmainx, tmainy, wxValue);
} }
@ -1609,8 +1614,9 @@ public class DiscreteInterp extends Interp {
// only keep a _fadeArea point inside the // only keep a _fadeArea point inside the
// limiting distance // limiting distance
// (also make sure it's on the main grid!) // (also make sure it's on the main grid!)
if (dist < testFAdist && tmainy >= 0 && tmainy < _yDim if ((dist < testFAdist) && (tmainy >= 0)
&& tmainx >= 0 && tmainx < _xDim) { && (tmainy < _yDim) && (tmainx >= 0)
&& (tmainx < _xDim)) {
newGrid.set(tmainx, tmainy, wxValue); newGrid.set(tmainx, tmainy, wxValue);
} }
} }

View file

@ -164,6 +164,7 @@ import com.vividsolutions.jts.geom.Envelope;
* Mar 04, 2013 1637 randerso Fix time matching for ISC grids * Mar 04, 2013 1637 randerso Fix time matching for ISC grids
* Aug 27, 2013 2287 randerso Fixed scaling and direction of wind arrows * Aug 27, 2013 2287 randerso Fixed scaling and direction of wind arrows
* Sep 23, 2013 2363 bsteffen Add more vector configuration options. * Sep 23, 2013 2363 bsteffen Add more vector configuration options.
* Oct 31, 2013 2508 randerso Change to use DiscreteGridSlice.getKeys()
* *
* </pre> * </pre>
* *
@ -340,7 +341,7 @@ public class GFEResource extends
* changed, data appeared/disappeared) * changed, data appeared/disappeared)
*/ */
private void resetFrame(TimeRange timeRange) { private void resetFrame(TimeRange timeRange) {
if (curTime != null && timeRange.overlaps(curTime.getValidPeriod())) { if ((curTime != null) && timeRange.overlaps(curTime.getValidPeriod())) {
lastDisplayedTime = null; lastDisplayedTime = null;
issueRefresh(); issueRefresh();
} }
@ -492,7 +493,7 @@ public class GFEResource extends
// hack to get around target.getDefaultFont()-centeredness in // hack to get around target.getDefaultFont()-centeredness in
// contourDisplay. // contourDisplay.
double contourMagnification = magnification * gfeFont.getFontSize() double contourMagnification = (magnification * gfeFont.getFontSize())
/ target.getDefaultFont().getFontSize(); / target.getDefaultFont().getFontSize();
double density = parm.getDisplayAttributes().getDensity(); double density = parm.getDisplayAttributes().getDensity();
@ -509,7 +510,7 @@ public class GFEResource extends
.getValidPeriod()); .getValidPeriod());
boolean iscParm = this.parm.isIscParm(); boolean iscParm = this.parm.isIscParm();
if (gd.length == 0 && !dataManager.getParmManager().iscMode()) { if ((gd.length == 0) && !dataManager.getParmManager().iscMode()) {
return; return;
} }
@ -519,7 +520,7 @@ public class GFEResource extends
if (!this.curTime.equals(this.lastDisplayedTime) if (!this.curTime.equals(this.lastDisplayedTime)
|| !visMode.equals(this.lastVisMode) || !visMode.equals(this.lastVisMode)
|| this.lastIscMode != dataManager.getParmManager().iscMode()) { || (this.lastIscMode != dataManager.getParmManager().iscMode())) {
this.lastDisplayedTime = this.curTime; this.lastDisplayedTime = this.curTime;
this.lastVisMode = visMode; this.lastVisMode = visMode;
@ -537,7 +538,7 @@ public class GFEResource extends
if (gd != null) { if (gd != null) {
IGridSlice gs = null; IGridSlice gs = null;
if (dataManager.getParmManager().iscMode() && gd.length == 0) { if (dataManager.getParmManager().iscMode() && (gd.length == 0)) {
GridParmInfo gpi = this.parm.getGridInfo(); GridParmInfo gpi = this.parm.getGridInfo();
GridType gridType = gpi.getGridType(); GridType gridType = gpi.getGridType();
@ -583,8 +584,8 @@ public class GFEResource extends
gs = gd[0].getGridSlice(); gs = gd[0].getGridSlice();
} }
if (gs instanceof VectorGridSlice if ((gs instanceof VectorGridSlice)
|| gs instanceof ScalarGridSlice) { || (gs instanceof ScalarGridSlice)) {
if (this.gridDisplay != null) { if (this.gridDisplay != null) {
this.gridDisplay.dispose(); this.gridDisplay.dispose();
@ -660,9 +661,8 @@ public class GFEResource extends
mag, dir, descriptor, MapUtil mag, dir, descriptor, MapUtil
.getGridGeometry(gs.getGridInfo() .getGridGeometry(gs.getGridInfo()
.getGridLoc()), .getGridLoc()),
VECTOR_DENSITY_FACTOR, VECTOR_DENSITY_FACTOR, false,
false, visTypeToDisplayType(type), visTypeToDisplayType(type), vectorConfig));
vectorConfig));
break; break;
case WIND_BARB: case WIND_BARB:
@ -753,7 +753,7 @@ public class GFEResource extends
gid, true, slice); gid, true, slice);
} }
for (DiscreteKey discreteKey : slice.getKey()) { for (DiscreteKey discreteKey : slice.getKeys()) {
if (discreteKey.isValid()) { if (discreteKey.isValid()) {
outlineShapes.put(discreteKey, target outlineShapes.put(discreteKey, target
@ -1330,9 +1330,9 @@ public class GFEResource extends
Coordinate gridCoord = MapUtil.latLonToGridCoordinate(coord, Coordinate gridCoord = MapUtil.latLonToGridCoordinate(coord,
PixelOrientation.CENTER, gridLocation); PixelOrientation.CENTER, gridLocation);
if (gridCoord.x < 0 || gridCoord.y < 0 if ((gridCoord.x < 0) || (gridCoord.y < 0)
|| gridCoord.x >= gridLocation.getNx() || (gridCoord.x >= gridLocation.getNx())
|| gridCoord.y >= gridLocation.getNy()) { || (gridCoord.y >= gridLocation.getNy())) {
return; return;
} }
@ -1471,21 +1471,21 @@ public class GFEResource extends
// now see if adjacent grid cells exist containing the // now see if adjacent grid cells exist containing the
// same data. // same data.
if ((xGrid + xLabelGrid > gridDim.x) || (xGrid - 1 < 0)) { if (((xGrid + xLabelGrid) > gridDim.x) || ((xGrid - 1) < 0)) {
continue; continue;
} }
if ((yGrid + yLabelGrid > gridDim.y) || (yGrid - 1 < 0)) { if (((yGrid + yLabelGrid) > gridDim.y) || ((yGrid - 1) < 0)) {
continue; continue;
} }
byte weatherByteVal = byteData.get(xGrid, yGrid); byte weatherByteVal = byteData.get(xGrid, yGrid);
boolean printLabel = true; boolean printLabel = true;
for (int ii = xGrid - 1; ii < xGrid + xLabelGrid; ii++) { for (int ii = xGrid - 1; ii < (xGrid + xLabelGrid); ii++) {
for (int j = yGrid - 1; j < yGrid + yLabelGrid; j++) { for (int j = yGrid - 1; j < (yGrid + yLabelGrid); j++) {
if (!parm.getDisplayAttributes().getDisplayMask() if (!parm.getDisplayAttributes().getDisplayMask()
.getAsBoolean(ii, j) .getAsBoolean(ii, j)
|| byteData.get(ii, j) != weatherByteVal) { || (byteData.get(ii, j) != weatherByteVal)) {
printLabel = false; printLabel = false;
break; break;
} }
@ -1550,9 +1550,9 @@ public class GFEResource extends
for (xpos = gridOffset; xpos < gridDim.x; xpos += gridInterval) { for (xpos = gridOffset; xpos < gridDim.x; xpos += gridInterval) {
yCounter++; yCounter++;
int xCounter = 0; int xCounter = 0;
for (ypos = yCounter % 4 + 1; ypos < gridDim.y - gridOffset; ypos += gridInterval) { for (ypos = (yCounter % 4) + 1; ypos < (gridDim.y - gridOffset); ypos += gridInterval) {
xCounter++; xCounter++;
int xGrid = xpos + (xCounter % 4 * gridOffset); int xGrid = xpos + ((xCounter % 4) * gridOffset);
if (xGrid > gridDim.x) { if (xGrid > gridDim.x) {
break; break;
} }

View file

@ -96,6 +96,7 @@ import com.vividsolutions.jts.geom.Coordinate;
* Jan 23, 2013 #1524 randerso Fix missing discrete color bar and error when clicking * Jan 23, 2013 #1524 randerso Fix missing discrete color bar and error when clicking
* on discrete color bar when no grid exists * on discrete color bar when no grid exists
* Feb 12, 2013 15719 jdynina Fixed out of bounds error in calcGridColorTable * Feb 12, 2013 15719 jdynina Fixed out of bounds error in calcGridColorTable
* Oct 31, 2013 #2508 randerso Change to use DiscreteGridSlice.getKeys()
* *
* </pre> * </pre>
* *
@ -213,7 +214,7 @@ public class DiscreteColorbar implements IColorBarDisplay,
public void paint(IGraphicsTarget target, PaintProperties paintProps) public void paint(IGraphicsTarget target, PaintProperties paintProps)
throws VizException { throws VizException {
DataTime currentTime = paintProps.getFramesInfo().getCurrentFrame(); DataTime currentTime = paintProps.getFramesInfo().getCurrentFrame();
if (parm == null || currentTime == null) { if ((parm == null) || (currentTime == null)) {
return; return;
} }
@ -241,7 +242,7 @@ public class DiscreteColorbar implements IColorBarDisplay,
DiscreteGridSlice slice = new DiscreteGridSlice(); DiscreteGridSlice slice = new DiscreteGridSlice();
parm.getDataManager().getIscDataAccess() parm.getDataManager().getIscDataAccess()
.getCompositeGrid(gid, true, slice); .getCompositeGrid(gid, true, slice);
if (slice.getKey().length == 0) { if (slice.getKeys().length == 0) {
return; return;
} }
iscGridData = new DiscreteGridData(this.parm, slice); iscGridData = new DiscreteGridData(this.parm, slice);
@ -365,7 +366,7 @@ public class DiscreteColorbar implements IColorBarDisplay,
} }
// for DISCRETE // for DISCRETE
else { else {
DiscreteKey[] dKeys = ((DiscreteGridSlice) gs).getKey(); DiscreteKey[] dKeys = ((DiscreteGridSlice) gs).getKeys();
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
if (cArray[i]) { if (cArray[i]) {
gridWValues.add(new DiscreteWxValue(dKeys[i], parm)); gridWValues.add(new DiscreteWxValue(dKeys[i], parm));
@ -485,7 +486,7 @@ public class DiscreteColorbar implements IColorBarDisplay,
double pickupLabelSize = target.getStringsBounds(dstring) double pickupLabelSize = target.getStringsBounds(dstring)
.getWidth(); .getWidth();
double pickupLabelDrawPoint = (minX + (pickupIndex * keywidth) + keywidth / 2) double pickupLabelDrawPoint = (minX + (pickupIndex * keywidth) + (keywidth / 2))
* xScaleFactor; * xScaleFactor;
pickupLabelMinX = pickupLabelDrawPoint - (pickupLabelSize / 2); pickupLabelMinX = pickupLabelDrawPoint - (pickupLabelSize / 2);
pickupLabelMaxX = pickupLabelDrawPoint + (pickupLabelSize / 2); pickupLabelMaxX = pickupLabelDrawPoint + (pickupLabelSize / 2);
@ -535,7 +536,7 @@ public class DiscreteColorbar implements IColorBarDisplay,
maxY, 0.0, seColorBarTickColor, 1.0f); maxY, 0.0, seColorBarTickColor, 1.0f);
String keyName = colorEntry.getValue().toString(); String keyName = colorEntry.getValue().toString();
labelLoc = (float) (minX + ikeywidth) + (float) keywidth / 2; labelLoc = (float) (minX + ikeywidth) + ((float) keywidth / 2);
double boxMinXCoord = (minX + ikeywidth) * xScaleFactor; double boxMinXCoord = (minX + ikeywidth) * xScaleFactor;
double boxMaxXCoord = boxMinXCoord + (keywidth * xScaleFactor); double boxMaxXCoord = boxMinXCoord + (keywidth * xScaleFactor);
@ -591,15 +592,15 @@ public class DiscreteColorbar implements IColorBarDisplay,
int x = 0; int x = 0;
for (ColorEntry colorEntry : colorTable) { for (ColorEntry colorEntry : colorTable) {
// calculate the bounding box from x // calculate the bounding box from x
PixelExtent pe = new PixelExtent(x1 + x * keywidth, x1 + (x + 1) PixelExtent pe = new PixelExtent(x1 + (x * keywidth), x1
* keywidth, y1, y2); + ((x + 1) * keywidth), y1, y2);
Coordinate[] coordinates = new Coordinate[5]; Coordinate[] coordinates = new Coordinate[5];
coordinates[0] = new Coordinate(x1 + x * keywidth, y1); coordinates[0] = new Coordinate(x1 + (x * keywidth), y1);
coordinates[1] = new Coordinate(x1 + (x + 1) * keywidth, y1); coordinates[1] = new Coordinate(x1 + ((x + 1) * keywidth), y1);
coordinates[2] = new Coordinate(x1 + (x + 1) * keywidth, y2); coordinates[2] = new Coordinate(x1 + ((x + 1) * keywidth), y2);
coordinates[3] = new Coordinate(x1 + x * keywidth, y2); coordinates[3] = new Coordinate(x1 + (x * keywidth), y2);
coordinates[4] = new Coordinate(x1 + x * keywidth, y1); coordinates[4] = new Coordinate(x1 + (x * keywidth), y1);
// draw the shaded rectangle with the correct color(s) and // draw the shaded rectangle with the correct color(s) and
// pattern(s) // pattern(s)

View file

@ -52,7 +52,7 @@ import com.raytheon.viz.gfe.types.MutableInteger;
/** /**
* Contains a complete histogram for a single grid and parameter * Contains a complete histogram for a single grid and parameter
* *
* <pre> * <pre>
* SOFTWARE HISTORY * SOFTWARE HISTORY
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
@ -63,9 +63,10 @@ import com.raytheon.viz.gfe.types.MutableInteger;
* May 29, 2009 2159 rjpeter Optimized sample methods. * May 29, 2009 2159 rjpeter Optimized sample methods.
* May 24, 2012 673 randerso Added defaulted method calls * May 24, 2012 673 randerso Added defaulted method calls
* Jun 17, 2013 15951 ryu Fix index to wx/discrete key array * Jun 17, 2013 15951 ryu Fix index to wx/discrete key array
* * Oct 31, 2013 2508 randerso Change to use DiscreteGridSlice.getKeys()
*
* </pre> * </pre>
* *
* @author mnash * @author mnash
* @version 1.0 * @version 1.0
*/ */
@ -176,7 +177,7 @@ public class HistSample {
* Description : Constructor far HistSample taking a histogram in the form * Description : Constructor far HistSample taking a histogram in the form
* of a time range and a sequence of HistPairs, stores the information in * of a time range and a sequence of HistPairs, stores the information in
* private data. Counts up the samples and stores that in _numSamplePoints. * private data. Counts up the samples and stores that in _numSamplePoints.
* *
* @param timeRange * @param timeRange
* @param histPairs * @param histPairs
*/ */
@ -211,7 +212,7 @@ public class HistSample {
* cached. Sets number of sample points to zero. Calls sampleGrid() to * cached. Sets number of sample points to zero. Calls sampleGrid() to
* sample the grid. If successful, stores the time range and counts up the * sample the grid. If successful, stores the time range and counts up the
* number of sample points. * number of sample points.
* *
* @param gridSlice * @param gridSlice
* @param sampleArea * @param sampleArea
* @param cachePoints * @param cachePoints
@ -251,13 +252,13 @@ public class HistSample {
* for WEATHER. The most common value for DISCRETE. For vector, if * for WEATHER. The most common value for DISCRETE. For vector, if
* separateMagDir is true, the magnitude is averaged separately from the * separateMagDir is true, the magnitude is averaged separately from the
* direction. * direction.
* *
* @param separateMagDir * @param separateMagDir
* @return * @return
*/ */
public final HistValue average(boolean separateMagDir) { public final HistValue average(boolean separateMagDir) {
if (separateMagDir == _averageMagDir && _average != null) { if ((separateMagDir == _averageMagDir) && (_average != null)) {
return _average; return _average;
} }
@ -326,7 +327,7 @@ public class HistSample {
* _histPairs.get(i).value().magnitude(); * _histPairs.get(i).value().magnitude();
float v = uSum / count; float v = uSum / count;
float u = vSum / count; float u = vSum / count;
float mag = binit((float) Math.sqrt(u * u + v * v), float mag = binit((float) Math.sqrt((u * u) + (v * v)),
_resolution); _resolution);
float dir = binit((float) (Math.atan2(u, v) * RAD_TO_DEG), float dir = binit((float) (Math.atan2(u, v) * RAD_TO_DEG),
10.0f); 10.0f);
@ -361,7 +362,7 @@ public class HistSample {
/** /**
* Description : the square root function * Description : the square root function
* *
* @param val * @param val
* @return * @return
*/ */
@ -378,7 +379,7 @@ public class HistSample {
* Returns the standard deviation of each component separately for VECTOR. * Returns the standard deviation of each component separately for VECTOR.
* Should not be called for WEATHER. For vector, if separate MagDir is true, * Should not be called for WEATHER. For vector, if separate MagDir is true,
* the magnitude is averaged separately from the direction. * the magnitude is averaged separately from the direction.
* *
* @return * @return
*/ */
public final HistValue stdDev() { public final HistValue stdDev() {
@ -408,7 +409,7 @@ public class HistSample {
float dev = 0.0f; float dev = 0.0f;
if (count != 0) { if (count != 0) {
dev = (float) squareRoot((sum2 - (sum * sum) / count) / count); dev = (float) squareRoot((sum2 - ((sum * sum) / count)) / count);
} }
hs._stdDev = new HistValue(dev); hs._stdDev = new HistValue(dev);
return _stdDev; return _stdDev;
@ -444,10 +445,10 @@ public class HistSample {
float vdev = 0.0f; float vdev = 0.0f;
if (count != 0) { if (count != 0) {
dev = (float) squareRoot((sum2 - (sum * sum) / count) / count); dev = (float) squareRoot((sum2 - ((sum * sum) / count)) / count);
udev = (float) squareRoot((uSum2 - (uSum * uSum) / count) udev = (float) squareRoot((uSum2 - ((uSum * uSum) / count))
/ count); / count);
vdev = (float) squareRoot((vSum2 - (vSum * vSum) / count) vdev = (float) squareRoot((vSum2 - ((vSum * vSum) / count))
/ count); / count);
} }
hs._stdDev = new HistValue(dev, udev + udev); hs._stdDev = new HistValue(dev, udev + udev);
@ -470,7 +471,7 @@ public class HistSample {
* the HistPair's for the maximum count value and returns it. In the case * the HistPair's for the maximum count value and returns it. In the case
* where more than one entry shares the maximum count value, then only the * where more than one entry shares the maximum count value, then only the
* highest value (sort order) value will be returned. * highest value (sort order) value will be returned.
* *
* @return * @return
*/ */
public final HistValue mostCommonValue() { public final HistValue mostCommonValue() {
@ -504,7 +505,7 @@ public class HistSample {
* case where more than one entyr shares the maximum count value, then only * case where more than one entyr shares the maximum count value, then only
* the highest value (sort order) value will be returned. Works only on * the highest value (sort order) value will be returned. Works only on
* SCALAR and VECTOR. * SCALAR and VECTOR.
* *
* @param resolution * @param resolution
* @return * @return
*/ */
@ -515,7 +516,7 @@ public class HistSample {
// cached? // cached?
if ((_binnedMostCommonValue != null) if ((_binnedMostCommonValue != null)
&& resolution == _binnedMostCommonValueFactor) { && (resolution == _binnedMostCommonValueFactor)) {
return _binnedMostCommonValue; return _binnedMostCommonValue;
} }
@ -543,11 +544,11 @@ public class HistSample {
* Finds and returns the middle value associated with the sample. The middle * Finds and returns the middle value associated with the sample. The middle
* value is that value that is halfway between the lowest and highest in * value is that value that is halfway between the lowest and highest in
* terms of count, and not value. This is a no-op for WEATHER/DISCRETE. * terms of count, and not value. This is a no-op for WEATHER/DISCRETE.
* *
* @return * @return
*/ */
public final HistValue middleValue() { public final HistValue middleValue() {
if (_histPairs.size() == 0 if ((_histPairs.size() == 0)
|| _histPairs.get(0).value().dataType() || _histPairs.get(0).value().dataType()
.equals(GridType.WEATHER) .equals(GridType.WEATHER)
|| _histPairs.get(0).value().dataType() || _histPairs.get(0).value().dataType()
@ -564,7 +565,7 @@ public class HistSample {
int runningCount = 0; int runningCount = 0;
for (int i = 0; i < _histPairs.get(i).count(); i++) { for (int i = 0; i < _histPairs.get(i).count(); i++) {
runningCount += _histPairs.get(i).count(); runningCount += _histPairs.get(i).count();
if ((float) runningCount / (float) _numSamplePoints > 0.50) { if (((float) runningCount / (float) _numSamplePoints) > 0.50) {
hs._middleValue = _histPairs.get(i).value(); hs._middleValue = _histPairs.get(i).value();
return _middleValue; return _middleValue;
} }
@ -577,11 +578,11 @@ public class HistSample {
* Description : Returns the absolute minimum value for the sample points. * Description : Returns the absolute minimum value for the sample points.
* This is a no-op for WEATHER/DISCRETE. Only the magnitude component for * This is a no-op for WEATHER/DISCRETE. Only the magnitude component for
* VECTOR is used for comparison. * VECTOR is used for comparison.
* *
* @return * @return
*/ */
public final HistValue absoluteMin() { public final HistValue absoluteMin() {
if (_histPairs.size() == 0 if ((_histPairs.size() == 0)
|| _histPairs.get(0).value().dataType() || _histPairs.get(0).value().dataType()
.equals(GridType.WEATHER) .equals(GridType.WEATHER)
|| _histPairs.get(0).value().dataType() || _histPairs.get(0).value().dataType()
@ -603,11 +604,11 @@ public class HistSample {
* Description : REturns the absolute maximum value for the sample points. * Description : REturns the absolute maximum value for the sample points.
* This is a no-op for WEATHER/DISCRETE. Only the magnitude component for * This is a no-op for WEATHER/DISCRETE. Only the magnitude component for
* VECTOR is used for comparison. * VECTOR is used for comparison.
* *
* @return * @return
*/ */
public final HistValue absoluteMax() { public final HistValue absoluteMax() {
if (_histPairs.size() == 0 if ((_histPairs.size() == 0)
|| _histPairs.get(0).value().dataType() || _histPairs.get(0).value().dataType()
.equals(GridType.WEATHER) .equals(GridType.WEATHER)
|| _histPairs.get(0).value().dataType() || _histPairs.get(0).value().dataType()
@ -643,7 +644,7 @@ public class HistSample {
* most common value is provide for WEATERH. Outliers are eliminated. * most common value is provide for WEATERH. Outliers are eliminated.
* Percent ranges from 0 to 50. For vector, if separateMagDir is true, the * Percent ranges from 0 to 50. For vector, if separateMagDir is true, the
* magnitude is averaged separately from the direction. * magnitude is averaged separately from the direction.
* *
* @param minpercent * @param minpercent
* @param maxpercent * @param maxpercent
* @param separateMagDir * @param separateMagDir
@ -653,17 +654,17 @@ public class HistSample {
boolean separateMagDir) { boolean separateMagDir) {
HistValue bogus = new HistValue(); HistValue bogus = new HistValue();
HistSample hs = this; HistSample hs = this;
if (_histPairs.size() == 0 || minpercent < 0 || minpercent > 50 if ((_histPairs.size() == 0) || (minpercent < 0) || (minpercent > 50)
|| maxpercent < 0 || maxpercent > 50) { || (maxpercent < 0) || (maxpercent > 50)) {
hs._moderatedAverage = new HistValue(); hs._moderatedAverage = new HistValue();
hs._moderatedAverageMinPercent = hs._moderatedAverageMaxPercent = 0; hs._moderatedAverageMinPercent = hs._moderatedAverageMaxPercent = 0;
return _moderatedAverage; return _moderatedAverage;
} }
// cached value // cached value
if (minpercent == _moderatedAverageMinPercent if ((minpercent == _moderatedAverageMinPercent)
&& maxpercent == _moderatedAverageMaxPercent && (maxpercent == _moderatedAverageMaxPercent)
&& _moderatedAverage != null) { && (_moderatedAverage != null)) {
return _moderatedAverage; return _moderatedAverage;
} }
@ -672,8 +673,8 @@ public class HistSample {
hs._moderatedAverageMaxPercent = maxpercent; hs._moderatedAverageMaxPercent = maxpercent;
float runningCount = 0; float runningCount = 0;
int minlimitCount = (int) (minpercent * _numSamplePoints / 100.0); int minlimitCount = (int) ((minpercent * _numSamplePoints) / 100.0);
int maxlimitCount = (int) ((100 - maxpercent) * _numSamplePoints / 100.0); int maxlimitCount = (int) (((100 - maxpercent) * _numSamplePoints) / 100.0);
switch (_histPairs.get(0).value().dataType()) { switch (_histPairs.get(0).value().dataType()) {
case SCALAR: { case SCALAR: {
@ -684,11 +685,11 @@ public class HistSample {
int maxVCount = (int) runningCount + _histPairs.get(i).count(); int maxVCount = (int) runningCount + _histPairs.get(i).count();
int numInclude = 0; int numInclude = 0;
if (minlimitCount > maxVCount || maxlimitCount < minVCount) { if ((minlimitCount > maxVCount) || (maxlimitCount < minVCount)) {
numInclude = 0; numInclude = 0;
} else { } else {
numInclude = Math.max(minlimitCount, minVCount) numInclude = (Math.max(minlimitCount, minVCount) - Math
- Math.min(maxlimitCount, maxVCount) + 1; .min(maxlimitCount, maxVCount)) + 1;
} }
if (numInclude != 0) { if (numInclude != 0) {
@ -714,11 +715,12 @@ public class HistSample {
+ _histPairs.get(i).count(); + _histPairs.get(i).count();
int numInclude = 0; int numInclude = 0;
if (minlimitCount > maxVCount || maxlimitCount < minVCount) { if ((minlimitCount > maxVCount)
|| (maxlimitCount < minVCount)) {
numInclude = 0; numInclude = 0;
} else { } else {
numInclude = Math.max(minlimitCount, minVCount) numInclude = (Math.max(minlimitCount, minVCount) - Math
- Math.min(maxlimitCount, maxVCount) + 1; .min(maxlimitCount, maxVCount)) + 1;
} }
if (numInclude != 0) { if (numInclude != 0) {
int tCount = numInclude; int tCount = numInclude;
@ -757,11 +759,12 @@ public class HistSample {
+ _histPairs.get(i).count(); + _histPairs.get(i).count();
int numInclude = 0; int numInclude = 0;
if (minlimitCount > maxVCount || maxlimitCount < minVCount) { if ((minlimitCount > maxVCount)
|| (maxlimitCount < minVCount)) {
numInclude = 0; numInclude = 0;
} else { } else {
numInclude = Math.max(minlimitCount, minVCount) numInclude = (Math.max(minlimitCount, minVCount) - Math
- Math.min(maxlimitCount, maxVCount) + 1; .min(maxlimitCount, maxVCount)) + 1;
} }
if (numInclude != 0) { if (numInclude != 0) {
@ -782,7 +785,8 @@ public class HistSample {
} }
float u = uSum / count; float u = uSum / count;
float v = vSum / count; float v = vSum / count;
float mag = binit((float) Math.sqrt(u * u + v * v), _resolution); float mag = binit((float) Math.sqrt((u * u) + (v * v)),
_resolution);
float dir = binit((float) (Math.atan2(u, v) * RAD_TO_DEG), float dir = binit((float) (Math.atan2(u, v) * RAD_TO_DEG),
10.0f); 10.0f);
while (dir < 0.0) { while (dir < 0.0) {
@ -821,29 +825,29 @@ public class HistSample {
* points. this is a no-op for WEATHER/DISCRETE. Percent should be between 0 * points. this is a no-op for WEATHER/DISCRETE. Percent should be between 0
* and 50. This routine eliminates the bottom xx% of sample values and * and 50. This routine eliminates the bottom xx% of sample values and
* returns that value. * returns that value.
* *
* @param percent * @param percent
* @return * @return
*/ */
public final HistValue moderatedMin(int percent) { public final HistValue moderatedMin(int percent) {
HistSample hs = this; HistSample hs = this;
if (_histPairs.size() == 0 || percent < 0 || percent > 50 if ((_histPairs.size() == 0) || (percent < 0) || (percent > 50)
|| _histPairs.get(0).value().dataType() == GridType.WEATHER || (_histPairs.get(0).value().dataType() == GridType.WEATHER)
|| _histPairs.get(0).value().dataType() == GridType.DISCRETE) { || (_histPairs.get(0).value().dataType() == GridType.DISCRETE)) {
hs._moderatedMin = new HistValue(); hs._moderatedMin = new HistValue();
hs._moderatedMinPercent = 0; hs._moderatedMinPercent = 0;
return _moderatedMin; // default histValue() return _moderatedMin; // default histValue()
} }
// cached? // cached?
if (_moderatedMinPercent == percent && _moderatedMin != null) { if ((_moderatedMinPercent == percent) && (_moderatedMin != null)) {
return _moderatedMin; return _moderatedMin;
} }
hs._moderatedMinPercent = percent; hs._moderatedMinPercent = percent;
float runningCount = 0; float runningCount = 0;
float limitCount = (float) (percent * _numSamplePoints / 100.0); float limitCount = (float) ((percent * _numSamplePoints) / 100.0);
for (int i = 0; i < _histPairs.size(); i++) { for (int i = 0; i < _histPairs.size(); i++) {
runningCount += _histPairs.get(i).count(); runningCount += _histPairs.get(i).count();
@ -865,15 +869,15 @@ public class HistSample {
* points. This is a no-op for WEATHER/DISCRETE. Percent should be between 0 * points. This is a no-op for WEATHER/DISCRETE. Percent should be between 0
* and 50. This routine eliminates the top 15% of sample values and returns * and 50. This routine eliminates the top 15% of sample values and returns
* that value. * that value.
* *
* @param percent * @param percent
* @return * @return
*/ */
public final HistValue moderatedMax(int percent) { public final HistValue moderatedMax(int percent) {
HistSample hs = this; HistSample hs = this;
if (_histPairs.size() == 0 if ((_histPairs.size() == 0)
|| percent < 0 || (percent < 0)
|| percent > 50 || (percent > 50)
|| _histPairs.get(0).value().dataType() || _histPairs.get(0).value().dataType()
.equals(GridType.WEATHER) .equals(GridType.WEATHER)
|| _histPairs.get(0).value().dataType() || _histPairs.get(0).value().dataType()
@ -884,14 +888,14 @@ public class HistSample {
} }
// cached? // cached?
if (_moderatedMax != null && _moderatedMaxPercent == percent) { if ((_moderatedMax != null) && (_moderatedMaxPercent == percent)) {
return _moderatedMax; return _moderatedMax;
} }
hs._moderatedMaxPercent = percent; hs._moderatedMaxPercent = percent;
float runningCount = 0; float runningCount = 0;
float limitCount = (float) (percent * _numSamplePoints / 100.0); float limitCount = (float) ((percent * _numSamplePoints) / 100.0);
for (int i = _histPairs.size() - 1; i >= 0; i--) { for (int i = _histPairs.size() - 1; i >= 0; i--) {
runningCount += _histPairs.get(i).count(); runningCount += _histPairs.get(i).count();
@ -922,7 +926,7 @@ public class HistSample {
* most common value is provided for WEATHER/DISCRETE. Outliers are * most common value is provided for WEATHER/DISCRETE. Outliers are
* eliminated based on standard deviation. For vector, if separateMagDir is * eliminated based on standard deviation. For vector, if separateMagDir is
* true, the magnitude is averaged separately from the direction. * true, the magnitude is averaged separately from the direction.
* *
* @param minStdD * @param minStdD
* @param maxStdD * @param maxStdD
* @param separateMagDir * @param separateMagDir
@ -933,7 +937,7 @@ public class HistSample {
HistValue bogus = new HistValue(); HistValue bogus = new HistValue();
HistSample hs = this; HistSample hs = this;
if (_histPairs.size() == 0 || minStdD < 0 || maxStdD < 0) { if ((_histPairs.size() == 0) || (minStdD < 0) || (maxStdD < 0)) {
hs._stdDevAvgMinStdD = hs._stdDevAvgMaxStdD = 0; hs._stdDevAvgMinStdD = hs._stdDevAvgMaxStdD = 0;
hs._stdDevMagDir = false; hs._stdDevMagDir = false;
hs._stdDevAvg = new HistValue(); hs._stdDevAvg = new HistValue();
@ -941,9 +945,9 @@ public class HistSample {
} }
// use cached value if possible // use cached value if possible
if (_stdDevAvg != null && _stdDevAvgMinStdD == minStdD if ((_stdDevAvg != null) && (_stdDevAvgMinStdD == minStdD)
&& _stdDevAvgMaxStdD == maxStdD && (_stdDevAvgMaxStdD == maxStdD)
&& separateMagDir == _stdDevMagDir) { && (separateMagDir == _stdDevMagDir)) {
return _stdDevAvg; return _stdDevAvg;
} }
@ -955,13 +959,13 @@ public class HistSample {
case SCALAR: { case SCALAR: {
float sDev = stdDev().scalar(); float sDev = stdDev().scalar();
float avg = average(true).scalar(); float avg = average(true).scalar();
float minValue = avg - minStdD * sDev; float minValue = avg - (minStdD * sDev);
float maxValue = avg + maxStdD * sDev; float maxValue = avg + (maxStdD * sDev);
float sum = 0.0f; float sum = 0.0f;
int count = 0; int count = 0;
for (int i = 0; i < _histPairs.size(); i++) { for (int i = 0; i < _histPairs.size(); i++) {
float v = _histPairs.get(i).value().scalar(); float v = _histPairs.get(i).value().scalar();
if (v >= minValue && v <= maxValue) { if ((v >= minValue) && (v <= maxValue)) {
sum += _histPairs.get(i).count() * v; sum += _histPairs.get(i).count() * v;
count += _histPairs.get(i).count(); count += _histPairs.get(i).count();
} }
@ -975,8 +979,8 @@ public class HistSample {
case VECTOR: { case VECTOR: {
float sDev = stdDev().scalar(); float sDev = stdDev().scalar();
float avg = average(true).scalar(); float avg = average(true).scalar();
float minValue = avg - minStdD * sDev; float minValue = avg - (minStdD * sDev);
float maxValue = avg + maxStdD * sDev; float maxValue = avg + (maxStdD * sDev);
float sum = 0.0f; float sum = 0.0f;
int count = 0; int count = 0;
float uSum = 0.0f; float uSum = 0.0f;
@ -984,7 +988,7 @@ public class HistSample {
if (separateMagDir) { if (separateMagDir) {
for (int i = 0; i < _histPairs.size(); i++) { for (int i = 0; i < _histPairs.size(); i++) {
float v = _histPairs.get(i).value().magnitude(); float v = _histPairs.get(i).value().magnitude();
if (v >= minValue && v <= maxValue) { if ((v >= minValue) && (v <= maxValue)) {
int tCount = _histPairs.get(i).count(); int tCount = _histPairs.get(i).count();
sum += tCount * _histPairs.get(i).value().magnitude(); sum += tCount * _histPairs.get(i).value().magnitude();
count += tCount; count += tCount;
@ -1018,7 +1022,7 @@ public class HistSample {
} else { } else {
for (int i = 0; i < _histPairs.size(); i++) { for (int i = 0; i < _histPairs.size(); i++) {
float v = _histPairs.get(i).value().magnitude(); float v = _histPairs.get(i).value().magnitude();
if (v >= minValue && v <= maxValue) { if ((v >= minValue) && (v <= maxValue)) {
int tCount = _histPairs.get(i).count(); int tCount = _histPairs.get(i).count();
count += tCount; count += tCount;
uSum += tCount uSum += tCount
@ -1038,7 +1042,7 @@ public class HistSample {
} }
float u = uSum / count; float u = uSum / count;
float v = vSum / count; float v = vSum / count;
float mag = binit((float) (Math.sqrt(u * u + v * v)), float mag = binit((float) (Math.sqrt((u * u) + (v * v))),
_resolution); _resolution);
float dir = binit((float) (Math.atan2(u, v) * RAD_TO_DEG), float dir = binit((float) (Math.atan2(u, v) * RAD_TO_DEG),
10.0f); 10.0f);
@ -1075,15 +1079,15 @@ public class HistSample {
* Description : Returns the representative minimum value for the sample * Description : Returns the representative minimum value for the sample
* points. This is a no-op for WEATHER/DISCRETE. Based on standard * points. This is a no-op for WEATHER/DISCRETE. Based on standard
* deviations. * deviations.
* *
* @param stdD * @param stdD
* @return * @return
*/ */
public final HistValue stdDevMin(float stdD) { public final HistValue stdDevMin(float stdD) {
HistSample hs = this; HistSample hs = this;
if (_histPairs.size() == 0 if ((_histPairs.size() == 0)
|| stdD < 0 || (stdD < 0)
|| _histPairs.get(0).value().dataType() || _histPairs.get(0).value().dataType()
.equals(GridType.WEATHER) .equals(GridType.WEATHER)
|| _histPairs.get(0).value().dataType() || _histPairs.get(0).value().dataType()
@ -1094,7 +1098,7 @@ public class HistSample {
} }
// use cached value if possible // use cached value if possible
if (_stdDevMin != null && _stdDevMinD == stdD) { if ((_stdDevMin != null) && (_stdDevMinD == stdD)) {
return _stdDevMin; return _stdDevMin;
} }
@ -1102,7 +1106,7 @@ public class HistSample {
float sDev = stdDev().scalar(); float sDev = stdDev().scalar();
float avg = average(true).scalar(); float avg = average(true).scalar();
float minValue = avg - stdD * sDev; float minValue = avg - (stdD * sDev);
if (_histPairs.get(0).value().scalar() > minValue) { if (_histPairs.get(0).value().scalar() > minValue) {
minValue = _histPairs.get(0).value().scalar(); minValue = _histPairs.get(0).value().scalar();
} }
@ -1118,15 +1122,15 @@ public class HistSample {
* Description : Returns the representative maximum value for the sample * Description : Returns the representative maximum value for the sample
* points. This is a no-op for WEATHER/DISCRETE. Based on standard * points. This is a no-op for WEATHER/DISCRETE. Based on standard
* deviations. * deviations.
* *
* @param stdD * @param stdD
* @return * @return
*/ */
public final HistValue stdDevMax(float stdD) { public final HistValue stdDevMax(float stdD) {
HistSample hs = this; HistSample hs = this;
if (_histPairs.size() == 0 if ((_histPairs.size() == 0)
|| stdD < 0 || (stdD < 0)
|| _histPairs.get(0).value().dataType() || _histPairs.get(0).value().dataType()
.equals(GridType.DISCRETE) .equals(GridType.DISCRETE)
|| _histPairs.get(0).value().dataType() || _histPairs.get(0).value().dataType()
@ -1137,14 +1141,14 @@ public class HistSample {
} }
// use cached value if possible // use cached value if possible
if (_stdDevMax != null && _stdDevMaxD == stdD) { if ((_stdDevMax != null) && (_stdDevMaxD == stdD)) {
return _stdDevMax; return _stdDevMax;
} }
hs._stdDevMaxD = stdD; hs._stdDevMaxD = stdD;
float sDev = stdDev().scalar(); float sDev = stdDev().scalar();
float avg = average(true).scalar(); float avg = average(true).scalar();
float maxValue = avg + stdD * sDev; float maxValue = avg + (stdD * sDev);
if (_histPairs.get(_histPairs.size() - 1).value().scalar() < maxValue) { if (_histPairs.get(_histPairs.size() - 1).value().scalar() < maxValue) {
maxValue = _histPairs.get(_histPairs.size() - 1).value().scalar(); maxValue = _histPairs.get(_histPairs.size() - 1).value().scalar();
} }
@ -1156,14 +1160,14 @@ public class HistSample {
/** /**
* OUtputs the histogram for this grid, but binned by the specified float * OUtputs the histogram for this grid, but binned by the specified float
* value. This only applies to SCALAR and VECTOR data. * value. This only applies to SCALAR and VECTOR data.
* *
* @param resolution * @param resolution
* @return * @return
*/ */
public List<HistPair> binnedHistogram(float resolution) { public List<HistPair> binnedHistogram(float resolution) {
HistSample hs = this; HistSample hs = this;
if (_histPairs.size() == 0 if ((_histPairs.size() == 0)
|| resolution <= 0.0 || (resolution <= 0.0)
|| _histPairs.get(0).value().dataType().equals(GridType.NONE) || _histPairs.get(0).value().dataType().equals(GridType.NONE)
|| _histPairs.get(0).value().dataType() || _histPairs.get(0).value().dataType()
.equals(GridType.WEATHER) .equals(GridType.WEATHER)
@ -1230,7 +1234,7 @@ public class HistSample {
/** /**
* Description : Bins the data sample based on the resolution * Description : Bins the data sample based on the resolution
* *
* @param v * @param v
* @param resolution * @param resolution
* @return * @return
@ -1255,7 +1259,7 @@ public class HistSample {
* that the grid is valid and grid and Grid2DBit sizes match. Ensures there * that the grid is valid and grid and Grid2DBit sizes match. Ensures there
* are points in the sample area. Switch cases on data type and then * are points in the sample area. Switch cases on data type and then
* extracts out the data for each sample point. * extracts out the data for each sample point.
* *
* @param grid * @param grid
* @param area * @param area
* @param cachePoints * @param cachePoints
@ -1310,7 +1314,7 @@ public class HistSample {
/** /**
* If the sample was of scalars this function is called * If the sample was of scalars this function is called
* *
* @param grid * @param grid
* @param area * @param area
* @param cachePoints * @param cachePoints
@ -1469,7 +1473,7 @@ public class HistSample {
ParmID parmId = grid.getGridInfo().getParmID(); ParmID parmId = grid.getGridInfo().getParmID();
Grid2DByte gs = ((DiscreteGridSlice) grid).getDiscreteGrid(); Grid2DByte gs = ((DiscreteGridSlice) grid).getDiscreteGrid();
String siteId = parmId.getDbId().getSiteId(); String siteId = parmId.getDbId().getSiteId();
DiscreteKey[] key = ((DiscreteGridSlice) grid).getKey(); DiscreteKey[] key = ((DiscreteGridSlice) grid).getKeys();
for (int x = ll.x; x <= ur.x; x++) { for (int x = ll.x; x <= ur.x; x++) {
for (int y = ll.y; y <= ur.y; y++) { for (int y = ll.y; y <= ur.y; y++) {
if (area.get(x, y) != 0) { if (area.get(x, y) != 0) {
@ -1525,7 +1529,7 @@ public class HistSample {
/** /**
* Description : counts the number of sample points and returns the number * Description : counts the number of sample points and returns the number
* *
* @return * @return
*/ */
private int countSamplePoints() { private int countSamplePoints() {
@ -1553,7 +1557,7 @@ public class HistSample {
/** /**
* Description : Returns the sample's valid time * Description : Returns the sample's valid time
* *
* @return * @return
*/ */
public final TimeRange validTime() { public final TimeRange validTime() {
@ -1562,7 +1566,7 @@ public class HistSample {
/** /**
* Description : Returns the histogram associated with this sample * Description : Returns the histogram associated with this sample
* *
* @return * @return
*/ */
public final HistPair[] histogram() { public final HistPair[] histogram() {
@ -1571,7 +1575,7 @@ public class HistSample {
/** /**
* Description : Returns the number of points associated with this sample * Description : Returns the number of points associated with this sample
* *
* @return * @return
*/ */
public int numOfPoints() { public int numOfPoints() {

View file

@ -70,6 +70,7 @@ import com.raytheon.viz.gfe.core.wxvalue.WxValue;
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Oct 20, 2008 njensen Initial creation * Oct 20, 2008 njensen Initial creation
* Oct 29, 2013 2476 njensen Renamed numeric methods to numpy * Oct 29, 2013 2476 njensen Renamed numeric methods to numpy
* 10/31/2013 2508 randerso Change to use DiscreteGridSlice.getKeys()
* </pre> * </pre>
* *
* @author njensen * @author njensen
@ -201,7 +202,7 @@ public class SmartToolController extends BaseGfePyController {
Set<String> set = null; Set<String> set = null;
String[] tools = new String[0]; String[] tools = new String[0];
try { try {
if (parmName == null && parmTypeName == null) { if ((parmName == null) && (parmTypeName == null)) {
set = (Set<String>) execute("getScripts", INTERFACE, null); set = (Set<String>) execute("getScripts", INTERFACE, null);
} else { } else {
HashMap<String, Object> argMap = new HashMap<String, Object>(2); HashMap<String, Object> argMap = new HashMap<String, Object>(2);
@ -325,7 +326,7 @@ public class SmartToolController extends BaseGfePyController {
jep.set("discreteGridData", grid); jep.set("discreteGridData", grid);
jep.eval("discreteGridNumpy = discreteGridData.__numpy__"); jep.eval("discreteGridNumpy = discreteGridData.__numpy__");
jep.eval("discreteGridNumpy = discreteGridNumpy[0]"); jep.eval("discreteGridNumpy = discreteGridNumpy[0]");
DiscreteKey[] keys = grid.getDiscreteSlice().getKey(); DiscreteKey[] keys = grid.getDiscreteSlice().getKeys();
ArrayList<String> stringKeys = new ArrayList<String>(); ArrayList<String> stringKeys = new ArrayList<String>();
for (DiscreteKey k : keys) { for (DiscreteKey k : keys) {
stringKeys.add(k.toString()); stringKeys.add(k.toString());

View file

@ -71,6 +71,7 @@ import com.vividsolutions.jts.geom.Coordinate;
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Apr 13, 2011 #8393 dgilling Initial creation * Apr 13, 2011 #8393 dgilling Initial creation
* 02/19/13 #1637 randerso Added exception handling for Discrete and Weather * 02/19/13 #1637 randerso Added exception handling for Discrete and Weather
* 10/31/2013 #2508 randerso Change to use DiscreteGridSlice.getKeys()
* *
* </pre> * </pre>
* *
@ -139,7 +140,7 @@ public class ASCIIGrid {
* @return * @return
*/ */
public boolean translateGrid(int index, GridParmInfo destGPI) { public boolean translateGrid(int index, GridParmInfo destGPI) {
if ((index < 0) || (index > gridSlices.size() - 1)) { if ((index < 0) || (index > (gridSlices.size() - 1))) {
return false; return false;
} }
@ -337,7 +338,7 @@ public class ASCIIGrid {
for (int i = discrete.getDiscreteGrid().getYdim() - 1; i >= 0; i--) { for (int i = discrete.getDiscreteGrid().getYdim() - 1; i >= 0; i--) {
for (int j = 0; j < discrete.getDiscreteGrid() for (int j = 0; j < discrete.getDiscreteGrid()
.getXdim(); j++) { .getXdim(); j++) {
String key = discrete.getKey()[discrete String key = discrete.getKeys()[discrete
.getDiscreteGrid().get(j, i)].toString(); .getDiscreteGrid().get(j, i)].toString();
outputStream.println(key); outputStream.println(key);
} }

View file

@ -111,6 +111,7 @@ import com.raytheon.uf.edex.database.DataAccessLayerException;
* 06/13/13 #2044 randerso Pass in GridDbConfig as construction parameter * 06/13/13 #2044 randerso Pass in GridDbConfig as construction parameter
* 07/30/13 #2057 randerso Added a static deleteDatabase method * 07/30/13 #2057 randerso Added a static deleteDatabase method
* 08/05/13 #1571 randerso Refactored to store GridParmInfo and ParmStorageinfo in postgres database * 08/05/13 #1571 randerso Refactored to store GridParmInfo and ParmStorageinfo in postgres database
* 10/31/2013 #2508 randerso Change to use DiscreteGridSlice.getKeys()
* *
* </pre> * </pre>
* *
@ -1664,7 +1665,7 @@ public class IFPGridDatabase extends GridDatabase {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
boolean first = true; boolean first = true;
for (DiscreteKey key : slice.getKey()) { for (DiscreteKey key : slice.getKeys()) {
if (first) { if (first) {
first = false; first = false;
} else { } else {

View file

@ -68,7 +68,8 @@ import com.vividsolutions.jts.geom.Coordinate;
* Aug 11, 2009 njensen Initial creation * Aug 11, 2009 njensen Initial creation
* Mar 06, 2013 1735 rferrel Change to retrieve multiple points * Mar 06, 2013 1735 rferrel Change to retrieve multiple points
* in a single grid request. * in a single grid request.
* Jun 13, 2013 #2044 randerso Refactored to use IFPServer * Jun 13, 2013 #2044 randerso Refactored to use IFPServer
* Oct 31, 2013 #2508 randerso Change to use DiscreteGridSlice.getKeys()
* *
* </pre> * </pre>
* *
@ -213,7 +214,7 @@ public class GetPointDataHandler extends BaseGfeRequestHandler implements
} else if (slice instanceof DiscreteGridSlice) { } else if (slice instanceof DiscreteGridSlice) {
DiscreteGridSlice gs = (DiscreteGridSlice) slice; DiscreteGridSlice gs = (DiscreteGridSlice) slice;
byte value = gs.getDiscreteGrid().get(x, y); byte value = gs.getDiscreteGrid().get(x, y);
String key = gs.getKey()[value].toString(); String key = gs.getKeys()[value].toString();
Type type = Type.STRING; Type type = Type.STRING;
view.setData(param, type, unit, key); view.setData(param, type, unit, key);
} }

View file

@ -70,6 +70,7 @@ from com.raytheon.uf.common.localization import LocalizationContext_Localization
# 08/09/2013 1571 randerso Changed projections to use the Java # 08/09/2013 1571 randerso Changed projections to use the Java
# ProjectionType enumeration # ProjectionType enumeration
# 09/20/13 2405 dgilling Clip grids before inserting into cache. # 09/20/13 2405 dgilling Clip grids before inserting into cache.
# 10/31/2013 2508 randerso Change to use DiscreteGridSlice.getKeys()
# #
# Original A1 BATCH WRITE COUNT was 10, we found doubling that # Original A1 BATCH WRITE COUNT was 10, we found doubling that
@ -140,18 +141,12 @@ class WECache(object):
elif gridType == "VECTOR": elif gridType == "VECTOR":
vecGrids = grid.__numpy__ vecGrids = grid.__numpy__
return (clipToExtrema(vecGrids[0], clipArea), clipToExtrema(vecGrids[1], clipArea)) return (clipToExtrema(vecGrids[0], clipArea), clipToExtrema(vecGrids[1], clipArea))
elif gridType == "WEATHER": elif gridType == "WEATHER" or gridType =="DISCRETE":
keys = grid.getKeys() keys = grid.getKeys()
keyList = [] keyList = []
for theKey in keys: for theKey in keys:
keyList.append(theKey.toString()) keyList.append(theKey.toString())
return (clipToExtrema(grid.__numpy__[0], clipArea), keyList) return (clipToExtrema(grid.__numpy__[0], clipArea), keyList)
elif gridType =="DISCRETE":
keys = grid.getKey()
keyList = []
for theKey in keys:
keyList.append(theKey.toString())
return (clipToExtrema(grid.__numpy__[0], clipArea), keyList)
def __encodeGridHistory(self, histories): def __encodeGridHistory(self, histories):
retVal = [] retVal = []

View file

@ -82,6 +82,7 @@ from com.raytheon.uf.edex.database.cluster import ClusterTask
# 06/05/13 2063 dgilling Change __siteInDbGrid() to # 06/05/13 2063 dgilling Change __siteInDbGrid() to
# call IFPWE.history() like A1. # call IFPWE.history() like A1.
# 09/05/13 2307 dgilling Fix breakage caused by #2044. # 09/05/13 2307 dgilling Fix breakage caused by #2044.
# 10/31/2013 2508 randerso Change to use DiscreteGridSlice.getKeys()
# #
# #
@ -204,18 +205,12 @@ class WECache(object):
elif gridType == "VECTOR": elif gridType == "VECTOR":
vecGrids = grid.__numpy__ vecGrids = grid.__numpy__
return (vecGrids[0], vecGrids[1]) return (vecGrids[0], vecGrids[1])
elif gridType == "WEATHER": elif gridType == "WEATHER" or gridType =="DISCRETE":
keys = grid.getKeys() keys = grid.getKeys()
keyList = [] keyList = []
for theKey in keys: for theKey in keys:
keyList.append(theKey.toString()) keyList.append(theKey.toString())
return (grid.__numpy__[0], keyList) return (grid.__numpy__[0], keyList)
elif gridType =="DISCRETE":
keys = grid.getKey()
keyList = []
for theKey in keys:
keyList.append(theKey.toString())
return (grid.__numpy__[0], keyList)
def __encodeGridHistory(self, histories): def __encodeGridHistory(self, histories):
retVal = [] retVal = []

View file

@ -36,7 +36,6 @@ import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.dataplugin.gfe.db.objects.GFERecord; import com.raytheon.uf.common.dataplugin.gfe.db.objects.GFERecord;
import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridLocation; import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridLocation;
import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridParmInfo; import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridParmInfo;
import com.raytheon.uf.common.dataplugin.gfe.discrete.DiscreteKey;
import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DByte; import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DByte;
import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DFloat; import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DFloat;
import com.raytheon.uf.common.dataplugin.gfe.grid.IGrid2D; import com.raytheon.uf.common.dataplugin.gfe.grid.IGrid2D;
@ -73,6 +72,7 @@ import com.raytheon.uf.common.util.StringUtil;
* May 02, 2013 1949 bsteffen Update GFE data access in Product * May 02, 2013 1949 bsteffen Update GFE data access in Product
* Browser, Volume Browser, and Data Access * Browser, Volume Browser, and Data Access
* Framework. * Framework.
* 10/31/2013 2508 randerso Change to use DiscreteGridSlice.getKeys()
* *
* </pre> * </pre>
* *
@ -221,7 +221,7 @@ public class GFEGridFactory extends AbstractGridDataPluginFactory implements
} else if (slice instanceof DiscreteGridSlice) { } else if (slice instanceof DiscreteGridSlice) {
DiscreteGridSlice castedSlice = (DiscreteGridSlice) slice; DiscreteGridSlice castedSlice = (DiscreteGridSlice) slice;
data = castedSlice.getDiscreteGrid(); data = castedSlice.getDiscreteGrid();
DiscreteKey[] dKeys = castedSlice.getKey(); Object[] dKeys = castedSlice.getKeys();
String[] keys = new String[dKeys.length]; String[] keys = new String[dKeys.length];
for (int i = 0; i < dKeys.length; i++) { for (int i = 0; i < dKeys.length; i++) {
keys[i] = dKeys[i].toString(); keys[i] = dKeys[i].toString();
@ -285,7 +285,7 @@ public class GFEGridFactory extends AbstractGridDataPluginFactory implements
} }
private GFERecord asGFERecord(Object obj) { private GFERecord asGFERecord(Object obj) {
if (obj instanceof GFERecord == false) { if ((obj instanceof GFERecord) == false) {
throw new DataRetrievalException(this.getClass().getSimpleName() throw new DataRetrievalException(this.getClass().getSimpleName()
+ " cannot handle " + obj.getClass().getSimpleName()); + " cannot handle " + obj.getClass().getSimpleName());
} }

View file

@ -44,7 +44,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.common.time.TimeRange; import com.raytheon.uf.common.time.TimeRange;
/** /**
* TODO Add Description * Grid slice for Discrete weather elements
* *
* <pre> * <pre>
* SOFTWARE HISTORY * SOFTWARE HISTORY
@ -58,6 +58,7 @@ import com.raytheon.uf.common.time.TimeRange;
* 08/13/2013 1571 randerso Removed toString to stop it from hanging the * 08/13/2013 1571 randerso Removed toString to stop it from hanging the
* debugger when trying to display the grid * debugger when trying to display the grid
* 10/29/2013 2476 njensen Updated getNumpy() and added getKeyList() * 10/29/2013 2476 njensen Updated getNumpy() and added getKeyList()
* 10/31/2013 2508 randerso Added getKeys(), deprecated getKey()
* </pre> * </pre>
* *
* @author chammack * @author chammack
@ -75,7 +76,7 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable {
private String cacheId; private String cacheId;
@DynamicSerializeElement @DynamicSerializeElement
private DiscreteKey[] key; private DiscreteKey[] keys;
/** /**
* Constructor for serialization only. * Constructor for serialization only.
@ -97,7 +98,7 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable {
Grid2DByte aGrid, DiscreteKey[] aKey) { Grid2DByte aGrid, DiscreteKey[] aKey) {
super(validTime, gfeRecord); super(validTime, gfeRecord);
setDiscreteGrid(aGrid); setDiscreteGrid(aGrid);
key = aKey; keys = aKey;
} }
/** /**
@ -113,7 +114,7 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable {
GridDataHistory[] history, Grid2DByte aGrid, DiscreteKey[] aKey) { GridDataHistory[] history, Grid2DByte aGrid, DiscreteKey[] aKey) {
super(validTime, gpi, history); super(validTime, gpi, history);
setDiscreteGrid(aGrid); setDiscreteGrid(aGrid);
key = aKey; keys = aKey;
} }
public DiscreteGridSlice(TimeRange validTime, GridParmInfo gpi, public DiscreteGridSlice(TimeRange validTime, GridParmInfo gpi,
@ -151,8 +152,8 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable {
Grid2DByte grid = rhs.getDiscreteGrid().clone(); Grid2DByte grid = rhs.getDiscreteGrid().clone();
setDiscreteGrid(grid); setDiscreteGrid(grid);
this.key = new DiscreteKey[rhs.key.length]; this.keys = new DiscreteKey[rhs.keys.length];
System.arraycopy(rhs.key, 0, this.key, 0, rhs.key.length); System.arraycopy(rhs.keys, 0, this.keys, 0, rhs.keys.length);
} }
@Override @Override
@ -178,11 +179,11 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable {
discreteGrid.assign(gsDiscreteGrid); discreteGrid.assign(gsDiscreteGrid);
setDiscreteGrid(discreteGrid); setDiscreteGrid(discreteGrid);
this.key = new DiscreteKey[slice.key.length]; this.keys = new DiscreteKey[slice.keys.length];
System.arraycopy(slice.key, 0, this.key, 0, slice.key.length); System.arraycopy(slice.keys, 0, this.keys, 0, slice.keys.length);
} else { } else {
setDiscreteGrid(null); setDiscreteGrid(null);
this.key = new DiscreteKey[0]; this.keys = new DiscreteKey[0];
} }
} }
@ -237,8 +238,8 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable {
byte[] thisData = grid.getBuffer().array(); byte[] thisData = grid.getBuffer().array();
byte[] rhsData = rhsGrid.getBuffer().array(); byte[] rhsData = rhsGrid.getBuffer().array();
for (int i = 0; i < thisData.length; i++) { for (int i = 0; i < thisData.length; i++) {
if (!this.key[0xFF & thisData[i]] if (!this.keys[0xFF & thisData[i]]
.equals(rhsDiscreteGridSlice.key[0xFF & rhsData[i]])) { .equals(rhsDiscreteGridSlice.keys[0xFF & rhsData[i]])) {
return false; return false;
} }
} }
@ -254,7 +255,7 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable {
* @return null if everything was ok, otherwise the reason why not * @return null if everything was ok, otherwise the reason why not
*/ */
public String checkKeyAndData() { public String checkKeyAndData() {
int keyLength = key.length; int keyLength = keys.length;
Grid2DByte discreteGrid = getDiscreteGrid(); Grid2DByte discreteGrid = getDiscreteGrid();
byte[] b = discreteGrid.getBuffer().array(); byte[] b = discreteGrid.getBuffer().array();
for (int i = 0; i < b.length; i++) { for (int i = 0; i < b.length; i++) {
@ -278,10 +279,10 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable {
* @return null if the key is ok, otherwise the reason why not * @return null if the key is ok, otherwise the reason why not
*/ */
public String checkKey() { public String checkKey() {
for (int i = 0; i < key.length; i++) { for (int i = 0; i < keys.length; i++) {
if (!this.key[i].isValid()) { if (!this.keys[i].isValid()) {
return "Invalid Key found in Grid. Key Position is " + i return "Invalid Key found in Grid. Key Position is " + i
+ " Key is: " + key[i].getOrigStr(); + " Key is: " + keys[i].getOrigStr();
} }
} }
return null; return null;
@ -316,19 +317,19 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable {
// find a key match // find a key match
byte dByte = 0; byte dByte = 0;
boolean found = false; boolean found = false;
for (int k = 0; k < key.length; k++) { for (int k = 0; k < keys.length; k++) {
if (key[k].equals(aValue)) { if (keys[k].equals(aValue)) {
dByte = (byte) k; dByte = (byte) k;
found = true; found = true;
} }
} }
if (!found) { if (!found) {
DiscreteKey newKey[] = new DiscreteKey[key.length + 1]; DiscreteKey newKey[] = new DiscreteKey[keys.length + 1];
System.arraycopy(key, 0, newKey, 0, key.length); System.arraycopy(keys, 0, newKey, 0, keys.length);
newKey[newKey.length - 1] = aValue; newKey[newKey.length - 1] = aValue;
key = newKey; keys = newKey;
dByte = (byte) (key.length - 1); dByte = (byte) (keys.length - 1);
} }
for (int i = ll.x; i <= ur.x; i++) { for (int i = ll.x; i <= ur.x; i++) {
@ -370,23 +371,23 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable {
if (editArea.get(i, j) != 0) { if (editArea.get(i, j) != 0) {
// Get the DiscreteKey from the source grid // Get the DiscreteKey from the source grid
byte dByte = gsDiscreteGrid.get(i, j); byte dByte = gsDiscreteGrid.get(i, j);
DiscreteKey dKey = gs.key[0xFF & dByte]; DiscreteKey dKey = gs.keys[0xFF & dByte];
// See if this key already exists in target grid // See if this key already exists in target grid
boolean found = false; boolean found = false;
byte keyIndex = 0; byte keyIndex = 0;
for (int k = 0; k < key.length; k++) { for (int k = 0; k < keys.length; k++) {
if (key[k] == dKey) { if (keys[k] == dKey) {
found = true; found = true;
keyIndex = (byte) k; keyIndex = (byte) k;
} }
} }
if (!found) // not found, so add the key if (!found) // not found, so add the key
{ {
DiscreteKey newKey[] = new DiscreteKey[key.length + 1]; DiscreteKey newKey[] = new DiscreteKey[keys.length + 1];
System.arraycopy(key, 0, newKey, 0, key.length); System.arraycopy(keys, 0, newKey, 0, keys.length);
newKey[newKey.length - 1] = dKey; newKey[newKey.length - 1] = dKey;
key = newKey; keys = newKey;
keyIndex = (byte) (key.length - 1); keyIndex = (byte) (keys.length - 1);
} }
discreteGrid.set(i, j, keyIndex); discreteGrid.set(i, j, keyIndex);
@ -414,19 +415,19 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable {
// find a key match // find a key match
byte dByte = 0; byte dByte = 0;
boolean found = false; boolean found = false;
for (int k = 0; k < key.length; k++) { for (int k = 0; k < keys.length; k++) {
if (key[k].equals(aValue)) { if (keys[k].equals(aValue)) {
dByte = (byte) k; dByte = (byte) k;
found = true; found = true;
} }
} }
if (!found) { if (!found) {
DiscreteKey newKey[] = new DiscreteKey[key.length + 1]; DiscreteKey newKey[] = new DiscreteKey[keys.length + 1];
System.arraycopy(key, 0, newKey, 0, key.length); System.arraycopy(keys, 0, newKey, 0, keys.length);
newKey[newKey.length - 1] = aValue; newKey[newKey.length - 1] = aValue;
key = newKey; keys = newKey;
dByte = (byte) (key.length - 1); dByte = (byte) (keys.length - 1);
} }
Grid2DByte discreteGrid = getDiscreteGrid(); Grid2DByte discreteGrid = getDiscreteGrid();
@ -448,22 +449,22 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable {
Grid2DByte discreteGrid = gs.discreteGrid.clone(); Grid2DByte discreteGrid = gs.discreteGrid.clone();
List<DiscreteKey> currentKeys = new ArrayList<DiscreteKey>( List<DiscreteKey> currentKeys = new ArrayList<DiscreteKey>(
Arrays.asList(this.key)); Arrays.asList(this.keys));
byte[] data = discreteGrid.getBuffer().array(); byte[] data = discreteGrid.getBuffer().array();
int thisB; int thisB;
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
thisB = 0xFF & data[i]; thisB = 0xFF & data[i];
byte keyIndex; byte keyIndex;
if ((keyIndex = (byte) currentKeys.indexOf(gs.key[thisB])) != -1) { if ((keyIndex = (byte) currentKeys.indexOf(gs.keys[thisB])) != -1) {
data[i] = keyIndex; data[i] = keyIndex;
} else { } else {
data[i] = (byte) currentKeys.size(); data[i] = (byte) currentKeys.size();
currentKeys.add(new DiscreteKey(gs.key[thisB])); currentKeys.add(new DiscreteKey(gs.keys[thisB]));
} }
} }
setDiscreteGrid(discreteGrid); setDiscreteGrid(discreteGrid);
this.key = currentKeys.toArray(new DiscreteKey[currentKeys.size()]); this.keys = currentKeys.toArray(new DiscreteKey[currentKeys.size()]);
return true; return true;
} }
@ -478,7 +479,7 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable {
*/ */
public Grid2DBit eq(DiscreteKey value) { public Grid2DBit eq(DiscreteKey value) {
if (!value.isValid()) { if (!value.isValid()) {
throw new IllegalArgumentException("Supplied key is invalid"); throw new IllegalArgumentException("Supplied keys is invalid");
} }
Grid2DByte discreteGrid = getDiscreteGrid(); Grid2DByte discreteGrid = getDiscreteGrid();
@ -489,8 +490,8 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable {
// Get or make a Discrete // Get or make a Discrete
byte dByte = 0; byte dByte = 0;
boolean found = false; boolean found = false;
for (int k = 0; k < key.length; k++) { for (int k = 0; k < keys.length; k++) {
if (key[k].equals(value)) { if (keys[k].equals(value)) {
dByte = (byte) k; dByte = (byte) k;
found = true; found = true;
} }
@ -545,17 +546,17 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable {
// Check for each value // Check for each value
// Get the list of subkey permutations from the value given // Get the list of subkey permutations from the value given
List<String> searchKeys = key[0].descriptionSubKeys(value); List<String> searchKeys = keys[0].descriptionSubKeys(value);
// Get the byte values that correspond to the specified textStrings // Get the byte values that correspond to the specified textStrings
List<Byte> byteValues = new ArrayList<Byte>(); List<Byte> byteValues = new ArrayList<Byte>();
// Check each discrete key for a match of a subkey // Check each discrete key for a match of a subkey
for (int i = 0; i < key.length; i++) { for (int i = 0; i < keys.length; i++) {
// Check each subkey // Check each subkey
for (int j = 0; j < key[i].getSubKeys().size(); j++) { for (int j = 0; j < keys[i].getSubKeys().size(); j++) {
for (int k = 0; k < searchKeys.size(); k++) { for (int k = 0; k < searchKeys.size(); k++) {
if (key[i].getSubKeys().get(j).equals(searchKeys.get(k))) { if (keys[i].getSubKeys().get(j).equals(searchKeys.get(k))) {
byteValues.add((byte) i); byteValues.add((byte) i);
break; break;
} }
@ -604,7 +605,7 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable {
byte[] rhsB = gs.getDiscreteGrid().getBuffer().array(); byte[] rhsB = gs.getDiscreteGrid().getBuffer().array();
byte[] b = bits.getBuffer().array(); byte[] b = bits.getBuffer().array();
for (int i = 0; i < thisB.length; i++) { for (int i = 0; i < thisB.length; i++) {
if (key[0xFF & thisB[i]].equals(gs.key[0xFF & rhsB[i]])) { if (keys[0xFF & thisB[i]].equals(gs.keys[0xFF & rhsB[i]])) {
b[i] = (byte) 1; b[i] = (byte) 1;
} }
} }
@ -639,9 +640,9 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable {
* for duplicate keys, set all locations in grid that match that key to * for duplicate keys, set all locations in grid that match that key to
* the "first" of the duplicate keys * the "first" of the duplicate keys
*/ */
for (int i = 0; i < (key.length - 1); i++) { for (int i = 0; i < (keys.length - 1); i++) {
for (int j = i; j < key.length; j++) { for (int j = i; j < keys.length; j++) {
if (key[i].equals(key[j])) { if (keys[i].equals(keys[j])) {
discreteGrid.setAllOfValue((byte) j, (byte) i); discreteGrid.setAllOfValue((byte) j, (byte) i);
} }
} }
@ -666,11 +667,11 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable {
.hasNext(); keyIndex++) { .hasNext(); keyIndex++) {
byte thisByte = usedKeysI.next(); byte thisByte = usedKeysI.next();
discreteGrid.setAllOfValue(thisByte, (byte) keyIndex); discreteGrid.setAllOfValue(thisByte, (byte) keyIndex);
newKey[keyIndex] = key[0xFF & thisByte]; newKey[keyIndex] = keys[0xFF & thisByte];
} }
setDiscreteGrid(discreteGrid); setDiscreteGrid(discreteGrid);
key = newKey; keys = newKey;
} }
@Override @Override
@ -688,9 +689,9 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable {
aGrid = aGrid.clone(); aGrid = aGrid.clone();
} }
DiscreteKey[] aKey = new DiscreteKey[this.key.length]; DiscreteKey[] aKey = new DiscreteKey[this.keys.length];
for (int i = 0; i < aKey.length; i++) { for (int i = 0; i < aKey.length; i++) {
aKey[i] = new DiscreteKey(this.key[i]); aKey[i] = new DiscreteKey(this.keys[i]);
} }
return new DiscreteGridSlice(aValidTime, aGpi, aHistory, aGrid, aKey); return new DiscreteGridSlice(aValidTime, aGpi, aHistory, aGrid, aKey);
} }
@ -742,12 +743,23 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable {
} }
/** /**
* Return the discrete key * Return the discrete keys
* *
* @return the discrete key * @return the discrete keys
* @deprecated use getKeys() instead
*/ */
@Deprecated
public DiscreteKey[] getKey() { public DiscreteKey[] getKey() {
return this.key; return this.keys;
}
/**
* Return the discrete keys
*
* @return the discrete keys
*/
public DiscreteKey[] getKeys() {
return this.keys;
} }
public void setDiscreteGrid(Grid2DByte grid) { public void setDiscreteGrid(Grid2DByte grid) {
@ -781,7 +793,7 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable {
} }
public void setKey(DiscreteKey[] key) { public void setKey(DiscreteKey[] key) {
this.key = key; this.keys = key;
} }
public void setKey(List<DiscreteKey[]> key) { public void setKey(List<DiscreteKey[]> key) {
@ -854,8 +866,8 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable {
} }
public List<String> getKeyList() { public List<String> getKeyList() {
List<String> list = new ArrayList<String>(key.length); List<String> list = new ArrayList<String>(keys.length);
for (DiscreteKey k : key) { for (DiscreteKey k : keys) {
list.add(k.toString()); list.add(k.toString());
} }
return list; return list;