Merge "Issue #1260 Changed D2DGridDatabase to do slab requests. Added GFEPerformance logging statements." into development

Former-commit-id: 3f3b2aed85 [formerly acc4307eb0] [formerly 7eea6e631b [formerly 6f972ca812fbc83598c50b40241c1d65714d11e4]]
Former-commit-id: 7eea6e631b
Former-commit-id: c94809b7f2
This commit is contained in:
Richard Peter 2012-10-12 09:11:46 -05:00 committed by Gerrit Code Review
commit ac2b6e3230
12 changed files with 270 additions and 111 deletions

View file

@ -56,6 +56,20 @@
</layout> </layout>
</appender> </appender>
<!-- GFEPerformance log -->
<appender name="GFEPerformanceLog" class="org.apache.log4j.rolling.RollingFileAppender">
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern" value="${edex.home}/logs/edex-ingest-GFEPerformance-%d{yyyyMMdd}.log"/>
</rollingPolicy>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %d [%t] %c{1}: %m%n"/>
</layout>
</appender>
<appender name="GFEPerformanceLogAsync" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="GFEPerformanceLog" />
</appender>
<!-- Purge log --> <!-- Purge log -->
<appender name="PurgeLog" class="org.apache.log4j.rolling.RollingFileAppender"> <appender name="PurgeLog" class="org.apache.log4j.rolling.RollingFileAppender">
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy"> <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
@ -264,6 +278,11 @@
<appender-ref ref="FailedTriggerLog"/> <appender-ref ref="FailedTriggerLog"/>
</logger> </logger>
<logger name="GFEPerformanceLogger" additivity="false">
<level value="Debug"/>
<appender-ref ref="GFEPerformanceLogAsync" />
</logger>
<!-- default logging --> <!-- default logging -->
<root> <root>
<level value="INFO"/> <level value="INFO"/>

View file

@ -41,6 +41,20 @@
<appender-ref ref="ThriftSrvRequestLog" /> <appender-ref ref="ThriftSrvRequestLog" />
</appender> </appender>
<!-- GFEPerformance log -->
<appender name="GFEPerformanceLog" class="org.apache.log4j.rolling.RollingFileAppender">
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern" value="${edex.home}/logs/edex-request-GFEPerformance-%d{yyyyMMdd}.log"/>
</rollingPolicy>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %d [%t] %c{1}: %m%n"/>
</layout>
</appender>
<appender name="GFEPerformanceLogAsync" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="GFEPerformanceLog" />
</appender>
<logger name="ProductSrvRequestLogger" additivity="false"> <logger name="ProductSrvRequestLogger" additivity="false">
<level value="DEBUG"/> <level value="DEBUG"/>
<appender-ref ref="ProductSrvRequestLogAsync"/> <appender-ref ref="ProductSrvRequestLogAsync"/>
@ -51,6 +65,10 @@
<appender-ref ref="ThriftSrvRequestLogAsync" /> <appender-ref ref="ThriftSrvRequestLogAsync" />
</logger> </logger>
<logger name="GFEPerformanceLogger" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="GFEPerformanceLogAsync" />
</logger>
<logger name="com.raytheon"> <logger name="com.raytheon">
<level value="INFO"/> <level value="INFO"/>

View file

@ -67,6 +67,7 @@ import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID.DataType;
import com.raytheon.uf.common.dataplugin.gfe.db.objects.GFERecord; import com.raytheon.uf.common.dataplugin.gfe.db.objects.GFERecord;
import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridParmInfo; 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.ParmID;
import com.raytheon.uf.common.dataplugin.gfe.exception.GfeException;
import com.raytheon.uf.common.dataplugin.gfe.server.notify.GridUpdateNotification; 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.server.notify.LockNotification;
import com.raytheon.uf.common.dataplugin.gfe.util.GfeUtil; import com.raytheon.uf.common.dataplugin.gfe.util.GfeUtil;
@ -102,9 +103,11 @@ import com.raytheon.uf.edex.database.query.DatabaseQuery;
* 06/17/08 #940 bphillip Implemented GFE Locking * 06/17/08 #940 bphillip Implemented GFE Locking
* 06/17/09 #2380 randerso Removed purging of grid history. * 06/17/09 #2380 randerso Removed purging of grid history.
* Should cascade when record deleted. * Should cascade when record deleted.
* 08/07/09 #2763 njensen Refactored queryByD2DParmId * 08/07/09 #2763 njensen Refactored queryByD2DParmId
* 09/10/12 DR15137 ryu Changed for MOSGuide D2D mxt/mnt grids for consistency * 09/10/12 DR15137 ryu Changed for MOSGuide D2D mxt/mnt grids for consistency
* with A1. * with A1.
* 10/10/12 #1260 randerso Added check to ensure db can be created before
* adding it to the inventory
* </pre> * </pre>
* *
* @author bphillip * @author bphillip
@ -923,10 +926,15 @@ public class GFEDao extends DefaultPluginDao {
DatabaseID dbId = null; DatabaseID dbId = null;
dbId = new DatabaseID(siteID, DataType.GRID, "D2D", gfeModel, dbId = new DatabaseID(siteID, DataType.GRID, "D2D", gfeModel,
(Date) result.getRowColumnValue(i, 0)); (Date) result.getRowColumnValue(i, 0));
if (!dbInventory.contains(dbId)) { try {
dbInventory.add(dbId); GridDatabase db = GridParmManager.getDb(dbId);
if (db != null && !dbInventory.contains(dbId)) {
dbInventory.add(dbId);
}
} catch (GfeException e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(),
e);
} }
} }
return dbInventory; return dbInventory;
} }

View file

@ -76,8 +76,10 @@ import com.raytheon.uf.edex.database.plugin.PluginFactory;
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* 04/08/08 #875 bphillip Initial Creation * 04/08/08 #875 bphillip Initial Creation
* 06/17/08 #940 bphillip Implemented GFE Locking * 06/17/08 #940 bphillip Implemented GFE Locking
* 07/09/09 #2590 njensen Changed from singleton to static * 07/09/09 #2590 njensen Changed from singleton to static
* 07/12/12 15162 ryu added check for invalid db * 07/12/12 15162 ryu added check for invalid db
* 10/10/12 #1260 randerso Added exception handling for domain not
* overlapping the dataset
* *
* </pre> * </pre>
* *
@ -1134,7 +1136,13 @@ public class GridParmManager {
if (db == null) { if (db == null) {
IFPServerConfig serverConfig = IFPServerConfigManager IFPServerConfig serverConfig = IFPServerConfigManager
.getServerConfig(siteId); .getServerConfig(siteId);
db = new D2DGridDatabase(serverConfig, dbId); try {
db = new D2DGridDatabase(serverConfig, dbId);
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM,
e.getLocalizedMessage());
db = null;
}
} }
} else { } else {
// Check for topo type // Check for topo type
@ -1142,18 +1150,18 @@ public class GridParmManager {
.getModelName(); .getModelName();
if (topoModel.equals(modelName)) { if (topoModel.equals(modelName)) {
db = TopoDatabaseManager.getTopoDatabase(dbId.getSiteId()); db = TopoDatabaseManager.getTopoDatabase(dbId.getSiteId());
} else {
db = new IFPGridDatabase(dbId);
if (db.databaseIsValid()) {
((IFPGridDatabase) db).updateDbs();
}
} }
} }
boolean isIFP = (db == null); if ((db != null) && db.databaseIsValid()) {
if (db == null) {
db = new IFPGridDatabase(dbId);
if (db.databaseIsValid())
((IFPGridDatabase) db).updateDbs();
}
if (!isIFP || db.databaseIsValid())
dbMap.put(dbId, db); dbMap.put(dbId, db);
}
} }
return db; return db;
} }

View file

@ -20,6 +20,7 @@
package com.raytheon.edex.plugin.gfe.server.database; package com.raytheon.edex.plugin.gfe.server.database;
import java.awt.Rectangle;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -61,9 +62,12 @@ import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerResponse;
import com.raytheon.uf.common.dataplugin.gfe.slice.IGridSlice; import com.raytheon.uf.common.dataplugin.gfe.slice.IGridSlice;
import com.raytheon.uf.common.dataplugin.gfe.slice.ScalarGridSlice; import com.raytheon.uf.common.dataplugin.gfe.slice.ScalarGridSlice;
import com.raytheon.uf.common.dataplugin.gfe.slice.VectorGridSlice; import com.raytheon.uf.common.dataplugin.gfe.slice.VectorGridSlice;
import com.raytheon.uf.common.dataplugin.gfe.util.GfeUtil; import com.raytheon.uf.common.dataplugin.grib.GribPathProvider;
import com.raytheon.uf.common.dataplugin.grib.GribRecord; import com.raytheon.uf.common.dataplugin.grib.GribRecord;
import com.raytheon.uf.common.dataplugin.grib.spatial.projections.GridCoverage; import com.raytheon.uf.common.dataplugin.grib.spatial.projections.GridCoverage;
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.FloatDataRecord; import com.raytheon.uf.common.datastorage.records.FloatDataRecord;
import com.raytheon.uf.common.datastorage.records.IDataRecord; import com.raytheon.uf.common.datastorage.records.IDataRecord;
import com.raytheon.uf.common.message.WsId; import com.raytheon.uf.common.message.WsId;
@ -82,12 +86,15 @@ import com.raytheon.uf.edex.database.plugin.PluginFactory;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* 05/16/08 875 bphillip Initial Creation * 05/16/08 875 bphillip Initial Creation
* 06/17/08 #940 bphillip Implemented GFE Locking * 06/17/08 #940 bphillip Implemented GFE Locking
* 07/23/09 2342 ryu Check for null gridConfig in getGridParmInfo * 07/23/09 2342 ryu Check for null gridConfig in getGridParmInfo
* 03/02/12 DR14651 ryu change time independency of staticTopo, staticCoriolis, staticSpacing * 03/02/12 DR14651 ryu change time independency of staticTopo, staticCoriolis, staticSpacing
* 05/04/12 #574 dgilling Implement missing methods from GridDatabase. * 05/04/12 #574 dgilling Implement missing methods from GridDatabase.
* 09/12/12 #1117 dgilling Fix getParmList() so it returns all parms defined * 09/12/12 #1117 dgilling Fix getParmList() so it returns all parms defined
* in the GribParamInfo file. * in the GribParamInfo file.
* 10/10/12 #1260 randerso Changed to only retrieve slab containing overlapping
* data instead of full grid. Added logging to support
* GFE performance testing
* *
* </pre> * </pre>
* *
@ -98,6 +105,10 @@ public class D2DGridDatabase extends VGridDatabase {
private static final transient IUFStatusHandler statusHandler = UFStatus private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(D2DGridDatabase.class); .getHandler(D2DGridDatabase.class);
// separate logger for GFE performance logging
private static final IUFStatusHandler gfePerformanceLogger = UFStatus
.getNamedHandler("GFEPerformanceLogger");
/** The remap object used for resampling grids */ /** The remap object used for resampling grids */
private RemapGrid remap; private RemapGrid remap;
@ -147,13 +158,29 @@ public class D2DGridDatabase extends VGridDatabase {
+ d2dModelName + "] returned null"); + d2dModelName + "] returned null");
} }
inputLoc = GfeUtil.transformGridCoverage(awipsGrid); inputLoc = new GridLocation(d2dModelName, awipsGrid);
inputLoc.setSiteId(d2dModelName);
locCache.addGridLocation(gfeModelName, inputLoc); locCache.addGridLocation(gfeModelName, inputLoc);
} }
outputLoc = this.config.dbDomain(); outputLoc = this.config.dbDomain();
remap = new RemapGrid(inputLoc, outputLoc); Rectangle subdomain = NetCDFUtils.getSubGridDims(this.inputLoc,
this.outputLoc);
// fix up coordinates for 0,0 in upper left in A2
subdomain.y = inputLoc.gridSize().y - subdomain.y
- subdomain.height;
if (subdomain.isEmpty()) {
valid = false;
throw new GfeException("Unable to create " + this.dbId
+ ". GFE domain does not overlap dataset domain.");
}
this.remap = new RemapGrid(NetCDFUtils.subGridGL(dbId.toString(),
this.inputLoc, subdomain), this.outputLoc);
} }
} }
@ -439,7 +466,7 @@ public class D2DGridDatabase extends VGridDatabase {
* @throws GfeException * @throws GfeException
* If the grid slice cannot be constructed * If the grid slice cannot be constructed
*/ */
public IGridSlice getGridSlice(ParmID parmId, GridParmInfo gpi, private IGridSlice getGridSlice(ParmID parmId, GridParmInfo gpi,
TimeRange time, boolean convertUnit) throws GfeException { TimeRange time, boolean convertUnit) throws GfeException {
IGridSlice gs = null; IGridSlice gs = null;
GridDataHistory[] gdh = { new GridDataHistory( GridDataHistory[] gdh = { new GridDataHistory(
@ -482,11 +509,12 @@ public class D2DGridDatabase extends VGridDatabase {
* @throws GfeException * @throws GfeException
* If the grid data cannot be retrieved * If the grid data cannot be retrieved
*/ */
public Grid2DFloat getGrid(ParmID parmId, TimeRange time, GridParmInfo gpi, private Grid2DFloat getGrid(ParmID parmId, TimeRange time,
boolean convertUnit) throws GfeException { GridParmInfo gpi, boolean convertUnit) throws GfeException {
Grid2DFloat bdata = null; Grid2DFloat bdata = null;
GribRecord d2dRecord = null; GribRecord d2dRecord = null;
long t0 = System.currentTimeMillis();
GFEDao dao = null; GFEDao dao = null;
try { try {
dao = (GFEDao) PluginFactory.getInstance().getPluginDao("gfe"); dao = (GFEDao) PluginFactory.getInstance().getPluginDao("gfe");
@ -501,6 +529,7 @@ public class D2DGridDatabase extends VGridDatabase {
throw new GfeException( throw new GfeException(
"Error retrieving D2D Grid record from database", e); "Error retrieving D2D Grid record from database", e);
} }
long t1 = System.currentTimeMillis();
if (d2dRecord == null) { if (d2dRecord == null) {
throw new GfeException("No data available for " + parmId throw new GfeException("No data available for " + parmId
@ -509,6 +538,7 @@ public class D2DGridDatabase extends VGridDatabase {
// Gets the raw data from the D2D grib HDF5 file // Gets the raw data from the D2D grib HDF5 file
bdata = getRawGridData(d2dRecord); bdata = getRawGridData(d2dRecord);
long t2 = System.currentTimeMillis();
float fillV = Float.MAX_VALUE; float fillV = Float.MAX_VALUE;
ParameterInfo atts = GribParamInfoLookup.getInstance() ParameterInfo atts = GribParamInfoLookup.getInstance()
@ -525,16 +555,21 @@ public class D2DGridDatabase extends VGridDatabase {
retVal = this.remap.remap(bdata, fillV, gpi.getMaxValue(), retVal = this.remap.remap(bdata, fillV, gpi.getMaxValue(),
gpi.getMinValue(), gpi.getMinValue()); gpi.getMinValue(), gpi.getMinValue());
if (convertUnit && d2dRecord != null) { if (convertUnit && d2dRecord != null) {
long t5 = System.currentTimeMillis();
convertUnits(d2dRecord, retVal, gpi.getUnitObject()); convertUnits(d2dRecord, retVal, gpi.getUnitObject());
long t6 = System.currentTimeMillis();
statusHandler
.info("Time spent converting units on d2d grid data: "
+ (t6 - t5));
} }
} catch (Exception e) { } catch (Exception e) {
throw new GfeException("Unable to get Grid", e); throw new GfeException("Unable to get Grid", e);
} }
long t3 = System.currentTimeMillis();
if (gfePerformanceLogger.isPriorityEnabled(Priority.DEBUG)) {
gfePerformanceLogger.handle(Priority.DEBUG,
"D2DGridDatabase.getGrid" + //
" metaData: " + (t1 - t0) + //
" hdf5: " + (t2 - t1) + //
" remap: " + (t3 - t2) + //
" total: " + (t3 - t0));
}
return retVal; return retVal;
@ -702,21 +737,47 @@ public class D2DGridDatabase extends VGridDatabase {
* @param d2dRecord * @param d2dRecord
* The grib metadata * The grib metadata
* @return The raw data * @return The raw data
* @throws GfeException
*/ */
private Grid2DFloat getRawGridData(GribRecord d2dRecord) { private Grid2DFloat getRawGridData(GribRecord d2dRecord)
FloatDataRecord hdf5Record; throws GfeException {
try { try {
GribDao dao = new GribDao(); GribDao dao = new GribDao();
IDataRecord[] hdf5Data = dao.getHDF5Data(d2dRecord, -1); // reimplementing this call here with subgrid support
hdf5Record = (FloatDataRecord) hdf5Data[0]; // dao.getHDF5Data(d2dRecord, -1);
} catch (PluginException e) { // TODO should we add subgrid support to GribDao or PluginDao
statusHandler.handle(Priority.PROBLEM, IDataStore dataStore = dao.getDataStore(d2dRecord);
"Unable to get grib hdf5 record", e);
return null;
}
return new Grid2DFloat((int) hdf5Record.getSizes()[0],
(int) hdf5Record.getSizes()[1], hdf5Record.getFloatData());
GridLocation gloc = this.remap.getSourceGloc();
String abbrev = d2dRecord.getModelInfo().getParameterAbbreviation();
String group, dataset;
if (GribPathProvider.STATIC_PARAMETERS.contains(abbrev)) {
group = "/";
dataset = abbrev;
} else {
group = d2dRecord.getDataURI();
dataset = DataStoreFactory.DEF_DATASET_NAME;
}
IDataRecord record = dataStore.retrieve(group, dataset, Request
.buildSlab(
new int[] { (int) Math.floor(gloc.getOrigin().x),
(int) Math.floor(gloc.getOrigin().y), },
new int[] {
(int) Math.ceil(gloc.getOrigin().x
+ gloc.getExtent().x),
(int) Math.ceil(gloc.getOrigin().y
+ gloc.getExtent().y), }));
FloatDataRecord hdf5Record = (FloatDataRecord) record;
return new Grid2DFloat((int) hdf5Record.getSizes()[0],
(int) hdf5Record.getSizes()[1], hdf5Record.getFloatData());
} catch (Exception e) {
throw new GfeException("Error retrieving hdf5 record. "
+ e.getLocalizedMessage(), e);
}
} }
/** /**

View file

@ -51,8 +51,9 @@ import com.raytheon.uf.edex.database.DataAccessLayerException;
* *
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* May 16, 2011 bphillip Initial creation * May 16, 2011 bphillip Initial creation
* May 04, 2012 #574 dgilling Add unimplemented methods from GridDatabase. * May 04, 2012 #574 dgilling Add unimplemented methods from GridDatabase.
* Oct 10 2012 #1260 randerso Added code to set valid flag
* *
* </pre> * </pre>
* *
@ -81,6 +82,7 @@ public class D2DSatDatabase extends VGridDatabase {
super(config); super(config);
this.dbId = new DatabaseID(config.getSiteID().get(0), DataType.GRID, this.dbId = new DatabaseID(config.getSiteID().get(0), DataType.GRID,
"D2D", "Satellite", "00000000_0000"); "D2D", "Satellite", "00000000_0000");
this.valid = this.dbId.isValid();
parms = new ArrayList<D2DSatParm>(); parms = new ArrayList<D2DSatParm>();
for (int i = 0; i < productURIs.size(); i++) { for (int i = 0; i < productURIs.size(); i++) {
D2DSatParm parm = new D2DSatParm(config, productURIs.get(i), D2DSatParm parm = new D2DSatParm(config, productURIs.get(i),

View file

@ -45,7 +45,9 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
* *
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* May 17, 2012 randerso Initial creation * May 17, 2012 randerso Initial creation
* Oct 10 2012 #1260 randerso Added exception handling for domain not
* overlapping the dataset
* *
* </pre> * </pre>
* *
@ -142,10 +144,15 @@ public class NetCDFDatabaseManager {
if (file.isValid()) { if (file.isValid()) {
DatabaseID dbId = NetCDFGridDatabase.getDBID(file, config); DatabaseID dbId = NetCDFGridDatabase.getDBID(file, config);
NetCDFGridDatabase db = new NetCDFGridDatabase(config, file); try {
statusHandler.handle(Priority.EVENTB, "New netCDF Database: " NetCDFGridDatabase db = new NetCDFGridDatabase(config, file);
+ dbId); statusHandler.handle(Priority.EVENTB,
databaseMap.put(dbId, db); "New netCDF Database: " + dbId);
databaseMap.put(dbId, db);
} catch (GfeException e) {
statusHandler.handle(Priority.PROBLEM,
e.getLocalizedMessage());
}
} }
} }
} }

View file

@ -61,7 +61,8 @@ import com.raytheon.uf.edex.database.DataAccessLayerException;
* *
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* May 14, 2012 randerso Initial creation * May 14, 2012 randerso Initial creation
* Oct 10 2012 #1260 randerso Added check for domain not overlapping the dataset
* *
* </pre> * </pre>
* *
@ -165,7 +166,8 @@ public class NetCDFGridDatabase extends VGridDatabase {
private RemapGrid remap; private RemapGrid remap;
public NetCDFGridDatabase(IFPServerConfig config, NetCDFFile file) { public NetCDFGridDatabase(IFPServerConfig config, NetCDFFile file)
throws GfeException {
super(config); super(config);
this.valid = true; this.valid = true;
this.file = file; this.file = file;
@ -197,8 +199,16 @@ public class NetCDFGridDatabase extends VGridDatabase {
if (this.valid) { if (this.valid) {
this.subdomain = NetCDFUtils.getSubGridDims(this.inputGloc, this.subdomain = NetCDFUtils.getSubGridDims(this.inputGloc,
this.outputGloc); this.outputGloc);
this.remap = new RemapGrid(NetCDFUtils.subGridGL(this.inputGloc,
this.subdomain), this.outputGloc); if (this.subdomain.isEmpty()) {
valid = false;
throw new GfeException("Unable to create " + this.dbId
+ ". GFE domain does not overlap dataset domain.");
}
this.remap = new RemapGrid(NetCDFUtils.subGridGL(
this.dbId.toString(), this.inputGloc, this.subdomain),
this.outputGloc);
loadParms(); loadParms();
} }
} }

View file

@ -31,8 +31,6 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.TimeZone; import java.util.TimeZone;
import org.opengis.metadata.spatial.PixelOrientation;
import ucar.ma2.ArrayFloat; import ucar.ma2.ArrayFloat;
import ucar.ma2.DataType; import ucar.ma2.DataType;
import ucar.nc2.Attribute; import ucar.nc2.Attribute;
@ -45,7 +43,6 @@ import com.raytheon.uf.common.dataplugin.gfe.config.ProjectionData.ProjectionTyp
import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridLocation; import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridLocation;
import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DFloat; import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DFloat;
import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerResponse; import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerResponse;
import com.raytheon.uf.common.geospatial.MapUtil;
import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Coordinate;
/** /**
@ -57,7 +54,9 @@ import com.vividsolutions.jts.geom.Coordinate;
* *
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* May 14, 2012 randerso Initial creation * May 14, 2012 randerso Initial creation
* Oct 10 2012 #1260 randerso Cleaned up getSubGridDims to better match A1
* Changed subGridGl to use new GridLocation constructor
* *
* </pre> * </pre>
* *
@ -331,41 +330,25 @@ public class NetCDFUtils {
List<Integer> xindex = new ArrayList<Integer>(); List<Integer> xindex = new ArrayList<Integer>();
List<Integer> yindex = new ArrayList<Integer>(); List<Integer> yindex = new ArrayList<Integer>();
for (int x = 0; x < ogloc.gridSize().x; x++) { for (int x = 0; x < ogloc.gridSize().x; x++) {
Coordinate ll = MapUtil.gridCoordinateToLatLon( Coordinate ll = ogloc.latLonCenter(new Coordinate(x, 0));
new Coordinate(x, 0), PixelOrientation.CENTER, ogloc);
Coordinate c = MapUtil.latLonToGridCoordinate(ll, Point igc = igloc.gridCell((float) ll.y, (float) ll.x);
PixelOrientation.CENTER, igloc);
Point igc = new Point((int) (c.x > -0.5 ? c.x + 0.5 : c.x - 0.5),
(int) (c.y > -0.5 ? c.y + 0.5 : c.y - 0.5));
xindex.add(igc.x); xindex.add(igc.x);
yindex.add(igc.y); yindex.add(igc.y);
ll = MapUtil.gridCoordinateToLatLon( ll = ogloc.latLonCenter(new Coordinate(x, ogloc.gridSize().y - 1));
new Coordinate(x, ogloc.gridSize().y - 1), igc = igloc.gridCell((float) ll.y, (float) ll.x);
PixelOrientation.CENTER, ogloc);
c = MapUtil.latLonToGridCoordinate(ll, PixelOrientation.CENTER,
igloc);
igc = new Point((int) (c.x > -0.5 ? c.x + 0.5 : c.x - 0.5),
(int) (c.y > -0.5 ? c.y + 0.5 : c.y - 0.5));
xindex.add(igc.x); xindex.add(igc.x);
yindex.add(igc.y); yindex.add(igc.y);
} }
for (int y = 0; y < ogloc.gridSize().y; y++) { for (int y = 0; y < ogloc.gridSize().y; y++) {
Coordinate ll = MapUtil.gridCoordinateToLatLon( Coordinate ll = ogloc.latLonCenter(new Coordinate(0, y));
new Coordinate(0, y), PixelOrientation.CENTER, ogloc); Point igc = igloc.gridCell((float) ll.y, (float) ll.x);
Coordinate c = MapUtil.latLonToGridCoordinate(ll,
PixelOrientation.CENTER, igloc);
Point igc = new Point((int) c.x, (int) c.y);
xindex.add(igc.x); xindex.add(igc.x);
yindex.add(igc.y); yindex.add(igc.y);
ll = MapUtil.gridCoordinateToLatLon(new Coordinate( ll = ogloc.latLonCenter(new Coordinate(ogloc.gridSize().x - 1, y));
ogloc.gridSize().x - 1, y), PixelOrientation.CENTER, ogloc); igc = igloc.gridCell((float) ll.y, (float) ll.x);
c = MapUtil.latLonToGridCoordinate(ll, PixelOrientation.CENTER,
igloc);
igc = new Point((int) (c.x > -0.5 ? c.x + 0.5 : c.x - 0.5),
(int) (c.y > -0.5 ? c.y + 0.5 : c.y - 0.5));
xindex.add(igc.x); xindex.add(igc.x);
yindex.add(igc.y); yindex.add(igc.y);
} }
@ -388,16 +371,14 @@ public class NetCDFUtils {
return rval; return rval;
} }
public static GridLocation subGridGL(GridLocation igloc, Rectangle subd) { public static GridLocation subGridGL(String id, GridLocation igloc,
Rectangle subd) {
// Coordinate nwo = igloc.worldCoordinate(subd.origin()); // Coordinate nwo = igloc.worldCoordinate(subd.origin());
// Coordinate nwe = igloc.worldCoordinate(subd.upperRight()); // Coordinate nwe = igloc.worldCoordinate(subd.upperRight());
// CartDomain2D<float> swd (nwo, nwe - nwo); // CartDomain2D<float> swd (nwo, nwe - nwo);
// return GridLocation(igloc.projection()->pdata(), // return GridLocation(igloc.projection()->pdata(),
// subd.extent() + Point (1, 1), swd); // subd.extent() + Point (1, 1), swd);
return new GridLocation(igloc.getProjection().getProjectionID(), return new GridLocation(id, igloc, subd);
igloc.getProjection(), new Point(subd.width, subd.height),
new Coordinate(subd.x, subd.y), new Coordinate(subd.width,
subd.height), "GMT");
} }
} }

View file

@ -65,6 +65,7 @@ import com.vividsolutions.jts.geom.Coordinate;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* 5/16/08 875 bphillip Initial Creation. * 5/16/08 875 bphillip Initial Creation.
* 10/10/12 #1260 randerso Added getters for source and destination glocs
* *
* </pre> * </pre>
* *
@ -107,6 +108,14 @@ public class RemapGrid {
this.rescale = rescale; this.rescale = rescale;
} }
public GridLocation getSourceGloc() {
return sourceGloc;
}
public GridLocation getDestinationGloc() {
return destinationGloc;
}
/** /**
* Returns a Grid2D<float> that has been remapped from the input grid in the * Returns a Grid2D<float> that has been remapped from the input grid in the
* source GridLocation domain space to the destination GridLocation domain * source GridLocation domain space to the destination GridLocation domain

View file

@ -20,6 +20,7 @@
package com.raytheon.uf.common.dataplugin.gfe.db.objects; package com.raytheon.uf.common.dataplugin.gfe.db.objects;
import java.awt.Point; import java.awt.Point;
import java.awt.Rectangle;
import java.util.ArrayList; import java.util.ArrayList;
import javax.persistence.Column; import javax.persistence.Column;
@ -56,6 +57,7 @@ import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DBit;
import com.raytheon.uf.common.dataplugin.gfe.reference.ReferenceData; import com.raytheon.uf.common.dataplugin.gfe.reference.ReferenceData;
import com.raytheon.uf.common.dataplugin.gfe.reference.ReferenceData.CoordinateType; import com.raytheon.uf.common.dataplugin.gfe.reference.ReferenceData.CoordinateType;
import com.raytheon.uf.common.dataplugin.gfe.reference.ReferenceID; import com.raytheon.uf.common.dataplugin.gfe.reference.ReferenceID;
import com.raytheon.uf.common.dataplugin.grib.spatial.projections.GridCoverage;
import com.raytheon.uf.common.dataplugin.persist.PersistableDataObject; import com.raytheon.uf.common.dataplugin.persist.PersistableDataObject;
import com.raytheon.uf.common.geospatial.CRSCache; import com.raytheon.uf.common.geospatial.CRSCache;
import com.raytheon.uf.common.geospatial.ISpatialObject; import com.raytheon.uf.common.geospatial.ISpatialObject;
@ -86,6 +88,7 @@ import com.vividsolutions.jts.simplify.TopologyPreservingSimplifier;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* 04/24/08 @1047 randerso Added fields to store projection information * 04/24/08 @1047 randerso Added fields to store projection information
* 10/10/12 #1260 randerso Added new constructor that takes a GridCoverage
* *
* *
* </pre> * </pre>
@ -235,9 +238,6 @@ public class GridLocation extends PersistableDataObject implements
+ e.getLocalizedMessage(), e); + e.getLocalizedMessage(), e);
} }
DefaultMathTransformFactory dmtf = new DefaultMathTransformFactory();
double[] latLon = new double[8];
// transform the grid corners from grid coordinates to CRS units // transform the grid corners from grid coordinates to CRS units
Coordinate ll = domainOrigin; Coordinate ll = domainOrigin;
Coordinate ur = new Coordinate(domainOrigin.x + domainExtent.x, Coordinate ur = new Coordinate(domainOrigin.x + domainExtent.x,
@ -270,11 +270,13 @@ public class GridLocation extends PersistableDataObject implements
PixelInCell.CELL_CORNER, mt, ge, null); PixelInCell.CELL_CORNER, mt, ge, null);
// set up the transform from grid coordinates to lon/lat // set up the transform from grid coordinates to lon/lat
DefaultMathTransformFactory dmtf = new DefaultMathTransformFactory();
mt = dmtf.createConcatenatedTransform( mt = dmtf.createConcatenatedTransform(
gridGeom.getGridToCRS(PixelOrientation.UPPER_LEFT), gridGeom.getGridToCRS(PixelOrientation.UPPER_LEFT),
MapUtil.getTransformToLatLon(crsObject)); MapUtil.getTransformToLatLon(crsObject));
// transform grid corner points to Lat/Lon // transform grid corner points to Lat/Lon
double[] latLon = new double[8];
mt.transform(new double[] { 0, this.ny, 0, 0, this.nx, 0, this.nx, mt.transform(new double[] { 0, this.ny, 0, 0, this.nx, 0, this.nx,
this.ny }, 0, latLon, 0, 4); this.ny }, 0, latLon, 0, 4);
@ -307,6 +309,54 @@ public class GridLocation extends PersistableDataObject implements
"GMT"); "GMT");
} }
public GridLocation(String id, GridCoverage coverage) {
this.siteId = id;
this.crsObject = coverage.getCrs();
this.crsWKT = this.crsObject.toWKT();
this.geometry = (Polygon) coverage.getGeometry();
this.nx = coverage.getNx();
this.ny = coverage.getNy();
}
public GridLocation(String id, GridLocation gloc, Rectangle subGrid) {
try {
this.siteId = id;
this.crsObject = gloc.crsObject;
this.crsWKT = gloc.crsWKT;
this.nx = subGrid.width;
this.ny = subGrid.height;
this.origin = new Coordinate(subGrid.x, subGrid.y);
this.extent = new Coordinate(subGrid.width, subGrid.height);
GridGeometry2D gridGeom = MapUtil.getGridGeometry(gloc);
// set up the transform from grid coordinates to lon/lat
DefaultMathTransformFactory dmtf = new DefaultMathTransformFactory();
MathTransform mt = dmtf.createConcatenatedTransform(
gridGeom.getGridToCRS(PixelOrientation.UPPER_LEFT),
MapUtil.getTransformToLatLon(crsObject));
// transform grid corner points to Lat/Lon
double[] latLon = new double[8];
mt.transform(new double[] { subGrid.x, subGrid.y + subGrid.height,
subGrid.x, subGrid.y, subGrid.x + subGrid.width, subGrid.y,
subGrid.x + subGrid.width, subGrid.y + subGrid.height }, 0,
latLon, 0, 4);
Coordinate[] corners = new Coordinate[] {
MapUtil.getCoordinate(latLon[0], latLon[1]),
MapUtil.getCoordinate(latLon[2], latLon[3]),
MapUtil.getCoordinate(latLon[4], latLon[5]),
MapUtil.getCoordinate(latLon[6], latLon[7]),
MapUtil.getCoordinate(latLon[0], latLon[1]) };
this.geometry = MapUtil.getPolygon(corners);
} catch (Exception e) {
statusHandler.handle(Priority.CRITICAL,
"Error creating GridLocation", e);
}
}
/** /**
* @return the timeZone * @return the timeZone
*/ */
@ -430,8 +480,9 @@ public class GridLocation extends PersistableDataObject implements
Math.abs(out1[0] - out2[0]) / 1000.0, Math.abs(out1[1] Math.abs(out1[0] - out2[0]) / 1000.0, Math.abs(out1[1]
- out2[1]) / 1000.0); - out2[1]) / 1000.0);
} catch (TransformException e) { } catch (TransformException e) {
// TODO Auto-generated catch block statusHandler.error(
e.printStackTrace(); "Error computing gridCellSize: "
+ e.getLocalizedMessage(), e);
} }
} else { } else {

View file

@ -39,7 +39,6 @@ import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID;
import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridLocation; import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridLocation;
import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID; import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID;
import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DBit; import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DBit;
import com.raytheon.uf.common.dataplugin.grib.spatial.projections.GridCoverage;
import com.raytheon.uf.common.time.TimeRange; import com.raytheon.uf.common.time.TimeRange;
import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.Geometry;
@ -61,6 +60,8 @@ import com.vividsolutions.jts.operation.polygonize.Polygonizer;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* 04/08/08 #875 bphillip Initial Creation * 04/08/08 #875 bphillip Initial Creation
* 10/10/12 #1260 randerso Removed transformGridCoverage in
* favor of new GridLocation constructor
* *
* </pre> * </pre>
* *
@ -224,22 +225,6 @@ public class GfeUtil {
return cal.getTime(); return cal.getTime();
} }
/**
* Transforms a D2D grid coverage object into a GFE grid location object
*
* @param coverage
* The D2D grid coverage object
* @return The GFE grid location object
*/
public static GridLocation transformGridCoverage(GridCoverage coverage) {
GridLocation location = new GridLocation();
location.setCrsObject(coverage.getCrs());
location.setGeometry(coverage.getGeometry());
location.setNx(coverage.getNx());
location.setNy(coverage.getNy());
return location;
}
/** /**
* Creates a grid for the specified GridLocation that has all bits set that * Creates a grid for the specified GridLocation that has all bits set that
* are inside the provided polygon. * are inside the provided polygon.