diff --git a/cave/build/static/common/cave/etc/gfe/userPython/utilities/SmartScript.py b/cave/build/static/common/cave/etc/gfe/userPython/utilities/SmartScript.py index 42a6445586..d08c12420b 100644 --- a/cave/build/static/common/cave/etc/gfe/userPython/utilities/SmartScript.py +++ b/cave/build/static/common/cave/etc/gfe/userPython/utilities/SmartScript.py @@ -46,6 +46,9 @@ # Cleaned up some constants # Jun 21, 2013 14983 ryu Fixed encodeEditArea() to evaluate query # when necessary +# Aug 14, 2013 1571 randerso Fixed encodeEditArea() to return astype(numpy.bool8) +# so mask can be used with advanced indexing +# (e.g. grid[mask] = value) # ######################################################################## import types, string, time, sys @@ -2080,7 +2083,7 @@ class SmartScript(BaseTool.BaseTool): if editArea.isQuery(): editArea = self.__refSetMgr.evaluateQuery(editArea.getQuery()) - return editArea.getGrid().__numpy__[0] + return editArea.getGrid().__numpy__[0].astype(numpy.bool8) def decodeEditArea(self, mask): # Returns a refData object for the given mask diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/MockParmManager.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/MockParmManager.java index 42fa8ccb02..f8cf1fbddb 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/MockParmManager.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/MockParmManager.java @@ -84,6 +84,7 @@ import com.vividsolutions.jts.geom.Coordinate; * ------------ ---------- ----------- -------------------------- * 02/04/2008 chammack Initial Creation * 03/20/2013 #1774 randerso Use TimeUtil constants + * 08/06/2013 #1571 randerso Changed ProjectionData constructor call * * * @@ -98,10 +99,9 @@ public class MockParmManager extends AbstractParmManager { private static final int TIME_OFFSET = -6; private static final ProjectionData grid211 = new ProjectionData("Grid211", - ProjectionType.LAMBERT_CONFORMAL.ordinal(), new Coordinate( - -133.459, 12.190), new Coordinate(-49.385, 57.290), - new Coordinate(-95.0, 25.0), 25.0f, 25.0f, new Point(1, 1), - new Point(93, 65), 0.0f, 0.0f, 0.0f); + ProjectionType.LAMBERT_CONFORMAL, new Coordinate(-133.459, 12.190), + new Coordinate(-49.385, 57.290), new Coordinate(-95.0, 25.0), + 25.0f, 25.0f, new Point(1, 1), new Point(93, 65), 0.0f, 0.0f, 0.0f); private static final GridLocation gloc = new GridLocation("OAX", grid211, new Point(145, 145), new Coordinate(45, 30), new Coordinate(9, 9), @@ -208,7 +208,7 @@ public class MockParmManager extends AbstractParmManager { // Hack for simulated data float[][] data = null; - if (Activator.getDefault() != null + if ((Activator.getDefault() != null) && (gpi.getDescriptiveName().equals("Surface Temperature") || gpi .getDescriptiveName().equals("Dewpoint"))) { UnitConverter conv = SI.KELVIN.getConverterTo(NonSI.FAHRENHEIT); @@ -281,8 +281,11 @@ public class MockParmManager extends AbstractParmManager { / (g2dFloat.getXdim() + g2dFloat.getYdim()); for (int m = 0; m < g2dFloat.getXdim(); m++) { for (int n = 0; n < g2dFloat.getYdim(); n++) { - g2dFloat.set(m, n, - ((float) m + n) * step + gpi.getMinValue()); + g2dFloat.set( + m, + n, + (((float) m + n) * step) + + gpi.getMinValue()); } } } @@ -306,7 +309,7 @@ public class MockParmManager extends AbstractParmManager { for (int m = 0; m < g2dFloat.getXdim(); m++) { for (int n = 0; n < g2dFloat.getYdim(); n++) { g2dFloat.set(m, n, - ((float) m + n) * step + gpi.getMinValue()); + (((float) m + n) * step) + gpi.getMinValue()); } } @@ -330,10 +333,10 @@ public class MockParmManager extends AbstractParmManager { // ADDED TO DISPLAY SOME DISCRETE DATA for (int m = 0; m < g2dByte.getXdim(); m++) { for (int n = 0; n < g2dByte.getYdim(); n++) { - if (m > 80 && m < 110 && n > 80 && n < 110) { + if ((m > 80) && (m < 110) && (n > 80) && (n < 110)) { g2dByte.set(m, n, (byte) 1); } - if (m > 90 && m < 100 && n > 110 && n < 140) { + if ((m > 90) && (m < 100) && (n > 110) && (n < 140)) { g2dByte.set(m, n, (byte) 1); } } @@ -362,10 +365,10 @@ public class MockParmManager extends AbstractParmManager { // ADDED TO DISPLAY SOME DISCRETE DATA for (int m = 0; m < g2dByte.getXdim(); m++) { for (int n = 0; n < g2dByte.getYdim(); n++) { - if (m > 80 && m < 110 && n > 80 && n < 110) { + if ((m > 80) && (m < 110) && (n > 80) && (n < 110)) { g2dByte.set(m, n, (byte) 1); } - if (m > 90 && m < 100 && n > 110 && n < 140) { + if ((m > 90) && (m < 100) && (n > 110) && (n < 140)) { g2dByte.set(m, n, (byte) 1); } } @@ -421,7 +424,7 @@ public class MockParmManager extends AbstractParmManager { this.dataManager); IGridData grid = null; - if (data == null || data.length == 0) { + if ((data == null) || (data.length == 0)) { grid = null; } else if (gpi.getGridType() == GridType.SCALAR) { grid = new ScalarGridData(parm, data[0]); @@ -715,13 +718,13 @@ public class MockParmManager extends AbstractParmManager { parms.acquireWriteLock(); try { for (Parm addParm : addParms) { - if (addParm != null && !this.parms.contains(addParm)) { + if ((addParm != null) && !this.parms.contains(addParm)) { this.parms.add(addParm); // add the additions } } for (Parm removeParm : removeParms) { - if (removeParm != null && this.parms.contains(removeParm)) { + if ((removeParm != null) && this.parms.contains(removeParm)) { this.parms.remove(removeParm); } } @@ -738,7 +741,7 @@ public class MockParmManager extends AbstractParmManager { } // send ParmListChanged notification - if (addParms.size() > 0 || removeParms.size() > 0) { + if ((addParms.size() > 0) || (removeParms.size() > 0)) { parms.acquireReadLock(); try { fireParmListChanged( @@ -765,7 +768,7 @@ public class MockParmManager extends AbstractParmManager { } // send DisplayedParmListChanged notification - if (removedDisplayed.size() > 0 || addedDisplayed.size() > 0) { + if ((removedDisplayed.size() > 0) || (addedDisplayed.size() > 0)) { parms.acquireReadLock(); try { fireDisplayedParmListChanged(this.parms diff --git a/deltaScripts/13.6.1/CleanupGfeHDF5Storage.py b/deltaScripts/13.6.1/CleanupGfeHDF5Storage.py new file mode 100644 index 0000000000..8bd66c2f46 --- /dev/null +++ b/deltaScripts/13.6.1/CleanupGfeHDF5Storage.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +## +# This software was developed and / or modified by Raytheon Company, +# pursuant to Contract DG133W-05-CQ-1067 with the US Government. +# +# U.S. EXPORT CONTROLLED TECHNICAL DATA +# This software product contains export-restricted data whose +# export/transfer/disclosure is restricted by U.S. law. Dissemination +# to non-U.S. persons whether in the United States or abroad requires +# an export license or other authorization. +# +# Contractor Name: Raytheon Company +# Contractor Address: 6825 Pine Street, Suite 340 +# Mail Stop B8 +# Omaha, NE 68106 +# 402.291.0100 +# +# See the AWIPS II Master Rights File ("Master Rights File.pdf") for +# further licensing information. +## + +# +# Update GFE HDF5 Group format to include minutes +# +# +# +# SOFTWARE HISTORY +# +# Date Ticket# Engineer Description +# ------------ ---------- ----------- -------------------------- +# 11/18/10 njensen Initial Creation. +# 06/13/13 #2044 randerso Fixed to use correct python +# +# +# +import os + +hdf5loc = "/awips2/edex/data/hdf5/gfe" + +def processDir(dir): + # walk the directory tree removing *_GridParm.h5 files + for file in os.listdir(dir): + filePath = os.path.join(dir, file) + if os.path.isfile(filePath) and str(filePath).endswith("_GridParm.h5"): + print "Removing ", filePath + os.remove(filePath) + elif os.path.isdir(filePath): + processDir(filePath) + + # if directory is empty remove it + if len(os.listdir(dir)) == 0: + print "Removing ", dir + os.removedirs(dir) + +def main(): + processDir(hdf5loc) + +if __name__ == '__main__': + main() diff --git a/deltaScripts/13.6.1/CreateNewGfeTables.sh b/deltaScripts/13.6.1/CreateNewGfeTables.sh new file mode 100644 index 0000000000..e14b1865e7 --- /dev/null +++ b/deltaScripts/13.6.1/CreateNewGfeTables.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# run the update +/awips2/psql/bin/psql -U awips -d metadata -f CreateNewGfeTables.sql +if [ $? -ne 0 ]; then + echo "FATAL: the update has failed!" + exit 1 +fi + +echo "INFO: the update has completed successfully!" + +exit 0 diff --git a/deltaScripts/13.6.1/CreateNewGfeTables.sql b/deltaScripts/13.6.1/CreateNewGfeTables.sql new file mode 100644 index 0000000000..5ada4eb2d1 --- /dev/null +++ b/deltaScripts/13.6.1/CreateNewGfeTables.sql @@ -0,0 +1,106 @@ +DROP TABLE IF EXISTS gfe_spatial; + +-- Sequence: gfe_gridlocation_seq + +-- DROP SEQUENCE gfe_gridlocation_seq; + +CREATE SEQUENCE gfe_gridlocation_seq + INCREMENT 1 + MINVALUE 1 + MAXVALUE 9223372036854775807 + START 1 + CACHE 1; +ALTER TABLE gfe_gridlocation_seq + OWNER TO awips; + +-- Table: gfe_gridlocation + +-- DROP TABLE gfe_gridlocation; + +CREATE TABLE gfe_gridlocation +( + id integer NOT NULL, + extent bytea NOT NULL, + nx integer NOT NULL, + ny integer NOT NULL, + origin bytea NOT NULL, + gridpointll bytea NOT NULL, + gridpointur bytea NOT NULL, + latintersect double precision NOT NULL, + latlonll bytea NOT NULL, + latlonorigin bytea NOT NULL, + latlonur bytea NOT NULL, + loncenter double precision NOT NULL, + lonorigin double precision NOT NULL, + projectionid character varying(32) NOT NULL, + projectiontype character varying(20) NOT NULL, + stdparallelone double precision NOT NULL, + stdparalleltwo double precision NOT NULL, + siteid character varying(8) NOT NULL, + timezone character varying(32) NOT NULL, + dbid_id integer NOT NULL, + CONSTRAINT gfe_gridlocation_pkey PRIMARY KEY (id), + CONSTRAINT fk22b8153412156549 FOREIGN KEY (dbid_id) + REFERENCES gfe_dbid (id) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE CASCADE, + CONSTRAINT gfe_gridlocation_dbid_id_key UNIQUE (dbid_id) +) +WITH ( + OIDS=FALSE +); +ALTER TABLE gfe_gridlocation + OWNER TO awips; + +-- Sequence: gfe_parminfo_seq + +-- DROP SEQUENCE gfe_parminfo_seq; + +CREATE SEQUENCE gfe_parminfo_seq + INCREMENT 1 + MINVALUE 1 + MAXVALUE 9223372036854775807 + START 1 + CACHE 1; +ALTER TABLE gfe_parminfo_seq + OWNER TO awips; + +-- Table: gfe_parminfo + +-- DROP TABLE gfe_parminfo; + +CREATE TABLE gfe_parminfo +( + id integer NOT NULL, + datamultiplier real NOT NULL, + dataoffset real NOT NULL, + datatype character varying(8) NOT NULL, + descriptivename character varying(64) NOT NULL, + gridtype character varying(8) NOT NULL, + maxvalue real NOT NULL, + minvalue real NOT NULL, + "precision" integer NOT NULL, + rateparm boolean NOT NULL, + duration integer NOT NULL, + repeatinterval integer NOT NULL, + starttime integer NOT NULL, + valid boolean NOT NULL, + timeindependentparm boolean NOT NULL, + unitstring character varying(64) NOT NULL, + storagetype character varying(8) NOT NULL, + gridloc_id integer NOT NULL, + parmid_id integer NOT NULL, + CONSTRAINT gfe_parminfo_pkey PRIMARY KEY (id), + CONSTRAINT fk1871875338803a4d FOREIGN KEY (gridloc_id) + REFERENCES gfe_gridlocation (id) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE CASCADE, + CONSTRAINT fk187187537bab05cc FOREIGN KEY (parmid_id) + REFERENCES gfe_parmid (id) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE CASCADE, + CONSTRAINT gfe_parminfo_parmid_id_key UNIQUE (parmid_id) +) +WITH ( + OIDS=FALSE +); +ALTER TABLE gfe_parminfo + OWNER TO awips; + \ No newline at end of file diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/GridDbConfig.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/GridDbConfig.java index 3f68b5ee68..46c80ba889 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/GridDbConfig.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/GridDbConfig.java @@ -33,6 +33,7 @@ import com.raytheon.uf.common.dataplugin.gfe.db.objects.GFERecord.GridType; 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.ParmID; +import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmStorageInfo; import com.raytheon.uf.common.dataplugin.gfe.db.objects.TimeConstraints; import com.raytheon.uf.common.dataplugin.gfe.discrete.DiscreteDefinition; import com.raytheon.uf.common.dataplugin.gfe.weather.WxDefinition; @@ -46,6 +47,7 @@ import com.raytheon.uf.common.dataplugin.gfe.weather.WxDefinition; * ------------ ---------- ----------- -------------------------- * 03/14/08 #1030 randerso Initial port * 04/8/08 #875 bphillip Added getter for Grid Parm Info dictionary + * 08/05/2013 #1571 randerso Made GridParmInfo a field in ParmStorageInfo * * * @@ -56,8 +58,6 @@ import com.raytheon.uf.common.dataplugin.gfe.weather.WxDefinition; public class GridDbConfig { private final Log theLogger = LogFactory.getLog(this.getClass()); - private HashMap _gridInfoDict; - private HashMap _parmInfoDict; private WxDefinition _wxDefinition; @@ -108,33 +108,33 @@ public class GridDbConfig { int nentries = (int) (((maxV - minV) * dprecision)); // check for byte possibilities - if (nentries <= Math.pow(2.0, 8.0) - 1) { + if (nentries <= (Math.pow(2.0, 8.0) - 1)) { format.dataMultiplier = dprecision; format.dataOffset = 0; int minVarValue = 0; int maxVarValue = 255; - if (minV * format.dataMultiplier < minVarValue) { - format.dataOffset = minV - minVarValue / format.dataMultiplier; + if ((minV * format.dataMultiplier) < minVarValue) { + format.dataOffset = minV + - (minVarValue / format.dataMultiplier); } - if (maxV * format.dataMultiplier > maxVarValue) { - format.dataOffset = maxV - maxVarValue / format.dataMultiplier; + if ((maxV * format.dataMultiplier) > maxVarValue) { + format.dataOffset = maxV + - (maxVarValue / format.dataMultiplier); } format.storageFormat = "byte"; } // check for short possibilities - else if (nentries <= Math.pow(2.0, 16.0) - 2) { + else if (nentries <= (Math.pow(2.0, 16.0) - 2)) { format.dataMultiplier = dprecision; format.dataOffset = 0; double maxVarValue = Math.pow(2.0, 15.0) - 1; double minVarValue = -(Math.pow(2.0, 15.0) - 2); - if (minV * format.dataMultiplier < minVarValue) { - format.dataOffset = (float) (minV - minVarValue - / format.dataMultiplier); + if ((minV * format.dataMultiplier) < minVarValue) { + format.dataOffset = (float) (minV - (minVarValue / format.dataMultiplier)); } - if (maxV * format.dataMultiplier > maxVarValue) { - format.dataOffset = (float) (maxV - maxVarValue - / format.dataMultiplier); + if ((maxV * format.dataMultiplier) > maxVarValue) { + format.dataOffset = (float) (maxV - (maxVarValue / format.dataMultiplier)); } format.storageFormat = "short"; } @@ -156,11 +156,9 @@ public class GridDbConfig { * @param parmStorageInfo * @return */ - private boolean addParmInfo(final GridParmInfo gridParmInfo, - final ParmStorageInfo parmStorageInfo) { - String key = gridParmInfo.getParmID().getParmName() + "_" - + gridParmInfo.getParmID().getParmLevel(); - _gridInfoDict.put(key, gridParmInfo); + private boolean addParmInfo(final ParmStorageInfo parmStorageInfo) { + String key = parmStorageInfo.getParmName() + "_" + + parmStorageInfo.getParmLevel(); _parmInfoDict.put(key, parmStorageInfo); return true; @@ -258,10 +256,9 @@ public class GridDbConfig { calcKrunchValues(dataFormat, config.maxAllowedValue, config.minAllowedValue, precision, format); - ParmStorageInfo psi = new ParmStorageInfo(dataFormat, config.gridSize, - parmID.getParmName(), parmID.getParmLevel(), format.dataOffset, - format.dataMultiplier, format.storageFormat); - return addParmInfo(gpi, psi); + ParmStorageInfo psi = new ParmStorageInfo(dataFormat, gpi, + format.dataOffset, format.dataMultiplier, format.storageFormat); + return addParmInfo(psi); } /** @@ -280,7 +277,6 @@ public class GridDbConfig { this._wxDefinition = wxDef; this._discreteDefinition = dDef; this._projectionData = projectionData; - this._gridInfoDict = new HashMap(); this._parmInfoDict = new HashMap(); for (int i = 0; i < smc.grids.size(); i++) { @@ -302,8 +298,6 @@ public class GridDbConfig { this._wxDefinition = orig._wxDefinition; this._discreteDefinition = orig._discreteDefinition; this._projectionData = orig._projectionData; - this._gridInfoDict = (HashMap) orig._gridInfoDict - .clone(); this._parmInfoDict = (HashMap) orig._parmInfoDict .clone(); } @@ -320,7 +314,7 @@ public class GridDbConfig { public List parmAndLevelList() { List parmAndLevels = new ArrayList(); - for (String key : _gridInfoDict.keySet()) { + for (String key : _parmInfoDict.keySet()) { parmAndLevels.add(key); } @@ -340,7 +334,7 @@ public class GridDbConfig { public GridParmInfo getGridParmInfo(final String parmName, final String level) { String composite = parmName + "_" + level; - return _gridInfoDict.get(composite); + return _parmInfoDict.get(composite).getGridParmInfo(); } /** @@ -364,8 +358,10 @@ public class GridDbConfig { StringBuffer s = new StringBuffer(); s.append("GRID INFO DICT\n"); - for (Map.Entry entry : _gridInfoDict.entrySet()) { - s.append(entry.getKey() + ' ' + entry.getValue() + '\n'); + for (Map.Entry entry : _parmInfoDict + .entrySet()) { + s.append(entry.getKey() + ' ' + entry.getValue().getGridParmInfo() + + '\n'); } s.append("PARM INFO DICT\n"); @@ -402,8 +398,4 @@ public class GridDbConfig { public ProjectionData projectionData() { return this._projectionData; } - - public HashMap get_gridInfoDict() { - return _gridInfoDict; - } } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/IFPServerConfig.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/IFPServerConfig.java index c58e3ed5da..6a2c7ab168 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/IFPServerConfig.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/IFPServerConfig.java @@ -54,6 +54,7 @@ import com.raytheon.uf.common.dataplugin.gfe.weather.WxDefinition; * 06/24/08 #1160 randerso Added a method to get the Topo dbId * 07/09/09 #2590 njensen No longer singleton * 06/24/13 #2044 randerso Renamed satdirs to satdata to match serverConfig.py + * 08/14/2013 #1571 randerso Changed to use ProjectionType enum * * * @@ -453,7 +454,7 @@ public class IFPServerConfig { // common database grid location ProjectionData dProj = new ProjectionData(config.domain.projectionID, - config.domain.projectionType.ordinal(), config.domain.latLonLL, + config.domain.projectionType, config.domain.latLonLL, config.domain.latLonUR, config.domain.latLonOrigin, config.domain.stdParallelOne, config.domain.stdParallelTwo, config.domain.gridPointLL, config.domain.gridPointUR, diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/ParmStorageInfo.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/ParmStorageInfo.java deleted file mode 100644 index b394fcf716..0000000000 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/ParmStorageInfo.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * This software was developed and / or modified by Raytheon Company, - * pursuant to Contract DG133W-05-CQ-1067 with the US Government. - * - * U.S. EXPORT CONTROLLED TECHNICAL DATA - * This software product contains export-restricted data whose - * export/transfer/disclosure is restricted by U.S. law. Dissemination - * to non-U.S. persons whether in the United States or abroad requires - * an export license or other authorization. - * - * Contractor Name: Raytheon Company - * Contractor Address: 6825 Pine Street, Suite 340 - * Mail Stop B8 - * Omaha, NE 68106 - * 402.291.0100 - * - * See the AWIPS II Master Rights File ("Master Rights File.pdf") for - * further licensing information. - **/ -package com.raytheon.edex.plugin.gfe.config; - -import java.awt.Point; - -/** - * Derived class that consolidates storage info for a Parm. - * - *
- * SOFTWARE HISTORY
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * 03/14/08     #1030      randerso    Initial port
- * 
- * 
- * - * @author randerso - * @version 1.0 - */ - -public class ParmStorageInfo extends StorageInfo { - private String _parmName; - - private String _level; - - private float _dataOffset; - - private float _dataMultiplier; - - private String _dataType; - - public ParmStorageInfo(final String dataType, final Point gridSize, - final String parmName, final String level, float dataOffset, - float dataMultiplier, final String storageType) { - super(storageType, gridSize); - _parmName = parmName; - _level = level; - _dataOffset = dataOffset; - _dataMultiplier = dataMultiplier; - _dataType = dataType; - } - - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (!(obj instanceof ParmStorageInfo)) { - return false; - } - ParmStorageInfo rhs = (ParmStorageInfo) obj; - - if (!_parmName.equals(rhs.parmName()) || !_level.equals(rhs.level()) - || _dataOffset != rhs.dataOffset() - || _dataMultiplier != rhs.dataMultiplier() - || !_dataType.equals(rhs.dataType())) { - return false; - } - return true; - } - - public String parmName() { - return _parmName; - } - - public String level() { - return _level; - } - - public float dataOffset() { - return _dataOffset; - } - - public float dataMultiplier() { - return _dataMultiplier; - } - - public String dataType() { - return _dataType; - } - - @Override - public String toString() { - return "ParmStorageInfo for parm: " + parmName() + " Level: " + level() - + " DataType: " + dataType() + " GridSize: " + gridSize() - + " DataOffset: " + dataOffset() + " DataMultiplier: " - + dataMultiplier() + " StorageAreaName: " + storageAreaName() - + " StorageType: " + storageType(); - } -} diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/SimpleGridLocation.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/SimpleGridLocation.java index 17ead64b9a..3dfc8bbb32 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/SimpleGridLocation.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/SimpleGridLocation.java @@ -32,7 +32,8 @@ import com.vividsolutions.jts.geom.Coordinate; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * 03/13/08 #1030 randerso Initial port + * 03/13/08 #1030 randerso Initial port + * 08/09/2013 #1571 randerso Changed to use ProjectionType enum * * * @@ -52,9 +53,8 @@ public class SimpleGridLocation { // ProjectionData public String projectionID; - public ProjectionData.ProjectionType projectionType; // NONE, + public ProjectionData.ProjectionType projectionType; - // // LAMBERT_CONFORMAL, MERCATOR, POLAR_STEOGRAPHIC, LATLON public Coordinate latLonLL; public Coordinate latLonUR; @@ -82,14 +82,14 @@ public class SimpleGridLocation { } public SimpleGridLocation(Point gridSize, Coordinate origin, - Coordinate extent, String projID, int projType, Coordinate llll, - Coordinate llur, Coordinate llo, float sp1, float sp2, Point gpll, - Point gpur, float li, float lc, float lo) { + Coordinate extent, String projID, ProjectionType projType, + Coordinate llll, Coordinate llur, Coordinate llo, float sp1, + float sp2, Point gpll, Point gpur, float li, float lc, float lo) { this.gridSize = gridSize; this.domainOrigin = origin; this.domainExtent = extent; this.projectionID = projID; - this.projectionType = ProjectionType.values()[projType]; + this.projectionType = projType; this.latLonLL = llll; this.latLonUR = llur; this.latLonOrigin = llo; diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/StorageInfo.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/StorageInfo.java deleted file mode 100644 index 3de93bee4c..0000000000 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/StorageInfo.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * This software was developed and / or modified by Raytheon Company, - * pursuant to Contract DG133W-05-CQ-1067 with the US Government. - * - * U.S. EXPORT CONTROLLED TECHNICAL DATA - * This software product contains export-restricted data whose - * export/transfer/disclosure is restricted by U.S. law. Dissemination - * to non-U.S. persons whether in the United States or abroad requires - * an export license or other authorization. - * - * Contractor Name: Raytheon Company - * Contractor Address: 6825 Pine Street, Suite 340 - * Mail Stop B8 - * Omaha, NE 68106 - * 402.291.0100 - * - * See the AWIPS II Master Rights File ("Master Rights File.pdf") for - * further licensing information. - **/ -package com.raytheon.edex.plugin.gfe.config; - -import java.awt.Point; - -/** - * StorageInfo is a base class for AreaStorageInfo and ParmStorageInfo. This - * contains the storage type and grid size. Storage type may be byte, short, or - * float. - * - *
- * SOFTWARE HISTORY
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * 03/18/08     #1030      randerso    Initial port
- * 
- * 
- * - * @author randerso - * @version 1.0 - */ - -public abstract class StorageInfo { - // TODO: if we don't end up porting AreaStorageInfo we should combine this - // with ParmStorageInfo - private String _storageType; - - private Point _gridSize; - - private String _storageAreaName; - - protected StorageInfo(final String storageType, final Point gridSize) { - this._storageType = storageType; - this._gridSize = gridSize; - this._storageAreaName = makeStorageAreaName(storageType, gridSize); - } - - public final String storageType() { - return _storageType; - } - - public final Point gridSize() { - return _gridSize; - } - - public final String storageAreaName() { - return _storageAreaName; - } - - public boolean equals(Object obj) { - if (obj == null) { - - } - if (!(obj instanceof StorageInfo)) { - return false; - } - StorageInfo rhs = (StorageInfo) obj; - if (!_storageType.equals(rhs.storageType()) - || !_gridSize.equals(rhs.gridSize())) { - return false; - } - - return true; - } - - /** - * Generates and returns a TextString that uniquely identifies the storage - * info. This string is a concatenation of the storageType and gridSize. - * - * @param storageType - * @param gridSize - * @return - */ - static String makeStorageAreaName(final String storageType, - final Point gridSize) { - return storageType + gridSize.x + 'x' + gridSize.y; - } -} diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFEDao.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFEDao.java index 6e190df30c..e127deea6d 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFEDao.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFEDao.java @@ -50,7 +50,9 @@ import com.raytheon.uf.common.dataplugin.PluginException; import com.raytheon.uf.common.dataplugin.gfe.GridDataHistory; import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID; 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.ParmID; +import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmStorageInfo; import com.raytheon.uf.common.dataplugin.gfe.server.notify.GridUpdateNotification; import com.raytheon.uf.common.dataplugin.gfe.server.notify.LockNotification; import com.raytheon.uf.common.dataplugin.gfe.util.GfeUtil; @@ -98,6 +100,8 @@ import com.raytheon.uf.edex.database.query.DatabaseQuery; * 07/30/13 #2057 randerso Added support marking and eventually purging obsolete databases * 08/08/13 DR16485 ryu Remove call to getDatabaseId() from getMaxInsertTimeByDbId() * so new GFE databases aren't accidentally created. + * 08/05/13 #1571 randerso Added support for storing GridLocation and ParmStorageInfo in database + * * * * @author bphillip @@ -219,13 +223,13 @@ public class GFEDao extends DefaultPluginDao { } /** - * Retrieves all known parm ids for the given database id. + * Retrieves ParmStorageInfo for all known ParmIDs for the given DatabaseID. * * @param dbId - * @return the list of ParmIDs for the database + * @return the list of ParmStorageInfo for the database * @throws DataAccessLayerException */ - public List getParmIds(final DatabaseID dbId) + public List getParmStorageInfo(final DatabaseID dbId) throws DataAccessLayerException { Session sess = null; Transaction tx = null; @@ -240,11 +244,17 @@ public class GFEDao extends DefaultPluginDao { // relations sess.buildLockRequest(LockOptions.NONE).lock(dbId); - Query query = sess.createQuery("FROM ParmID WHERE dbId = ?"); + Query query = sess + .createQuery("FROM ParmStorageInfo WHERE gridParmInfo.parmID.dbId = ?"); query.setParameter(0, dbId); @SuppressWarnings("unchecked") - List list = query.list(); + List list = query.list(); tx.commit(); + + // initialize the grid location objects + for (ParmStorageInfo psi : list) { + psi.getGridParmInfo().getGridLoc().init(); + } return list; } catch (Exception e) { if (tx != null) { @@ -256,7 +266,7 @@ public class GFEDao extends DefaultPluginDao { } throw new DataAccessLayerException( - "Unable to look up parm id inventory for database id " + "Unable to retrieve ParmStorageInfos for DatabaseID: " + dbId, e); } finally { if (sess != null) { @@ -270,6 +280,100 @@ public class GFEDao extends DefaultPluginDao { } } + /** + * Stores a list of ParmStorageInfo + * + * @param psiList + * @throws DataAccessLayerException + */ + public void saveParmStorageInfo(List psiList) + throws DataAccessLayerException { + + if (psiList.isEmpty()) { + return; + } + + StatelessSession sess = null; + Transaction tx = null; + + try { + sess = getHibernateTemplate().getSessionFactory() + .openStatelessSession(); + tx = sess.beginTransaction(); + + for (ParmStorageInfo psi : psiList) { + sess.insert(psi); + } + + tx.commit(); + return; + } catch (Exception e) { + if (tx != null) { + try { + tx.rollback(); + } catch (Exception e1) { + logger.error("Error occurred rolling back transaction", e1); + } + } + + throw new DataAccessLayerException( + "Unable to save ParmStorageInfos for " + + psiList.get(0).getParmID().getDbId(), e); + } finally { + if (sess != null) { + try { + sess.close(); + } catch (Exception e) { + statusHandler.error( + "Error occurred closing database session", e); + } + } + } + } + + /** + * Update a ParmStorageInfo + * + * @param psi + * @throws DataAccessLayerException + */ + public void updateParmStorageInfo(ParmStorageInfo psi) + throws DataAccessLayerException { + + StatelessSession sess = null; + Transaction tx = null; + + try { + sess = getHibernateTemplate().getSessionFactory() + .openStatelessSession(); + tx = sess.beginTransaction(); + sess.update(psi); + tx.commit(); + return; + } catch (Exception e) { + if (tx != null) { + try { + tx.rollback(); + } catch (Exception e1) { + logger.error("Error occurred rolling back transaction", e1); + } + } + + throw new DataAccessLayerException( + "Unable to update ParmStorageInfos for " + psi.getParmID(), + e); + } finally { + if (sess != null) { + try { + sess.close(); + } catch (Exception e) { + statusHandler.error( + "Error occurred closing database session", e); + } + } + } + } + /** * Returns the database row for the passed parmId. If the row does not * exist, the row will be created. @@ -353,7 +457,7 @@ public class GFEDao extends DefaultPluginDao { * transaction. * * @param sess - * @param dbId + * @param parmId * @return */ private ParmID getParmId(Session sess, ParmID parmId) { @@ -960,8 +1064,7 @@ public class GFEDao extends DefaultPluginDao { } /** - * Removes GridParmInfo from the HDF5 file and any data associated with that - * info + * Removes all grids associated with a parm * * @param parmId * The parm to delete data for @@ -969,20 +1072,8 @@ public class GFEDao extends DefaultPluginDao { * If errors occur */ public void removeParmData(ParmID parmId) throws DataAccessLayerException { - - try { - IDataStore ds = DataStoreFactory.getDataStore(GfeUtil - .getGridParmHdf5File(GridDatabase.gfeBaseDataDir, - parmId.getDbId())); - ds.deleteDatasets("/GridParmInfo/" + parmId.getCompositeName(), - "/GridParmStorageInfo/" + parmId.getCompositeName()); - } catch (Exception e1) { - throw new DataAccessLayerException("Error deleting data from HDF5", - e1); - } List trs = this.getTimes(parmId); this.deleteRecords(parmId, trs); - // TODO: Remove all Locks?? } /** @@ -1317,4 +1408,45 @@ public class GFEDao extends DefaultPluginDao { } } } + + /** + * Save or update a GridLocation object + * + * @param gloc + * the GridLocation object + * @throws DataAccessLayerException + */ + public void saveOrUpdateGridLocation(GridLocation gloc) + throws DataAccessLayerException { + Session sess = null; + Transaction tx = null; + + try { + sess = getHibernateTemplate().getSessionFactory().openSession(); + tx = sess.beginTransaction(); + sess.saveOrUpdate(gloc); + tx.commit(); + return; + } catch (Exception e) { + if (tx != null) { + try { + tx.rollback(); + } catch (Exception e1) { + logger.error("Error occurred rolling back transaction", e1); + } + } + + throw new DataAccessLayerException( + "Unable to save GridLocation for " + gloc.getSiteId(), e); + } finally { + if (sess != null) { + try { + sess.close(); + } catch (Exception e) { + statusHandler.error( + "Error occurred closing database session", e); + } + } + } + } } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/GridDatabase.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/GridDatabase.java index 1f5747478e..2f49c42569 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/GridDatabase.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/GridDatabase.java @@ -21,7 +21,6 @@ package com.raytheon.edex.plugin.gfe.server.database; import java.io.File; -import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -39,10 +38,6 @@ import com.raytheon.uf.common.dataplugin.gfe.slice.IGridSlice; import com.raytheon.uf.common.dataplugin.gfe.util.GfeUtil; import com.raytheon.uf.common.datastorage.DataStoreFactory; import com.raytheon.uf.common.datastorage.IDataStore; -import com.raytheon.uf.common.datastorage.Request; -import com.raytheon.uf.common.datastorage.records.ByteDataRecord; -import com.raytheon.uf.common.datastorage.records.FloatDataRecord; -import com.raytheon.uf.common.datastorage.records.IDataRecord; import com.raytheon.uf.common.message.WsId; import com.raytheon.uf.common.time.TimeRange; import com.raytheon.uf.common.util.Pair; @@ -76,6 +71,8 @@ import com.raytheon.uf.common.util.Pair; * and cachedParmId * 05/02/13 #1969 randerso Removed unnecessary updateDbs method * 06/13/13 #2044 randerso Code cleanup + * 08/13/13 #1571 randerso Moved retrieveFromHDF5 methods into IFPGridDatabase + * * * * @author bphillip @@ -110,245 +107,19 @@ public abstract class GridDatabase { * * @param dbId * The database ID for this database - * @param gridConfig - * The configuration information for this database */ protected GridDatabase(DatabaseID dbId) { this.dbId = dbId; } /** - * Retrieve the FloatDataRecord for a grid from HDF5 - * - * @param parmId - * @param time - * @return the FloatDataRecord - * @throws GfeException - */ - public FloatDataRecord retrieveFromHDF5(ParmID parmId, TimeRange time) - throws GfeException { - return retrieveFromHDF5(parmId, Arrays.asList(new TimeRange[] { time }))[0]; - } - - /** - * Retrieve FloatDataRecords for a multiple time ranges from HDF5 + * Returns the mapping of ParmIds and TimeRanges to DataStores and groups + * where the data should be stored. * * @param parmId * @param times - * @return the FloatDataRecords - * @throws GfeException + * @return mapping */ - public FloatDataRecord[] retrieveFromHDF5(ParmID parmId, - List times) throws GfeException { - FloatDataRecord[] scalarData = null; - Map, String[]>> dsAndGroups = getDataStoreAndGroups( - parmId, times); - - try { - Map records = new HashMap( - (int) (1.25 * times.size()) + 1); - - // loop over the dataStores and their respective groups to pull all - // data, stored into records to reorder requests by times - for (Map.Entry, String[]>> entry : dsAndGroups - .entrySet()) { - Pair, String[]> pair = entry.getValue(); - String[] groups = pair.getSecond(); - - IDataRecord[] rawData = entry.getKey().retrieveGroups(groups, - Request.ALL); - - if (rawData.length != groups.length) { - throw new IllegalArgumentException( - "Invalid number of dataSets returned expected 1 per group, received: " - + ((double) rawData.length / groups.length)); - } - - int count = 0; - for (TimeRange timeRange : pair.getFirst()) { - records.put(timeRange, (FloatDataRecord) rawData[count++]); - } - } - - scalarData = new FloatDataRecord[times.size()]; - int count = 0; - for (TimeRange timeRange : times) { - scalarData[count++] = records.get(timeRange); - } - } catch (Exception e) { - throw new GfeException("Unable to get data from HDF5 for ParmID: " - + parmId + " TimeRange: " + times, e); - } - - return scalarData; - } - - /** - * Retrieve the magnitude and direction grids for a vector parm from HDF5 - * - * @param parmId - * @param time - * @return the the magnitude and direction grids - * @throws GfeException - */ - public FloatDataRecord[] retrieveVectorFromHDF5(ParmID parmId, - TimeRange time) throws GfeException { - return retrieveVectorFromHDF5(parmId, - Arrays.asList(new TimeRange[] { time }))[0]; - } - - /** - * Retrieve the magnitude and direction grids for multiple time ranges for a - * vector parm from HDF5 - * - * @param parmId - * @param times - * @return array of magnitude and direction grids - * @throws GfeException - */ - public FloatDataRecord[][] retrieveVectorFromHDF5(ParmID parmId, - List times) throws GfeException { - FloatDataRecord[][] vectorData = null; - Map, String[]>> dsAndGroups = getDataStoreAndGroups( - parmId, times); - - try { - Map records = new HashMap( - (int) (1.25 * times.size()) + 1); - - // loop over the dataStores and their respective groups to pull all - // data, stored into records to reorder requests by times - for (Map.Entry, String[]>> entry : dsAndGroups - .entrySet()) { - Pair, String[]> pair = entry.getValue(); - String[] groups = pair.getSecond(); - - IDataRecord[] rawData = entry.getKey().retrieveGroups(groups, - Request.ALL); - - if (rawData.length != (groups.length * 2)) { - throw new IllegalArgumentException( - "Invalid number of dataSets returned expected per group, received: " - + ((double) rawData.length / groups.length)); - } - - // iterate over the data from this dataStore adding it records - int count = 0; - for (TimeRange timeRange : pair.getFirst()) { - FloatDataRecord[] recs = new FloatDataRecord[2]; - for (int i = 0; i < 2; i++) { - IDataRecord rec = rawData[(count * 2) + i]; - if ("Mag".equals(rec.getName())) { - recs[0] = (FloatDataRecord) rec; - } else if ("Dir".equals(rec.getName())) { - recs[1] = (FloatDataRecord) rec; - } else { - throw new IllegalArgumentException( - "Unknown dataset retrieved for vector data. Valid values: Mag, Dir Received: " - + rec.getName()); - } - } - records.put(timeRange, recs); - count++; - } - } - - vectorData = new FloatDataRecord[times.size()][2]; - int count = 0; - for (TimeRange timeRange : times) { - vectorData[count++] = records.get(timeRange); - } - } catch (Exception e) { - throw new GfeException("Unable to get data from HDF5 for ParmID: " - + parmId + " TimeRange: " + times, e); - } - - return vectorData; - } - - /** - * Retrieves the data and keys for a Discrete grid from HDF5 - * - * @param parmId - * @param time - * @return ByteDataRecords[] array containing the data and keys - * @throws GfeException - */ - public ByteDataRecord[] retrieveDiscreteFromHDF5(ParmID parmId, - TimeRange time) throws GfeException { - return retrieveDiscreteFromHDF5(parmId, - Arrays.asList(new TimeRange[] { time }))[0]; - } - - /** - * Retrieves the ByteDataRecord for a Discrete grid for multiple time ranges - * from HDF5 - * - * @param parmId - * @param times - * @return array containing the data and keys for the specified times - * @throws GfeException - */ - public ByteDataRecord[][] retrieveDiscreteFromHDF5(ParmID parmId, - List times) throws GfeException { - ByteDataRecord[][] byteRecords = null; - Map, String[]>> dsAndGroups = getDataStoreAndGroups( - parmId, times); - - try { - // loop over the dataStores and their respective groups to pull all - // data - Map records = new HashMap( - (int) (1.25 * times.size()) + 1); - - for (Map.Entry, String[]>> entry : dsAndGroups - .entrySet()) { - Pair, String[]> pair = entry.getValue(); - String[] groups = pair.getSecond(); - - IDataRecord[] rawData = entry.getKey().retrieveGroups(groups, - Request.ALL); - - if (rawData.length != (groups.length * 2)) { - throw new IllegalArgumentException( - "Invalid number of dataSets returned expected 2 per group, received: " - + ((double) rawData.length / groups.length)); - } - - // iterate over the data from this dataStore adding it records - int count = 0; - for (TimeRange timeRange : pair.getFirst()) { - ByteDataRecord[] recs = new ByteDataRecord[2]; - for (int i = 0; i < 2; i++) { - IDataRecord rec = rawData[(count * 2) + i]; - - if ("Data".equals(rec.getName())) { - recs[0] = (ByteDataRecord) rec; - } else if ("Keys".equals(rec.getName())) { - recs[1] = (ByteDataRecord) rec; - } else { - throw new IllegalArgumentException( - "Unknown dataset retrieved for vector data. Valid values: Data, Keys Received: " - + rec.getName()); - } - } - records.put(timeRange, recs); - count++; - } - } - - byteRecords = new ByteDataRecord[times.size()][2]; - int count = 0; - for (TimeRange timeRange : times) { - byteRecords[count++] = records.get(timeRange); - } - } catch (Exception e) { - throw new GfeException("Unable to get data from HDF5 for ParmID: " - + parmId + " TimeRange: " + times, e); - } - return byteRecords; - } - protected Map, String[]>> getDataStoreAndGroups( ParmID parmId, List times) { Map, String[]>> fileMap = GfeUtil diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/IFPGridDatabase.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/IFPGridDatabase.java index 2b63370bfd..a84ae30caa 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/IFPGridDatabase.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/IFPGridDatabase.java @@ -20,7 +20,6 @@ package com.raytheon.edex.plugin.gfe.server.database; -import java.awt.Point; import java.io.File; import java.util.ArrayList; import java.util.Arrays; @@ -28,32 +27,24 @@ import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.regex.Pattern; -import javax.measure.converter.UnitConverter; -import javax.measure.unit.Unit; - import com.raytheon.edex.plugin.gfe.config.GridDbConfig; -import com.raytheon.edex.plugin.gfe.config.IFPServerConfig; -import com.raytheon.edex.plugin.gfe.config.IFPServerConfigManager; -import com.raytheon.edex.plugin.gfe.config.ParmStorageInfo; import com.raytheon.edex.plugin.gfe.db.dao.GFEDao; -import com.raytheon.edex.plugin.gfe.exception.GfeConfigurationException; -import com.raytheon.uf.common.dataplugin.PluginException; import com.raytheon.uf.common.dataplugin.gfe.GridDataHistory; import com.raytheon.uf.common.dataplugin.gfe.RemapGrid; -import com.raytheon.uf.common.dataplugin.gfe.config.ProjectionData; -import com.raytheon.uf.common.dataplugin.gfe.config.ProjectionData.ProjectionType; import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID; import com.raytheon.uf.common.dataplugin.gfe.db.objects.GFERecord; import com.raytheon.uf.common.dataplugin.gfe.db.objects.GFERecord.GridType; 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.ParmID; +import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmStorageInfo; import com.raytheon.uf.common.dataplugin.gfe.db.objects.TimeConstraints; import com.raytheon.uf.common.dataplugin.gfe.discrete.DiscreteKey; import com.raytheon.uf.common.dataplugin.gfe.exception.GfeException; @@ -92,8 +83,6 @@ import com.raytheon.uf.common.time.util.TimeUtil; import com.raytheon.uf.common.util.Pair; import com.raytheon.uf.edex.core.dataplugin.PluginRegistry; import com.raytheon.uf.edex.database.DataAccessLayerException; -import com.raytheon.uf.edex.database.plugin.PluginFactory; -import com.vividsolutions.jts.geom.Coordinate; /** * GFE Grid database containing IFP Grid data. All public methods that take a @@ -121,6 +110,8 @@ import com.vividsolutions.jts.geom.Coordinate; * 05/02/13 #1969 randerso Removed updateDbs from parent class * 06/13/13 #2044 randerso Pass in GridDbConfig as construction parameter * 07/30/13 #2057 randerso Added a static deleteDatabase method + * 08/05/13 #1571 randerso Refactored to store GridParmInfo and ParmStorageinfo in postgres database + * * * * @author bphillip @@ -135,141 +126,128 @@ public class IFPGridDatabase extends GridDatabase { private final IPerformanceStatusHandler perfLog = PerformanceStatus .getHandler("GFE:"); - protected static final String GRID_PARM_INFO = "GridParmInfo"; - - protected static final String GRID_PARM_STORAGE_INFO = "GridParmStorageInfo"; - - protected static final String GRID_PARM_INFO_GRP = File.separator - + GRID_PARM_INFO + File.separator; - - protected static final String GRID_PARM_STORAGE_INFO_GRP = File.separator - + GRID_PARM_STORAGE_INFO + File.separator; - - private boolean parmInfoInitialized = false; - private static final float VECTOR_DIR_DATA_MULTIPLIER = 0.5f; private static final float VECTOR_DIR_DATA_OFFSET = 0.0f; - private final Map parmInfo = new HashMap(); - - private final Map parmStorageInfo = new HashMap(); - - private final Map parmIdMap = new HashMap(); + private Map parmStorageInfo = new HashMap(); /** The grid configuration for this database */ - protected GridDbConfig gridConfig; + protected GridDbConfig gridDbConfig; + + private GFEDao dao; /** * Creates a new IFPGridDatabase * * @param dbId * The database ID for this database - * @param gridConfig + * @param gridDbConfig * the database configuration */ - public IFPGridDatabase(DatabaseID dbId, GridDbConfig gridConfig) { + public IFPGridDatabase(DatabaseID dbId, GridDbConfig gridDbConfig) { super(dbId); - this.gridConfig = gridConfig; + this.gridDbConfig = gridDbConfig; this.valid = true; + ServerResponse failResponse = new ServerResponse(); try { // lookup actual database id row from database // if it doesn't exist, it will be created at this point - GFEDao dao = new GFEDao(); + this.dao = new GFEDao(); + + // Make a DatabaseID and save it. this.dbId = dao.getDatabaseId(dbId); } catch (Exception e) { - statusHandler.handle(Priority.PROBLEM, - "Unable to look up database id for ifp database: " + dbId, - e); - this.valid = false; + String msg = "Unable to look up database id for ifp database: " + + dbId; + statusHandler.handle(Priority.PROBLEM, msg, e); + failResponse.addMessage(msg); } - - this.updateDbs(); - } - - /** - * Upon site activation, this method is called to calculate any changes to - * parm info or grid locations - */ - public void updateDbs() { - Map parmInfoUser = new HashMap(); - Map parmStorageInfoUser = new HashMap(); - - try { - getDBConfiguration(); - applyProjectionAndDomainChanges(); - } catch (GfeException e) { - statusHandler.handle(Priority.PROBLEM, - "Error getting db configuration for " + this.dbId, e); - } - - if (!this.getUserConfiguration(parmInfoUser, parmStorageInfoUser)) { + if (!failInitCheck(failResponse)) { return; } + // Get the current database configuration and store the information + // in private data _parmInfo, _parmStorageInfo, and _areaStorageInfo + failResponse.addMessages(getDBConfiguration()); + if (!failInitCheck(failResponse)) { + return; + } + + // Get the current user configuration file + ServerResponse> ssr = getUserConfiguration(); + failResponse.addMessages(ssr); + if (!failInitCheck(failResponse)) { + return; + } + Map parmStorageInfoUser = ssr.getPayload(); + List toBeAddedParms = new ArrayList(); List toBeRemovedParms = new ArrayList(); List toBeChangedParms = new ArrayList(); // Compare the variables in the database with config - compareParmInfoWithDB(parmInfoUser, parmStorageInfoUser, - toBeAddedParms, toBeRemovedParms, toBeChangedParms); + compareParmInfoWithDB(parmStorageInfoUser, toBeAddedParms, + toBeRemovedParms, toBeChangedParms); + + // handle any projection and domain change + failResponse + .addMessages(applyProjectionAndDomainChanges(parmStorageInfoUser)); + if (!failInitCheck(failResponse)) { + return; + } // Add in new weather elements - addNewParms(toBeAddedParms, parmInfoUser, parmStorageInfoUser); + failResponse.addMessages(addNewParms(toBeAddedParms, + parmStorageInfoUser)); + if (!failInitCheck(failResponse)) { + return; + } // Remove all old parms removeOldParms(toBeRemovedParms); // accommodate changes - changeParmCharacteristics(toBeChangedParms, parmInfoUser, - parmStorageInfoUser); - - // verify current parms are still in database - can be removed once - // gridParamInfo is in database - try { - GFEDao dao = new GFEDao(); - for (String item : parmInfo.keySet()) { - if (!parmIdMap.containsKey(item)) { - String[] nameLevel = splitNameAndLevel(item); - ParmID parmId = new ParmID(nameLevel[0], dbId, nameLevel[1]); - parmIdMap.put(item, dao.getParmId(parmId)); - } - } - } catch (Exception e) { - statusHandler.handle(Priority.PROBLEM, - "Error getting db configuration for " + this.dbId, e); - } + changeParmCharacteristics(toBeChangedParms, parmStorageInfoUser); } - private void addNewParms(List newParms, - Map parmInfoUser, + private boolean failInitCheck(ServerResponse failResponse) { + if (!failResponse.isOkay()) { + statusHandler.error("DatabaseFAIL: " + this.dbId + "\n" + + failResponse.getMessages()); + this.valid = false; + } + return this.valid; + } + + private ServerResponse addNewParms(List newParms, Map parmStorageUser) { + ServerResponse sr = new ServerResponse(); if (newParms.isEmpty()) { - return; + return sr; } statusHandler.handle(Priority.INFO, "Creating new weather elements..."); try { - List gpis = new ArrayList( - newParms.size()); List psis = new ArrayList( newParms.size()); - GFEDao dao = new GFEDao(); for (String item : newParms) { String[] nameLevel = splitNameAndLevel(item); - ParmID parmId = new ParmID(nameLevel[0], dbId, nameLevel[1]); - parmIdMap.put(item, dao.getParmId(parmId)); - statusHandler.handle(Priority.INFO, "Adding: " + item - + " to the " + this.dbId + " database."); - gpis.add(parmInfoUser.get(item)); - psis.add(parmStorageUser.get(item)); + ParmID parmId = dao.getParmId(new ParmID(nameLevel[0], dbId, + nameLevel[1])); + statusHandler.debug("Adding: " + item + " to the " + this.dbId + + " database."); + ParmStorageInfo psi = parmStorageUser.get(item); + psi.getGridParmInfo().resetParmID(parmId); + parmStorageInfo.put(item, psi); + psis.add(psi); } - storeGridParmInfo(gpis, psis, StoreOp.STORE_ONLY); + dao.saveParmStorageInfo(psis); } catch (Exception e) { statusHandler.handle(Priority.PROBLEM, "Error adding new parms", e); + sr.addMessage("Error adding new parms"); } - + return sr; } /** @@ -277,26 +255,33 @@ public class IFPGridDatabase extends GridDatabase { * * @param toBeChangedParms * The parms whose info has changed - * @param parmInfoUser - * The GridParmInfo to update to + * @param parmStorageUser + * The ParmStorageInfo to update to */ private void changeParmCharacteristics(List toBeChangedParms, - Map parmInfoUser, Map parmStorageUser) { - for (int i = 0; i < toBeChangedParms.size(); i++) { - // Denotes whether the units were changed - boolean unitsChanged = false; String compositeName = toBeChangedParms.get(i); // get the current database information - GridParmInfo dbGPI = this.parmInfo.get(compositeName); ParmStorageInfo dbPSI = this.parmStorageInfo.get(compositeName); + GridParmInfo dbGPI = dbPSI.getGridParmInfo(); // get the desired configuration - GridParmInfo userGPI = parmInfoUser.get(compositeName); ParmStorageInfo userPSI = parmStorageUser.get(compositeName); + GridParmInfo userGPI = userPSI.getGridParmInfo(); + + // update the parm info in postgres + try { + userGPI.setParmID(dbGPI.getParmID()); + userPSI.setId(dbPSI.getId()); + dao.updateParmStorageInfo(userPSI); + } catch (DataAccessLayerException e) { + statusHandler.error("Error updating parm info for " + + userPSI.getGridParmInfo().getParmID(), e); + continue; + } // data type change if (!userGPI.getGridType().equals(dbGPI.getGridType())) { @@ -304,7 +289,7 @@ public class IFPGridDatabase extends GridDatabase { + dbGPI.getParmID() + " from " + dbGPI.getGridType() + " to " + userGPI.getGridType()); - changeDataType(compositeName, userGPI, userPSI); + changeDataType(dbGPI.getParmID()); } // unit change @@ -314,8 +299,9 @@ public class IFPGridDatabase extends GridDatabase { "Changing Units: " + dbGPI.getParmID() + " from " + dbGPI.getUnitString() + " to " + userGPI.getUnitString()); - changeUnits(compositeName, userGPI); - unitsChanged = true; + // Only changes stored unit string, does not convert values + // This is intended to correct incorrectly labeled units not + // change stored data. } // rate parm change @@ -333,7 +319,7 @@ public class IFPGridDatabase extends GridDatabase { "Changing TimeConstraints: " + dbGPI.getParmID() + " from " + dbGPI.getTimeConstraints() + " to " + userGPI.getTimeConstraints()); - adjustTimeConstraints(compositeName, + adjustTimeConstraints(dbGPI.getParmID(), userGPI.getTimeConstraints()); } @@ -358,9 +344,11 @@ public class IFPGridDatabase extends GridDatabase { // max/min changes if ((userGPI.getMaxValue() != dbGPI.getMaxValue()) || (userGPI.getMinValue() != dbGPI.getMinValue()) - || unitsChanged || !userPSI.equals(dbPSI)) { - // If units were changed, the values need to be clamped to the - // min and max values + || !userPSI.getStorageType().equals(dbPSI.getStorageType()) + || !userPSI.getDataType().equals(dbPSI.getDataType()) + || (userPSI.getDataMultiplier() != dbPSI + .getDataMultiplier()) + || (userPSI.getDataOffset() != dbPSI.getDataOffset())) { if ((userGPI.getMaxValue() != dbGPI.getMaxValue()) || (userGPI.getMinValue() != dbGPI.getMinValue())) { statusHandler.handle( @@ -371,38 +359,27 @@ public class IFPGridDatabase extends GridDatabase { + userGPI.getMinValue() + "," + userGPI.getMaxValue() + ")"); } - if (userPSI.dataOffset() != dbPSI.dataOffset()) { - statusHandler.handle(Priority.INFO, "Changing DataOffset: " - + dbGPI.getParmID() + " from " + dbPSI.dataOffset() - + " to " + userPSI.dataOffset()); + if (userPSI.getDataOffset() != dbPSI.getDataOffset()) { + statusHandler.handle(Priority.INFO, + "Changing DataOffset: " + dbGPI.getParmID() + + " from " + dbPSI.getDataOffset() + " to " + + userPSI.getDataOffset()); } - if (userPSI.dataMultiplier() != dbPSI.dataMultiplier()) { + if (userPSI.getDataMultiplier() != dbPSI.getDataMultiplier()) { statusHandler.handle(Priority.INFO, "Changing DataMultiplier: " + dbGPI.getParmID() - + " from " + dbPSI.dataMultiplier() - + " to " + userPSI.dataMultiplier()); + + " from " + dbPSI.getDataMultiplier() + + " to " + userPSI.getDataMultiplier()); } - if (!userPSI.storageType().equals(dbPSI.storageType())) { + if (!userPSI.getStorageType().equals(dbPSI.getStorageType())) { statusHandler.handle(Priority.INFO, "Changing StorageType: " + dbGPI.getParmID() - + " from " + dbPSI.storageType() + " to " - + userPSI.storageType()); + + " from " + dbPSI.getStorageType() + + " to " + userPSI.getStorageType()); } - changeMinMaxValues(compositeName, userGPI, userPSI); + changeMinMaxValues(compositeName, dbPSI, userPSI); } - - // store the updated GridParmInfo - dbGPI = new GridParmInfo(dbGPI.getParmID(), dbGPI.getGridLoc(), - userGPI.getGridType(), userGPI.getUnitString(), - userGPI.getDescriptiveName(), userGPI.getMinValue(), - userGPI.getMaxValue(), userGPI.getPrecision(), - userGPI.isTimeIndependentParm(), - userGPI.getTimeConstraints(), userGPI.isRateParm()); - dbPSI = new ParmStorageInfo(userPSI.dataType(), userGPI - .getGridLoc().gridSize(), dbPSI.parmName(), dbPSI.level(), - userPSI.dataOffset(), userPSI.dataMultiplier(), - userPSI.storageType()); - updateParmAttributes(compositeName, userGPI, userPSI); + this.parmStorageInfo.put(compositeName, userPSI); } } @@ -413,11 +390,16 @@ public class IFPGridDatabase extends GridDatabase { * * @param compositeName * The parm name for which the min/max values have changed - * @param newGPI - * The GridParmInfo + * @param oldPSI + * The old ParmStorageInfo + * @param newPSI + * The new ParmStorageInfo */ - private void changeMinMaxValues(String compositeName, GridParmInfo newGPI, - ParmStorageInfo newPSI) { + private void changeMinMaxValues(String compositeName, + ParmStorageInfo oldPSI, ParmStorageInfo newPSI) { + + GridParmInfo newGPI = newPSI.getGridParmInfo(); + // Make sure the specified parm is of type Scalar or Vector GridType gridType = newGPI.getGridType(); if (!(gridType.equals(GridType.SCALAR) || gridType @@ -430,7 +412,6 @@ public class IFPGridDatabase extends GridDatabase { try { parmId = getCachedParmID(compositeName); - GFEDao dao = new GFEDao(); records = dao.queryByParmID(parmId); } catch (Exception e) { statusHandler.handle(Priority.PROBLEM, @@ -456,7 +437,7 @@ public class IFPGridDatabase extends GridDatabase { } try { scalarRecord = this.retrieveFromHDF5(parmId, - rec.getTimeRange()); + rec.getTimeRange(), oldPSI); } catch (GfeException e) { statusHandler.handle(Priority.PROBLEM, "Error changing min/max values. Unable to retrieve data from HDF5 " @@ -485,7 +466,7 @@ public class IFPGridDatabase extends GridDatabase { vSlice = (VectorGridSlice) result.getPayload().get(0); try { vectorRecord = this.retrieveVectorFromHDF5(parmId, - rec.getTimeRange()); + rec.getTimeRange(), oldPSI); } catch (GfeException e) { statusHandler .handle(Priority.PROBLEM, @@ -529,16 +510,21 @@ public class IFPGridDatabase extends GridDatabase { * Adjusts the time constraints for a given parm. This method simply deletes * any grids that are in the db for the modified ParmID * - * @param compositeName - * The parm name that needs to be modified + * @param parmId + * The parm that needs to be modified * @param timeConstraints * The new time constraints */ - private void adjustTimeConstraints(String compositeName, + private void adjustTimeConstraints(ParmID parmId, TimeConstraints timeConstraints) { - List puntList = new ArrayList(); - puntList.add(compositeName); - this.removeOldParmData(puntList); + + // TODO: re-implement from A1 + + try { + dao.removeParmData(parmId); + } catch (DataAccessLayerException e) { + statusHandler.error("Error removing data for " + parmId, e); + } } /** @@ -561,130 +547,19 @@ public class IFPGridDatabase extends GridDatabase { } } - /** - * Changes the units for a parm. This method also executes a unit conversion - * on the data in the HDF5 repository - * - * @param compositeName - * The parm to be modified - * @param gpi - * The grid parm info - */ - private void changeUnits(String compositeName, GridParmInfo gpi) { - GFEDao dao = null; - try { - GridType gridType = gpi.getGridType(); - ParmID parmId = new ParmID( - this.splitNameAndLevel(compositeName)[0], this.dbId); - dao = new GFEDao(); - List records = dao.queryByParmID(parmId); - if (!records.isEmpty()) { - for (GFERecord rec : records) { - switch (gridType) { - case SCALAR: - FloatDataRecord scalarRecord = this.retrieveFromHDF5( - parmId, rec.getTimeRange()); - float[] convertedScalarData = this.convertData( - this.parmInfo.get(compositeName) - .getUnitObject(), gpi.getUnitObject(), - scalarRecord.getFloatData()); - scalarRecord.setFloatData(convertedScalarData); - rec.setMessageData(scalarRecord); - break; - case VECTOR: - FloatDataRecord[] vectorRecord = this - .retrieveVectorFromHDF5(parmId, - rec.getTimeRange()); - float[] convertedVectorData = this.convertData( - this.parmInfo.get(compositeName) - .getUnitObject(), gpi.getUnitObject(), - vectorRecord[0].getFloatData()); - vectorRecord[0].setFloatData(convertedVectorData); - rec.setMessageData(vectorRecord); - break; - - default: - // do nothing - } - } - this.saveGridsToHdf5(records); - } - } catch (Exception e) { - statusHandler.handle(Priority.PROBLEM, "Error changing units", e); - } - - } - - /** - * Converts data in the given array to the desired unit - * - * @param from - * The unit to convert from - * @param to - * The unit to convert to - * @param dataToConvert - * The data to convert - * @return The converted array of data - * @throws GfeException - * If the data cannot be converted - */ - private float[] convertData(Unit from, Unit to, float[] dataToConvert) - throws GfeException { - - UnitConverter converter = null; - - if ((from != null) && (to != null)) { - if (to.isCompatible(from)) { - converter = from.getConverterTo(to); - } else { - throw new GfeException(from + " is not compatible with " + to); - } - } else { - throw new GfeException("Units cannot be null!"); - } - - float[] convertedData = new float[dataToConvert.length]; - - for (int i = 0; i < dataToConvert.length; i++) { - convertedData[i] = (float) converter.convert(dataToConvert[i]); - } - - return convertedData; - } - /** * Changes the data type in the database for a given parm * - * @param compositeName - * The name of the parm - * @param newGPI - * The GridParmInfo associated with the parm - */ - private void changeDataType(String compositeName, GridParmInfo newGPI, - ParmStorageInfo newPSI) { - List entries = new ArrayList(); - entries.add(compositeName); - removeOldParmData(entries); - updateParmAttributes(compositeName, newGPI, newPSI); - this.parmInfo.put(compositeName, newGPI); - this.parmStorageInfo.put(compositeName, newPSI); - } - - /** - * Stores the new GridParmInfo to the HDF5 repository + * Removes the data for the specified parm * - * @param compositeName - * The parm to update the GridParmInfo for - * @param newGPI - * The new GridParmInfo + * @param parmId + * The affected parm */ - private void updateParmAttributes(String compositeName, - GridParmInfo newGPI, ParmStorageInfo newPSI) { + private void changeDataType(ParmID parmId) { try { - storeGridParmInfo(newGPI, newPSI, StoreOp.REPLACE); - } catch (Exception e) { - statusHandler.handle(Priority.PROBLEM, - "Error updating GridParmInfo in the HDF5 repository", e); + dao.removeParmData(parmId); + } catch (DataAccessLayerException e) { + statusHandler.error("Error removing data for " + parmId, e); } } @@ -696,64 +571,28 @@ public class IFPGridDatabase extends GridDatabase { * The list of parms to delete */ private void removeOldParms(List parms) { - - try { - GFEDao dao = new GFEDao(); - for (String item : parms) { - statusHandler.handle(Priority.INFO, "Removing: " + item - + " from the " + this.dbId + " database."); - try { - // Remove the entire data structure for the parm - dao.removeParm(parmIdMap.get(item)); - parmIdMap.remove(item); - this.parmInfo.remove(item); - this.parmStorageInfo.remove(item); - } catch (DataAccessLayerException e) { - statusHandler.handle(Priority.PROBLEM, "Error removing: " - + item + " from the database"); - } + for (String item : parms) { + statusHandler.handle(Priority.INFO, "Removing: " + item + + " from the " + this.dbId + " database."); + try { + // Remove the entire data structure for the parm + dao.removeParm(parmStorageInfo.get(item).getParmID()); + // parmIdMap.remove(item); + this.parmStorageInfo.remove(item); + } catch (DataAccessLayerException e) { + statusHandler.handle(Priority.PROBLEM, "Error removing: " + + item + " from the database"); } - } catch (PluginException e) { - statusHandler.handle(Priority.PROBLEM, "Error removing old parms!", - e); } - - } - - /** - * Removes the data in the database and HDF5 repository for the list of - * parms. - * - * @param parms - * The list of parms to delete - */ - private void removeOldParmData(List parms) { - - try { - GFEDao dao = new GFEDao(); - for (String item : parms) { - statusHandler.handle(Priority.INFO, "Removing: " + item - + " from the " + this.dbId + " database."); - try { - // Remove the grids for the parm - dao.removeParmData(parmIdMap.get(item)); - this.parmInfo.remove(item); - this.parmStorageInfo.remove(item); - } catch (DataAccessLayerException e) { - statusHandler.handle(Priority.PROBLEM, "Error removing: " - + item + " from the database"); - } - } - } catch (PluginException e) { - statusHandler.handle(Priority.PROBLEM, "Error removing old parms!", - e); - } - } @Override public ServerResponse> getParmList() { - List parmIds = new ArrayList(parmIdMap.values()); + // List parmIds = new ArrayList(parmIdMap.values()); + List parmIds = new ArrayList(parmStorageInfo.size()); + for (ParmStorageInfo psi : parmStorageInfo.values()) { + parmIds.add(psi.getParmID()); + } ServerResponse> sr = new ServerResponse>(); sr.setPayload(parmIds); return sr; @@ -763,9 +602,7 @@ public class IFPGridDatabase extends GridDatabase { public ServerResponse> getGridInventory(ParmID id) { ServerResponse> sr = new ServerResponse>(); - GFEDao dao = null; try { - dao = (GFEDao) PluginFactory.getInstance().getPluginDao("gfe"); sr.setPayload(dao.getTimes(getCachedParmID(id))); } catch (Exception e) { sr.setPayload(new ArrayList(0)); @@ -781,9 +618,7 @@ public class IFPGridDatabase extends GridDatabase { public ServerResponse> getGridInventory(ParmID id, TimeRange tr) { ServerResponse> sr = new ServerResponse>(); - GFEDao dao = null; try { - dao = (GFEDao) PluginFactory.getInstance().getPluginDao("gfe"); sr.setPayload(dao.getOverlappingTimes(getCachedParmID(id), tr)); } catch (Exception e) { sr.setPayload(new ArrayList(0)); @@ -799,9 +634,7 @@ public class IFPGridDatabase extends GridDatabase { public ServerResponse>> getGridHistory( ParmID id, List trs) { ServerResponse>> sr = new ServerResponse>>(); - GFEDao dao = null; try { - dao = (GFEDao) PluginFactory.getInstance().getPluginDao("gfe"); Map> history = dao.getGridHistory( getCachedParmID(id), trs); sr.setPayload(history); @@ -810,8 +643,6 @@ public class IFPGridDatabase extends GridDatabase { + e.getLocalizedMessage()); statusHandler.handle(Priority.PROBLEM, "Error getting grid history for: " + id, e); - } catch (PluginException e) { - statusHandler.handle(Priority.PROBLEM, "Unable to get gfe dao", e); } catch (UnknownParmIdException e) { statusHandler.handle(Priority.PROBLEM, "Unknown parmId: " + id, e); } @@ -878,7 +709,7 @@ public class IFPGridDatabase extends GridDatabase { * The database parm ID to save * @param originalTimeRange * The time range to save - * @param records + * @param recordsToSave * The records to save, records are not db records at this point. * @param requesterId * who requested to save the grids @@ -896,12 +727,9 @@ public class IFPGridDatabase extends GridDatabase { } long t0 = System.currentTimeMillis(); - GFEDao dao = null; Map existingMap = null; try { - dao = new GFEDao(); - // Grab the current records for the general time range in question existingMap = dao.getOverlappingRecords(id, originalTimeRange); } catch (Exception e) { @@ -985,7 +813,7 @@ public class IFPGridDatabase extends GridDatabase { existingMap.size() + newRecords.size()); recList.addAll(newRecords); recList.addAll(existingMap.values()); - failedGrids = saveGridsToHdf5(recList); + failedGrids = saveGridsToHdf5(recList, null); hdf5SaveSuccess = true; } catch (GfeException e) { statusHandler.handle(Priority.PROBLEM, "Error saving to hdf5", e); @@ -1088,12 +916,14 @@ public class IFPGridDatabase extends GridDatabase { public ServerResponse getGridParmInfo(ParmID id) { ServerResponse sr = new ServerResponse(); String compositeName = id.getCompositeName(); - GridParmInfo gpi = parmInfo.get(compositeName); - if (gpi == null) { - sr.addMessage("GridParmInfoNotFound - " + id.getCompositeName() + ParmStorageInfo psi = parmStorageInfo.get(compositeName); + if (psi == null) { + sr.addMessage("GridParmInfoNotFound - " + compositeName + " was not found in the database"); + } else { + GridParmInfo gpi = psi.getGridParmInfo(); + sr.setPayload(gpi); } - sr.setPayload(gpi); return sr; } @@ -1104,9 +934,9 @@ public class IFPGridDatabase extends GridDatabase { ServerResponse ssr = this.dbIsValid(); sr.addMessages(ssr); - ServerResponse gpiSsr = getGridParmInfo(parmId); - sr.addMessages(gpiSsr); - GridParmInfo gpi = gpiSsr.getPayload().clone(); + ParmStorageInfo psi = this.parmStorageInfo.get(parmId + .getCompositeName()); + GridParmInfo gpi = psi.getGridParmInfo().clone(); gpi.setGridLoc(location); ServerResponse>> ssr2 = getGridHistory( parmId, timeRanges); @@ -1127,7 +957,7 @@ public class IFPGridDatabase extends GridDatabase { case SCALAR: FloatDataRecord[] records = null; try { - records = this.retrieveFromHDF5(parmId, timeRanges); + records = this.retrieveFromHDF5(parmId, timeRanges, psi); } catch (GfeException e) { statusHandler.handle(Priority.PROBLEM, "Error retrieving SCALAR data from HDF5", e); @@ -1148,7 +978,8 @@ public class IFPGridDatabase extends GridDatabase { case VECTOR: FloatDataRecord[][] vecRecords = null; try { - vecRecords = this.retrieveVectorFromHDF5(parmId, timeRanges); + vecRecords = this.retrieveVectorFromHDF5(parmId, timeRanges, + psi); } catch (GfeException e) { statusHandler.handle(Priority.PROBLEM, "Error retrieving VECTOR data from HDF5", e); @@ -1262,196 +1093,206 @@ public class IFPGridDatabase extends GridDatabase { @Override public String getProjectionId() { - return this.gridConfig.projectionData().getProjectionID(); + return this.gridDbConfig.projectionData().getProjectionID(); } /** * Examines the user vs. the database projection and domains, and determines * if the database needs to be remapped to be in line with the desired * projection and domain. Performs the remapping of all data as needed. + * + * @param parmStorageInfoUser + * @return ServerResponse containing status only */ - private void applyProjectionAndDomainChanges() { + private ServerResponse applyProjectionAndDomainChanges( + Map parmStorageInfoUser) { + ServerResponse sr = new ServerResponse(); - try { - IFPServerConfig serverConfig = IFPServerConfigManager - .getServerConfig(dbId.getSiteId()); - GridLocation currentGridLocation = serverConfig.dbDomain(); - if (currentGridLocation.getSiteId().equals("")) { - currentGridLocation.setSiteId(dbId.getSiteId()); + // get database GridLocation, if any + GridLocation glocDb = null; + if (!parmStorageInfo.isEmpty()) { + glocDb = parmStorageInfo.values().iterator().next() + .getGridParmInfo().getGridLoc(); + } + + // get user GridLocation + GridLocation glocUser = parmStorageInfoUser.values().iterator().next() + .getGridParmInfo().getGridLoc(); + + // get the hibernate ids set correctly + glocUser.setDbId(this.dbId); + if (glocDb != null) { + glocUser.setId(glocDb.getId()); + } + + // if GridLocation has changed + if (!glocUser.equals(glocDb)) { + + // save/update the database GridLocation + try { + dao.saveOrUpdateGridLocation(glocUser); + + // remap the actual gridded data to the new gridLocation + statusHandler.info("Remapping Grids to new domain: " + + this.dbId); + sr.addMessages(remapAllGrids(parmStorageInfoUser)); + } catch (DataAccessLayerException e) { + String msg = "Error storing gridLocation for " + this.dbId; + statusHandler.error(msg, e); + sr.addMessage(msg); + return sr; + } + } + + // update parmStorageInfoUser with databased GridLocation + Iterator iter = parmStorageInfoUser.values() + .iterator(); + while (iter.hasNext()) { + ParmStorageInfo psi = iter.next(); + psi.getGridParmInfo().setGridLoc(glocUser); + } + + return sr; + } + + private ServerResponse remapAllGrids( + Map parmStorageInfoUser) { + ServerResponse sr = new ServerResponse(); + + for (Entry entry : this.parmStorageInfo + .entrySet()) { + String compositeName = entry.getKey(); + + ParmStorageInfo oldPSI = entry.getValue(); + GridParmInfo oldGPI = oldPSI.getGridParmInfo(); + ParmStorageInfo newPSI = parmStorageInfoUser.get(compositeName); + if (newPSI == null) { + continue; // this parm not in new database, so skip } - GFEDao gfeDao = new GFEDao(); + GridParmInfo newGPI = newPSI.getGridParmInfo(); - for (String parmNameAndLevel : parmInfo.keySet()) { - GridLocation storedGridLocation = parmInfo - .get(parmNameAndLevel).getGridLoc(); - String parmName = parmNameAndLevel.split("_")[0]; - String parmLevel = parmNameAndLevel.split("_")[1]; + GridLocation oldGL = oldGPI.getGridLoc(); + GridLocation newGL = newGPI.getGridLoc(); + RemapGrid remapper = new RemapGrid(oldGL, newGL); - if (!storedGridLocation.equals(currentGridLocation)) { - GridParmInfo gpi = gridConfig.getGridParmInfo(parmName, - parmLevel); - if (gpi == null) { - continue; - } - ParmStorageInfo psi = gridConfig.getParmStorageInfo( - parmName, parmLevel); - this.storeGridParmInfo(gpi, psi, StoreOp.REPLACE); - - RemapGrid remap = new RemapGrid(storedGridLocation, - currentGridLocation, true); - - ParmID currentParm = getCachedParmID(parmNameAndLevel); - List records = gfeDao.queryByParmID(currentParm); - if (!records.isEmpty()) { - statusHandler.handle( - Priority.WARN, - "Resolution has been changed for site: " - + dbId.getSiteId() - + ". Resampling parm [" - + currentParm.toString() + "] (" - + records.size() - + " grids) to new resolution..."); - } - - for (GFERecord rec : records) { - List times = new ArrayList(); - times.add(rec.getTimeRange()); - IGridSlice slice = this - .getGridData(rec.getParmId(), times, - storedGridLocation).getPayload().get(0); - IGridSlice newSlice = null; - try { - switch (slice.getGridInfo().getGridType()) { - case NONE: - break; - case SCALAR: - ScalarGridSlice scalarSlice = (ScalarGridSlice) slice; - Grid2DFloat newGrid = remap - .remap(scalarSlice.getScalarGrid(), - scalarSlice.getGridInfo() - .getMinValue(), - scalarSlice.getGridInfo() - .getMaxValue(), - scalarSlice.getGridInfo() - .getMinValue(), - scalarSlice.getGridInfo() - .getMinValue()); - scalarSlice.setGridParmInfo(this - .getGridParmInfo(rec.getParmId()) - .getPayload()); - scalarSlice.setScalarGrid(newGrid); - newSlice = scalarSlice; - break; - case VECTOR: - VectorGridSlice vectorSlice = (VectorGridSlice) slice; - Grid2DFloat magOutput = new Grid2DFloat( - currentGridLocation.getNx(), - currentGridLocation.getNy()); - Grid2DFloat dirOutput = new Grid2DFloat( - currentGridLocation.getNx(), - currentGridLocation.getNy()); - remap.remap( - vectorSlice.getMagGrid(), - vectorSlice.getDirGrid(), - vectorSlice.getGridInfo().getMinValue(), - vectorSlice.getGridInfo().getMaxValue(), - vectorSlice.getGridInfo().getMinValue(), - vectorSlice.getGridInfo().getMinValue(), - magOutput, dirOutput); - vectorSlice.setGridParmInfo(this - .getGridParmInfo(rec.getParmId()) - .getPayload()); - vectorSlice.setDirGrid(dirOutput); - vectorSlice.setMagGrid(magOutput); - newSlice = vectorSlice; - break; - case WEATHER: - WeatherGridSlice weatherSlice = (WeatherGridSlice) slice; - Grid2DByte newWeatherGrid = remap.remap( - weatherSlice.getWeatherGrid(), 0, 0); - weatherSlice.setGridParmInfo(this - .getGridParmInfo(rec.getParmId()) - .getPayload()); - weatherSlice.setWeatherGrid(newWeatherGrid); - newSlice = weatherSlice; - break; - case DISCRETE: - DiscreteGridSlice discreteSlice = (DiscreteGridSlice) slice; - Grid2DByte newDiscreteGrid = remap.remap( - discreteSlice.getDiscreteGrid(), 0, 0); - discreteSlice.setGridParmInfo(this - .getGridParmInfo(rec.getParmId()) - .getPayload()); - discreteSlice.setDiscreteGrid(newDiscreteGrid); - newSlice = discreteSlice; - break; - } - rec.setMessageData(newSlice); - this.removeFromHDF5(rec); - this.saveGridsToHdf5(Arrays - .asList(new GFERecord[] { rec })); - } catch (Exception e) { - statusHandler.handle(Priority.PROBLEM, - "Error remapping data for record [" + rec - + "]", e); - } + List records; + try { + ParmID currentParm = getCachedParmID(compositeName); + records = dao.queryByParmID(currentParm); + } catch (UnknownParmIdException e) { + statusHandler.error("Unable to retrieve ParmID for " + + compositeName, e); + continue; + } catch (DataAccessLayerException e) { + statusHandler.error("Unable to retrieve GFERecords for " + + compositeName, e); + continue; + } + + // process each grid + for (GFERecord rec : records) { + List times = new ArrayList(); + times.add(rec.getTimeRange()); + ServerResponse> ssr = this.getGridData( + rec.getParmId(), times, oldGL); + sr.addMessages(ssr); + if (!sr.isOkay()) { + statusHandler + .error("Unable to retrieve data in remapAllGrids() " + + sr.getMessages()); + continue; + } + IGridSlice slice = ssr.getPayload().get(0); + IGridSlice newSlice = null; + try { + switch (slice.getGridInfo().getGridType()) { + case NONE: + break; + case SCALAR: + ScalarGridSlice scalarSlice = (ScalarGridSlice) slice; + Grid2DFloat newGrid = remapper.remap(scalarSlice + .getScalarGrid(), scalarSlice.getGridInfo() + .getMinValue(), scalarSlice.getGridInfo() + .getMaxValue(), scalarSlice.getGridInfo() + .getMinValue(), scalarSlice.getGridInfo() + .getMinValue()); + scalarSlice.setScalarGrid(newGrid); + newSlice = scalarSlice; + break; + case VECTOR: + VectorGridSlice vectorSlice = (VectorGridSlice) slice; + Grid2DFloat magOutput = new Grid2DFloat(newGL.getNx(), + newGL.getNy()); + Grid2DFloat dirOutput = new Grid2DFloat(newGL.getNx(), + newGL.getNy()); + remapper.remap(vectorSlice.getMagGrid(), vectorSlice + .getDirGrid(), vectorSlice.getGridInfo() + .getMinValue(), vectorSlice.getGridInfo() + .getMaxValue(), vectorSlice.getGridInfo() + .getMinValue(), vectorSlice.getGridInfo() + .getMinValue(), magOutput, dirOutput); + vectorSlice.setDirGrid(dirOutput); + vectorSlice.setMagGrid(magOutput); + newSlice = vectorSlice; + break; + case WEATHER: + WeatherGridSlice weatherSlice = (WeatherGridSlice) slice; + Grid2DByte newWeatherGrid = remapper.remap( + weatherSlice.getWeatherGrid(), 0, 0); + weatherSlice.setWeatherGrid(newWeatherGrid); + newSlice = weatherSlice; + break; + case DISCRETE: + DiscreteGridSlice discreteSlice = (DiscreteGridSlice) slice; + Grid2DByte newDiscreteGrid = remapper.remap( + discreteSlice.getDiscreteGrid(), 0, 0); + discreteSlice.setDiscreteGrid(newDiscreteGrid); + newSlice = discreteSlice; + break; } + newSlice.setGridInfo(newGPI); + rec.setMessageData(newSlice); + this.removeFromHDF5(rec); + this.saveGridsToHdf5(Arrays.asList(rec), newPSI); + } catch (Exception e) { + statusHandler.handle(Priority.PROBLEM, + "Error remapping data for record [" + rec + "]", e); } } - } catch (DataAccessLayerException e) { - statusHandler.handle(Priority.PROBLEM, - "Unable to query for grid location!", e); - } catch (PluginException e) { - statusHandler.handle(Priority.PROBLEM, - "Unable to instantiate GFEDao!", e); - } catch (GfeConfigurationException e) { - statusHandler.handle(Priority.PROBLEM, "Unable to get config for " - + this.dbId.getSiteId(), e); - } catch (Exception e) { - statusHandler.handle(Priority.PROBLEM, "Unable to get config for " - + this.dbId.getSiteId(), e); } + + return sr; } - private void getDBConfiguration() throws GfeException { - parmInfo.clear(); - parmStorageInfo.clear(); - parmIdMap.clear(); - - if (!parmInfoInitialized) { - initGridParmInfo(); - } + private ServerResponse getDBConfiguration() { + ServerResponse sr = new ServerResponse(); try { - IDataStore ds = DataStoreFactory.getDataStore(GfeUtil - .getGridParmHdf5File(gfeBaseDataDir, this.dbId)); + List parmInfoList = dao.getParmStorageInfo(dbId); + parmStorageInfo = new HashMap( + parmInfoList.size(), 1.0f); + // parmIdMap = new HashMap(parmInfoList.size(), + // 1.0f); - IDataRecord[] parmInfoRecords = ds.retrieve(GRID_PARM_INFO_GRP); - for (IDataRecord gpiRecord : parmInfoRecords) { - GridParmInfo gpi = populateGpi(gpiRecord.getDataAttributes()); - parmInfo.put(gpiRecord.getName(), gpi); + for (ParmStorageInfo psi : parmInfoList) { + ParmID pid = psi.getParmID(); + String compositeName = pid.getCompositeName(); + // parmIdMap.put(compositeName, pid); + parmStorageInfo.put(compositeName, psi); } - IDataRecord[] parmStorageRecords = ds - .retrieve(GRID_PARM_STORAGE_INFO_GRP); - for (IDataRecord psiRecord : parmStorageRecords) { - ParmStorageInfo psi = populateStorageInfo(psiRecord - .getDataAttributes()); - parmStorageInfo.put(psiRecord.getName(), psi); - } - - GFEDao dao = new GFEDao(); - List currentIds = dao.getParmIds(dbId); - for (ParmID parmId : currentIds) { - parmIdMap.put(parmId.getCompositeName(), parmId); - } - } catch (Exception e) { - throw new GfeException("Error getting db configuration", e); + } catch (DataAccessLayerException e) { + parmStorageInfo = Collections.emptyMap(); + // parmIdMap = Collections.emptyMap(); + String msg = "Error retrieving parm info from Database: " + + e.getLocalizedMessage(); + statusHandler.error(msg, e); + sr.addMessage(msg); } - + return sr; } - private void compareParmInfoWithDB(Map parmInfoUser, + private void compareParmInfoWithDB( Map parmStorageInfoUser, List toBeAdded, List toBeDeleted, List toBeChanged) { @@ -1462,29 +1303,21 @@ public class IFPGridDatabase extends GridDatabase { toBeChanged.clear(); // Check for entries to be added - for (String key : parmInfoUser.keySet()) { - if (!this.parmInfo.containsKey(key)) { + for (String key : parmStorageInfoUser.keySet()) { + if (!this.parmStorageInfo.containsKey(key)) { toBeAdded.add(key); } } // check for entries to be deleted - for (String key : this.parmInfo.keySet()) { - if (!parmInfoUser.containsKey(key)) { + for (String key : this.parmStorageInfo.keySet()) { + if (!parmStorageInfoUser.containsKey(key)) { toBeDeleted.add(key); } } // Check for entries to modified - for (String key : parmInfoUser.keySet()) { - GridParmInfo dbGpi, userGpi = null; - if (this.parmInfo.containsKey(key)) { - dbGpi = this.parmInfo.get(key); - userGpi = parmInfoUser.get(key); - if (!dbGpi.equals(userGpi)) { - toBeChanged.add(key); - } - } + for (String key : parmStorageInfoUser.keySet()) { ParmStorageInfo dbPsi, userPsi = null; if (this.parmStorageInfo.containsKey(key) && !toBeChanged.contains(key)) { @@ -1501,81 +1334,69 @@ public class IFPGridDatabase extends GridDatabase { * IFPGridDatabase::getUserConfiguration() This function, which is called at * construction time, reads all the information from the supplied * GridDbConfig class and creates information in the calling arguments - * parmInfo, parmStorageInfo, and areaStorageInfo. These dictionaries are - * used later by other functions in this class. + * parmStorageInfo. These dictionaries are used later by other functions in + * this class. * - * @param parmInfo - * Map of GridParmInfo - * @param parmStorageInfo - * Map of ParmStorageInfo - * @return True if the operation is successful, false + * @return ServerResponse containing the user configuration */ - private boolean getUserConfiguration(Map parmInfo, - Map parmStorageInfo) { - parmInfo.clear(); - parmStorageInfo.clear(); + private ServerResponse> getUserConfiguration() { + ServerResponse> sr = new ServerResponse>(); + Map parmStorageInfoUser = new HashMap(); - if (this.gridConfig == null) { - return false; + if (this.gridDbConfig == null) { + sr.addMessage("No gridDbConfig found for " + this.dbId); + return sr; } - List nameLevel = this.gridConfig.parmAndLevelList(); // For each variable get the info and stuff it in the correct object - for (int i = 0; i < nameLevel.size(); i++) { + for (String nameLevel : this.gridDbConfig.parmAndLevelList()) { + ParmStorageInfo psi = getUserConfigForWE(nameLevel); - Object[] gpiPsi = new Object[2]; - - if (getUserConfigForWE(nameLevel.get(i), gpiPsi)) { - parmInfo.put(nameLevel.get(i), (GridParmInfo) gpiPsi[0]); - parmStorageInfo.put(nameLevel.get(i), - (ParmStorageInfo) gpiPsi[1]); + if (psi != null) { + parmStorageInfoUser.put(nameLevel, psi); } else { - statusHandler.handle(Priority.PROBLEM, - "GPI/PSI attributes not found in configuration for " - + nameLevel.get(i) + "."); - return false; + String msg = "ParmStorageInfo not found in configuration for " + + nameLevel; + statusHandler.error(msg); + sr.addMessage("msg"); + return sr; } } - return true; + sr.setPayload(parmStorageInfoUser); + return sr; } /** - * This function reads the elements of a GridParmInfo and ParmStorageInfo - * from the GridDBConfig for a single weather element (compositeName). + * This function reads the ParmStorageInfo from the GridDBConfig for a + * single weather element (compositeName). + * + * @param compositeName + * the desired weather element + * @return the ParmStorageInfo */ - private boolean getUserConfigForWE(String compositeName, Object[] gpiPsi) { + private ParmStorageInfo getUserConfigForWE(String compositeName) { String[] nameLevel = splitNameAndLevel(compositeName); - GridParmInfo gpi = null; + ParmStorageInfo psi = null; - if (gridConfig == null) { + if (gridDbConfig == null) { statusHandler.handle(Priority.DEBUG, toString() + " has no GridParmInfo config"); - return false; + return null; } else { - gpi = this.gridConfig.getGridParmInfo(nameLevel[0], nameLevel[1]); + psi = this.gridDbConfig.getParmStorageInfo(nameLevel[0], + nameLevel[1]); + if (psi == null) { + statusHandler.handle(Priority.DEBUG, compositeName + + " not found in ParmStorageInfo config"); + return null; + } } - if (gpi == null) { - statusHandler.handle(Priority.DEBUG, compositeName - + " not found in GridParmInfo config"); - return false; - } + psi.getGridParmInfo().resetParmID( + new ParmID(nameLevel[0], this.dbId, nameLevel[1])); - gpi.resetParmID(new ParmID(nameLevel[0], this.dbId, nameLevel[1])); - - // get the ParmStorageInfo - ParmStorageInfo psi = this.gridConfig.getParmStorageInfo(nameLevel[0], - nameLevel[1]); - if (psi == null) { - statusHandler.handle(Priority.DEBUG, compositeName - + " not found in ParmStorageInfo config"); - return false; - } - - gpiPsi[0] = gpi; - gpiPsi[1] = psi; - return true; + return psi; } /** @@ -1601,232 +1422,6 @@ public class IFPGridDatabase extends GridDatabase { return sr; } - protected void initGridParmInfo() { - try { - if ((gridConfig != null) - && (gridConfig.parmAndLevelList().size() > 0)) { - IDataStore ds = DataStoreFactory.getDataStore(GfeUtil - .getGridParmHdf5File(gfeBaseDataDir, this.dbId)); - ds.getDatasets(GRID_PARM_INFO_GRP); - parmInfoInitialized = true; - } - } catch (Exception e1) { - if (gridConfig != null) { - try { - List parmsAndLevels = gridConfig.parmAndLevelList(); - String[] parmAndLevel = null; - List gpis = new ArrayList(); - List psis = new ArrayList(); - for (String parm : parmsAndLevels) { - parmAndLevel = this.splitNameAndLevel(parm); - gpis.add(gridConfig.getGridParmInfo(parmAndLevel[0], - parmAndLevel[1])); - psis.add(gridConfig.getParmStorageInfo(parmAndLevel[0], - parmAndLevel[1])); - } - storeGridParmInfo(gpis, psis, StoreOp.STORE_ONLY); - parmInfoInitialized = true; - } catch (Exception e) { - statusHandler.handle(Priority.PROBLEM, - "Error getting GridParmInfo file", e); - parmInfoInitialized = false; - } - } - } - } - - private ParmStorageInfo populateStorageInfo( - Map dataAttributes) { - - String storageType = (String) dataAttributes.get("storageType"); - Point gridSize = new Point((Integer) dataAttributes.get("gridSize.x"), - (Integer) dataAttributes.get("gridSize.y")); - - String parmName = (String) dataAttributes.get("parmName"); - String level = (String) dataAttributes.get("level"); - Float dataOffset = (Float) dataAttributes.get("dataOffset"); - Float dataMultiplier = (Float) dataAttributes.get("dataMultiplier"); - String dataType = (String) dataAttributes.get("dataType"); - - ParmStorageInfo storageInfo = new ParmStorageInfo(dataType, gridSize, - parmName, level, dataOffset, dataMultiplier, storageType); - return storageInfo; - - } - - protected GridParmInfo populateGpi(Map dataAttributes) - throws Exception { - - String projID = (String) dataAttributes - .get("gridLoc.projection.projectionID"); - ProjectionType projType = ProjectionType - .valueOf((String) dataAttributes - .get("gridLoc.projection.projectionType")); - Coordinate latLonLL = new Coordinate( - (Float) dataAttributes.get("gridLoc.projection.latLonLL.x"), - (Float) dataAttributes.get("gridLoc.projection.latLonLL.y")); - Coordinate latLonUR = new Coordinate( - (Float) dataAttributes.get("gridLoc.projection.latLonUR.x"), - (Float) dataAttributes.get("gridLoc.projection.latLonUR.y")); - Coordinate latLonOrig = new Coordinate( - (Float) dataAttributes.get("gridLoc.projection.latLonOrigin.x"), - (Float) dataAttributes.get("gridLoc.projection.latLonOrigin.y")); - Float stdPar1 = (Float) dataAttributes - .get("gridLoc.projection.stdParallelOne"); - Float stdPar2 = (Float) dataAttributes - .get("gridLoc.projection.stdParallelTwo"); - Point gridLL = new Point( - (Integer) dataAttributes - .get("gridLoc.projection.gridPointLL.x"), - (Integer) dataAttributes - .get("gridLoc.projection.gridPointLL.y")); - Point gridUR = new Point( - (Integer) dataAttributes - .get("gridLoc.projection.gridPointUR.x"), - (Integer) dataAttributes - .get("gridLoc.projection.gridPointUR.y")); - Float latInt = (Float) dataAttributes - .get("gridLoc.projection.latIntersect"); - Float lonCenter = (Float) dataAttributes - .get("gridLoc.projection.lonCenter"); - Float lonOrig = (Float) dataAttributes - .get("gridLoc.projection.lonOrigin"); - ProjectionData proj = new ProjectionData(projID, projType, latLonLL, - latLonUR, latLonOrig, stdPar1, stdPar2, gridLL, gridUR, latInt, - lonCenter, lonOrig); - - String id = (String) dataAttributes.get("gridLoc.siteID"); - int nx = (Integer) dataAttributes.get("gridLoc.nx"); - int ny = (Integer) dataAttributes.get("gridLoc.ny"); - Coordinate domainOrigin = new Coordinate( - (Float) dataAttributes.get("gridLoc.origin.x"), - (Float) dataAttributes.get("gridLoc.origin.y")); - Coordinate domainExtent = new Coordinate( - (Float) dataAttributes.get("gridLoc.extent.x"), - (Float) dataAttributes.get("gridLoc.extent.y")); - String timeZone = (String) dataAttributes.get("gridLoc.timeZone"); - GridLocation gridLoc = new GridLocation(id, proj, new Point(nx, ny), - domainOrigin, domainExtent, timeZone); - - int duration = (Integer) dataAttributes.get("timeConstraints.duration"); - int repeatInterval = (Integer) dataAttributes - .get("timeConstraints.repeatInterval"); - int startTime = (Integer) dataAttributes - .get("timeConstraints.startTime"); - TimeConstraints timeConstraints = new TimeConstraints(duration, - repeatInterval, startTime); - - ParmID parmId = new ParmID((String) dataAttributes.get("parmID")); - GridType gridType = GridType.valueOf((String) dataAttributes - .get("gridType")); - String descriptiveName = (String) dataAttributes.get("descriptiveName"); - String unit = (String) dataAttributes.get("unitString"); - Float minValue = (Float) dataAttributes.get("minValue"); - Float maxValue = (Float) dataAttributes.get("maxValue"); - int precision = (Integer) dataAttributes.get("precision"); - boolean timeIndependentParm = (Boolean) dataAttributes - .get("timeIndependentParm"); - boolean rateParm = (Boolean) dataAttributes.get("rateParm"); - GridParmInfo gpi = new GridParmInfo(parmId, gridLoc, gridType, unit, - descriptiveName, minValue, maxValue, precision, - timeIndependentParm, timeConstraints, rateParm); - - return gpi; - } - - private Map getStorageInfoAsMap(ParmStorageInfo info) { - Map dataAttributes = new HashMap(); - dataAttributes.put("storageType", info.storageType()); - dataAttributes.put("gridSize.x", info.gridSize().x); - dataAttributes.put("gridSize.y", info.gridSize().y); - dataAttributes.put("storageAreaName", info.storageAreaName()); - dataAttributes.put("parmName", info.parmName()); - dataAttributes.put("level", info.level()); - dataAttributes.put("dataOffset", info.dataOffset()); - dataAttributes.put("dataMultiplier", info.dataMultiplier()); - dataAttributes.put("dataType", info.dataType()); - return dataAttributes; - } - - protected Map getGpiAsMap(GridParmInfo gpi) - throws Exception { - - Map dataAttributes = new HashMap(); - - dataAttributes.put("parmID", gpi.getParmID().toString()); - dataAttributes.put("gridType", gpi.getGridType().toString()); - dataAttributes.put("descriptiveName", gpi.getDescriptiveName()); - dataAttributes.put("unitString", gpi.getUnitString()); - dataAttributes.put("minValue", gpi.getMinValue()); - dataAttributes.put("maxValue", gpi.getMaxValue()); - dataAttributes.put("precision", gpi.getPrecision()); - dataAttributes.put("rateParm", gpi.isRateParm()); - dataAttributes.put("timeIndependentParm", gpi.isTimeIndependentParm()); - - TimeConstraints tc = gpi.getTimeConstraints(); - dataAttributes.put("timeConstraints.duration", tc.getDuration()); - dataAttributes.put("timeConstraints.repeatInterval", - tc.getRepeatInterval()); - dataAttributes.put("timeConstraints.startTime", tc.getStartTime()); - - GridLocation location = gpi.getGridLoc(); - dataAttributes.put("gridLoc.siteID", location.getSiteId()); - dataAttributes.put("gridLoc.nx", location.getNx()); - dataAttributes.put("gridLoc.ny", location.getNy()); - dataAttributes.put("gridLoc.timeZone", location.getTimeZone()); - dataAttributes.put("gridLoc.origin.x", location.getOrigin().x); - dataAttributes.put("gridLoc.origin.y", location.getOrigin().y); - dataAttributes.put("gridLoc.extent.x", location.getExtent().x); - dataAttributes.put("gridLoc.extent.y", location.getExtent().y); - dataAttributes.put("gridLoc.geometry", location.getGeometry().toText()); - dataAttributes.put("gridLoc.crs", location.getCrsWKT()); - - ProjectionData proj = location.getProjection(); - dataAttributes.put("gridLoc.projection.projectionID", - proj.getProjectionID()); - dataAttributes.put("gridLoc.projection.projectionType", proj - .getProjectionType().toString()); - dataAttributes.put("gridLoc.projection.latLonLL.x", - proj.getLatLonLL().x); - dataAttributes.put("gridLoc.projection.latLonLL.y", - proj.getLatLonLL().y); - dataAttributes.put("gridLoc.projection.latLonUR.x", - proj.getLatLonUR().x); - dataAttributes.put("gridLoc.projection.latLonUR.y", - proj.getLatLonUR().y); - dataAttributes.put("gridLoc.projection.latLonOrigin.x", - proj.getLatLonOrigin().x); - dataAttributes.put("gridLoc.projection.latLonOrigin.y", - proj.getLatLonOrigin().y); - dataAttributes.put("gridLoc.projection.stdParallelOne", - proj.getStdParallelOne()); - dataAttributes.put("gridLoc.projection.stdParallelTwo", - proj.getStdParallelTwo()); - dataAttributes.put("gridLoc.projection.gridPointLL.x", - proj.getGridPointLL().x); - dataAttributes.put("gridLoc.projection.gridPointLL.y", - proj.getGridPointLL().y); - dataAttributes.put("gridLoc.projection.gridPointUR.x", - proj.getGridPointUR().x); - dataAttributes.put("gridLoc.projection.gridPointUR.y", - proj.getGridPointUR().y); - dataAttributes.put("gridLoc.projection.latIntersect", - proj.getLatIntersect()); - dataAttributes.put("gridLoc.projection.lonCenter", proj.getLonCenter()); - dataAttributes.put("gridLoc.projection.lonOrigin", proj.getLonOrigin()); - return dataAttributes; - } - - /** - * @param dataObjects - * @return Returns records that failed to store - * @throws GfeException - */ - public List saveGridsToHdf5(List dataObjects) - throws GfeException { - return saveGridsToHdf5(dataObjects, null); - } - /** * Saves GFERecords to the HDF5 repository * @@ -1839,7 +1434,7 @@ public class IFPGridDatabase extends GridDatabase { * If errors occur during the interaction with the HDF5 * repository */ - public List saveGridsToHdf5(List dataObjects, + private List saveGridsToHdf5(List dataObjects, ParmStorageInfo parmStorageInfo) throws GfeException { List failedGrids = new ArrayList(); try { @@ -1880,7 +1475,7 @@ public class IFPGridDatabase extends GridDatabase { parmStorageInfo = findStorageInfo(rec.getParmId()); } // Get storage info (for float and vector data) - String storageType = parmStorageInfo.storageType(); + String storageType = parmStorageInfo.getStorageType(); if ((data instanceof FloatDataRecord) && !"float".equals(storageType)) { @@ -1893,45 +1488,21 @@ public class IFPGridDatabase extends GridDatabase { dataStore.addDataRecord((IDataRecord) data, sp); correlationMap.put(((IDataRecord) data), rec); } else if (data instanceof VectorGridSlice) { - storeVectorGridSlice(data, dataStore, sp, groupName, - parmStorageInfo, correlationMap, rec); + storeVectorGridSlice((VectorGridSlice) data, dataStore, + sp, groupName, parmStorageInfo, correlationMap, + rec); } else if (data instanceof ScalarGridSlice) { - storeScalarGridSlice(data, dataStore, sp, groupName, - parmStorageInfo, correlationMap, rec); + storeScalarGridSlice((ScalarGridSlice) data, dataStore, + sp, groupName, parmStorageInfo, correlationMap, + rec); } else if (data instanceof DiscreteGridSlice) { - storeDiscreteGridSlice(data, dataStore, sp, groupName, - parmStorageInfo, correlationMap, rec); + storeDiscreteGridSlice((DiscreteGridSlice) data, + dataStore, sp, groupName, parmStorageInfo, + correlationMap, rec); } else if (data instanceof WeatherGridSlice) { - WeatherGridSlice slice = (WeatherGridSlice) data; - if (slice.getWeatherGrid() != null) { - byte[] rawData = slice.getWeatherGrid().getBuffer() - .array(); - ByteDataRecord rawRecord = new ByteDataRecord( - "Data", groupName, rawData, 2, new long[] { - slice.getGridInfo().getGridLoc() - .getNx(), - slice.getGridInfo().getGridLoc() - .getNy() }); - dataStore.addDataRecord(rawRecord, sp); - - StringBuffer sb = new StringBuffer(); - boolean first = true; - for (WeatherKey key : slice.getKeys()) { - if (first) { - first = false; - } else { - sb.append(GfeUtil.KEY_SEPARATOR); - } - sb.append(key.toString()); - } - byte[] keyBytes = sb.toString().getBytes(); - ByteDataRecord keyRecord = new ByteDataRecord( - "Keys", groupName, keyBytes, 1, - new long[] { keyBytes.length }); - dataStore.addDataRecord(keyRecord, sp); - correlationMap.put(rawRecord, rec); - correlationMap.put(keyRecord, rec); - } + storeWeatherGridSlice((WeatherGridSlice) data, + dataStore, sp, groupName, parmStorageInfo, + correlationMap, rec); } } @@ -1974,10 +1545,12 @@ public class IFPGridDatabase extends GridDatabase { /** * Store a grid slice of scalar data. * - * @param data + * @param slice * The scalar grid slice to store. * @param dataStore * The data store in which to put the slice. + * @param sp + * The storage properties * @param groupName * The group name under which to store the slice. * @param parmStorageInfo @@ -1988,12 +1561,11 @@ public class IFPGridDatabase extends GridDatabase { * The GFERecord the slice is associated with. * @throws StorageException */ - protected void storeScalarGridSlice(Object data, IDataStore dataStore, - StorageProperties sp, String groupName, + protected void storeScalarGridSlice(ScalarGridSlice slice, + IDataStore dataStore, StorageProperties sp, String groupName, ParmStorageInfo parmStorageInfo, Map correlationMap, GFERecord rec) throws StorageException { - ScalarGridSlice slice = (ScalarGridSlice) data; if (slice.getScalarGrid() != null) { float[] rawData = slice.getScalarGrid().getFloats(); FloatDataRecord rawRecord = new FloatDataRecord("Data", groupName, @@ -2008,10 +1580,12 @@ public class IFPGridDatabase extends GridDatabase { /** * Store a grid slice of vector data. * - * @param data + * @param slice * The vector grid slice * @param dataStore * The data store in which to save the slice + * @param sp + * The storage properties * @param groupName * The group name under which to save the slice * @param parmStorageInfo @@ -2023,12 +1597,11 @@ public class IFPGridDatabase extends GridDatabase { * The GFERecord associated with the slice * @throws StorageException */ - protected void storeVectorGridSlice(Object data, IDataStore dataStore, - StorageProperties sp, String groupName, + protected void storeVectorGridSlice(VectorGridSlice slice, + IDataStore dataStore, StorageProperties sp, String groupName, ParmStorageInfo parmStorageInfo, Map correlationMap, GFERecord rec) throws StorageException { - VectorGridSlice slice = (VectorGridSlice) data; if ((slice.getMagGrid() != null) || (slice.getDirGrid() != null)) { float[] rawMagData = slice.getMagGrid().getFloats(); float[] rawDirData = slice.getDirGrid().getFloats(); @@ -2045,10 +1618,10 @@ public class IFPGridDatabase extends GridDatabase { // Direction grids use the same storage type as the mag grid, // but offset is always 0 and multiplier is always 0.5. ParmStorageInfo dirStorageInfo = new ParmStorageInfo( - parmStorageInfo.dataType(), parmStorageInfo.gridSize(), - parmStorageInfo.parmName(), parmStorageInfo.level(), - VECTOR_DIR_DATA_OFFSET, VECTOR_DIR_DATA_MULTIPLIER, - parmStorageInfo.storageType()); + parmStorageInfo.getDataType(), + parmStorageInfo.getGridParmInfo(), VECTOR_DIR_DATA_OFFSET, + VECTOR_DIR_DATA_MULTIPLIER, + parmStorageInfo.getStorageType()); this.storeConvertedFloatRecord(rawMagRecord, dataStore, sp, groupName, parmStorageInfo, correlationMap, rec); this.storeConvertedFloatRecord(rawDirRecord, dataStore, sp, @@ -2059,7 +1632,7 @@ public class IFPGridDatabase extends GridDatabase { /** * Store a grid slice of discrete data. * - * @param data + * @param slice * The discrete grid slice * @param dataStore * The data store in which to save the slice @@ -2076,12 +1649,11 @@ public class IFPGridDatabase extends GridDatabase { * The GFERecord associated with the slice * @throws StorageException */ - protected void storeDiscreteGridSlice(Object data, IDataStore dataStore, - StorageProperties sp, String groupName, + protected void storeDiscreteGridSlice(DiscreteGridSlice slice, + IDataStore dataStore, StorageProperties sp, String groupName, ParmStorageInfo parmStorageInfo, Map correlationMap, GFERecord rec) throws StorageException { - DiscreteGridSlice slice = (DiscreteGridSlice) data; if (slice.getDiscreteGrid() != null) { byte[] rawData = slice.getDiscreteGrid().getBuffer().array(); ByteDataRecord rawRecord = new ByteDataRecord("Data", groupName, @@ -2112,10 +1684,12 @@ public class IFPGridDatabase extends GridDatabase { /** * Store a grid slice of weather data. * - * @param data + * @param slice * The weather grid slice * @param dataStore * The data store in which to save the slice + * @param sp + * The storage properties * @param groupName * The group name under which to save the slice * @param parmStorageInfo @@ -2127,11 +1701,36 @@ public class IFPGridDatabase extends GridDatabase { * The GFERecord associated with the slice * @throws StorageException */ - protected void storeWeatherGridSlice(Object data, IDataStore dataStore, - String groupName, ParmStorageInfo parmStorageInfo, + protected void storeWeatherGridSlice(WeatherGridSlice slice, + IDataStore dataStore, StorageProperties sp, String groupName, + ParmStorageInfo parmStorageInfo, Map correlationMap, GFERecord rec) throws StorageException { + if (slice.getWeatherGrid() != null) { + byte[] rawData = slice.getWeatherGrid().getBuffer().array(); + ByteDataRecord rawRecord = new ByteDataRecord("Data", groupName, + rawData, 2, new long[] { + slice.getGridInfo().getGridLoc().getNx(), + slice.getGridInfo().getGridLoc().getNy() }); + dataStore.addDataRecord(rawRecord, sp); + StringBuffer sb = new StringBuffer(); + boolean first = true; + for (WeatherKey key : slice.getKeys()) { + if (first) { + first = false; + } else { + sb.append(GfeUtil.KEY_SEPARATOR); + } + sb.append(key.toString()); + } + byte[] keyBytes = sb.toString().getBytes(); + ByteDataRecord keyRecord = new ByteDataRecord("Keys", groupName, + keyBytes, 1, new long[] { keyBytes.length }); + dataStore.addDataRecord(keyRecord, sp); + correlationMap.put(rawRecord, rec); + correlationMap.put(keyRecord, rec); + } } /** @@ -2142,6 +1741,8 @@ public class IFPGridDatabase extends GridDatabase { * the FloatDataRecord to convert * @param dataStore * The data store in which to put the data + * @param sp + * the storage properties * @param groupName * The group name to assign to the stored record * @param parmStorageInfo @@ -2150,6 +1751,7 @@ public class IFPGridDatabase extends GridDatabase { * Used to look up failed saves * @param rec * The GFE record being stored + * @throws StorageException */ protected void storeConvertedFloatRecord(FloatDataRecord data, IDataStore dataStore, StorageProperties sp, String groupName, @@ -2158,9 +1760,9 @@ public class IFPGridDatabase extends GridDatabase { throws StorageException { float[] fdata = data.getFloatData(); - String storageType = parmStorageInfo.storageType(); - float offset = parmStorageInfo.dataOffset(); - float multiplier = parmStorageInfo.dataMultiplier(); + String storageType = parmStorageInfo.getStorageType(); + float offset = parmStorageInfo.getDataOffset(); + float multiplier = parmStorageInfo.getDataMultiplier(); float fcvt; IDataRecord storeDataRec = null; if ("short".equals(storageType) && (multiplier != 0.0f)) { @@ -2189,9 +1791,9 @@ public class IFPGridDatabase extends GridDatabase { correlationMap.put(storeDataRec, rec); } - @Override - public FloatDataRecord[] retrieveFromHDF5(ParmID parmId, - List times) throws GfeException { + private FloatDataRecord[] retrieveFromHDF5(ParmID parmId, + List times, ParmStorageInfo parmStorageInfo) + throws GfeException { FloatDataRecord[] scalarData = null; Map, String[]>> dsAndGroups = getDataStoreAndGroups( parmId, times); @@ -2222,7 +1824,7 @@ public class IFPGridDatabase extends GridDatabase { if (rec instanceof FloatDataRecord) { records.put(timeRange, (FloatDataRecord) rec); - } else if (gridConfig == null) { + } else if (gridDbConfig == null) { throw new IllegalArgumentException("Data array for " + parmId.getParmName() + " " + parmId.getParmLevel() @@ -2231,9 +1833,8 @@ public class IFPGridDatabase extends GridDatabase { + " does not contain a grid configuration."); } else { // Convert to a FloatDataRecord for internal use - ParmStorageInfo psi = parmStorageInfo.get(parmId - .getCompositeName()); - records.put(timeRange, storageToFloat(rec, psi)); + records.put(timeRange, + storageToFloat(rec, parmStorageInfo)); } } } @@ -2251,9 +1852,9 @@ public class IFPGridDatabase extends GridDatabase { return scalarData; } - @Override - public FloatDataRecord[][] retrieveVectorFromHDF5(ParmID parmId, - List times) throws GfeException { + private FloatDataRecord[][] retrieveVectorFromHDF5(ParmID parmId, + List times, ParmStorageInfo magStorageInfo) + throws GfeException { FloatDataRecord[][] vectorData = null; Map, String[]>> dsAndGroups = getDataStoreAndGroups( parmId, times); @@ -2305,7 +1906,7 @@ public class IFPGridDatabase extends GridDatabase { if (magRec instanceof FloatDataRecord) { recs[0] = (FloatDataRecord) magRec; recs[1] = (FloatDataRecord) dirRec; - } else if (gridConfig == null) { + } else if (gridDbConfig == null) { throw new IllegalArgumentException( "Data array for " + parmId.getParmName() @@ -2315,16 +1916,12 @@ public class IFPGridDatabase extends GridDatabase { + toString() + " does not contain a grid configuration."); } else { - ParmStorageInfo magStorageInfo = parmStorageInfo - .get(parmId.getCompositeName()); ParmStorageInfo dirStorageInfo = new ParmStorageInfo( - magStorageInfo.dataType(), - magStorageInfo.gridSize(), - magStorageInfo.parmName(), - magStorageInfo.level(), + magStorageInfo.getDataType(), + magStorageInfo.getGridParmInfo(), VECTOR_DIR_DATA_OFFSET, VECTOR_DIR_DATA_MULTIPLIER, - magStorageInfo.storageType()); + magStorageInfo.getStorageType()); recs[0] = storageToFloat(magRec, magStorageInfo); recs[1] = storageToFloat(dirRec, dirStorageInfo); } @@ -2366,9 +1963,9 @@ public class IFPGridDatabase extends GridDatabase { protected FloatDataRecord storageToFloat(IDataRecord rawData, ParmStorageInfo parmStorageInfo) { FloatDataRecord data; - String storageType = parmStorageInfo.storageType(); - float multiplier = parmStorageInfo.dataMultiplier(); - float offset = parmStorageInfo.dataOffset(); + String storageType = parmStorageInfo.getStorageType(); + float multiplier = parmStorageInfo.getDataMultiplier(); + float offset = parmStorageInfo.getDataOffset(); float[] floats = null; if ("byte".equals(storageType)) { byte[] rawBytes = ((ByteDataRecord) rawData).getByteData(); @@ -2398,63 +1995,25 @@ public class IFPGridDatabase extends GridDatabase { } /** - * @param rec - * @return + * Retrieve the ParmStorageInfo for a parm + * + * @param parmID + * the desired parmID + * @return the ParmStorageInfo */ protected ParmStorageInfo findStorageInfo(ParmID parmID) { - ParmStorageInfo parmStorageInfo = null; + ParmStorageInfo parmStorageInfo = this.parmStorageInfo.get(parmID + .getCompositeName()); - if (gridConfig == null) { + if (parmStorageInfo == null) { // Default to a no-conversion float storage - GridLocation gridLoc = getGridParmInfo(parmID).getPayload() - .getGridLoc(); - parmStorageInfo = new ParmStorageInfo("float", gridLoc.gridSize(), - parmID.getParmName(), parmID.getParmLevel(), 0.0f, 1.0f, + GridParmInfo gpi = getGridParmInfo(parmID).getPayload(); + parmStorageInfo = new ParmStorageInfo("float", gpi, 0.0f, 1.0f, "float"); - } else { - // look up the parm storage info - parmStorageInfo = gridConfig.getParmStorageInfo( - parmID.getParmName(), parmID.getParmLevel()); } return parmStorageInfo; } - private void storeGridParmInfo(List gridParmInfo, - List parmStorageInfoList, StoreOp storeOp) - throws Exception { - IDataStore ds = DataStoreFactory.getDataStore(GfeUtil - .getGridParmHdf5File(gfeBaseDataDir, this.dbId)); - String parmNameAndLevel = null; - for (GridParmInfo gpi : gridParmInfo) { - parmNameAndLevel = gpi.getParmID().getParmName() + "_" - + gpi.getParmID().getParmLevel(); - ByteDataRecord br = new ByteDataRecord(parmNameAndLevel, - GRID_PARM_INFO_GRP, new byte[1]); - br.setDataAttributes(getGpiAsMap(gpi)); - ds.addDataRecord(br); - parmInfo.put(parmNameAndLevel, gpi); - } - - for (ParmStorageInfo psi : parmStorageInfoList) { - parmNameAndLevel = psi.parmName() + "_" + psi.level(); - ByteDataRecord br2 = new ByteDataRecord(parmNameAndLevel, - GRID_PARM_STORAGE_INFO_GRP, new byte[1]); - br2.setDataAttributes(getStorageInfoAsMap(psi)); - ds.addDataRecord(br2); - parmStorageInfo.put(parmNameAndLevel, psi); - } - ds.store(storeOp); - } - - private void storeGridParmInfo(GridParmInfo gpi, ParmStorageInfo psi, - StoreOp storeOp) throws Exception { - List gpis = new ArrayList(); - gpis.add(gpi); - List psis = new ArrayList(); - psis.add(psi); - storeGridParmInfo(gpis, psis, storeOp); - } - /* * (non-Javadoc) * @@ -2518,8 +2077,10 @@ public class IFPGridDatabase extends GridDatabase { * Removes records from the HDF5 repository. If the records do not exist in * the HDF5, the operation is ignored * - * @param record - * The record to remove + * @param parmId + * the parmID of the records to be removed + * @param times + * the timeRanges of the records to be removed */ private void removeFromHDF5(ParmID parmId, List times) { Map, String[]>> fileMap = GfeUtil @@ -2570,12 +2131,8 @@ public class IFPGridDatabase extends GridDatabase { Date publishTime) { ServerResponse sr = new ServerResponse(); - GFEDao dao = null; try { - dao = (GFEDao) PluginFactory.getInstance().getPluginDao("gfe"); dao.updatePublishTime(history, publishTime); - } catch (PluginException e1) { - statusHandler.handle(Priority.PROBLEM, "Unable to get gfe dao", e1); } catch (DataAccessLayerException e) { statusHandler.handle(Priority.PROBLEM, "Unable to update grid history!", e); @@ -2594,7 +2151,8 @@ public class IFPGridDatabase extends GridDatabase { */ public ParmID getCachedParmID(String parmNameAndLevel) throws UnknownParmIdException { - ParmID rval = parmIdMap.get(parmNameAndLevel); + // ParmID rval = parmIdMap.get(parmNameAndLevel); + ParmID rval = this.parmStorageInfo.get(parmNameAndLevel).getParmID(); if (rval == null) { throw new UnknownParmIdException("ParmId: " + parmNameAndLevel @@ -2606,7 +2164,9 @@ public class IFPGridDatabase extends GridDatabase { @Override public ParmID getCachedParmID(ParmID parmId) throws UnknownParmIdException { - ParmID rval = parmIdMap.get(parmId.getCompositeName()); + // ParmID rval = parmIdMap.get(parmId.getCompositeName()); + ParmID rval = this.parmStorageInfo.get(parmId.getCompositeName()) + .getParmID(); if (rval == null) { throw new UnknownParmIdException("ParmId: " + parmId.toString() @@ -2634,7 +2194,6 @@ public class IFPGridDatabase extends GridDatabase { ServerResponse>> sr = new ServerResponse>>(); try { ParmID dbParmId = getCachedParmID(parmId); - GFEDao dao = new GFEDao(); sr.setPayload(dao.updateSentTime(dbParmId, tr, sentTime)); } catch (UnknownParmIdException e) { sr.addMessage(e.getLocalizedMessage()); @@ -2646,4 +2205,103 @@ public class IFPGridDatabase extends GridDatabase { return sr; } + + /** + * Retrieves the ByteDataRecord for a Discrete grid for multiple time ranges + * from HDF5 + * + * @param parmId + * @param times + * @return array containing the data and keys for the specified times + * @throws GfeException + */ + public ByteDataRecord[][] retrieveDiscreteFromHDF5(ParmID parmId, + List times) throws GfeException { + ByteDataRecord[][] byteRecords = null; + Map, String[]>> dsAndGroups = getDataStoreAndGroups( + parmId, times); + + try { + // loop over the dataStores and their respective groups to pull all + // data + Map records = new HashMap( + (int) (1.25 * times.size()) + 1); + + for (Map.Entry, String[]>> entry : dsAndGroups + .entrySet()) { + Pair, String[]> pair = entry.getValue(); + String[] groups = pair.getSecond(); + + IDataRecord[] rawData = entry.getKey().retrieveGroups(groups, + Request.ALL); + + if (rawData.length != (groups.length * 2)) { + throw new IllegalArgumentException( + "Invalid number of dataSets returned expected 2 per group, received: " + + ((double) rawData.length / groups.length)); + } + + // iterate over the data from this dataStore adding it records + int count = 0; + for (TimeRange timeRange : pair.getFirst()) { + ByteDataRecord[] recs = new ByteDataRecord[2]; + for (int i = 0; i < 2; i++) { + IDataRecord rec = rawData[(count * 2) + i]; + + if ("Data".equals(rec.getName())) { + recs[0] = (ByteDataRecord) rec; + } else if ("Keys".equals(rec.getName())) { + recs[1] = (ByteDataRecord) rec; + } else { + throw new IllegalArgumentException( + "Unknown dataset retrieved for vector data. Valid values: Data, Keys Received: " + + rec.getName()); + } + } + records.put(timeRange, recs); + count++; + } + } + + byteRecords = new ByteDataRecord[times.size()][2]; + int count = 0; + for (TimeRange timeRange : times) { + byteRecords[count++] = records.get(timeRange); + } + } catch (Exception e) { + throw new GfeException("Unable to get data from HDF5 for ParmID: " + + parmId + " TimeRange: " + times, e); + } + return byteRecords; + } + + /** + * Retrieve the FloatDataRecord for a grid from HDF5 + * + * @param parmId + * @param time + * @param parmStorageInfo + * @return the FloatDataRecord + * @throws GfeException + */ + private FloatDataRecord retrieveFromHDF5(ParmID parmId, TimeRange time, + ParmStorageInfo parmStorageInfo) throws GfeException { + return retrieveFromHDF5(parmId, + Arrays.asList(new TimeRange[] { time }), parmStorageInfo)[0]; + } + + /** + * Retrieve the magnitude and direction grids for a vector parm from HDF5 + * + * @param parmId + * @param time + * @param magStorageInfo + * @return the the magnitude and direction grids + * @throws GfeException + */ + private FloatDataRecord[] retrieveVectorFromHDF5(ParmID parmId, + TimeRange time, ParmStorageInfo magStorageInfo) throws GfeException { + return retrieveVectorFromHDF5(parmId, + Arrays.asList(new TimeRange[] { time }), magStorageInfo)[0]; + } } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/util/CreateGFEGridsSQL.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/util/CreateGFEGridsSQL.java deleted file mode 100644 index a2e1687c2d..0000000000 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/util/CreateGFEGridsSQL.java +++ /dev/null @@ -1,549 +0,0 @@ -/** - * This software was developed and / or modified by Raytheon Company, - * pursuant to Contract DG133W-05-CQ-1067 with the US Government. - * - * U.S. EXPORT CONTROLLED TECHNICAL DATA - * This software product contains export-restricted data whose - * export/transfer/disclosure is restricted by U.S. law. Dissemination - * to non-U.S. persons whether in the United States or abroad requires - * an export license or other authorization. - * - * Contractor Name: Raytheon Company - * Contractor Address: 6825 Pine Street, Suite 340 - * Mail Stop B8 - * Omaha, NE 68106 - * 402.291.0100 - * - * See the AWIPS II Master Rights File ("Master Rights File.pdf") for - * further licensing information. - **/ -package com.raytheon.edex.plugin.gfe.util; - -import java.awt.Point; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.StreamTokenizer; -import java.util.LinkedHashMap; -import java.util.TimeZone; - -import org.geotools.coverage.grid.GeneralGridEnvelope; -import org.geotools.coverage.grid.GridGeometry2D; -import org.geotools.geometry.GeneralEnvelope; -import org.geotools.referencing.operation.DefaultMathTransformFactory; -import org.opengis.metadata.spatial.PixelOrientation; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.crs.CoordinateReferenceSystem; -import org.opengis.referencing.operation.MathTransform; -import org.opengis.referencing.operation.TransformException; - -import com.raytheon.uf.common.dataplugin.gfe.config.ProjectionData; -import com.raytheon.uf.common.dataplugin.gfe.config.ProjectionData.ProjectionType; -import com.raytheon.uf.common.geospatial.MapUtil; -import com.vividsolutions.jts.geom.Coordinate; - -public class CreateGFEGridsSQL { - static final CreateGFEGridsSQL x = new CreateGFEGridsSQL(); - - // public class ProjectionData { - // String projectionType; - // - // Coordinate latLonLL; - // - // Coordinate latLonUR; - // - // Coordinate latLonOrigin; - // - // double stdParallelOne; - // - // double stdParallelTwo; - // - // Coordinate gridPointLL; - // - // Coordinate gridPointUR; - // - // double latIntersect; - // - // double lonCenter; - // - // double lonOrigin; - // - // public ProjectionData() { - // latLonLL = new Coordinate(); - // latLonUR = new Coordinate(); - // latLonOrigin = new Coordinate(); - // gridPointLL = new Coordinate(); - // gridPointUR = new Coordinate(); - // } - // - // /* - // * (non-Javadoc) - // * - // * @see java.lang.Object#toString() - // */ - // @Override - // public String toString() { - // String result = "{"; - // - // result += projectionType + ", "; - // result += latLonLL + ", "; - // result += latLonUR + ", "; - // result += latLonOrigin + ", "; - // result += stdParallelOne + ", "; - // result += stdParallelTwo + ", "; - // result += gridPointLL + ", "; - // result += gridPointUR + ", "; - // result += latIntersect + ", "; - // result += lonCenter + ", "; - // result += lonOrigin; - // - // result += "}"; - // return result; - // } - // - // } - - public class GridData { - Coordinate gridSize; - - Coordinate origin; - - Coordinate extent; - - String timeZone; - - String projName; - - public GridData() { - gridSize = new Coordinate(); - origin = new Coordinate(); - extent = new Coordinate(); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - String result = "{"; - - result += gridSize + ", "; - result += origin + ", "; - result += extent + ", "; - result += timeZone + ", "; - result += projName; - - result += "}"; - return result; - } - - } - - /** - * @param args - */ - public static void main(String[] args) { - try { - BufferedReader in = new BufferedReader(new FileReader( - "/home/randerso/gfe/GFEProjs.txt")); - StreamTokenizer st = new StreamTokenizer(in); - st.eolIsSignificant(false); - st.parseNumbers(); - st.quoteChar('\''); - st.commentChar('#'); - st.wordChars('_', '_'); - - LinkedHashMap projMap = new LinkedHashMap(); - while (st.ttype != StreamTokenizer.TT_EOF) { - if (getToken(st) != StreamTokenizer.TT_WORD) { - continue; - } - - ProjectionData proj = readProj(st); - if (proj != null) { - projMap.put(proj.getProjectionID(), proj); - } - } - in.close(); - - in = new BufferedReader(new FileReader( - "/home/randerso/gfe/GFEGrids.txt")); - - st = new StreamTokenizer(in); - st.eolIsSignificant(false); - st.parseNumbers(); - st.ordinaryChar('\''); - st.commentChar('#'); - st.wordChars('_', '_'); - st.wordChars('/', '/'); - - LinkedHashMap gridMap = new LinkedHashMap(); - while (st.ttype != StreamTokenizer.TT_EOF) { - if (getToken(st) != StreamTokenizer.TT_WORD) { - continue; - } - String id = st.sval; - - GridData grid = readGrid(st); - if (grid != null) { - if (projMap.containsKey(grid.projName)) { - gridMap.put(id, grid); - } else { - System.out.println("Grid: " + id - + " refers to unknown projection " - + grid.projName); - } - } - } - in.close(); - - BufferedWriter out = new BufferedWriter(new FileWriter( - "/home/randerso/gfe/spatial_gfe.sql")); - out.write("DROP TABLE IF EXISTS awips.spatial_gfe;\n"); - out.write("CREATE TABLE awips.spatial_gfe\n"); - out.write("(\n"); - out.write(" siteId character varying(4),\n"); - out.write(" nx integer,\n"); - out.write(" ny integer,\n"); - out.write(" timeZone character varying(32),\n"); - out.write(" crs character varying(2047),\n"); - out.write(" coverage geometry,\n"); - out.write(" CONSTRAINT spatial_gfe_pkey PRIMARY KEY (siteId)\n"); - out.write(")\n"); - out.write("WITHOUT OIDS;\n"); - out.write("ALTER TABLE awips.spatial_gfe OWNER TO awips;\n"); - out.write("\n\n"); - - for (String gridId : gridMap.keySet()) { - GridData grid = gridMap.get(gridId); - String sql = createInsert(gridId, grid, projMap - .get(grid.projName)); - out.write(sql); - out.write("\n\n"); - } - out.close(); - - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - - public static int getToken(StreamTokenizer st) throws IOException { - loop: while (st.nextToken() != StreamTokenizer.TT_EOF) { - switch (st.ttype) { - case StreamTokenizer.TT_NUMBER: - case StreamTokenizer.TT_WORD: - break loop; - } - } - return st.ttype; - } - - public static GridData readGrid(StreamTokenizer st) throws IOException { - GridData grid = x.new GridData(); - - if (getToken(st) != StreamTokenizer.TT_NUMBER) { - return null; - } - grid.gridSize.x = st.nval; - if (getToken(st) != StreamTokenizer.TT_NUMBER) { - return null; - } - grid.gridSize.y = st.nval; - - if (getToken(st) != StreamTokenizer.TT_NUMBER) { - return null; - } - grid.origin.x = st.nval; - if (getToken(st) != StreamTokenizer.TT_NUMBER) { - return null; - } - grid.origin.y = st.nval; - - if (getToken(st) != StreamTokenizer.TT_NUMBER) { - return null; - } - grid.extent.x = st.nval; - if (getToken(st) != StreamTokenizer.TT_NUMBER) { - return null; - } - grid.extent.y = st.nval; - - if (getToken(st) != StreamTokenizer.TT_WORD) { - return null; - } - grid.timeZone = st.sval; - - if (getToken(st) != StreamTokenizer.TT_WORD) { - return null; - } - grid.projName = st.sval; - - TimeZone tz = TimeZone.getTimeZone(grid.timeZone); - - if (!grid.timeZone.equals(tz.getID())) { - System.out - .println("ERROR: unrecognized time zone " + grid.timeZone); - } - - return grid; - } - - public static ProjectionData readProj(StreamTokenizer st) - throws IOException { - - String id = st.sval; - if (getToken(st) != StreamTokenizer.TT_WORD) { - return null; - } - String s = st.sval; - ProjectionType projectionType = ProjectionType.valueOf(s); - - if (getToken(st) != StreamTokenizer.TT_NUMBER) { - return null; - } - Coordinate latLonLL = new Coordinate(); - latLonLL.x = MapUtil.correctLon(st.nval); - if (getToken(st) != StreamTokenizer.TT_NUMBER) { - return null; - } - latLonLL.y = st.nval; - - Coordinate latLonUR = new Coordinate(); - if (getToken(st) != StreamTokenizer.TT_NUMBER) { - return null; - } - latLonUR.x = MapUtil.correctLon(st.nval); - if (getToken(st) != StreamTokenizer.TT_NUMBER) { - return null; - } - latLonUR.y = st.nval; - - Coordinate latLonOrigin = new Coordinate(); - if (getToken(st) != StreamTokenizer.TT_NUMBER) { - return null; - } - latLonOrigin.x = MapUtil.correctLon(st.nval); - if (getToken(st) != StreamTokenizer.TT_NUMBER) { - return null; - } - latLonOrigin.y = st.nval; - - if (getToken(st) != StreamTokenizer.TT_NUMBER) { - return null; - } - float stdParallelOne = (float) st.nval; - - if (getToken(st) != StreamTokenizer.TT_NUMBER) { - return null; - } - float stdParallelTwo = (float) st.nval; - - if (getToken(st) != StreamTokenizer.TT_NUMBER) { - return null; - } - Point gridPointLL = new Point(); - gridPointLL.x = (int) st.nval; - if (getToken(st) != StreamTokenizer.TT_NUMBER) { - return null; - } - gridPointLL.y = (int) st.nval; - - Point gridPointUR = new Point(); - if (getToken(st) != StreamTokenizer.TT_NUMBER) { - return null; - } - gridPointUR.x = (int) st.nval; - if (getToken(st) != StreamTokenizer.TT_NUMBER) { - return null; - } - gridPointUR.y = (int) st.nval; - - if (getToken(st) != StreamTokenizer.TT_NUMBER) { - return null; - } - float latIntersect = (float) MapUtil.correctLat(st.nval); - - if (getToken(st) != StreamTokenizer.TT_NUMBER) { - return null; - } - float lonCenter = (float) MapUtil.correctLon(st.nval); - - if (getToken(st) != StreamTokenizer.TT_NUMBER) { - return null; - } - float lonOrigin = (float) MapUtil.correctLon(st.nval); - - ProjectionData proj = new ProjectionData(id, projectionType.ordinal(), - latLonLL, latLonUR, latLonOrigin, stdParallelOne, - stdParallelTwo, gridPointLL, gridPointUR, latIntersect, - lonCenter, lonOrigin); - return proj; - } - - public static String createInsert(String gridId, GridData grid, - ProjectionData proj) { - try { - // construct the appropriate CRS based on the projection type - CoordinateReferenceSystem crs; - switch (proj.getProjectionType()) { - case LAMBERT_CONFORMAL: - crs = MapUtil.constructLambertConformal( - MapUtil.AWIPS_EARTH_RADIUS, MapUtil.AWIPS_EARTH_RADIUS, - proj.getStdParallelOne(), proj.getStdParallelTwo(), - proj.getLatLonOrigin().x); - break; - - case MERCATOR: - crs = MapUtil.constructMercator(MapUtil.AWIPS_EARTH_RADIUS, - MapUtil.AWIPS_EARTH_RADIUS, proj.getStdParallelOne(), - proj.getLonCenter()); - break; - - case POLAR_STEREOGRAPHIC: - crs = MapUtil.constructNorthPolarStereo( - MapUtil.AWIPS_EARTH_RADIUS, MapUtil.AWIPS_EARTH_RADIUS, - 60.0, proj.getLonOrigin()); - break; - - case LATLON: - crs = MapUtil.LATLON_PROJECTION; - break; - - case NONE: - default: - System.out.println("ERROR: unknown projection type: " - + proj.getProjectionType()); - return ""; - } - - // transform the projection corner points to CRS units - MathTransform mt = MapUtil.getTransformFromLatLon(crs); - double[] output = new double[4]; - mt.transform(new double[] { proj.getLatLonLL().x, - proj.getLatLonLL().y, proj.getLatLonUR().x, - proj.getLatLonUR().y }, 0, output, 0, 2); - - // create a grid geometry for the projection - GeneralEnvelope ge = new GeneralEnvelope(2); - ge.setCoordinateReferenceSystem(crs); - ge.setRange(0, Math.min(output[0], output[2]), Math.max(output[0], - output[2])); - ge.setRange(1, Math.min(output[1], output[3]), Math.max(output[1], - output[3])); - - GeneralGridEnvelope gr = new GeneralGridEnvelope(new int[] { - proj.getGridPointLL().x, proj.getGridPointLL().y }, - new int[] { proj.getGridPointUR().x, - proj.getGridPointUR().y }, false); - - GridGeometry2D projGeom = new GridGeometry2D(gr, ge); - - DefaultMathTransformFactory dmtf = new DefaultMathTransformFactory(); - double[] latLon = new double[8]; - - // check to see if the projection looks right - // mt = dmtf.createConcatenatedTransform(projGeom - // .getGridToCRS(PixelOrientation.UPPER_LEFT), MapUtil - // .getTransformToLatLon(crs)); - // mt.transform(new double[] { proj.getGridPointLL().x, - // proj.getGridPointUR().y, proj.getGridPointLL().x, - // proj.getGridPointLL().y, proj.getGridPointUR().x, - // proj.getGridPointLL().y, proj.getGridPointUR().x, - // proj.getGridPointUR().y }, 0, latLon, 0, 4); - // - // System.out.println(); - // System.out.println(grid.projName); - // for (int i = 0; i < latLon.length; i += 2) { - // System.out - // .println("(" + latLon[i + 1] + ", " + latLon[i] + ")"); - // } - - // transform the grid corners from grid coordinates to CRS units - // need to adjust for the fact that AWIPS considers 1,1 to be in - // lower left - // and GeoTools considers 1,1 to be in upper left - Coordinate ll = new Coordinate(grid.origin.x, - proj.getGridPointUR().y - grid.origin.y - + proj.getGridPointLL().y); - Coordinate ur = new Coordinate(grid.origin.x + grid.extent.x, ll.y - - grid.extent.y); - - mt.transform(new double[] { ll.x, ll.y, ur.x, ur.y }, 0, output, 0, - 2); - - // System.out.println(); - // for (int i = 0; i < output.length; i += 2) { - // System.out - // .println("(" + output[i + 1] + ", " + output[i] + ")"); - // } - - mt = projGeom.getGridToCRS(PixelOrientation.UPPER_LEFT); - output = new double[4]; - mt.transform(new double[] { ll.x, ll.y, ur.x, ur.y }, 0, output, 0, - 2); - - // construct the grid geometry that covers the GFE grid - ge.setRange(0, Math.min(output[0], output[2]), Math.max(output[0], - output[2])); - ge.setRange(1, Math.min(output[1], output[3]), Math.max(output[1], - output[3])); - GridGeometry2D gridGeom = new GridGeometry2D( - new GeneralGridEnvelope(new int[] { 0, 0 }, new int[] { - (int) grid.gridSize.x - 1, - (int) grid.gridSize.y - 1 }, false), ge); - - // set up the transform from grid coordinates to lon/lat - mt = dmtf.createConcatenatedTransform(gridGeom - .getGridToCRS(PixelOrientation.CENTER), MapUtil - .getTransformToLatLon(crs)); - - // transform grid corner points to Lat/Lon - mt.transform(new double[] { -1.0, grid.gridSize.y - 1, -1.0, -1.0, - grid.gridSize.x - 1, -1.0, grid.gridSize.x - 1, - grid.gridSize.y - 1 }, 0, latLon, 0, 4); - - // System.out.println(); - // System.out.println(gridId); - // for (int i = 0; i < latLon.length; i += 2) { - // System.out - // .println("(" + latLon[i + 1] + ", " + latLon[i] + ")"); - // } - - StringBuffer sql = new StringBuffer(); - sql - .append("INSERT INTO awips.spatial_gfe (siteId,nx,ny,timeZone,crs,coverage) VALUES ("); - - sql.append("'" + gridId + "',"); - sql.append((int) grid.gridSize.x + ","); - sql.append((int) grid.gridSize.y + ","); - sql.append("'" + grid.timeZone + "',"); - sql.append("'" + crs.toWKT() + "',\n"); - sql.append("GeomFromText('POLYGON ((" + latLon[0] + " " + latLon[1] - + ",\n" + latLon[2] + " " + latLon[3] + ",\n" + latLon[4] - + " " + latLon[5] + ",\n" + latLon[6] + " " + latLon[7] - + ",\n" + latLon[0] + " " + latLon[1] + "))',-1)"); - - sql.append(");"); - return sql.toString(); - - } catch (TransformException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (FactoryException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return ""; - } -} diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/config/gfe/doConfig.py b/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/config/gfe/doConfig.py index 336455fb56..42d6d43356 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/config/gfe/doConfig.py +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/config/gfe/doConfig.py @@ -17,8 +17,21 @@ # See the AWIPS II Master Rights File ("Master Rights File.pdf") for # further licensing information. ## +# doConfig - validate and convert serverConfig into simple Java objects +# # this file was originally config.py # it was renamed to avoid a conflict with jep's built-in config module +# +# ---------------------------------------------------------------------------- +# +# SOFTWARE HISTORY +# +# Date Ticket# Engineer Description +# ------------ ---------- ----------- -------------------------- +# 08/09/2013 #1571 randerso Changed projections to use the Java +# ProjectionType enumeration +# +######################################################################## import types from java.util import ArrayList,LinkedHashMap @@ -50,10 +63,16 @@ def check(data, fmt, message, allData = None): if allData is not None: m = m + ' All: ' + `allData` raise AssertionError, m - for i in xrange(len(data)): - if type(data[i]) != fmt[i]: + for i in xrange(len(data)): + obj = data[i] + if hasattr(obj, "jclassname"): + t = obj.jclassname + else: + t = type(obj) + + if t != fmt[i]: m = message + ": Wrong data type found, " + \ - "Expected " + `fmt[i]` + ", got " + `type(data[i])` + \ + "Expected " + `fmt[i]` + ", got " + `t` + \ " for position #" + `i+1` + " Input: " + `data` if allData is not None: m = m + ' All: ' + `allData` @@ -235,8 +254,9 @@ def parseDBItm(site, domain, item): def updateProjections(projection): from com.raytheon.uf.common.dataplugin.gfe.config import ProjectionData # extract projection data - projFmt = (str, int, tuple, tuple, tuple, float, float, tuple, tuple, - float, float, float) + projFmt = (str, + "com.raytheon.uf.common.dataplugin.gfe.config.ProjectionData$ProjectionType", + tuple, tuple, tuple, float, float, tuple, tuple, float, float, float) projID, ptype, pllll, pllur, pllo, pspo, pspt, pgpll, pgpur, pli, \ plc, plo = check(projection, projFmt, "Format error in Projection") check(pllll, (float, float), @@ -276,8 +296,9 @@ def parseGridLocation(domain): check(origin, (float, float), "Origin format error from SITES", domain) check(extent, (float, float), "Extent format error from SITES", domain) - projFmt = (str, int, tuple, tuple, tuple, float, float, tuple, tuple, - float, float, float) + projFmt = (str, + "com.raytheon.uf.common.dataplugin.gfe.config.ProjectionData$ProjectionType", + tuple, tuple, tuple, float, float, tuple, tuple, float, float, float) projID, projType, llll, llur, llo, sp1, sp2, gpll, gpur, li, lc, lo = \ check(proj, projFmt, "Format error in Projection") check(llll, (float, float), diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/config/gfe/serverConfig.py b/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/config/gfe/serverConfig.py index 74fca65b69..ed52ed847b 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/config/gfe/serverConfig.py +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/config/gfe/serverConfig.py @@ -17,8 +17,21 @@ # See the AWIPS II Master Rights File ("Master Rights File.pdf") for # further licensing information. ## +# serverConfig -- base GFE server configuration file +# # NOTE: THIS FILE SHOULD NOT BE USER-MODIFIED. INSTEAD REFER TO THE # LOCAL CONFIG DOCUMENTATION ON HOW TO OVERRIDE SETTINGS IN THIS FILE. +# +# ---------------------------------------------------------------------------- +# +# SOFTWARE HISTORY +# +# Date Ticket# Engineer Description +# ------------ ---------- ----------- -------------------------- +# 08/09/2013 #1571 randerso Changed projections to use the Java +# ProjectionType enumeration +# +######################################################################## #---------------------------------------------------------------------------- # USEFUL DEFINES @@ -458,11 +471,12 @@ if not BASELINE and siteImport('localWxConfig'): # Projection Configuration section. # #--------------------------------------------------------------------------- -NONE = 0 -LAMBERT_CONFORMAL = 1 -MERCATOR = 2 -POLAR_STEREOGRAPHIC = 3 -LATLON = 4 +from com.raytheon.uf.common.dataplugin.gfe.config import ProjectionData_ProjectionType as ProjectionType +NONE = ProjectionType.NONE +LAMBERT_CONFORMAL = ProjectionType.LAMBERT_CONFORMAL +MERCATOR = ProjectionType.MERCATOR +POLAR_STEREOGRAPHIC = ProjectionType.POLAR_STEREOGRAPHIC +LATLON = ProjectionType.LATLON # projectionID / projectionType / latLonLL / latLonUR / # latLonOrigin / stdParallelOne / stdParallelTwo / gridPointLL / gridPointUR diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/gfe/isc/ifpnetCDF.py b/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/gfe/isc/ifpnetCDF.py index c4c8a39830..5bb780eb47 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/gfe/isc/ifpnetCDF.py +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/gfe/isc/ifpnetCDF.py @@ -67,6 +67,8 @@ from com.raytheon.uf.common.localization import LocalizationContext_Localization # 05/23/13 1759 dgilling Remove unnecessary imports. # 06/13/13 2044 randerso Updated for changes to TopoDatabaseManager # 07/25/13 2233 randerso Improved memory utilization and performance +# 08/09/2013 1571 randerso Changed projections to use the Java +# ProjectionType enumeration # # @@ -650,15 +652,15 @@ def storeProjectionAttributes(var, projectionData): setattr(var, "projectionType", projectionType.toString()) # Now store the projection specific attributes - if projectionType.toString() == "LAMBERT_CONFORMAL": + if ProjectionType.LAMBERT_CONFORMAL.equals(projectionType): setattr(var, "latLonOrigin", (projectionData.getLatLonOrigin().x, projectionData.getLatLonOrigin().y)) setattr(var, "stdParallelOne", projectionData.getStdParallelOne()) setattr(var, "stdParallelTwo", projectionData.getStdParallelTwo()) - if projectionType.toString() == "POLAR_STEREOGRAPHIC": + if ProjectionType.POLAR_STEREOGRAPHIC.equals(projectionType): setattr(var, "lonOrigin", projectionData.getLonOrigin()) - if projectionType.toString() == "MERCATOR": + if ProjectionType.MERCATOR.equals(projectionType): setattr(var, "lonCenter", projectionData.getLonCenter()) return @@ -1098,7 +1100,7 @@ def storeDiscreteWE(we, trList, file, timeRange, databaseID, invMask, clipArea): grid = clipToExtrema(dis[0], clipArea) byteCube[i] = grid keyList.append(dis[1]) - + # make the variable name varName = we.getParmid().getParmName() + "_" + we.getParmid().getParmLevel() @@ -1349,8 +1351,8 @@ def main(outputFilename, parmList, databaseID, startTime, clipArea = extremaOfSetBits(maskGrid) maskGrid = clipToExtrema(maskGrid, clipArea) clippedGridSize = maskGrid.shape - validPointCount = numpy.add.reduce(numpy.add.reduce(maskGrid)) - + validPointCount = numpy.add.reduce(numpy.add.reduce(maskGrid)) + #invert the mask grid invMask = numpy.logical_not(maskGrid) #del maskGrid diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject index 78a8b673f5..b7f03fd211 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject @@ -2,7 +2,9 @@ com.raytheon.uf.common.dataplugin.gfe.config.ProjectionData com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID com.raytheon.uf.common.dataplugin.gfe.db.objects.GFERecord com.raytheon.uf.common.dataplugin.gfe.db.objects.GridLocation +com.raytheon.uf.common.dataplugin.gfe.db.objects.GridParmInfo com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID +com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmStorageInfo com.raytheon.uf.common.dataplugin.gfe.reference.ReferenceData com.raytheon.uf.common.dataplugin.gfe.sample.SampleData com.raytheon.uf.common.dataplugin.gfe.server.lock.Lock diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/RemapGrid.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/RemapGrid.java index 211ff05626..60666d9995 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/RemapGrid.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/RemapGrid.java @@ -49,7 +49,6 @@ import com.raytheon.uf.common.geospatial.interpolation.GridReprojection; import com.raytheon.uf.common.geospatial.interpolation.NearestNeighborInterpolation; import com.raytheon.uf.common.geospatial.interpolation.PrecomputedGridReprojection; import com.raytheon.uf.common.geospatial.interpolation.data.ByteBufferWrapper; -import com.raytheon.uf.common.geospatial.interpolation.data.DataSource; import com.raytheon.uf.common.geospatial.interpolation.data.FloatArrayWrapper; import com.vividsolutions.jts.geom.Coordinate; @@ -68,6 +67,7 @@ import com.vividsolutions.jts.geom.Coordinate; * 07/09/13 #2044 randerso Made SoftReferences to interp and rotation since * they can be quite large and may not be needed frequently * 07/17/13 #2185 bsteffen Cache computed grid reprojections. + * 08/13/13 #1571 randerso Passed fill values into interpolator. * * * @@ -154,7 +154,7 @@ public class RemapGrid { float max, float min, float outputFill) throws FactoryException, TransformException { - Grid2DFloat retVal = resample(input); + Grid2DFloat retVal = resample(input, inputFill, outputFill); limitGrid(retVal, inputFill, max, min, outputFill); return retVal; } @@ -195,7 +195,7 @@ public class RemapGrid { return input; } - retVal = resample(input); + retVal = resample(input, inputFill, outputFill); ByteBuffer buffer = retVal.getBuffer(); buffer.rewind(); @@ -259,7 +259,7 @@ public class RemapGrid { * The max value for data values * @param minLimit * The min value for data values - * @param outputFillValue + * @param outputFill * The output fill value * @param rotate * The rotation flag @@ -273,9 +273,9 @@ public class RemapGrid { * If grid dimensions do not match or resampling fails */ public void remapUV(final Grid2DFloat uinput, final Grid2DFloat vinput, - float inputFill, float maxLimit, float minLimit, - float outputFillValue, boolean rotate, boolean flip, - Grid2DFloat magGrid, Grid2DFloat dirGrid) throws Exception { + float inputFill, float maxLimit, float minLimit, float outputFill, + boolean rotate, boolean flip, Grid2DFloat magGrid, + Grid2DFloat dirGrid) throws Exception { if ((uinput.getXdim() != sourceGloc.getNx()) || (uinput.getYdim() != sourceGloc.getNy()) @@ -303,13 +303,13 @@ public class RemapGrid { } } - Grid2DFloat resampledUinput = resample(uinput); - Grid2DFloat resampledVinput = resample(vinput); + Grid2DFloat resampledUinput = resample(uinput, Float.NaN, Float.NaN); + Grid2DFloat resampledVinput = resample(vinput, Float.NaN, Float.NaN); calculateWindGrid(resampledUinput, resampledVinput, rotate, flip, magGrid, dirGrid); - limitGrid(magGrid, inputFill, maxLimit, minLimit, outputFillValue); + limitGrid(magGrid, inputFill, maxLimit, minLimit, outputFill); limitGrid(dirGrid, 0.0f, 360.0f, 0.0f, 0.0f); } @@ -476,12 +476,16 @@ public class RemapGrid { * * @param input * The input data + * @param inputFill + * the input fill value + * @param outputFill + * the output fill value * @return The resampled data * @throws TransformException * @throws FactoryException */ - private Grid2DByte resample(final Grid2DByte input) - throws FactoryException, TransformException { + private Grid2DByte resample(final Grid2DByte input, float inputFill, + float outputFill) throws FactoryException, TransformException { GridGeometry2D sourceGeometry = MapUtil.getGridGeometry(sourceGloc); @@ -491,10 +495,15 @@ public class RemapGrid { GridGeometry2D destGeometry = MapUtil.getGridGeometry(destinationGloc); GridReprojection interp = PrecomputedGridReprojection.getReprojection( sourceGeometry, destGeometry); - DataSource source = new ByteBufferWrapper(data, sourceGeometry); + + ByteBufferWrapper source = new ByteBufferWrapper(data, sourceGeometry); + source.setFillValue(inputFill); + + ByteBufferWrapper dest = new ByteBufferWrapper(destGeometry); + dest.setFillValue(outputFill); + resampledData = interp.reprojectedGrid( - new NearestNeighborInterpolation(), source, - new ByteBufferWrapper(destGeometry)).getBuffer(); + new NearestNeighborInterpolation(), source, dest).getBuffer(); // Remap the the output data into a Grid2DFloat object @@ -510,12 +519,16 @@ public class RemapGrid { * * @param input * The input data + * @param inputFill + * the input fill value + * @param outputFill + * the output fill value * @return The resampled data * @throws TransformException * @throws FactoryException */ - private Grid2DFloat resample(final Grid2DFloat input) - throws FactoryException, TransformException { + private Grid2DFloat resample(final Grid2DFloat input, float inputFill, + float outputFill) throws FactoryException, TransformException { GridGeometry2D sourceGeometry = MapUtil.getGridGeometry(sourceGloc); @@ -566,9 +579,16 @@ public class RemapGrid { GridReprojection interp = PrecomputedGridReprojection .getReprojection(sourceGeometry, destGeometry); - DataSource source = new FloatArrayWrapper(data, sourceGeometry); + + FloatArrayWrapper source = new FloatArrayWrapper(data, + sourceGeometry); + source.setFillValue(inputFill); + + FloatArrayWrapper dest = new FloatArrayWrapper(destGeometry); + dest.setFillValue(outputFill); + f1 = interp.reprojectedGrid(new BilinearInterpolation(), source, - new FloatArrayWrapper(destGeometry)).getArray(); + dest).getArray(); } // Remap the the output data into a Grid2DFloat object diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/config/ProjectionData.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/config/ProjectionData.java index 13a1a763ec..e9c51e89da 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/config/ProjectionData.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/config/ProjectionData.java @@ -22,6 +22,11 @@ package com.raytheon.uf.common.dataplugin.gfe.config; import java.awt.Point; import java.util.HashMap; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.Transient; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; @@ -44,6 +49,8 @@ import com.raytheon.uf.common.serialization.adapters.CoordAdapter; import com.raytheon.uf.common.serialization.adapters.PointAdapter; import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; import com.vividsolutions.jts.geom.Coordinate; /** @@ -56,91 +63,136 @@ import com.vividsolutions.jts.geom.Coordinate; * 03/13/08 #1030 randerso Initial port * 04/24/08 #1047 randerso Made all fields private and created getters * 04/24/13 #1935 randerso Fixed date line spanning issue + * 08/06/13 #1571 randerso Added hibernate annotations + * Removed constructor with int for ProjectionType * * * * @author randerso * @version 1.0 */ +@Embeddable @XmlAccessorType(XmlAccessType.NONE) @DynamicSerialize public class ProjectionData implements ISerializableObject { + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(ProjectionData.class); private static float COMPARISON_THRESHOLD = 0.005f; + /** + * Enumeration of supported map projections + */ public static enum ProjectionType { - NONE, LAMBERT_CONFORMAL, MERCATOR, POLAR_STEREOGRAPHIC, LATLON + /** Undefined map projection */ + NONE, + + /** Lambert Conformal map projection */ + LAMBERT_CONFORMAL, + + /** MERCATOR map projection */ + MERCATOR, + + /** North polar stereographic map projection */ + POLAR_STEREOGRAPHIC, + + /** Lat/Lon (implemented as Equidistant Cylindrical) map projection */ + LATLON }; + @Column(length = 32, nullable = false) @XmlAttribute @DynamicSerializeElement private String projectionID; + @Column(length = 20, nullable = false) + @Enumerated(EnumType.STRING) @XmlAttribute @DynamicSerializeElement private ProjectionType projectionType; + @Column(nullable = false) @XmlElement @XmlJavaTypeAdapter(value = CoordAdapter.class) @DynamicSerializeElement private Coordinate latLonLL; + @Column(nullable = false) @XmlElement @XmlJavaTypeAdapter(value = CoordAdapter.class) @DynamicSerializeElement private Coordinate latLonUR; + @Column(nullable = false) @XmlElement @XmlJavaTypeAdapter(value = CoordAdapter.class) @DynamicSerializeElement private Coordinate latLonOrigin; + @Column(nullable = false) @XmlAttribute @DynamicSerializeElement private double stdParallelOne; + @Column(nullable = false) @XmlAttribute @DynamicSerializeElement private double stdParallelTwo; + @Column(nullable = false) @XmlElement @XmlJavaTypeAdapter(value = PointAdapter.class) @DynamicSerializeElement private Point gridPointLL; + @Column(nullable = false) @XmlElement @XmlJavaTypeAdapter(value = PointAdapter.class) @DynamicSerializeElement private Point gridPointUR; + @Column(nullable = false) @XmlAttribute @DynamicSerializeElement private double latIntersect; + @Column(nullable = false) @XmlAttribute @DynamicSerializeElement private double lonCenter; + @Column(nullable = false) @XmlAttribute @DynamicSerializeElement private double lonOrigin; + @Transient private CoordinateReferenceSystem crs; + @Transient private GridGeometry2D gridGeometry; + @Transient private MathTransform crsToLatLon; + @Transient private MathTransform latLonToCrs; + @Transient private HashMap gridToLatLon; + @Transient private HashMap latLonToGrid; + @Transient private HashMap gridToCrs; + @Transient private boolean initialized; + /** + * Default constructor + */ public ProjectionData() { latLonLL = new Coordinate(); latLonUR = new Coordinate(); @@ -155,17 +207,34 @@ public class ProjectionData implements ISerializableObject { initialized = false; } - public ProjectionData(String projID, int projType, Coordinate latLonLL, - Coordinate latLonUR, Coordinate latLonOrig, float stdPar1, - float stdPar2, Point gridLL, Point gridUR, float latInt, - float lonCenter, float lonOrig) { - this(projID, ProjectionType.values()[projType], latLonLL, latLonUR, - latLonOrig, stdPar1, stdPar2, gridLL, gridUR, latInt, - lonCenter, lonOrig); - - init(); - } - + /** + * Constructor + * + * @param projID + * name associated with this projection + * @param projType + * projection type + * @param latLonLL + * lat/lon of lower left corner + * @param latLonUR + * lat/lon of upper right corner + * @param latLonOrig + * lat/lon of origin (Lambert) + * @param stdPar1 + * standard parallel one (Lambert, Mercator) + * @param stdPar2 + * standard parallel two (Lambert) + * @param gridLL + * coordinates of lower left grid cell, typically (1,1) + * @param gridUR + * coordinates of upper right grid cell, typically (nX,nY) + * @param latInt + * lat intersect (unused, preserved for A1 compatibility) + * @param lonCenter + * lon center (Mercator, LatLon) + * @param lonOrig + * lon origin (Lambert, Polar Stereographic) + */ public ProjectionData(String projID, ProjectionType projType, Coordinate latLonLL, Coordinate latLonUR, Coordinate latLonOrig, float stdPar1, float stdPar2, Point gridLL, Point gridUR, @@ -188,7 +257,10 @@ public class ProjectionData implements ISerializableObject { init(); } - private void init() { + /** + * Initialize the object. Must be called after database retrieval + */ + public void init() { if (initialized) { return; } @@ -259,6 +331,11 @@ public class ProjectionData implements ISerializableObject { return result; } + /** + * Retrieve the Coordinate Reference System (CRS) of this projection + * + * @return the CRS + */ public synchronized CoordinateReferenceSystem getCrs() { if (crs == null) { @@ -310,20 +387,20 @@ public class ProjectionData implements ISerializableObject { return false; } - if (Math.abs(this.latLonLL.y - rhs.latLonLL.y) > COMPARISON_THRESHOLD - || Math.abs(this.latLonLL.x - rhs.latLonLL.x) > COMPARISON_THRESHOLD - || Math.abs(this.latLonUR.y - rhs.latLonUR.y) > COMPARISON_THRESHOLD - || Math.abs(this.latLonLL.x - rhs.latLonLL.x) > COMPARISON_THRESHOLD) { + if ((Math.abs(this.latLonLL.y - rhs.latLonLL.y) > COMPARISON_THRESHOLD) + || (Math.abs(this.latLonLL.x - rhs.latLonLL.x) > COMPARISON_THRESHOLD) + || (Math.abs(this.latLonUR.y - rhs.latLonUR.y) > COMPARISON_THRESHOLD) + || (Math.abs(this.latLonLL.x - rhs.latLonLL.x) > COMPARISON_THRESHOLD)) { return false; } // specific projection comparisons switch (this.projectionType) { case LAMBERT_CONFORMAL: - return (Math.abs(this.latLonOrigin.y - rhs.latLonOrigin.y) < COMPARISON_THRESHOLD - || Math.abs(this.latLonOrigin.x - rhs.latLonOrigin.x) < COMPARISON_THRESHOLD - || Math.abs(this.stdParallelOne - rhs.stdParallelOne) < COMPARISON_THRESHOLD || Math - .abs(this.stdParallelTwo - rhs.stdParallelTwo) < COMPARISON_THRESHOLD); + return ((Math.abs(this.latLonOrigin.y - rhs.latLonOrigin.y) < COMPARISON_THRESHOLD) + || (Math.abs(this.latLonOrigin.x - rhs.latLonOrigin.x) < COMPARISON_THRESHOLD) + || (Math.abs(this.stdParallelOne - rhs.stdParallelOne) < COMPARISON_THRESHOLD) || (Math + .abs(this.stdParallelTwo - rhs.stdParallelTwo) < COMPARISON_THRESHOLD)); case POLAR_STEREOGRAPHIC: return (Math.abs(this.lonOrigin - rhs.lonOrigin) < COMPARISON_THRESHOLD); case MERCATOR: @@ -335,6 +412,15 @@ public class ProjectionData implements ISerializableObject { } } + /** + * Return the lat/lon of the specified corner or center of a grid cell + * + * @param gridCoord + * coordinates of the grid cell + * @param orientation + * desired corner or center + * @return the lat/lon + */ public Coordinate gridCoordinateToLatLon(Coordinate gridCoord, PixelOrientation orientation) { Coordinate latLon = new Coordinate(); @@ -354,51 +440,40 @@ public class ProjectionData implements ISerializableObject { latLon.x = output[0]; latLon.y = output[1]; } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + statusHandler.error( + "Error computing grid coordinate to lat/lon transform", e); } return latLon; } - public Coordinate latLonToGridCoordinate(Coordinate latLon, - PixelOrientation orientation) { - Coordinate gridCoord = new Coordinate(); - MathTransform mt = latLonToGrid.get(orientation); - try { - if (mt == null) { - init(); - DefaultMathTransformFactory dmtf = new DefaultMathTransformFactory(); - mt = dmtf.createConcatenatedTransform(latLonToCrs, gridGeometry - .getGridToCRS(orientation).inverse()); - latLonToGrid.put(orientation, mt); - } - - double[] output = new double[2]; - mt.transform(new double[] { latLon.x, latLon.y }, 0, output, 0, 1); - gridCoord.x = output[0]; - gridCoord.y = output[1]; - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return gridCoord; - } - + /** + * Return the math transform from grid coordinate to the specified corner or + * center lat/lon + * + * @param orientation + * desired corner or center + * @return the transform + */ public MathTransform getGridToCrs(PixelOrientation orientation) { MathTransform mt = gridToCrs.get(orientation); - try { - if (mt == null) { - init(); - mt = gridGeometry.getGridToCRS(orientation); - gridToCrs.put(orientation, mt); - } - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + if (mt == null) { + init(); + mt = gridGeometry.getGridToCRS(orientation); + gridToCrs.put(orientation, mt); } return mt; } + /** + * Convert a grid cell coordinate to the native CRS coordinate of this + * projection + * + * @param gridCoord + * grid cell coordinate + * @param orientation + * desired corner or center of the grid cell + * @return native CRS coordinate + */ public Coordinate gridCoordinateToCrs(Coordinate gridCoord, PixelOrientation orientation) { Coordinate crsCoordinate = new Coordinate(); @@ -410,114 +485,204 @@ public class ProjectionData implements ISerializableObject { crsCoordinate.x = output[0]; crsCoordinate.y = output[1]; } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + statusHandler.error( + "Error computing grid coordinate to CRS transform", e); } return crsCoordinate; } + /** + * @return the projectionID + */ public String getProjectionID() { return projectionID; } + /** + * @return the projectionType + */ public ProjectionType getProjectionType() { return projectionType; } + /** + * @return the latLonLL + */ public Coordinate getLatLonLL() { return latLonLL; } + /** + * @return the latLonUR + */ public Coordinate getLatLonUR() { return latLonUR; } + /** + * @return the latLonOrigin + */ public Coordinate getLatLonOrigin() { return latLonOrigin; } + /** + * @return the stdParallelOne + */ public double getStdParallelOne() { return stdParallelOne; } + /** + * @return the stdParallelTwo + */ public double getStdParallelTwo() { return stdParallelTwo; } + /** + * @return the gridPointLL + */ public Point getGridPointLL() { return gridPointLL; } + /** + * @return the gridPointUR + */ public Point getGridPointUR() { return gridPointUR; } + /** + * @return the latIntersect + */ public double getLatIntersect() { return latIntersect; } + /** + * @return the lonCenter + */ public double getLonCenter() { return lonCenter; } + /** + * @return the lonOrigin + */ public double getLonOrigin() { return lonOrigin; } + /** + * @param projectionID + * the projectionID to set + */ public void setProjectionID(String projectionID) { this.projectionID = projectionID; } + /** + * @param projectionType + * the projectionType to set + */ public void setProjectionType(ProjectionType projectionType) { this.projectionType = projectionType; } + /** + * @param latLonLL + * the latLonLL to set + */ public void setLatLonLL(Coordinate latLonLL) { this.latLonLL = latLonLL; } + /** + * @param latLonUR + * the latLonUR to set + */ public void setLatLonUR(Coordinate latLonUR) { this.latLonUR = latLonUR; } + /** + * @param latLonOrigin + * the latLonOrigin to set + */ public void setLatLonOrigin(Coordinate latLonOrigin) { this.latLonOrigin = latLonOrigin; } + /** + * @param stdParallelOne + * the stdParallelOne to set + */ public void setStdParallelOne(double stdParallelOne) { this.stdParallelOne = stdParallelOne; } + /** + * @param stdParallelTwo + * the stdParallelTwo to set + */ public void setStdParallelTwo(double stdParallelTwo) { this.stdParallelTwo = stdParallelTwo; } + /** + * @param gridPointLL + * the gridPointLL to set + */ public void setGridPointLL(Point gridPointLL) { this.gridPointLL = gridPointLL; } + /** + * @param gridPointUR + * the gridPointUR to set + */ public void setGridPointUR(Point gridPointUR) { this.gridPointUR = gridPointUR; } + /** + * @param latIntersect + * the latIntersect to set + */ public void setLatIntersect(double latIntersect) { this.latIntersect = latIntersect; } + /** + * @param lonCenter + * the lonCenter to set + */ public void setLonCenter(double lonCenter) { this.lonCenter = lonCenter; } + /** + * @param lonOrigin + * the lonOrigin to set + */ public void setLonOrigin(double lonOrigin) { this.lonOrigin = lonOrigin; } + /** + * @return the width of the projection in grid cells + */ public Integer getNx() { - return this.gridPointUR.x - this.gridPointLL.x + 1; + return (this.gridPointUR.x - this.gridPointLL.x) + 1; } + /** + * @return the height of the projection in grid cells + */ public Integer getNy() { - return this.gridPointUR.y - this.gridPointLL.y + 1; + return (this.gridPointUR.y - this.gridPointLL.y) + 1; } } diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/GridLocation.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/GridLocation.java index 68e5962bf0..b946b38e10 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/GridLocation.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/GridLocation.java @@ -24,10 +24,18 @@ import java.awt.Rectangle; import java.util.ArrayList; import javax.persistence.Column; +import javax.persistence.Embedded; import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; import javax.persistence.Transient; +import javax.persistence.UniqueConstraint; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; @@ -42,7 +50,8 @@ import org.geotools.geometry.GeneralEnvelope; import org.geotools.referencing.GeodeticCalculator; import org.geotools.referencing.operation.DefaultMathTransformFactory; import org.geotools.referencing.operation.builder.GridToEnvelopeMapper; -import org.hibernate.annotations.Type; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; import org.opengis.metadata.spatial.PixelOrientation; import org.opengis.referencing.FactoryException; import org.opengis.referencing.crs.CoordinateReferenceSystem; @@ -91,6 +100,8 @@ import com.vividsolutions.jts.simplify.TopologyPreservingSimplifier; * 07/10/13 #2044 randerso Changed constructor to take ISpatialObject instead of GridCoverage * 07/16/13 #2181 bsteffen Convert geometry types to use hibernate- * spatial + * 08/06/13 #1571 randerso Added hibernate annotations, javadoc cleanup, + * made init method public for use in GFEDao * * * @@ -99,24 +110,27 @@ import com.vividsolutions.jts.simplify.TopologyPreservingSimplifier; * @version 1.0 */ @Entity -@Table(name = "gfe_spatial") +@Table(name = "gfe_gridlocation", uniqueConstraints = { @UniqueConstraint(columnNames = { "dbId_id" }) }) @XmlAccessorType(XmlAccessType.NONE) @DynamicSerialize -public class GridLocation extends PersistableDataObject implements +public class GridLocation extends PersistableDataObject implements ISpatialObject, ISerializableObject { private static final transient IUFStatusHandler statusHandler = UFStatus .getHandler(GridLocation.class); - private static class PythonNumpyFloatGrid implements INumpyable { - private int nx; - - private int ny; - + /** + * Container for lat/lon grids to be returned to python where they are + * reshaped using numpy for performance + * + */ + private static class PythonNumpyLatLonGrid implements INumpyable { private float[] data; - public PythonNumpyFloatGrid(int nx, int ny, float[] data) { - this.nx = nx; - this.ny = ny; + public PythonNumpyLatLonGrid(int nx, int ny, float[] data) { + if ((nx * ny * 2) != data.length) { + throw new IllegalArgumentException( + "data must be of length nx*ny*2"); + } this.data = data; } @@ -144,24 +158,38 @@ public class GridLocation extends PersistableDataObject implements private static final long serialVersionUID = 1L; + /** + * Auto-generated surrogate key + */ @Id + @SequenceGenerator(name = "GFE_GRIDLOCATION_GENERATOR", sequenceName = "gfe_gridlocation_seq") + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "GFE_GRIDLOCATION_GENERATOR") + private int id; + + /** The database id associated with this grid location */ + @OneToOne(fetch = FetchType.EAGER, optional = false) + @OnDelete(action = OnDeleteAction.CASCADE) + @JoinColumn(referencedColumnName = "id", name = "dbId_id") + private DatabaseID dbId; + + @Column(length = 8, nullable = false) @XmlAttribute @DynamicSerializeElement private String siteId; /** Number of points along the x-axis */ - @Column + @Column(nullable = false) @XmlAttribute @DynamicSerializeElement protected Integer nx; /** Number of points along the y-axis */ - @Column + @Column(nullable = false) @XmlAttribute @DynamicSerializeElement protected Integer ny; - @Column + @Column(length = 32, nullable = false) @XmlAttribute @DynamicSerializeElement private String timeZone; @@ -169,31 +197,30 @@ public class GridLocation extends PersistableDataObject implements @Transient private Coordinate gridCellSize; - @Transient + @Embedded @XmlElement @DynamicSerializeElement private ProjectionData projection; - @Transient + @Column(nullable = false) @XmlElement @XmlJavaTypeAdapter(value = CoordAdapter.class) @DynamicSerializeElement private Coordinate origin; - @Transient + @Column(nullable = false) @XmlElement @XmlJavaTypeAdapter(value = CoordAdapter.class) @DynamicSerializeElement private Coordinate extent; - @Column(name = "coverage") - @Type(type = "org.hibernatespatial.GeometryUserType") + @Transient @XmlElement @XmlJavaTypeAdapter(value = GeometryAdapter.class) @DynamicSerializeElement private Polygon geometry; - @Column(name = "crs", length = 2047) + @Transient @XmlElement @DynamicSerializeElement private String crsWKT; @@ -201,32 +228,50 @@ public class GridLocation extends PersistableDataObject implements @Transient private CoordinateReferenceSystem crsObject; + /** + * Default constructor for serialization + */ public GridLocation() { } /** - * @param data + * Constructor + * + * @param id + * @param proj * @param gridSize * @param domainOrigin * @param domainExtent + * @param timeZone */ public GridLocation(String id, ProjectionData proj, java.awt.Point gridSize, Coordinate domainOrigin, Coordinate domainExtent, String timeZone) { + if ((id == null) || id.isEmpty()) { + throw new IllegalArgumentException("id may not be null or empty"); + } + this.siteId = id; + this.nx = gridSize.x; + this.ny = gridSize.y; + this.projection = proj; + this.origin = domainOrigin; + this.extent = domainExtent; + this.timeZone = timeZone; + + init(); + } + + /** + * Initialize the object. Must be called after database retrieval + */ + /** + * + */ + public void init() { try { - if ((id == null) || id.isEmpty()) { - throw new IllegalArgumentException( - "id may not be null or empty"); - } - this.siteId = id; - this.nx = gridSize.x; - this.ny = gridSize.y; - this.projection = proj; - this.origin = domainOrigin; - this.extent = domainExtent; - this.timeZone = timeZone; - this.crsObject = proj.getCrs(); + this.projection.init(); + this.crsObject = this.projection.getCrs(); this.crsWKT = this.crsObject.toWKT(); // This is here to help find issues where the WKT won't parse. @@ -241,13 +286,13 @@ public class GridLocation extends PersistableDataObject implements } // transform the grid corners from grid coordinates to CRS units - Coordinate ll = domainOrigin; - Coordinate ur = new Coordinate(domainOrigin.x + domainExtent.x, - domainOrigin.y + domainExtent.y); + Coordinate ll = this.origin; + Coordinate ur = new Coordinate(this.origin.x + this.extent.x, + this.origin.y + this.extent.y); - Coordinate llCrs = proj.gridCoordinateToCrs(ll, + Coordinate llCrs = this.projection.gridCoordinateToCrs(ll, PixelOrientation.CENTER); - Coordinate urCrs = proj.gridCoordinateToCrs(ur, + Coordinate urCrs = this.projection.gridCoordinateToCrs(ur, PixelOrientation.CENTER); // construct the grid geometry that covers the GFE grid @@ -296,6 +341,9 @@ public class GridLocation extends PersistableDataObject implements } } + /** + * @param proj + */ public GridLocation(ProjectionData proj) { this( proj.getProjectionID(), // @@ -311,6 +359,10 @@ public class GridLocation extends PersistableDataObject implements "GMT"); } + /** + * @param id + * @param coverage + */ public GridLocation(String id, ISpatialObject coverage) { this.siteId = id; this.crsObject = coverage.getCrs(); @@ -320,6 +372,11 @@ public class GridLocation extends PersistableDataObject implements this.ny = coverage.getNy(); } + /** + * @param id + * @param gloc + * @param subGrid + */ public GridLocation(String id, GridLocation gloc, Rectangle subGrid) { try { this.siteId = id; @@ -359,6 +416,29 @@ public class GridLocation extends PersistableDataObject implements } } + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id + * the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @param dbId + * the dbId to set + */ + public void setDbId(DatabaseID dbId) { + this.dbId = dbId; + } + /** * @return the timeZone */ @@ -375,7 +455,7 @@ public class GridLocation extends PersistableDataObject implements } /** - * @return + * @return the grid size */ public java.awt.Point gridSize() { return new java.awt.Point(nx, ny); @@ -431,7 +511,7 @@ public class GridLocation extends PersistableDataObject implements * make sure each point is exactly one point away and save it. * * @param points - * @return + * @return the connected grid points array */ public java.awt.Point[] connectGridPoints(java.awt.Point points[]) { if (points.length == 0) { @@ -454,7 +534,7 @@ public class GridLocation extends PersistableDataObject implements /** * Returns the size in kilometers for each grid cell. * - * @return + * @return grid cell size in kilometers */ public Coordinate gridCellSize() { @@ -577,10 +657,23 @@ public class GridLocation extends PersistableDataObject implements return ref.getGrid(); } + /** + * Compute grid cell coordinate containing a lat/lon + * + * @param lat + * @param lon + * @return the grid cell coordinate + */ public Point gridCell(float lat, float lon) { return gridCoordinate(new Coordinate(lon, lat)); } + /** + * Compute grid cell coordinate containing a lat/lon + * + * @param lonLat + * @return the grid cell coordinate + */ public Point gridCoordinate(Coordinate lonLat) { Coordinate gcf = MapUtil.latLonToGridCoordinate(lonLat, PixelOrientation.CENTER, this); @@ -589,6 +682,12 @@ public class GridLocation extends PersistableDataObject implements return new Point(x, y); } + /** + * Compute the lat/lon coordinate at the center of a grid cell + * + * @param gridCell + * @return the lat/lon + */ public Coordinate latLonCenter(Coordinate gridCell) { return MapUtil.gridCoordinateToLatLon(gridCell, PixelOrientation.CENTER, this); @@ -605,30 +704,54 @@ public class GridLocation extends PersistableDataObject implements return s; } + /** + * @return the projection + */ public ProjectionData getProjection() { return projection; } + /** + * @return the origin + */ public Coordinate getOrigin() { return origin; } + /** + * @return the extent + */ public Coordinate getExtent() { return extent; } + /** + * @return the serialVersionUID + */ public static long getSerialVersionUID() { return serialVersionUID; } + /** + * @param projection + * the projection + */ public void setProjection(ProjectionData projection) { this.projection = projection; } + /** + * @param origin + * the origin + */ public void setOrigin(Coordinate origin) { this.origin = origin; } + /** + * @param extent + * the extent + */ public void setExtent(Coordinate extent) { this.extent = extent; } @@ -701,11 +824,11 @@ public class GridLocation extends PersistableDataObject implements return false; } - if (projection == null) { - if (other.projection != null) { + if (crsWKT == null) { + if (other.crsWKT != null) { return false; } - } else if (!projection.equals(other.projection)) { + } else if (!crsWKT.equals(other.crsWKT)) { return false; } return true; @@ -761,47 +884,91 @@ public class GridLocation extends PersistableDataObject implements return ny; } + /** + * @return the siteId + */ public String getSiteId() { return siteId; } + /** + * @param siteId + * the siteId + */ public void setSiteId(String siteId) { this.siteId = siteId; } + /** + * @return the crsWKT + */ public String getCrsWKT() { return crsWKT; } + /** + * @param crsWKT + * the crsWKT + */ public void setCrsWKT(String crsWKT) { this.crsWKT = crsWKT; } + /** + * @return the crs + */ public CoordinateReferenceSystem getCrsObject() { return getCrs(); } + /** + * @param crsObject + * the crs + */ public void setCrsObject(CoordinateReferenceSystem crsObject) { this.crsObject = crsObject; } + /** + * @param nx + * the nx + */ public void setNx(Integer nx) { this.nx = nx; } + /** + * @param ny + * the ny + */ public void setNy(Integer ny) { this.ny = ny; } + /** + * @param geometry + */ public void setGeometry(Geometry geometry) { this.geometry = (Polygon) geometry; } + /** + * @param geometry + */ public void setGeometry(Polygon geometry) { this.geometry = geometry; } - public PythonNumpyFloatGrid getLatLonGrid() { + /** + * Returns a 1-dimensional lat/lon grid to be reshaped by numpy for + * performance. End users should use the getLatLonGrids function in + * SmartScript.py or MetLib.py + * + * This function is not intended for use by Java code. + * + * @return the lat/lon grid + */ + public PythonNumpyLatLonGrid getLatLonGrid() { float[] gridCells = new float[2 * nx * ny]; int i = 0; for (float x = 0; x < nx; x++) { @@ -820,13 +987,16 @@ public class GridLocation extends PersistableDataObject implements e.printStackTrace(); } - return new PythonNumpyFloatGrid(nx, ny, latLon); + return new PythonNumpyLatLonGrid(nx, ny, latLon); } + /** + * @param args + */ public static void main(String[] args) { ProjectionData grid211 = new ProjectionData("Grid211", - ProjectionType.LAMBERT_CONFORMAL.ordinal(), new Coordinate( - -133.459, 12.190), new Coordinate(-49.385, 57.290), + ProjectionType.LAMBERT_CONFORMAL, new Coordinate(-133.459, + 12.190), new Coordinate(-49.385, 57.290), new Coordinate(-95.0, 25.0), 25.0f, 25.0f, new Point(1, 1), new Point(93, 65), 0.0f, 0.0f, 0.0f); @@ -863,7 +1033,7 @@ public class GridLocation extends PersistableDataObject implements latLon = MapUtil.gridCoordinateToLatLon(gridCoord, orientation, gloc); System.out.println(gridCoord.x + "," + gridCoord.y + " " + latLon); - PythonNumpyFloatGrid latLonGrid = gloc.getLatLonGrid(); + PythonNumpyLatLonGrid latLonGrid = gloc.getLatLonGrid(); float[] data = (float[]) latLonGrid.getNumPy()[0]; for (int x = 0; x < gloc.getNx(); x++) { for (int y = 0; y < gloc.getNy(); y++) { diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/GridParmInfo.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/GridParmInfo.java index 7d9410afbf..43f3fd00c3 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/GridParmInfo.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/GridParmInfo.java @@ -28,6 +28,20 @@ import javax.measure.unit.NonSI; import javax.measure.unit.SI; import javax.measure.unit.Unit; import javax.measure.unit.UnitFormat; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.Embedded; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToOne; +import javax.persistence.PrimaryKeyJoinColumn; +import javax.persistence.Transient; + +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; import com.raytheon.uf.common.dataplugin.gfe.db.objects.GFERecord.GridType; import com.raytheon.uf.common.dataplugin.gfe.discrete.DiscreteKey; @@ -52,6 +66,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority; * 03/20/2013 #1774 randerso Removed unnecessary XML annotations, * added isValid method to match A1 * 04/02/2013 #1774 randerso Improved error message in validCheck + * 08/06/13 #1571 randerso Added hibernate annotations, javadoc cleanup * * * @@ -59,6 +74,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority; * @version 1.0 */ +@Embeddable @DynamicSerialize public class GridParmInfo implements Cloneable, ISerializableObject { private static final transient IUFStatusHandler statusHandler = UFStatus @@ -89,52 +105,73 @@ public class GridParmInfo implements Cloneable, ISerializableObject { } /** The parm id associated with this grid parm info */ + @OneToOne(fetch = FetchType.EAGER, optional = false) + @OnDelete(action = OnDeleteAction.CASCADE) + @JoinColumn(referencedColumnName = "id", name = "parmId_id") @DynamicSerializeElement private ParmID parmID; /** The grid location associated with this grid parm info */ + @ManyToOne(fetch = FetchType.EAGER, optional = false) + @OnDelete(action = OnDeleteAction.CASCADE) + @PrimaryKeyJoinColumn @DynamicSerializeElement private GridLocation gridLoc; /** The grid type */ + @Column(length = 8, nullable = false) + @Enumerated(EnumType.STRING) @DynamicSerializeElement private GridType gridType; /** The parameter descriptive name */ + @Column(length = 64, nullable = false) @DynamicSerializeElement private String descriptiveName; /** The units associated with the parameter */ + @Column(length = 64, nullable = false) @DynamicSerializeElement private String unitString; + @Transient private Unit unitObject; /** The minimum allowed value */ + @Column(nullable = false) @DynamicSerializeElement private float minValue; /** The maximum allowed value */ + @Column(nullable = false) @DynamicSerializeElement private float maxValue; /** The precision of the value */ + @Column(nullable = false) @DynamicSerializeElement private int precision; /** Is value a rate parameter */ + @Column(nullable = false) @DynamicSerializeElement private boolean rateParm; /** Time Constraints */ + @Embedded @DynamicSerializeElement private TimeConstraints timeConstraints; + @Column(nullable = false) @DynamicSerializeElement private boolean timeIndependentParm; + @Transient private String errorMessage; + /** + * Default constructor for serialization + */ public GridParmInfo() { gridType = GridType.NONE; timeIndependentParm = false; @@ -150,6 +187,11 @@ public class GridParmInfo implements Cloneable, ISerializableObject { timeConstraints = null; } + /** + * Copy constructor + * + * @param orig + */ public GridParmInfo(GridParmInfo orig) { this.parmID = orig.parmID; this.gridLoc = orig.gridLoc; @@ -202,6 +244,20 @@ public class GridParmInfo implements Cloneable, ISerializableObject { } } + /** + * Constructor with rateParm defaulted to false + * + * @param id + * @param gridLoc + * @param gridType + * @param unit + * @param descriptiveName + * @param minValue + * @param maxValue + * @param precision + * @param timeIndependentParm + * @param timeConstraints + */ public GridParmInfo(ParmID id, GridLocation gridLoc, GridType gridType, String unit, String descriptiveName, float minValue, float maxValue, int precision, boolean timeIndependentParm, @@ -255,7 +311,7 @@ public class GridParmInfo implements Cloneable, ISerializableObject { } // units defined - if (unitString == null || unitString.isEmpty()) { + if ((unitString == null) || unitString.isEmpty()) { sb.append("GridParmInfo.Units are not defined.\n"); } @@ -269,7 +325,7 @@ public class GridParmInfo implements Cloneable, ISerializableObject { } // precision check - if (precision < -2 || precision > 5) { + if ((precision < -2) || (precision > 5)) { sb.append("GridParmInfo is invalid. Precision out of limits. "); sb.append(" Precision is: "); sb.append(precision); @@ -317,6 +373,9 @@ public class GridParmInfo implements Cloneable, ISerializableObject { return unitString; } + /** + * @return the unitObject + */ public synchronized Unit getUnitObject() { if (unitObject == null) { try { @@ -378,6 +437,9 @@ public class GridParmInfo implements Cloneable, ISerializableObject { return new GridParmInfo(this); } + /** + * @return the parmID + */ public ParmID getParmID() { return parmID; } @@ -391,20 +453,21 @@ public class GridParmInfo implements Cloneable, ISerializableObject { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + result = (prime * result) + ((descriptiveName == null) ? 0 : descriptiveName.hashCode()); - result = prime * result + ((gridLoc == null) ? 0 : gridLoc.hashCode()); - result = prime * result + result = (prime * result) + + ((gridLoc == null) ? 0 : gridLoc.hashCode()); + result = (prime * result) + ((gridType == null) ? 0 : gridType.hashCode()); - result = prime * result + Float.floatToIntBits(maxValue); - result = prime * result + Float.floatToIntBits(minValue); - result = prime * result + ((parmID == null) ? 0 : parmID.hashCode()); - result = prime * result + precision; - result = prime * result + (rateParm ? 1231 : 1237); - result = prime * result + result = (prime * result) + Float.floatToIntBits(maxValue); + result = (prime * result) + Float.floatToIntBits(minValue); + result = (prime * result) + ((parmID == null) ? 0 : parmID.hashCode()); + result = (prime * result) + precision; + result = (prime * result) + (rateParm ? 1231 : 1237); + result = (prime * result) + ((timeConstraints == null) ? 0 : timeConstraints.hashCode()); - result = prime * result + (timeIndependentParm ? 1231 : 1237); - result = prime * result + result = (prime * result) + (timeIndependentParm ? 1231 : 1237); + result = (prime * result) + ((unitString == null) ? 0 : unitString.hashCode()); return result; } @@ -502,6 +565,11 @@ public class GridParmInfo implements Cloneable, ISerializableObject { return timeIndependentParm; } + /** + * Reset the parmId + * + * @param parmId + */ public void resetParmID(ParmID parmId) { this.parmID = parmId; } @@ -516,50 +584,98 @@ public class GridParmInfo implements Cloneable, ISerializableObject { + " GridType: " + gridType; } + /** + * @param parmID + * the parmID to set + */ public void setParmID(ParmID parmID) { this.parmID = parmID; } + /** + * @param gridLoc + * the gridLoc to set + */ public void setGridLoc(GridLocation gridLoc) { this.gridLoc = gridLoc; } + /** + * @param gridType + * the gridType to set + */ public void setGridType(GridType gridType) { this.gridType = gridType; } + /** + * @param descriptiveName + * the descriptiveName to set + */ public void setDescriptiveName(String descriptiveName) { this.descriptiveName = descriptiveName; } + /** + * @param unitString + * the unitString to set + */ public void setUnitString(String unitString) { this.unitString = unitString; } + /** + * @param unitObject + * the unitObject to set + */ public void setUnitObject(Unit unitObject) { this.unitObject = unitObject; } + /** + * @param minValue + * the minValue to set + */ public void setMinValue(float minValue) { this.minValue = minValue; } + /** + * @param maxValue + * the maxValue to set + */ public void setMaxValue(float maxValue) { this.maxValue = maxValue; } + /** + * @param precision + * the precision to set + */ public void setPrecision(int precision) { this.precision = precision; } + /** + * @param rateParm + * the rateParm to set + */ public void setRateParm(boolean rateParm) { this.rateParm = rateParm; } + /** + * @param timeConstraints + * the timeConstraints to set + */ public void setTimeConstraints(TimeConstraints timeConstraints) { this.timeConstraints = timeConstraints; } + /** + * @param timeIndependentParm + * the timeIndependentParm to set + */ public void setTimeIndependentParm(boolean timeIndependentParm) { this.timeIndependentParm = timeIndependentParm; } diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/ParmStorageInfo.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/ParmStorageInfo.java new file mode 100644 index 0000000000..193da9a784 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/ParmStorageInfo.java @@ -0,0 +1,275 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.common.dataplugin.gfe.db.objects; + +import java.awt.Point; + +import javax.persistence.Column; +import javax.persistence.Embedded; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; + +import com.raytheon.uf.common.serialization.ISerializableObject; + +/** + * Derived class that consolidates storage info for a Parm. + * + *
+ * SOFTWARE HISTORY
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * 03/14/08     #1030      randerso    Initial port
+ * 08/05/2013   #1571      randerso    Moved to com.raytheon.uf.common.dataplugin
+ *                                     Added GridParmInfo as a field.
+ *                                     Added hibernate annotations
+ * 
+ * 
+ * + * @author randerso + * @version 1.0 + */ + +@Entity +@Table(name = "gfe_parminfo", uniqueConstraints = { @UniqueConstraint(columnNames = { "parmId_id" }) }) +public class ParmStorageInfo implements ISerializableObject { + + /** + * Auto-generated surrogate key + */ + @Id + @SequenceGenerator(name = "GFE_PARMINFO_GENERATOR", sequenceName = "gfe_parminfo_seq") + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "GFE_PARMINFO_GENERATOR") + private int id; + + @Embedded + private GridParmInfo gridParmInfo; + + @Column(length = 8, nullable = false) + private String storageType; + + @Column(nullable = false) + private float dataOffset; + + @Column(nullable = false) + private float dataMultiplier; + + @Column(length = 8, nullable = false) + private String dataType; + + /** + * Default constructor + */ + public ParmStorageInfo() { + + } + + /** + * Constructor + * + * @param dataType + * @param gridParmInfo + * @param dataOffset + * @param dataMultiplier + * @param storageType + */ + public ParmStorageInfo(final String dataType, + final GridParmInfo gridParmInfo, float dataOffset, + float dataMultiplier, final String storageType) { + this.storageType = storageType; + this.dataOffset = dataOffset; + this.dataMultiplier = dataMultiplier; + this.dataType = dataType; + this.gridParmInfo = gridParmInfo; + } + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id + * the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the storageType + */ + public String getStorageType() { + return storageType; + } + + /** + * @return the gridSize + */ + public Point getGridSize() { + return this.gridParmInfo.getGridLoc().gridSize(); + } + + /** + * @return the parmID + */ + public ParmID getParmID() { + return gridParmInfo.getParmID(); + } + + /** + * @return the parmName + */ + public String getParmName() { + return gridParmInfo.getParmID().getParmName(); + } + + /** + * @return the parmLevel + */ + public String getParmLevel() { + return gridParmInfo.getParmID().getParmLevel(); + } + + /** + * @return the level + */ + public String getLevel() { + return gridParmInfo.getParmID().getParmLevel(); + } + + /** + * @return the dataOffset + */ + public float getDataOffset() { + return dataOffset; + } + + /** + * @return the dataMultiplier + */ + public float getDataMultiplier() { + return dataMultiplier; + } + + /** + * @return the dataType + */ + public String getDataType() { + return dataType; + } + + /** + * @return the gridParmInfo + */ + public GridParmInfo getGridParmInfo() { + return gridParmInfo; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = (prime * result) + Float.floatToIntBits(dataMultiplier); + result = (prime * result) + Float.floatToIntBits(dataOffset); + result = (prime * result) + + ((dataType == null) ? 0 : dataType.hashCode()); + result = (prime * result) + + ((gridParmInfo == null) ? 0 : gridParmInfo.hashCode()); + result = (prime * result) + + ((storageType == null) ? 0 : storageType.hashCode()); + return result; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof ParmStorageInfo)) { + return false; + } + ParmStorageInfo other = (ParmStorageInfo) obj; + if (Float.floatToIntBits(dataMultiplier) != Float + .floatToIntBits(other.dataMultiplier)) { + return false; + } + if (Float.floatToIntBits(dataOffset) != Float + .floatToIntBits(other.dataOffset)) { + return false; + } + if (dataType == null) { + if (other.dataType != null) { + return false; + } + } else if (!dataType.equals(other.dataType)) { + return false; + } + if (gridParmInfo == null) { + if (other.gridParmInfo != null) { + return false; + } + } else if (!gridParmInfo.equals(other.gridParmInfo)) { + return false; + } + if (storageType == null) { + if (other.storageType != null) { + return false; + } + } else if (!storageType.equals(other.storageType)) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append("ParmStorageInfo for parm: ").append(getParmName()); + sb.append(" Level: ").append(getLevel()); + sb.append(" DataType: ").append(getDataType()); + sb.append(" GridSize: ").append(getGridSize()); + sb.append(" DataOffset: ").append(getDataOffset()); + sb.append(" DataMultiplier: ").append(getDataMultiplier()); + sb.append(" StorageType: ").append(getStorageType()); + + return sb.toString(); + } +} diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/TimeConstraints.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/TimeConstraints.java index 399c0b1f66..9b984825d8 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/TimeConstraints.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/TimeConstraints.java @@ -23,6 +23,9 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import javax.persistence.Column; +import javax.persistence.Embeddable; + import com.raytheon.uf.common.dataplugin.gfe.serialize.TimeConstraintsAdapter; import com.raytheon.uf.common.serialization.ISerializableObject; import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; @@ -43,6 +46,7 @@ import com.raytheon.uf.common.time.util.TimeUtil; * 2/19/2008 chammack Ported from AWIPS I * 03/20/2013 #1774 randerso Added isValid method, use TimeUtil constants, * added serialization adapter, removed setters. + * 08/06/13 #1571 randerso Added hibernate annotations, javadoc cleanup * * * @@ -50,21 +54,26 @@ import com.raytheon.uf.common.time.util.TimeUtil; * @version 1.0 */ +@Embeddable @DynamicSerialize @DynamicSerializeTypeAdapter(factory = TimeConstraintsAdapter.class) public class TimeConstraints implements ISerializableObject { private static final transient IUFStatusHandler statusHandler = UFStatus .getHandler(TimeConstraints.class); + @Column(nullable = false) @DynamicSerializeElement private int duration; + @Column(nullable = false) @DynamicSerializeElement private int repeatInterval; + @Column(nullable = false) @DynamicSerializeElement private int startTime; + @Column(nullable = false) boolean valid; /** @@ -77,21 +86,28 @@ public class TimeConstraints implements ISerializableObject { valid = false; } + /** + * Constructor + * + * @param duration + * @param repeatInterval + * @param startTime + */ public TimeConstraints(int duration, int repeatInterval, int startTime) { this.duration = duration; this.repeatInterval = repeatInterval; this.startTime = startTime; - if (this.duration == 0 && this.repeatInterval == 0 - && this.startTime == 0) { + if ((this.duration == 0) && (this.repeatInterval == 0) + && (this.startTime == 0)) { valid = true; } else { - if (repeatInterval <= 0 - || repeatInterval > TimeUtil.SECONDS_PER_DAY - || TimeUtil.SECONDS_PER_DAY % repeatInterval != 0 - || repeatInterval < duration || startTime < 0 - || startTime > TimeUtil.SECONDS_PER_DAY || duration < 0 - || duration > TimeUtil.SECONDS_PER_DAY) { + if ((repeatInterval <= 0) + || (repeatInterval > TimeUtil.SECONDS_PER_DAY) + || ((TimeUtil.SECONDS_PER_DAY % repeatInterval) != 0) + || (repeatInterval < duration) || (startTime < 0) + || (startTime > TimeUtil.SECONDS_PER_DAY) || (duration < 0) + || (duration > TimeUtil.SECONDS_PER_DAY)) { statusHandler.warn("Bad init values for TimeConstraints: " + this); valid = false; @@ -112,6 +128,7 @@ public class TimeConstraints implements ISerializableObject { * * @param absTime * the time that the range should contain + * @return the time range */ public TimeRange constraintTime(Date absTime) { if (!valid) { @@ -127,17 +144,18 @@ public class TimeConstraints implements ISerializableObject { int tStart = startTime - repeatInterval; - while (tStart + duration >= 0) { + while ((tStart + duration) >= 0) { // tstart+duration is ending time tStart -= repeatInterval; // keep going until below 0 } while (tStart < TimeUtil.SECONDS_PER_DAY) { int tEnd = tStart + duration; - if ((tStart * TimeUtil.MILLIS_PER_SECOND) <= secSinceMidnight - && secSinceMidnight < (tEnd * TimeUtil.MILLIS_PER_SECOND)) { - return new TimeRange(midnight + TimeUtil.MILLIS_PER_SECOND - * tStart, midnight + TimeUtil.MILLIS_PER_SECOND * tEnd); + if (((tStart * TimeUtil.MILLIS_PER_SECOND) <= secSinceMidnight) + && (secSinceMidnight < (tEnd * TimeUtil.MILLIS_PER_SECOND))) { + return new TimeRange(midnight + + (TimeUtil.MILLIS_PER_SECOND * tStart), midnight + + (TimeUtil.MILLIS_PER_SECOND * tEnd)); } tStart += repeatInterval; } @@ -197,8 +215,8 @@ public class TimeConstraints implements ISerializableObject { TimeConstraints rhs = (TimeConstraints) obj; - return (valid == rhs.valid && duration == rhs.duration - && repeatInterval == rhs.repeatInterval && startTime == rhs.startTime); + return ((valid == rhs.valid) && (duration == rhs.duration) + && (repeatInterval == rhs.repeatInterval) && (startTime == rhs.startTime)); } @@ -207,7 +225,7 @@ public class TimeConstraints implements ISerializableObject { * * @param tr * the time range - * @return + * @return true if the input time range matches the time constraints */ public boolean validTR(final TimeRange tr) { if (!anyConstraints()) { @@ -251,9 +269,8 @@ public class TimeConstraints implements ISerializableObject { // is beyond the time range given List sbs = new ArrayList(); // returned value TimeRange tr = firstSB(timeRange.getStart()); - while (timeRange.getEnd().getTime() - + (duration * TimeUtil.MILLIS_PER_SECOND) > tr.getEnd() - .getTime()) { + while ((timeRange.getEnd().getTime() + (duration * TimeUtil.MILLIS_PER_SECOND)) > tr + .getEnd().getTime()) { if (tr.overlaps(timeRange)) { sbs.add(tr); } diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/slice/DiscreteGridSlice.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/slice/DiscreteGridSlice.java index 40b38d8428..012a72637d 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/slice/DiscreteGridSlice.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/slice/DiscreteGridSlice.java @@ -56,6 +56,8 @@ import com.raytheon.uf.common.time.TimeRange; * 06/10/2009 2159 rjpeter Updated checkDims to check grid for null * 01/30/2013 15719 jdynina Allowed more than 128 char width wx * string + * 08/13/2013 1571 randerso Removed toString to stop it from hanging the + * debugger when trying to display the grid * * * @author chammack @@ -167,8 +169,8 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable { if (gsDiscreteGrid != null) { Grid2DByte discreteGrid = getDiscreteGrid(); - if (discreteGrid.getXdim() != gsDiscreteGrid.getXdim() - || discreteGrid.getYdim() != gsDiscreteGrid.getYdim()) { + if ((discreteGrid.getXdim() != gsDiscreteGrid.getXdim()) + || (discreteGrid.getYdim() != gsDiscreteGrid.getYdim())) { throw new IllegalArgumentException( "Supplied grid is not of same dimension"); } @@ -302,8 +304,8 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable { Grid2DByte discreteGrid = getDiscreteGrid(); Point gridSize = new Point(discreteGrid.getXdim(), discreteGrid.getYdim()); - if (editArea.getXdim() != gridSize.x - || editArea.getYdim() != gridSize.y) { + if ((editArea.getXdim() != gridSize.x) + || (editArea.getYdim() != gridSize.y)) { return false; } @@ -353,8 +355,8 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable { */ public boolean assign(DiscreteGridSlice gs, Grid2DBit editArea) { Grid2DByte discreteGrid = getDiscreteGrid(); - if (editArea.getXdim() != discreteGrid.getXdim() - || editArea.getYdim() != discreteGrid.getYdim()) { + if ((editArea.getXdim() != discreteGrid.getXdim()) + || (editArea.getYdim() != discreteGrid.getYdim())) { return false; } @@ -637,7 +639,7 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable { * for duplicate keys, set all locations in grid that match that key to * the "first" of the duplicate keys */ - for (int i = 0; i < key.length - 1; i++) { + for (int i = 0; i < (key.length - 1); i++) { for (int j = i; j < key.length; j++) { if (key[i].equals(key[j])) { discreteGrid.setAllOfValue((byte) j, (byte) i); @@ -693,16 +695,6 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable { return new DiscreteGridSlice(aValidTime, aGpi, aHistory, aGrid, aKey); } - @Override - public String toString() { - StringBuilder rVal = new StringBuilder(super.toString()); - - rVal.append("Discrete grid: ").append(getDiscreteGrid()).append("\n"); - rVal.append("Discrete keys: ").append(getKey()).append("\n"); - - return rVal.toString(); - } - private String checkDims() { Grid2DByte discreteGrid = getDiscreteGrid(); if (discreteGrid == null) { @@ -712,8 +704,8 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable { int x = discreteGrid.getXdim(); int y = discreteGrid.getYdim(); - if (x != gridParmInfo.getGridLoc().getNx() - || y != gridParmInfo.getGridLoc().getNy()) { + if ((x != gridParmInfo.getGridLoc().getNx()) + || (y != gridParmInfo.getGridLoc().getNy())) { return "Grid Dimensions and GridParmInfo Dimensions are not identical GridDim: " + x + "," @@ -733,7 +725,7 @@ public class DiscreteGridSlice extends AbstractGridSlice implements Cloneable { * @return the discrete grid */ public Grid2DByte getDiscreteGrid() { - if (useCache && cacheId != null) { + if (useCache && (cacheId != null)) { try { @SuppressWarnings("unchecked") ICache diskCache = CacheFactory.getInstance() diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/slice/ScalarGridSlice.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/slice/ScalarGridSlice.java index 7f3a206f66..f215d2afb5 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/slice/ScalarGridSlice.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/slice/ScalarGridSlice.java @@ -55,6 +55,8 @@ import com.raytheon.uf.common.time.TimeRange; * 01/30/2008 chammack Stubbed-out class based on AWIPS I * 02/20/2008 879 rbell Legacy conversion * 06/10/2009 2159 rjpeter Updated checkDims to check scalarGrid for null + * 08/13/2013 1571 randerso Removed toString to stop it from hanging the + * debugger when trying to display the grid * * * @author chammack @@ -172,8 +174,8 @@ public class ScalarGridSlice extends AbstractGridSlice implements if (rhsScalarGrid != null) { Grid2DFloat scalarGrid = getScalarGrid(); - if (scalarGrid.getXdim() != rhsScalarGrid.getXdim() - || scalarGrid.getYdim() != rhsScalarGrid.getYdim()) { + if ((scalarGrid.getXdim() != rhsScalarGrid.getXdim()) + || (scalarGrid.getYdim() != rhsScalarGrid.getYdim())) { throw new IllegalArgumentException( "Supplied grid is not of same dimension"); } @@ -191,7 +193,7 @@ public class ScalarGridSlice extends AbstractGridSlice implements * @return the scalar grid */ public Grid2DFloat getScalarGrid() { - if (useCache && cacheId != null) { + if (useCache && (cacheId != null)) { try { @SuppressWarnings("unchecked") ICache diskCache = CacheFactory.getInstance() @@ -304,8 +306,8 @@ public class ScalarGridSlice extends AbstractGridSlice implements Grid2DFloat thisGrid = getScalarGrid(); Grid2DFloat rhsGrid = rhs.getScalarGrid(); - if (thisGrid.getXdim() != rhsGrid.getXdim() - || thisGrid.getYdim() != rhsGrid.getYdim()) { + if ((thisGrid.getXdim() != rhsGrid.getXdim()) + || (thisGrid.getYdim() != rhsGrid.getYdim())) { throw new IllegalArgumentException( "This grid and supplied grid have different dimensions"); } @@ -370,8 +372,8 @@ public class ScalarGridSlice extends AbstractGridSlice implements @Override public void limitValue(float minValue, float maxValue, Grid2DBit editArea) { Grid2DFloat grid = getScalarGrid(); - if (editArea.getXdim() != grid.getXdim() - || editArea.getYdim() != grid.getYdim()) { + if ((editArea.getXdim() != grid.getXdim()) + || (editArea.getYdim() != grid.getYdim())) { throw new IllegalArgumentException( "This grid and edit area have different dimensions"); } @@ -425,8 +427,8 @@ public class ScalarGridSlice extends AbstractGridSlice implements Grid2DFloat thisGrid = getScalarGrid(); Grid2DFloat rhsGrid = rhs.getScalarGrid(); - if (thisGrid.getXdim() != rhsGrid.getXdim() - || thisGrid.getYdim() != rhsGrid.getYdim()) { + if ((thisGrid.getXdim() != rhsGrid.getXdim()) + || (thisGrid.getYdim() != rhsGrid.getYdim())) { throw new IllegalArgumentException( "This and supplied GridSlice are different dimensions"); } @@ -458,8 +460,8 @@ public class ScalarGridSlice extends AbstractGridSlice implements Grid2DFloat thisGrid = getScalarGrid(); Grid2DFloat rhsGrid = rhs.getScalarGrid(); - if (thisGrid.getXdim() != rhsGrid.getXdim() - || thisGrid.getYdim() != rhsGrid.getYdim()) { + if ((thisGrid.getXdim() != rhsGrid.getXdim()) + || (thisGrid.getYdim() != rhsGrid.getYdim())) { throw new IllegalArgumentException( "This and supplied GridSlice are different dimensions"); } @@ -485,8 +487,8 @@ public class ScalarGridSlice extends AbstractGridSlice implements public void operateEquals(Op op, float value, Grid2DBit editArea) { Grid2DFloat grid = getScalarGrid(); - if (grid.getXdim() != editArea.getXdim() - || grid.getYdim() != editArea.getYdim()) { + if ((grid.getXdim() != editArea.getXdim()) + || (grid.getYdim() != editArea.getYdim())) { throw new IllegalArgumentException( "This grid and edit area have different dimensions"); } @@ -577,13 +579,13 @@ public class ScalarGridSlice extends AbstractGridSlice implements Grid2DFloat thisGrid = getScalarGrid(); Grid2DFloat rhsGrid = rhs.getScalarGrid(); - if (thisGrid.getXdim() != editArea.getXdim() - || thisGrid.getYdim() != editArea.getYdim()) { + if ((thisGrid.getXdim() != editArea.getXdim()) + || (thisGrid.getYdim() != editArea.getYdim())) { throw new IllegalArgumentException( "This grid and edit area have different dimensions"); } - if (thisGrid.getXdim() != rhsGrid.getXdim() - || thisGrid.getYdim() != rhsGrid.getYdim()) { + if ((thisGrid.getXdim() != rhsGrid.getXdim()) + || (thisGrid.getYdim() != rhsGrid.getYdim())) { throw new IllegalArgumentException( "This grid and supplied grid have different dimensions"); } @@ -649,8 +651,8 @@ public class ScalarGridSlice extends AbstractGridSlice implements Grid2DFloat thisGrid = getScalarGrid(); Grid2DFloat rhsGrid = rhs.getScalarGrid(); - if (thisGrid.getXdim() != rhsGrid.getXdim() - || thisGrid.getYdim() != rhsGrid.getYdim()) { + if ((thisGrid.getXdim() != rhsGrid.getXdim()) + || (thisGrid.getYdim() != rhsGrid.getYdim())) { throw new IllegalArgumentException( "This grid and supplied grid have different dimensions"); } @@ -742,15 +744,6 @@ public class ScalarGridSlice extends AbstractGridSlice implements return rVal; } - @Override - public String toString() { - StringBuilder rVal = new StringBuilder(super.toString()); - - rVal.append(" Scalar grid: ").append(getScalarGrid()).append("\n"); - - return rVal.toString(); - } - @Override public boolean equals(Object obj) { if (!super.equals(obj)) { @@ -810,8 +803,8 @@ public class ScalarGridSlice extends AbstractGridSlice implements x = grid.getXdim(); y = grid.getYdim(); - if (x != gridParmInfo.getGridLoc().getNx() - || y != gridParmInfo.getGridLoc().getNy()) { + if ((x != gridParmInfo.getGridLoc().getNx()) + || (y != gridParmInfo.getGridLoc().getNy())) { return "Grid Dimensions and GridParmInfo Dimensions are not identical GridDim: " + x + "," @@ -844,7 +837,7 @@ public class ScalarGridSlice extends AbstractGridSlice implements float f; for (int i = 0; i < b.capacity(); i++) { f = b.get(i); - if (f < minV || f > maxV) { + if ((f < minV) || (f > maxV)) { return "Data Values Exceeded in Grid at coordinate: " + (i % grid.getXdim()) + ',' + (i / grid.getXdim()) + " Value=" + f + " MinAllowed=" + minV diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/slice/VectorGridSlice.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/slice/VectorGridSlice.java index ab0d0a36e8..c0c565ccc6 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/slice/VectorGridSlice.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/slice/VectorGridSlice.java @@ -55,6 +55,9 @@ import com.raytheon.uf.common.time.TimeRange; * 02/22/2008 879 rbell Legacy conversion, extended ScalarSlice * 06/10/2009 2159 rjpeter Updated checkDims to check dirGrid for null * 04/23/2013 1949 rjpeter Updated wind checks to keep float precision. + * 08/13/2013 1571 randerso Removed toString to stop it from hanging the + * debugger when trying to display the grid + * * * * @author chammack @@ -315,23 +318,6 @@ public class VectorGridSlice extends ScalarGridSlice implements Cloneable, return thisDirGrid.equals(rhsDirGrid); } - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - StringBuilder rVal = new StringBuilder(super.toString()); - - rVal.append("Vector Magnitude grid: ").append(getMagGrid()) - .append("\n"); - rVal.append("Vector Direction grid: ").append(getDirGrid()) - .append("\n"); - - return rVal.toString(); - } - /** * Makes a vector grid slice from u and v components. * @@ -356,8 +342,8 @@ public class VectorGridSlice extends ScalarGridSlice implements Cloneable, magGrid.set( i, j, - (float) Math.sqrt(u.get(i, j) * u.get(i, j) - + v.get(i, j) * v.get(i, j))); + (float) Math.sqrt((u.get(i, j) * u.get(i, j)) + + (v.get(i, j) * v.get(i, j)))); float dir = (float) Math.toDegrees(Math.atan2(u.get(i, j), v.get(i, j))); while (dir < 0.0f) { @@ -401,8 +387,8 @@ public class VectorGridSlice extends ScalarGridSlice implements Cloneable, magGrid.set( i, j, - (float) Math.sqrt(u.get(i, j) * u.get(i, j) - + v.get(i, j) * v.get(i, j))); + (float) Math.sqrt((u.get(i, j) * u.get(i, j)) + + (v.get(i, j) * v.get(i, j)))); float dir = (float) Math.toDegrees(Math.atan2(u.get(i, j), v.get(i, j))); while (dir < 0.0f) { @@ -613,8 +599,8 @@ public class VectorGridSlice extends ScalarGridSlice implements Cloneable, // u and v components // (convert from knots to meters per second 1.94384 knots / m/s ) - float uw = (float) (Math.sin(rads) * mGrid.get(xc, yc) / 1.94384); - float vw = (float) (Math.cos(rads) * mGrid.get(xc, yc) / 1.94384); + float uw = (float) ((Math.sin(rads) * mGrid.get(xc, yc)) / 1.94384); + float vw = (float) ((Math.cos(rads) * mGrid.get(xc, yc)) / 1.94384); // (you might already have uw and vw to work with; // make sure they are in meters per second.) @@ -631,7 +617,7 @@ public class VectorGridSlice extends ScalarGridSlice implements Cloneable, // multiply (dot product) wind vector by slope vector // to get the value of the vertical air motion. - vertAirSpeed = uw * svx + vw * svy; + vertAirSpeed = (uw * svx) + (vw * svy); return vertAirSpeed; // meters per second, positive upward. } diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/slice/WeatherGridSlice.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/slice/WeatherGridSlice.java index aba75e680e..d71db3d1f3 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/slice/WeatherGridSlice.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/slice/WeatherGridSlice.java @@ -44,7 +44,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.time.TimeRange; /** - * TODO Add Description + * Weather Grid Slize * *
  * 
