Issue #2060 fix sat precip for grid data URI removal
Change-Id: Iaa5144a63ff455f5c12a060a9daad0dd0bd04e58 Former-commit-id:f76ace3c9b
[formerly2b6c30e67d
] [formerly0cf0f724f4
] [formerlyf76ace3c9b
[formerly2b6c30e67d
] [formerly0cf0f724f4
] [formerlyd82f6e5ff6
[formerly0cf0f724f4
[formerly cf0bb31583f0ec0b2135aa9101f3247e88e877d0]]]] Former-commit-id:d82f6e5ff6
Former-commit-id:3853ef16bb
[formerly09091ccf25
] [formerly 7beb650628fb602c30c71cbf5eab29724e2cc3f8 [formerly97597c3ab1
]] Former-commit-id: 34e886c76b22b953edb7a826d23a880a02b62b77 [formerly0840a62eb8
] Former-commit-id:d50f19d715
This commit is contained in:
parent
766d9f09a7
commit
0fc04a8c55
2 changed files with 97 additions and 130 deletions
|
@ -19,10 +19,13 @@
|
|||
**/
|
||||
package com.raytheon.uf.edex.ohd.pproc;
|
||||
|
||||
import com.raytheon.uf.common.dataplugin.annotations.DataURI;
|
||||
import com.raytheon.uf.common.dataplugin.grid.GridConstants;
|
||||
import com.raytheon.uf.common.dataplugin.message.DataURINotificationMessage;
|
||||
|
||||
/**
|
||||
* TODO Add Description
|
||||
* Filters URIs for Satellite Precip and generates an xmrg file if the filter
|
||||
* matches.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
|
@ -30,8 +33,9 @@ import com.raytheon.uf.common.dataplugin.message.DataURINotificationMessage;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Sep 10, 2009 snaples Initial creation
|
||||
* Feb 12, 2010 4635 snaples Updated to match more generically.
|
||||
* Feb 12, 2010 4635 snaples Updated to match more generically.
|
||||
* Feb 15, 2013 1638 mschenke Moved DataURINotificationMessage to uf.common.dataplugin
|
||||
* May 05, 2014 2060 njensen Cleanup
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -41,22 +45,22 @@ import com.raytheon.uf.common.dataplugin.message.DataURINotificationMessage;
|
|||
|
||||
public class SatPreURIFilter {
|
||||
|
||||
DataURINotificationMessage message;
|
||||
private static final String AUTOSPE = "AUTOSPE";
|
||||
|
||||
String outpath = "";
|
||||
private String startFilter;
|
||||
|
||||
static final String AUTOSPE = "AUTOSPE";
|
||||
private SatPrecipFileBuilder builder;
|
||||
|
||||
public SatPreURIFilter() {
|
||||
public SatPreURIFilter() throws Exception {
|
||||
startFilter = DataURI.SEPARATOR + GridConstants.GRID;
|
||||
builder = new SatPrecipFileBuilder();
|
||||
}
|
||||
|
||||
public void matchURI(DataURINotificationMessage msg) {
|
||||
message = msg;
|
||||
|
||||
if (message instanceof DataURINotificationMessage) {
|
||||
public void matchURI(DataURINotificationMessage msg) throws Exception {
|
||||
if (msg instanceof DataURINotificationMessage) {
|
||||
String uri = "";
|
||||
for (String data : message.getDataURIs()) {
|
||||
if (data.startsWith("/grid")) {
|
||||
for (String data : msg.getDataURIs()) {
|
||||
if (data.startsWith(startFilter)) {
|
||||
if (data.contains(AUTOSPE)) {
|
||||
uri = data;
|
||||
break;
|
||||
|
@ -68,10 +72,7 @@ public class SatPreURIFilter {
|
|||
}
|
||||
}
|
||||
if (uri.length() > 1) {
|
||||
SatPrecipFileBuilder sb = new SatPrecipFileBuilder(uri);
|
||||
sb.createSatPre();
|
||||
} else {
|
||||
return;
|
||||
builder.createSatPre(uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,42 +22,43 @@ package com.raytheon.uf.edex.ohd.pproc;
|
|||
import java.awt.Rectangle;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import javax.measure.converter.UnitConverter;
|
||||
import javax.measure.unit.SI;
|
||||
import javax.measure.unit.Unit;
|
||||
|
||||
import com.raytheon.uf.common.dataplugin.PluginException;
|
||||
import com.raytheon.uf.common.dataplugin.grid.GridRecord;
|
||||
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.IDataRecord;
|
||||
import com.raytheon.uf.common.datastorage.records.ShortDataRecord;
|
||||
import com.raytheon.uf.common.hydro.spatial.HRAP;
|
||||
import com.raytheon.uf.common.hydro.spatial.HRAPCoordinates;
|
||||
import com.raytheon.uf.common.mpe.util.XmrgFile;
|
||||
import com.raytheon.uf.common.mpe.util.XmrgFile.XmrgHeader;
|
||||
import com.raytheon.uf.common.ohd.AppsDefaults;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.time.util.TimeUtil;
|
||||
import com.raytheon.uf.common.units.UnitConv;
|
||||
import com.raytheon.uf.edex.database.plugin.PluginDao;
|
||||
import com.raytheon.uf.edex.database.plugin.PluginFactory;
|
||||
|
||||
/**
|
||||
* TODO Add Description
|
||||
* Builder for xmrg files that contain satellite precip data.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Sep 8, 2009 snaples Initial creation
|
||||
* Sep 08, 2009 snaples Initial creation
|
||||
* Feb 15, 2013 1638 mschenke Moved DataURINotificationMessage to uf.common.dataplugin
|
||||
* Mar 19, 2014 17109 snaples Removed code that adds 1 hour to grid reftime, was not needed.
|
||||
* Mar 19, 2014 17109 snaples Removed code that adds 1 hour to grid reftime, was not needed.
|
||||
* May 05, 2014 2060 njensen Major cleanup and remove dependency on grid dataURI
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -67,25 +68,8 @@ import com.raytheon.uf.edex.database.plugin.PluginFactory;
|
|||
|
||||
public class SatPrecipFileBuilder {
|
||||
|
||||
Rectangle extent = null;
|
||||
|
||||
XmrgFile xmfile = null;
|
||||
|
||||
GridRecord gr = null;
|
||||
|
||||
private IDataRecord dataRec;
|
||||
|
||||
private String uri = "";
|
||||
|
||||
private String outputPath = "";
|
||||
|
||||
private short[] data;
|
||||
|
||||
private static final SimpleDateFormat sdf = new SimpleDateFormat(
|
||||
"yyyyMMddHH");
|
||||
static {
|
||||
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
}
|
||||
private static final IUFStatusHandler logger = UFStatus
|
||||
.getHandler(SatPrecipFileBuilder.class);
|
||||
|
||||
private static final String FILEPRE = "SATPRE";
|
||||
|
||||
|
@ -99,70 +83,81 @@ public class SatPrecipFileBuilder {
|
|||
|
||||
private static final String USER = "SANmdY";
|
||||
|
||||
private Date grReftime = null;
|
||||
private Rectangle extent = null;
|
||||
|
||||
private int height;
|
||||
|
||||
private int width;
|
||||
|
||||
private static int minX;
|
||||
private int minX;
|
||||
|
||||
private static int minY;
|
||||
private int minY;
|
||||
|
||||
private static int maxX;
|
||||
private int maxY;
|
||||
|
||||
private static int maxY;
|
||||
private SimpleDateFormat sdf;
|
||||
|
||||
public SatPrecipFileBuilder(String datauri) {
|
||||
uri = datauri;
|
||||
}
|
||||
private String outputPath;
|
||||
|
||||
public void createSatPre() {
|
||||
try {
|
||||
getGridRecord();
|
||||
} catch (PluginException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
float[] fa = null;
|
||||
fa = new float[((float[]) gr.getMessageData()).length];
|
||||
fa = (float[]) gr.getMessageData();
|
||||
String gribUnit = gr.getParameter().getUnitString();
|
||||
UnitConverter cv = null;
|
||||
Unit<?> gi = Unit.ONE;
|
||||
try {
|
||||
gi = UnitConv.deserializer(gribUnit);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Unit<?> xOut = SI.MILLIMETER;
|
||||
cv = gi.getConverterTo(xOut);
|
||||
data = new short[fa.length];
|
||||
int k = 0;
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < width; j++) {
|
||||
if (fa[k] < 0) {
|
||||
fa[k] = 0;
|
||||
}
|
||||
data[(i * width) + j] = (short) (cv.convert(fa[k]) * 100.0);
|
||||
k++;
|
||||
}
|
||||
}
|
||||
fa = null;
|
||||
createXmrgFile();
|
||||
}
|
||||
public SatPrecipFileBuilder() throws Exception {
|
||||
extent = HRAPCoordinates.getHRAPCoordinates();
|
||||
maxY = (int) (HRAP.getInstance().getNy() - extent.getMinY());
|
||||
minY = (int) (maxY - extent.getHeight());
|
||||
minX = (int) extent.getMinX();
|
||||
width = (int) (extent.getWidth());
|
||||
height = (int) (extent.getHeight());
|
||||
|
||||
private void createXmrgFile() {
|
||||
sdf = new SimpleDateFormat("yyyyMMddHH");
|
||||
sdf.setTimeZone(TimeUtil.GMT_TIME_ZONE);
|
||||
|
||||
AppsDefaults appsDefaults = AppsDefaults.getInstance();
|
||||
outputPath = appsDefaults.getToken("mpe_satpre_dir");
|
||||
File op = new File(outputPath);
|
||||
if (op.exists() == false) {
|
||||
op.mkdir();
|
||||
File outputDir = new File(outputPath);
|
||||
if (!outputDir.exists()) {
|
||||
outputDir.mkdirs();
|
||||
}
|
||||
op = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a grid record, converts the data to millimeters, and stores it
|
||||
* to an xmrg file.
|
||||
*
|
||||
* @param uri
|
||||
* the data URI of the grid record
|
||||
*/
|
||||
public void createSatPre(String uri) {
|
||||
try {
|
||||
GridRecord gr = getGridRecord(uri);
|
||||
float[] fa = (float[]) gr.getMessageData();
|
||||
String gribUnit = gr.getParameter().getUnitString();
|
||||
UnitConverter cv = null;
|
||||
Unit<?> gi = UnitConv.deserializer(gribUnit);
|
||||
Unit<?> xOut = SI.MILLIMETER;
|
||||
cv = gi.getConverterTo(xOut);
|
||||
short[] data = new short[fa.length];
|
||||
int k = 0;
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < width; j++) {
|
||||
if (fa[k] < 0) {
|
||||
fa[k] = 0;
|
||||
}
|
||||
data[(i * width) + j] = (short) (cv.convert(fa[k]) * 100.0);
|
||||
k++;
|
||||
}
|
||||
}
|
||||
fa = null;
|
||||
createXmrgFile(data, gr.getDataTime().getRefTime());
|
||||
} catch (Exception e) {
|
||||
logger.error("Error creating sat precip xmrg file for URI " + uri,
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
private void createXmrgFile(short[] data, Date grReftime)
|
||||
throws IOException {
|
||||
String fname = outputPath + File.separatorChar + FILEPRE
|
||||
+ sdf.format(grReftime) + "z";
|
||||
xmfile = new XmrgFile(fname);
|
||||
XmrgFile xmfile = new XmrgFile(fname);
|
||||
XmrgHeader xmhead = new XmrgHeader();
|
||||
xmhead.setValidDate(grReftime);
|
||||
xmhead.setSaveDate(grReftime);
|
||||
|
@ -174,63 +169,34 @@ public class SatPrecipFileBuilder {
|
|||
xmfile.setHeader(xmhead);
|
||||
xmfile.setHrapExtent(extent);
|
||||
xmfile.setData(data);
|
||||
try {
|
||||
xmfile.save(fname);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
xmfile.save(fname);
|
||||
}
|
||||
|
||||
/**
|
||||
* get Populated grib record
|
||||
* Get Populated grid record
|
||||
*
|
||||
* @param uri
|
||||
* the uri of the grid record
|
||||
* @return
|
||||
*/
|
||||
public void getGridRecord() throws PluginException {
|
||||
try {
|
||||
extent = HRAPCoordinates.getHRAPCoordinates();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
HRAP hr = HRAP.getInstance();
|
||||
|
||||
maxY = (int) (hr.getNy() - extent.getMinY());
|
||||
minY = (int) (maxY - extent.getHeight());
|
||||
minX = (int) extent.getMinX();
|
||||
maxX = (int) extent.getMaxX();
|
||||
width = (int) (extent.getWidth());
|
||||
height = (int) (extent.getHeight());
|
||||
private GridRecord getGridRecord(String uri) throws Exception {
|
||||
GridRecord gr = new GridRecord(uri);
|
||||
PluginDao gd = PluginFactory.getInstance().getPluginDao(
|
||||
gr.getPluginName());
|
||||
IDataStore dataStore = gd.getDataStore(gr);
|
||||
|
||||
int[] minIndex = { minX, minY };
|
||||
int[] maxIndex = { minX + width, minY + height };
|
||||
|
||||
gr = new GridRecord(uri);
|
||||
PluginDao gd = PluginFactory.getInstance().getPluginDao(
|
||||
gr.getPluginName());
|
||||
gr = (GridRecord) gd.getMetadata(uri);
|
||||
IDataStore dataStore = gd.getDataStore(gr);
|
||||
|
||||
try {
|
||||
dataRec = dataStore.retrieve(uri, "Data",
|
||||
Request.buildSlab(minIndex, maxIndex));
|
||||
} catch (Exception se) {
|
||||
se.printStackTrace();
|
||||
}
|
||||
IDataRecord dataRec = dataStore.retrieve(uri, "Data",
|
||||
Request.buildSlab(minIndex, maxIndex));
|
||||
if (dataRec instanceof FloatDataRecord) {
|
||||
gr.setMessageData(((FloatDataRecord) dataRec).getFloatData());
|
||||
} else if (dataRec instanceof ShortDataRecord) {
|
||||
gr.setMessageData(((ShortDataRecord) dataRec).getShortData());
|
||||
} else {
|
||||
gr.setMessageData(dataRec);
|
||||
}
|
||||
// this get the reftime of the record
|
||||
grReftime = gr.getDataTime().getRefTime();
|
||||
long millis = grReftime.getTime();
|
||||
grReftime.setTime(millis);
|
||||
|
||||
return gr;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue