VLab Issue #6278 - Model soundings being interpolated below the surface

for elevated sites

Change-Id: I4acf7182250ecaad1893432296069e54f62d458c

Former-commit-id: 66e8f998d8d400d3d4ba736a2826b5e22a3f174b
This commit is contained in:
Chin Chen 2015-02-03 11:03:14 -05:00
parent ddaca01b1d
commit 5d2b504d03
3 changed files with 1208 additions and 1070 deletions

View file

@ -33,6 +33,7 @@ Import-Package: com.raytheon.uf.common.dataplugin.bufrua,
com.raytheon.uf.common.dataplugin.level,
com.raytheon.uf.common.pointdata,
com.raytheon.uf.common.pointdata.spatial,
com.raytheon.uf.common.topo,
com.raytheon.uf.edex.pointdata,
gov.noaa.nws.ncep.common.tools,
gov.noaa.nws.ncep.edex.common.metparameters,

View file

@ -20,6 +20,7 @@ package gov.noaa.nws.ncep.edex.uengine.tasks.profile;
* 03/2014 1116 T. Lee Added DpD
* 01/2015 DR#16959 Chin Chen Added DpT support to fix DR 16959 NSHARP freezes when loading a sounding from
* HiRes-ARW/NMM models
* 02/03/2015 DR#17084 Chin Chen Model soundings being interpolated below the surface for elevated sites
* </pre>
*
* @author Chin Chen
@ -53,6 +54,7 @@ import com.raytheon.uf.common.dataplugin.grid.GridRecord;
import com.raytheon.uf.common.geospatial.ISpatialObject;
import com.raytheon.uf.common.geospatial.MapUtil;
import com.raytheon.uf.common.geospatial.PointUtil;
import com.raytheon.uf.common.topo.TopoQuery;
import com.raytheon.uf.edex.database.DataAccessLayerException;
import com.raytheon.uf.edex.database.dao.CoreDao;
import com.raytheon.uf.edex.database.dao.DaoConfig;
@ -585,7 +587,7 @@ public class MdlSoundingQuery {
}
/**
* Returns the value of surface pressure for a specified location, time, and
* Returns the value of surface layer for a specified location, time, and
* model for grib or ncgrib data.
*
* @param pnt
@ -595,45 +597,145 @@ public class MdlSoundingQuery {
* @param modelName
* the name of the model
* @return surface pressure
*
* DR17084
*/
public static Float getModelSfcPressure(Point pnt, String refTime,
String validTime, String pluginName, String modelName) {
@SuppressWarnings("unchecked")
public static NcSoundingLayer getModelSfcLayer(Point pnt, String refTime,
String validTime, String pluginName, String modelName, Coordinate coordinate) {
if (pluginName.equalsIgnoreCase(GRID_TBL_NAME)) {
CoreDao dao = new CoreDao(DaoConfig.forClass(GridRecord.class));
DatabaseQuery query = new DatabaseQuery(GridRecord.class.getName());
query.addQueryParam(GridConstants.LEVEL_ONE, "0.0");
query.addQueryParam(GridConstants.LEVEL_TWO, "-999999.0");
query.addQueryParam(GridConstants.MASTER_LEVEL_NAME, "MSL");
query.addQueryParam(GridConstants.PARAMETER_ABBREVIATION, "PMSL");
query.addQueryParam(GridConstants.DATASET_ID, modelName);
query.addQueryParam("dataTime.refTime", refTime);
query.addQueryParam("dataTime.validPeriod.start", validTime);
GridRecord rec = null;
NcSoundingLayer soundingLy = new NcSoundingLayer();
TableQuery query;
try {
List<GridRecord> recList = ((List<GridRecord>) dao
.queryByCriteria(query));
if (recList.size() == 0) {
return null;
} else {
rec = recList.get(0);
PointIn pointIn = new PointIn(pluginName, rec, pnt.x, pnt.y);
try {
float fdata = pointIn.getPointData();
return new Float(fdata);
} catch (PluginException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
query = new TableQuery("metadata", GridRecord.class.getName());
query.addParameter(GridConstants.LEVEL_ONE, "0.0");
query.addParameter(GridConstants.LEVEL_TWO, "-999999.0");
query.addParameter(GridConstants.MASTER_LEVEL_NAME, "SFC");
query.addList(GridConstants.PARAMETER_ABBREVIATION, "P, GH");
query.addParameter(GridConstants.DATASET_ID, modelName);
query.addParameter("dataTime.refTime", refTime);
query.addParameter("dataTime.validPeriod.start", validTime);
List<GridRecord> recList = (List<GridRecord>) query.execute();
boolean presureAvailable=false, heightAvailable=false;
if (recList!=null && recList.size() > 0) {
for(GridRecord rec:recList ){
PointIn pointIn = new PointIn(pluginName, rec, pnt.x, pnt.y);
try {
float fdata = pointIn.getPointData();
String parm = rec.getParameter().getAbbreviation();
if(parm.equals("P")){
soundingLy.setPressure(fdata/100);
presureAvailable = true;
} if(parm.equals("GH")){
soundingLy.setGeoHeight(fdata);
heightAvailable = true;
}
//System.out.println("prm="+rec.getParameter().getAbbreviation()+" value="+fdata);
} catch (PluginException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
recList.clear();
}
query = new TableQuery("metadata", GridRecord.class.getName());
query.addParameter(GridConstants.LEVEL_ONE, "2.0");
query.addParameter(GridConstants.LEVEL_TWO, "-999999.0");
query.addParameter(GridConstants.MASTER_LEVEL_NAME, "FHAG");
query.addList(GridConstants.PARAMETER_ABBREVIATION, "T, RH");
query.addParameter(GridConstants.DATASET_ID, modelName);
query.addParameter("dataTime.refTime", refTime);
query.addParameter("dataTime.validPeriod.start", validTime);
recList = (List<GridRecord>) query.execute();
if (recList!=null && recList.size() > 0) {
for(GridRecord rec:recList ){
PointIn pointIn = new PointIn(pluginName, rec, pnt.x, pnt.y);
try {
float fdata = pointIn.getPointData();
String parm = rec.getParameter().getAbbreviation();
if(parm.equals("T")){
soundingLy.setTemperature((float) kelvinToCelsius
.convert(fdata));
} if(parm.equals("RH")){
soundingLy.setRelativeHumidity(fdata);
}
//System.out.println("prm="+rec.getParameter().getAbbreviation()+" value="+fdata);
} catch (PluginException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
recList.clear();
}
query = new TableQuery("metadata", GridRecord.class.getName());
query.addParameter(GridConstants.LEVEL_ONE, "10.0");
query.addParameter(GridConstants.LEVEL_TWO, "-999999.0");
query.addParameter(GridConstants.MASTER_LEVEL_NAME, "FHAG");
query.addList(GridConstants.PARAMETER_ABBREVIATION, "vW, uW");
query.addParameter(GridConstants.DATASET_ID, modelName);
query.addParameter("dataTime.refTime", refTime);
query.addParameter("dataTime.validPeriod.start", validTime);
recList = (List<GridRecord>) query.execute();
if (recList!=null && recList.size() > 0) {
for(GridRecord rec:recList ){
PointIn pointIn = new PointIn(pluginName, rec, pnt.x, pnt.y);
try {
float fdata = pointIn.getPointData();
String parm = rec.getParameter().getAbbreviation();
if(parm.equals("vW")){
soundingLy.setWindV((float) metersPerSecondToKnots
.convert(fdata));
} if(parm.equals("uW")){
soundingLy.setWindU((float) metersPerSecondToKnots
.convert(fdata));
}
//System.out.println("prm="+rec.getParameter().getAbbreviation()+" value="+fdata);
} catch (PluginException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
}
if (presureAvailable==false || heightAvailable==false) {
float surfaceElevation = NcSoundingProfile.MISSING;
TopoQuery topoQuery = TopoQuery.getInstance();
if (topoQuery != null) {
//System.out.println("Nsharp coordinate.x="+coordinate.x);
surfaceElevation = (float) topoQuery
.getHeight(coordinate);
if(surfaceElevation >=0)
soundingLy.setGeoHeight(surfaceElevation);
else {
if (presureAvailable==false)
//no pressure and no height, no hope to continue.
return null;
}
}
else {
if (presureAvailable==false)
//no pressure and no height, no hope to continue.
return null;
}
}
return soundingLy;
} catch (DataAccessLayerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
return null;
@ -766,23 +868,48 @@ public class MdlSoundingQuery {
// TODO Auto-generated catch block
e.printStackTrace();
}
// System.out.println(" point coord.y="+coord.y+ " coord.x="+
//System.out.println(" point coord.y="+coord.y+ " coord.x="+
// coord.x);
pf.setStationLatitude(coord.y);
pf.setStationLongitude(coord.x);
// Float sfcPressure = getModelSfcPressure(pnt, refTime,
// validTime,
// pluginName, modelName);
// System.out.println("getModelSfcPressure took "+
// (System.currentTimeMillis()-t013) + " ms");
// /if (sfcPressure == null) {
pf.setSfcPress(-9999.f);
// }
// else {
// pf.setSfcPress(sfcPressure/100F);
// }
// System.out.println("surface pressure ="+pf.getSfcPress()+
// " lat= "+lat+ " lon="+lon);
// DR17084
NcSoundingLayer sfcLayer = getModelSfcLayer(pnt, refTime,
validTime,pluginName, modelName, coord);
if (sfcLayer != null) {
if(sfcLayer.getPressure()== NcSoundingLayer.MISSING &&
sfcLayer.getGeoHeight()!= NcSoundingLayer.MISSING){
//surface layer does not have pressure, but surface height is available
//see if we can interpolate surface pressure from upper and lower layer pressure
for (int i = 0; i < soundLyList.size(); i++) {
if (soundLyList.get(i).getGeoHeight() > sfcLayer.getGeoHeight()) {
if (i > 0) {
float p1 = soundLyList.get(i - 1).getPressure();
float p2 = soundLyList.get(i).getPressure();
float h1 = soundLyList.get(i - 1).getGeoHeight();
float h2 = soundLyList.get(i).getGeoHeight();
float h = sfcLayer.getGeoHeight();
float p = p1 + (h - h1) * (p1 - p2) / (h1 - h2);
sfcLayer.setPressure(p);
}
break;
}
}
}
if(sfcLayer.getPressure()!= NcSoundingLayer.MISSING){
// cut sounding layer under ground, i.e. below surface layer
for(int i= soundLyList.size()-1; i>=0 ; i--){
NcSoundingLayer ly = soundLyList.get(i);
if(ly.getPressure() >= sfcLayer.getPressure()){
soundLyList.remove(i);
}
}
soundLyList.add(0, sfcLayer);
}
pf.setSfcPress(sfcLayer.getPressure());
pf.setStationElevation(sfcLayer.getGeoHeight());
}
//System.out.println("surface pressure ="+pf.getSfcPress());
//end DR17084
// calculate dew point if necessary
MergeSounding ms = new MergeSounding();
// ms.spfhToDewpoint(layerList);

View file

@ -17,6 +17,7 @@ package gov.noaa.nws.ncep.ui.nsharp.display.rsc;
* 01/27/2015 DR#17006,
* Task#5929 Chin Chen NSHARP freezes when loading a sounding from MDCRS products
* in Volume Browser
* 02/03/2015 DR#17084 Chin Chen Model soundings being interpolated below the surface for elevated sites
*
* </pre>
*
@ -38,6 +39,7 @@ import gov.noaa.nws.ncep.ui.nsharp.background.NsharpSkewTPaneBackground;
import gov.noaa.nws.ncep.ui.nsharp.background.NsharpTurbulencePaneBackground;
import gov.noaa.nws.ncep.ui.nsharp.display.NsharpSkewTPaneDescriptor;
import gov.noaa.nws.ncep.ui.nsharp.natives.NsharpNative;
import gov.noaa.nws.ncep.ui.nsharp.natives.NsharpNative.NsharpLibrary;
import gov.noaa.nws.ncep.ui.nsharp.natives.NsharpNative.NsharpLibrary._lplvalues;
import gov.noaa.nws.ncep.ui.nsharp.natives.NsharpNative.NsharpLibrary._parcel;
import gov.noaa.nws.ncep.ui.nsharp.natives.NsharpNativeConstants;
@ -1256,32 +1258,40 @@ public class NsharpSkewTPaneResource extends NsharpAbstractPaneResource {
double p_mb = c.y;
double temp = c.x;
float htFt, htM, relh = -1;
String curStrFormat, curStrFormat1;
String curStrFormat, curStrFormat1, htMStr, htFtStr;
String curStr, curStr1;// , curStr2,curStr3;
VerticalAlignment vAli;
HorizontalAlignment hAli;
// curStr3 = rscHandler.getPickedStnInfoStr()+"\n";
htM = nsharpNative.nsharpLib.agl(nsharpNative.nsharpLib
//Chin, DR17084
if(soundingLys.get(0).getGeoHeight() <0){
htMStr="M";
htFtStr="M";
}
else {
htM = nsharpNative.nsharpLib.agl(nsharpNative.nsharpLib
.ihght((float) p_mb));
htFt = nsharpNative.nsharpLib.mtof(htM);
htFt = nsharpNative.nsharpLib.mtof(htM);
htMStr = Integer.toString(Math.round(htM));
htFtStr = Integer.toString(Math.round(htFt));
}
if (nsharpNative.nsharpLib.itemp((float) p_mb) > -9998.0
&& nsharpNative.nsharpLib.idwpt((float) p_mb) > -9998.0) {
FloatByReference parm = new FloatByReference(0);
relh = nsharpNative.nsharpLib.relh((float) p_mb, parm);
curStrFormat = "%4.0f/%.0fkt %4.0fmb %5.0fft/%.0fm agl %2.0f%%\n";
curStrFormat = "%4.0f/%.0fkt %4.0fmb %sft/%sm agl %2.0f%%\n";
curStr = String.format(curStrFormat,
nsharpNative.nsharpLib.iwdir((float) p_mb),
nsharpNative.nsharpLib.iwspd((float) p_mb), p_mb, htFt,
htM, relh);
nsharpNative.nsharpLib.iwspd((float) p_mb), p_mb, htFtStr,
htMStr, relh);
} else {
curStrFormat = "%4.0f/%.0fkt %4.0fmb %5.0fft/%.0fm agl\n";
curStrFormat = "%4.0f/%.0fkt %4.0fmb %sft/%sm agl\n";
curStr = String
.format(curStrFormat,
nsharpNative.nsharpLib.iwdir((float) p_mb),
nsharpNative.nsharpLib.iwspd((float) p_mb), p_mb,
htFt, htM);
htFtStr, htMStr);
}
/*
* curStrFormat1 = "%s/%s %4.1f/%4.1f%cC %4.0f/%.0f kt\n"; curStr1 =
@ -2695,11 +2705,11 @@ public class NsharpSkewTPaneResource extends NsharpAbstractPaneResource {
// Chin 08/04/2014, fixed surface height plotting bug
// also fixed to draw height mraker based on AGL (i.e. above surface
// level)
int sfcIndex = nsharpNative.nsharpLib.sfc();
int sfcIndex = 0; ////DR#17084 nnsharpNative.nsharpLib.sfc();
int sfcAsl = 0;
if (sfcIndex >= 0
&& sfcIndex < soundingLys.size()
&& soundingLys.get(sfcIndex).getGeoHeight() != NsharpNativeConstants.NSHARP_NATIVE_INVALID_DATA) {
if (//DR#17084 sfcIndex >= 0
//DR#17084 && sfcIndex < soundingLys.size()
soundingLys.get(sfcIndex).getGeoHeight() != NsharpNativeConstants.NSHARP_NATIVE_INVALID_DATA) {
double y = world.mapY(NsharpWxMath.getSkewTXY(
soundingLys.get(sfcIndex).getPressure(), 0).y);
try {