@@ -53,7 +53,9 @@ import com.raytheon.uf.common.time.TimeRange;
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
  * Mar 15, 2011            randerso     Initial creation
- * Jan 30, 2013 15719      jdynina      Allowed more than 128 char wx string 
+ * Jan 30, 2013 15719      jdynina      Allowed more than 128 char wx string
+ * Aug 13, 2013  1571      randerso     Removed toString to stop it from hanging the 
+ *                                      debugger when trying to display the grid
  * 
  * 
* @@ -168,8 +170,8 @@ public class WeatherGridSlice extends AbstractGridSlice { if (gsWeatherGrid != null) { Grid2DByte weatherGrid = getWeatherGrid(); - if (weatherGrid.getXdim() != gsWeatherGrid.getXdim() - || weatherGrid.getYdim() != gsWeatherGrid.getYdim()) { + if ((weatherGrid.getXdim() != gsWeatherGrid.getXdim()) + || (weatherGrid.getYdim() != gsWeatherGrid.getYdim())) { throw new IllegalArgumentException( "Supplied grid is not of same dimension"); } @@ -228,8 +230,8 @@ public class WeatherGridSlice extends AbstractGridSlice { return false; } - if (grid.getXdim() != rhsGrid.getXdim() - || grid.getYdim() != rhsGrid.getYdim()) { + if ((grid.getXdim() != rhsGrid.getXdim()) + || (grid.getYdim() != rhsGrid.getYdim())) { return false; } @@ -303,8 +305,8 @@ public class WeatherGridSlice extends AbstractGridSlice { Grid2DByte weatherGrid = getWeatherGrid(); Point gridSize = new Point(weatherGrid.getXdim(), weatherGrid.getYdim()); - if (editArea.getXdim() != gridSize.x - || editArea.getYdim() != gridSize.y) { + if ((editArea.getXdim() != gridSize.x) + || (editArea.getYdim() != gridSize.y)) { return false; } @@ -354,8 +356,8 @@ public class WeatherGridSlice extends AbstractGridSlice { */ public boolean assign(WeatherGridSlice gs, Grid2DBit editArea) { Grid2DByte weatherGrid = getWeatherGrid(); - if (editArea.getXdim() != weatherGrid.getXdim() - || editArea.getYdim() != weatherGrid.getYdim()) { + if ((editArea.getXdim() != weatherGrid.getXdim()) + || (editArea.getYdim() != weatherGrid.getYdim())) { return false; } @@ -718,14 +720,6 @@ public class WeatherGridSlice extends AbstractGridSlice { return new WeatherGridSlice(aValidTime, aGpi, aHistory, aGrid, aKey); } - @Override - public String toString() { - StringBuilder rVal = new StringBuilder(super.toString()); - rVal.append("Weather grid: ").append(getWeatherGrid()).append("\n"); - rVal.append("Weather keys: ").append(getKeys()).append("\n"); - return rVal.toString(); - } - private String checkDims() { Grid2DByte weatherGrid = getWeatherGrid(); if (weatherGrid == null) { @@ -735,8 +729,8 @@ public class WeatherGridSlice extends AbstractGridSlice { int x = weatherGrid.getXdim(); int y = weatherGrid.getYdim(); - if (x != gridParmInfo.getGridLoc().getNx() - || y != gridParmInfo.getGridLoc().getNy()) { + if ((x != gridParmInfo.getGridLoc().getNx()) + || (y != gridParmInfo.getGridLoc().getNy())) { return "Grid Dimensions and GridParmInfo Dimensions are not identical GridDim: " + x + "," @@ -756,7 +750,7 @@ public class WeatherGridSlice extends AbstractGridSlice { * @return the discrete grid */ public Grid2DByte getWeatherGrid() { - if (useCache && cacheId != null) { + if (useCache && (cacheId != null)) { try { @SuppressWarnings("unchecked") ICache diskCache = CacheFactory.getInstance() diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/test/com/raytheon/uf/common/dataplugin/gfe/db/objects/GridLocationTest.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/test/com/raytheon/uf/common/dataplugin/gfe/db/objects/GridLocationTest.java deleted file mode 100644 index 9e304b1e39..0000000000 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/test/com/raytheon/uf/common/dataplugin/gfe/db/objects/GridLocationTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * This software was developed and / or modified by Raytheon Company, - * pursuant to Contract DG133W-05-CQ-1067 with the US Government. - * - * U.S. EXPORT CONTROLLED TECHNICAL DATA - * This software product contains export-restricted data whose - * export/transfer/disclosure is restricted by U.S. law. Dissemination - * to non-U.S. persons whether in the United States or abroad requires - * an export license or other authorization. - * - * Contractor Name: Raytheon Company - * Contractor Address: 6825 Pine Street, Suite 340 - * Mail Stop B8 - * Omaha, NE 68106 - * 402.291.0100 - * - * See the AWIPS II Master Rights File ("Master Rights File.pdf") for - * further licensing information. - **/ -package com.raytheon.uf.common.dataplugin.gfe.db.objects; - -import java.awt.Point; - -import org.opengis.metadata.spatial.PixelOrientation; - -import com.raytheon.uf.common.dataplugin.gfe.config.ProjectionData; -import com.raytheon.uf.common.dataplugin.gfe.config.ProjectionData.ProjectionType; -import com.raytheon.uf.common.geospatial.MapUtil; -import com.vividsolutions.jts.geom.Coordinate; - -/** - * TODO Add Description - * - *
- * 
- * SOFTWARE HISTORY
- * 
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * Jan 6, 2011            randerso     Initial creation
- * 
- * 
- * - * @author randerso - * @version 1.0 - */ - -public class GridLocationTest { - - /** - * @param args - */ - public static void main(String[] args) { - ProjectionData grid211 = new ProjectionData("Grid211", - ProjectionType.LAMBERT_CONFORMAL.ordinal(), new Coordinate( - -133.459, 12.190), new Coordinate(-49.385, 57.290), - new Coordinate(-95.0, 25.0), 25.0f, 25.0f, new Point(1, 1), - new Point(93, 65), 0, 0, 0); - GridLocation tbw = new GridLocation("TBW", grid211, - new Point(145, 145), new Coordinate(64.00, 11.00), - new Coordinate(9.0, 9.0), "EST5EDT"); - - GridLocation gloc = tbw; - PixelOrientation orient = PixelOrientation.UPPER_LEFT; - Coordinate c = new Coordinate(); - Coordinate ll; - - ll = MapUtil.gridCoordinateToLatLon(c, orient, gloc); - System.out.println("grid cell: " + c + " lonlat: " + ll); - - c.x = gloc.getNx(); - ll = MapUtil.gridCoordinateToLatLon(c, orient, gloc); - System.out.println("grid cell: " + c + " lonlat: " + ll); - - c.y = gloc.getNy(); - ll = MapUtil.gridCoordinateToLatLon(c, orient, gloc); - System.out.println("grid cell: " + c + " lonlat: " + ll); - - c.x = 0; - ll = MapUtil.gridCoordinateToLatLon(c, orient, gloc); - System.out.println("grid cell: " + c + " lonlat: " + ll); - } -} diff --git a/tests/unit/com/raytheon/edex/plugin/gfe/config/ProjectionDataTest.java b/tests/unit/com/raytheon/edex/plugin/gfe/config/ProjectionDataTest.java index cb632059d6..45d1592297 100644 --- a/tests/unit/com/raytheon/edex/plugin/gfe/config/ProjectionDataTest.java +++ b/tests/unit/com/raytheon/edex/plugin/gfe/config/ProjectionDataTest.java @@ -30,6 +30,23 @@ import com.raytheon.uf.common.dataplugin.gfe.config.ProjectionData; import com.raytheon.uf.common.dataplugin.gfe.config.ProjectionData.ProjectionType; import com.vividsolutions.jts.geom.Coordinate; +/** + * Unit test for ProjectionData + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Aug  9, 2013            randerso    Initial creation
+ * Aug 14, 2013       1571 randerso    Changed to use ProjectionType enum
+ * 
+ * 
+ * + * @author randerso + * @version 1.0 + */ public class ProjectionDataTest { private static final double TOLERANCE = 1e-3; @@ -53,11 +70,11 @@ public class ProjectionDataTest { new TestCase( // new ProjectionData("Grid211", - ProjectionType.LAMBERT_CONFORMAL.ordinal(), - new Coordinate(-133.459, 12.190), new Coordinate( - -49.385, 57.290), new Coordinate(-95.0, - 25.0), 25.0f, 25.0f, new Point(1, 1), - new Point(93, 65), 0.0f, 0.0f, 0.0f), + ProjectionType.LAMBERT_CONFORMAL, new Coordinate( + -133.459, 12.190), new Coordinate(-49.385, + 57.290), new Coordinate(-95.0, 25.0), + 25.0f, 25.0f, new Point(1, 1), new Point(93, 65), + 0.0f, 0.0f, 0.0f), new Coordinate[][] { { new Coordinate(1, 1), @@ -72,11 +89,11 @@ public class ProjectionDataTest { new TestCase( // new ProjectionData("Grid203", - ProjectionType.POLAR_STEREOGRAPHIC.ordinal(), - new Coordinate(-185.837, 19.132), new Coordinate( - -53.660, 57.634), new Coordinate(0.0, 0.0), - 0.0f, 0.0f, new Point(1, 1), new Point(45, 39), - 0.0f, 0.0f, -150.0f), + ProjectionType.POLAR_STEREOGRAPHIC, new Coordinate( + -185.837, 19.132), new Coordinate(-53.660, + 57.634), new Coordinate(0.0, 0.0), 0.0f, + 0.0f, new Point(1, 1), new Point(45, 39), 0.0f, + 0.0f, -150.0f), new Coordinate[][] { { new Coordinate(1, 1), @@ -90,11 +107,12 @@ public class ProjectionDataTest { ), // new TestCase( // - new ProjectionData("Grid204", ProjectionType.MERCATOR - .ordinal(), new Coordinate(-250.0, -25.0), - new Coordinate(-109.129, 60.644), new Coordinate( - 0.0, 0.0), 0.0f, 0.0f, new Point(1, 1), - new Point(93, 68), 0.0f, -179.564f, 0.0f), + new ProjectionData("Grid204", ProjectionType.MERCATOR, + new Coordinate(-250.0, -25.0), new Coordinate( + -109.129, 60.644), + new Coordinate(0.0, 0.0), 0.0f, 0.0f, new Point(1, + 1), new Point(93, 68), 0.0f, -179.564f, + 0.0f), new Coordinate[][] { { new Coordinate(1, 1), @@ -109,11 +127,12 @@ public class ProjectionDataTest { new TestCase( // - new ProjectionData("Grid208", ProjectionType.MERCATOR - .ordinal(), new Coordinate(-167.315, 9.343), - new Coordinate(-145.878, 28.092), new Coordinate( - 0.0, 0.0), 0.0f, 0.0f, new Point(1, 1), - new Point(29, 27), 0.0f, -157.082f, 0.0f), + new ProjectionData("Grid208", ProjectionType.MERCATOR, + new Coordinate(-167.315, 9.343), new Coordinate( + -145.878, 28.092), + new Coordinate(0.0, 0.0), 0.0f, 0.0f, new Point(1, + 1), new Point(29, 27), 0.0f, -157.082f, + 0.0f), new Coordinate[][] { { new Coordinate(1, 1), @@ -128,11 +147,11 @@ public class ProjectionDataTest { new TestCase( // - new ProjectionData("Grid210", ProjectionType.MERCATOR - .ordinal(), new Coordinate(-77.000, 9.000), - new Coordinate(-58.625, 26.422), new Coordinate( - 0.0, 0.0), 0.0f, 0.0f, new Point(1, 1), - new Point(25, 25), 0.0f, -67.812f, 0.0f), + new ProjectionData("Grid210", ProjectionType.MERCATOR, + new Coordinate(-77.000, 9.000), new Coordinate( + -58.625, 26.422), new Coordinate(0.0, 0.0), + 0.0f, 0.0f, new Point(1, 1), new Point(25, 25), + 0.0f, -67.812f, 0.0f), new Coordinate[][] { { new Coordinate(1, 1), @@ -148,11 +167,11 @@ public class ProjectionDataTest { new TestCase( // new ProjectionData("Grid214AK", - ProjectionType.POLAR_STEREOGRAPHIC.ordinal(), - new Coordinate(-178.571, 40.5301), new Coordinate( - -93.689, 63.975), new Coordinate(0.0, 0.0), - 0.0f, 0.0f, new Point(1, 1), new Point(104, 70), - 0.0f, 0.0f, -150.0f), + ProjectionType.POLAR_STEREOGRAPHIC, new Coordinate( + -178.571, 40.5301), new Coordinate(-93.689, + 63.975), new Coordinate(0.0, 0.0), 0.0f, + 0.0f, new Point(1, 1), new Point(104, 70), 0.0f, + 0.0f, -150.0f), new Coordinate[][] { { new Coordinate(1, 1), @@ -167,6 +186,9 @@ public class ProjectionDataTest { }; + /** + * test grid coordinate to lat/lon conversion + */ @Test public void testGridCoordinateToLatLon() { PixelOrientation orientation = PixelOrientation.CENTER; @@ -181,34 +203,11 @@ public class ProjectionDataTest { gridCoord, orientation); System.out.println(gridCoord + " " + latLon); Assert.assertTrue("expected: " + expected.x + ", got: " - + latLon.x, withinTolerance(latLon.x, expected.x, - TOLERANCE)); + + latLon.x, + withinTolerance(latLon.x, expected.x, TOLERANCE)); Assert.assertTrue("expected: " + expected.y + ", got: " - + latLon.y, withinTolerance(latLon.y, expected.y, - TOLERANCE)); - } - } - } - - @Test - public void testLatLonToGridCoordinate() { - PixelOrientation orientation = PixelOrientation.CENTER; - - for (TestCase testCase : testCases) { - System.out - .println("Projection: " + testCase.proj.getProjectionID()); - for (Coordinate[] coords : testCase.testInOut) { - Coordinate expected = coords[0]; - Coordinate latLon = coords[1]; - Coordinate gridCoord = testCase.proj.latLonToGridCoordinate( - latLon, orientation); - System.out.println(gridCoord + " " + latLon); - Assert.assertTrue("expected: " + expected.x + ", got: " - + gridCoord.x, withinTolerance(gridCoord.x, expected.x, - TOLERANCE)); - Assert.assertTrue("expected: " + expected.y + ", got: " - + gridCoord.y, withinTolerance(gridCoord.y, expected.y, - TOLERANCE)); + + latLon.y, + withinTolerance(latLon.y, expected.y, TOLERANCE)); } } } diff --git a/tests/unit/com/raytheon/edex/plugin/gfe/db/objects/GridLocationTest.java b/tests/unit/com/raytheon/edex/plugin/gfe/db/objects/GridLocationTest.java index cd4a3a1cf3..2ca58c2057 100644 --- a/tests/unit/com/raytheon/edex/plugin/gfe/db/objects/GridLocationTest.java +++ b/tests/unit/com/raytheon/edex/plugin/gfe/db/objects/GridLocationTest.java @@ -32,6 +32,22 @@ import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridLocation; import com.raytheon.uf.common.geospatial.MapUtil; import com.vividsolutions.jts.geom.Coordinate; +/** + * GridLocation Unit Test + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Aug 14, 2013       1571 randerso    Changed to use ProjectionType enum
+ * 
+ * 
+ * + * @author randerso + * @version 1.0 + */ public class GridLocationTest { private static final double LATLON_TOLERANCE = 1e-3; @@ -43,30 +59,28 @@ public class GridLocationTest { } private static final ProjectionData grid211 = new ProjectionData("Grid211", - ProjectionType.LAMBERT_CONFORMAL.ordinal(), new Coordinate( - -133.459, 12.190), new Coordinate(-49.385, 57.290), - new Coordinate(-95.0, 25.0), 25.0f, 25.0f, new Point(1, 1), - new Point(93, 65), 0.0f, 0.0f, 0.0f); + ProjectionType.LAMBERT_CONFORMAL, new Coordinate(-133.459, 12.190), + new Coordinate(-49.385, 57.290), new Coordinate(-95.0, 25.0), + 25.0f, 25.0f, new Point(1, 1), new Point(93, 65), 0.0f, 0.0f, 0.0f); private static final ProjectionData grid204 = new ProjectionData("Grid204", - ProjectionType.MERCATOR.ordinal(), new Coordinate(-250.0, -25.0), + ProjectionType.MERCATOR, new Coordinate(-250.0, -25.0), new Coordinate(-109.129, 60.644), new Coordinate(0.0, 0.0), 0.0f, 0.0f, new Point(1, 1), new Point(93, 68), 0.0f, -179.564f, 0.0f); private static final ProjectionData grid208 = new ProjectionData("Grid208", - ProjectionType.MERCATOR.ordinal(), - new Coordinate(-166.219, 10.656), new Coordinate(-147.844, 27.917), - new Coordinate(0.0, 0.0), 0.0f, 0.0f, new Point(1, 1), new Point( - 25, 25), 0.0f, -157.082f, 0.0f); + ProjectionType.MERCATOR, new Coordinate(-166.219, 10.656), + new Coordinate(-147.844, 27.917), new Coordinate(0.0, 0.0), 0.0f, + 0.0f, new Point(1, 1), new Point(25, 25), 0.0f, -157.082f, 0.0f); private static final ProjectionData grid210 = new ProjectionData("Grid210", - ProjectionType.MERCATOR.ordinal(), new Coordinate(-77.000, 9.000), + ProjectionType.MERCATOR, new Coordinate(-77.000, 9.000), new Coordinate(-58.625, 26.422), new Coordinate(0.0, 0.0), 0.0f, 0.0f, new Point(1, 1), new Point(25, 25), 0.0f, -67.812f, 0.0f); private static final ProjectionData grid214AK = new ProjectionData( - "Grid214AK", ProjectionType.POLAR_STEREOGRAPHIC.ordinal(), - new Coordinate(-178.571, 40.5301), new Coordinate(-93.689, 63.975), + "Grid214AK", ProjectionType.POLAR_STEREOGRAPHIC, new Coordinate( + -178.571, 40.5301), new Coordinate(-93.689, 63.975), new Coordinate(0.0, 0.0), 0.0f, 0.0f, new Point(1, 1), new Point( 104, 70), 0.0f, 0.0f, -150.0f); @@ -116,7 +130,7 @@ public class GridLocationTest { ), new TestCase( - // + // new GridLocation("HFO", grid208, new Point(321, 225), new Coordinate(7.00, 11.00), new Coordinate(10.0, 7.0), "Pacific/Honolulu"), @@ -133,7 +147,7 @@ public class GridLocationTest { ), new TestCase( - // + // new GridLocation("SJU", grid210, new Point(32, 28), new Coordinate(10.0, 10.0), new Coordinate(8.0, 7.0), "America/Puerto_Rico"), @@ -150,7 +164,7 @@ public class GridLocationTest { ), new TestCase( - // + // new GridLocation("AJK", grid214AK, new Point(337, 241), new Coordinate(62.0, 23.0), new Coordinate(21.0, 15.0), "America/Juneau"), @@ -179,11 +193,11 @@ public class GridLocationTest { orientation, testCase.gloc); System.out.println(gridCoord + " " + latLon); Assert.assertTrue("expected: " + expected.x + ", got: " - + latLon.x, withinTolerance(latLon.x, expected.x, - LATLON_TOLERANCE)); + + latLon.x, + withinTolerance(latLon.x, expected.x, LATLON_TOLERANCE)); Assert.assertTrue("expected: " + expected.y + ", got: " - + latLon.y, withinTolerance(latLon.y, expected.y, - LATLON_TOLERANCE)); + + latLon.y, + withinTolerance(latLon.y, expected.y, LATLON_TOLERANCE)); } } } @@ -201,12 +215,14 @@ public class GridLocationTest { orientation, testCase.gloc); System.out.println(String.format("(%.3f,%.3f) (%.4f,%.4f)", gridCoord.x, gridCoord.y, latLon.x, latLon.y)); - Assert.assertTrue("expected: " + expected.x + ", got: " - + gridCoord.x, withinTolerance(gridCoord.x, expected.x, - GRIDCELL_TOLERANCE)); - Assert.assertTrue("expected: " + expected.y + ", got: " - + gridCoord.y, withinTolerance(gridCoord.y, expected.y, - GRIDCELL_TOLERANCE)); + Assert.assertTrue( + "expected: " + expected.x + ", got: " + gridCoord.x, + withinTolerance(gridCoord.x, expected.x, + GRIDCELL_TOLERANCE)); + Assert.assertTrue( + "expected: " + expected.y + ", got: " + gridCoord.y, + withinTolerance(gridCoord.y, expected.y, + GRIDCELL_TOLERANCE)); } } } diff --git a/tests/unit/com/raytheon/uf/common/dataplugin/gfe/slice/DiscreteGridSliceTest.java b/tests/unit/com/raytheon/uf/common/dataplugin/gfe/slice/DiscreteGridSliceTest.java index 09cd3be33c..63a3891039 100644 --- a/tests/unit/com/raytheon/uf/common/dataplugin/gfe/slice/DiscreteGridSliceTest.java +++ b/tests/unit/com/raytheon/uf/common/dataplugin/gfe/slice/DiscreteGridSliceTest.java @@ -52,7 +52,8 @@ import com.vividsolutions.jts.geom.Coordinate; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * 02/27/2008 879 rbell Initial Creation. - * 01/30/2013 15719 jdynina Allowed more than 128 chars in wx string + * 01/30/2013 15719 jdynina Allowed more than 128 chars in wx string + * 08/14/2013 1571 randerso Changed to use ProjectionType enum * * * @@ -244,10 +245,9 @@ public class DiscreteGridSliceTest { private final TimeRange testTR1 = new TimeRange(new Date(), 1000); private final ProjectionData grid211 = new ProjectionData("Grid211", - ProjectionType.LAMBERT_CONFORMAL.ordinal(), new Coordinate( - -133.459, 12.190), new Coordinate(-49.385, 57.290), - new Coordinate(-95.0, 25.0), 25.0f, 25.0f, new Point(1, 1), - new Point(93, 65), 0.0f, 0.0f, 0.0f); + ProjectionType.LAMBERT_CONFORMAL, new Coordinate(-133.459, 12.190), + new Coordinate(-49.385, 57.290), new Coordinate(-95.0, 25.0), + 25.0f, 25.0f, new Point(1, 1), new Point(93, 65), 0.0f, 0.0f, 0.0f); private final GridLocation gloc = new GridLocation("BOU", grid211, new Point(4, 4), new Coordinate(38, 27), new Coordinate(9, 9), diff --git a/tests/unit/com/raytheon/uf/common/dataplugin/gfe/slice/ScalarGridSliceTest.java b/tests/unit/com/raytheon/uf/common/dataplugin/gfe/slice/ScalarGridSliceTest.java index 6f5f46cf99..7344b659c0 100644 --- a/tests/unit/com/raytheon/uf/common/dataplugin/gfe/slice/ScalarGridSliceTest.java +++ b/tests/unit/com/raytheon/uf/common/dataplugin/gfe/slice/ScalarGridSliceTest.java @@ -52,6 +52,7 @@ import com.vividsolutions.jts.geom.Coordinate; * ------------ ---------- ----------- -------------------------- * 03/03/2008 879 rbell Initial Creation. * Jul 25, 2013 2208 njensen Moved to tests project + * Aug 14, 2013 1571 randerso Changed to use ProjectionType enum * * * @@ -73,10 +74,9 @@ public class ScalarGridSliceTest { private final TimeRange testTR1 = new TimeRange(new Date(), 1000); private final ProjectionData grid211 = new ProjectionData("Grid211", - ProjectionType.LAMBERT_CONFORMAL.ordinal(), new Coordinate( - -133.459, 12.190), new Coordinate(-49.385, 57.290), - new Coordinate(-95.0, 25.0), 25.0f, 25.0f, new Point(1, 1), - new Point(93, 65), 0.0f, 0.0f, 0.0f); + ProjectionType.LAMBERT_CONFORMAL, new Coordinate(-133.459, 12.190), + new Coordinate(-49.385, 57.290), new Coordinate(-95.0, 25.0), + 25.0f, 25.0f, new Point(1, 1), new Point(93, 65), 0.0f, 0.0f, 0.0f); private final GridLocation gloc = new GridLocation("BOU", grid211, new Point(4, 4), new Coordinate(38, 27), new Coordinate(9, 9), diff --git a/tests/unit/com/raytheon/uf/common/dataplugin/gfe/slice/VectorGridSliceTest.java b/tests/unit/com/raytheon/uf/common/dataplugin/gfe/slice/VectorGridSliceTest.java index 5d7bc9a7ab..835106e1d0 100644 --- a/tests/unit/com/raytheon/uf/common/dataplugin/gfe/slice/VectorGridSliceTest.java +++ b/tests/unit/com/raytheon/uf/common/dataplugin/gfe/slice/VectorGridSliceTest.java @@ -43,6 +43,22 @@ import com.raytheon.uf.common.dataplugin.gfe.grid.Op; import com.raytheon.uf.common.time.TimeRange; import com.vividsolutions.jts.geom.Coordinate; +/** + * VectorGridSlice Unit Test + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Aug 14, 2013       1571 randerso    Changed to use ProjectionType enum
+ * 
+ * 
+ * + * @author randerso + * @version 1.0 + */ // TODO fix? @Ignore public class VectorGridSliceTest { @@ -61,10 +77,9 @@ public class VectorGridSliceTest { private final TimeRange testTR1 = new TimeRange(new Date(), 1000); private final ProjectionData grid211 = new ProjectionData("Grid211", - ProjectionType.LAMBERT_CONFORMAL.ordinal(), new Coordinate( - -133.459, 12.190), new Coordinate(-49.385, 57.290), - new Coordinate(-95.0, 25.0), 25.0f, 25.0f, new Point(1, 1), - new Point(93, 65), 0.0f, 0.0f, 0.0f); + ProjectionType.LAMBERT_CONFORMAL, new Coordinate(-133.459, 12.190), + new Coordinate(-49.385, 57.290), new Coordinate(-95.0, 25.0), + 25.0f, 25.0f, new Point(1, 1), new Point(93, 65), 0.0f, 0.0f, 0.0f); private final GridLocation gloc = new GridLocation("BOU", grid211, new Point(4, 4), new Coordinate(38, 27), new Coordinate(9, 9), diff --git a/tests/unit/com/raytheon/viz/gfe/core/griddata/ScalarGridDataTest.java b/tests/unit/com/raytheon/viz/gfe/core/griddata/ScalarGridDataTest.java index aac961375a..367381eead 100644 --- a/tests/unit/com/raytheon/viz/gfe/core/griddata/ScalarGridDataTest.java +++ b/tests/unit/com/raytheon/viz/gfe/core/griddata/ScalarGridDataTest.java @@ -56,8 +56,9 @@ import com.vividsolutions.jts.geom.Coordinate; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Mar 26, 2008 rbell Initial creation + * Mar 26, 2008 rbell Initial creation * Mar 20, 2013 #1774 randerso Use TimeUtil constants + * Aug 14, 2013 #1571 randerso Changed to use ProjectionType enum * * * @@ -102,8 +103,8 @@ public class ScalarGridDataTest { ParmID.defaultLevel()); ProjectionData grid211 = new ProjectionData("Grid211", - ProjectionType.LAMBERT_CONFORMAL.ordinal(), new Coordinate( - -133.459, 12.190), new Coordinate(-49.385, 57.290), + ProjectionType.LAMBERT_CONFORMAL, new Coordinate(-133.459, + 12.190), new Coordinate(-49.385, 57.290), new Coordinate(-95.0, 25.0), 25.0f, 25.0f, new Point(1, 1), new Point(93, 65), 0.0f, 0.0f, 0.0f); diff --git a/tests/unit/com/raytheon/viz/gfe/core/griddata/VectorGridDataTest.java b/tests/unit/com/raytheon/viz/gfe/core/griddata/VectorGridDataTest.java index d08d32967d..154b595045 100644 --- a/tests/unit/com/raytheon/viz/gfe/core/griddata/VectorGridDataTest.java +++ b/tests/unit/com/raytheon/viz/gfe/core/griddata/VectorGridDataTest.java @@ -57,6 +57,7 @@ import com.vividsolutions.jts.geom.Coordinate; * ------------ ---------- ----------- -------------------------- * Mar 26, 2008 rbell Initial creation * Mar 20, 2013 #1774 randerso Use TimeUtil constants + * Aug 14, 2013 #1571 randerso Changed to use ProjectionType enum * * * @@ -70,7 +71,7 @@ public class VectorGridDataTest { private final float testFA1[] = new float[145 * 145]; { - for (int i = 0; i < 145 * 145; i++) { + for (int i = 0; i < (145 * 145); i++) { this.testFA1[i] = (float) (i + (i / (Math.pow(10.0, (i + "").length())))); } @@ -81,7 +82,7 @@ public class VectorGridDataTest { private final float testFA1b[] = new float[145 * 145]; { - for (int i = 0; i < 145 * 145; i++) { + for (int i = 0; i < (145 * 145); i++) { this.testFA1b[i] = i % 365; } } @@ -99,10 +100,9 @@ public class VectorGridDataTest { "OAX_GRID__Practice_00000000_0000", ParmID.defaultLevel()); private final ProjectionData grid211 = new ProjectionData("Grid211", - ProjectionType.LAMBERT_CONFORMAL.ordinal(), new Coordinate( - -133.459, 12.190), new Coordinate(-49.385, 57.290), - new Coordinate(-95.0, 25.0), 25.0f, 25.0f, new Point(1, 1), - new Point(93, 65), 0.0f, 0.0f, 0.0f); + ProjectionType.LAMBERT_CONFORMAL, new Coordinate(-133.459, 12.190), + new Coordinate(-49.385, 57.290), new Coordinate(-95.0, 25.0), + 25.0f, 25.0f, new Point(1, 1), new Point(93, 65), 0.0f, 0.0f, 0.0f); private final GridLocation testGL1 = new GridLocation("OAX", this.grid211, new Point(145, 145), new Coordinate(45, 30), new Coordinate(9, 9), @@ -126,7 +126,7 @@ public class VectorGridDataTest { private final byte testBA2[] = new byte[145 * 145]; { - for (int i = 0; i < 145 * 145; i++) { + for (int i = 0; i < (145 * 145); i++) { this.testFA1[i] = 0; } this.testFA1[0] = 1; @@ -136,7 +136,7 @@ public class VectorGridDataTest { private final float testFA2[] = new float[145 * 145]; { - for (int i = 0; i < 145 * 145; i++) { + for (int i = 0; i < (145 * 145); i++) { this.testFA1[i] = -1; } } diff --git a/tests/unit/com/raytheon/viz/gfe/core/internal/ReferenceSetManagerTest.java b/tests/unit/com/raytheon/viz/gfe/core/internal/ReferenceSetManagerTest.java index 4a95f09e3f..db596c9e4b 100644 --- a/tests/unit/com/raytheon/viz/gfe/core/internal/ReferenceSetManagerTest.java +++ b/tests/unit/com/raytheon/viz/gfe/core/internal/ReferenceSetManagerTest.java @@ -54,13 +54,14 @@ import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Envelope; /** - * TODO Add Description + * ReferenceSetManager Unit Test * *
  * SOFTWARE HISTORY
  * Date			Ticket#		Engineer	Description
  * ------------	----------	-----------	--------------------------
  * Apr 8, 2008				randerso	Initial creation
+ * Aug 14, 2013       1571  randerso    Changed to use ProjectionType enum
  * 
  * 
* @@ -133,10 +134,9 @@ public class ReferenceSetManagerTest { private static final RefIDChangedListener refIDChangedListener = new RefIDChangedListener(); private static final ProjectionData grid211 = new ProjectionData("Grid211", - ProjectionType.LAMBERT_CONFORMAL.ordinal(), new Coordinate( - -133.459, 12.190), new Coordinate(-49.385, 57.290), - new Coordinate(-95.0, 25.0), 25.0f, 25.0f, new Point(1, 1), - new Point(93, 65), 0.0f, 0.0f, 0.0f); + ProjectionType.LAMBERT_CONFORMAL, new Coordinate(-133.459, 12.190), + new Coordinate(-49.385, 57.290), new Coordinate(-95.0, 25.0), + 25.0f, 25.0f, new Point(1, 1), new Point(93, 65), 0.0f, 0.0f, 0.0f); private static final GridLocation gloc = new GridLocation("OAX", grid211, new Point(145, 145), new Coordinate(45, 30), new Coordinate(9, 9), @@ -184,7 +184,7 @@ public class ReferenceSetManagerTest { static { Grid2DBit grid = new Grid2DBit(gloc1.getNx(), gloc1.getNy(), true); for (int i = 0; i < grid.getXdim(); i++) { - if (i == 0 || i == grid.getXdim() - 1) { + if ((i == 0) || (i == (grid.getXdim() - 1))) { for (int j = 0; j < grid.getYdim(); j++) { grid.clear(i, j); }