Issue #2262: Port hgt2pres, ztopsa, ptozsa, calcrh from meteolib into

Java. Convert to use of these new methods where possible. Create unit tests.

Change-Id: Ib21dc7e92eb7324dba79d128d785ced58aaeae2d

Former-commit-id: 40b5d54bf3 [formerly 5992197809236553e9c021526e42d28ed327b413]
Former-commit-id: 0b6b0e06cc
This commit is contained in:
David Gillingham 2013-08-13 18:23:40 -05:00
parent 5afcf8bee2
commit c17f8b4409
23 changed files with 805 additions and 60 deletions

View file

@ -23,4 +23,4 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0",
com.raytheon.uf.viz.core;bundle-version="1.12.1174",
com.raytheon.uf.viz.derivparam;bundle-version="1.12.1174",
com.raytheon.viz.pointdata;bundle-version="1.12.1174",
com.raytheon.edex.meteolib;bundle-version="1.12.1174"
com.raytheon.uf.common.wxmath

View file

@ -29,7 +29,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import com.raytheon.edex.meteoLib.Controller;
import com.raytheon.uf.common.dataplugin.acarssounding.ACARSSoundingLayer;
import com.raytheon.uf.common.dataplugin.acarssounding.ACARSSoundingRecord;
import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
@ -42,6 +41,7 @@ import com.raytheon.uf.common.pointdata.PointDataContainer;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.common.wxmath.ZToPsa;
import com.raytheon.uf.viz.core.catalog.ScriptCreator;
import com.raytheon.uf.viz.core.comm.Loader;
import com.raytheon.uf.viz.core.exception.VizException;
@ -63,6 +63,7 @@ import com.raytheon.viz.pointdata.util.PointDataCubeAdapter;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 26, 2012 bsteffen Initial javadoc
* Aug 14, 2013 2262 dgilling Use new wxmath method for ztopsa.
*
* </pre>
*
@ -258,7 +259,7 @@ public class ACARSSoundingDataCubeAdapter extends PointDataCubeAdapter {
} else if (levelParam.equals(PRESSURE)) {
value = layers[j].getPressure();
if (value == null) {
value = Controller.ztopsa(layers[j]
value = ZToPsa.ztopsa(layers[j]
.getFlightLevel());
} else {
value = value.floatValue() / 100;

View file

@ -21,14 +21,14 @@ package com.raytheon.uf.viz.acarssounding;
import java.util.ArrayList;
import com.raytheon.edex.meteoLib.Controller;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.dataplugin.acarssounding.ACARSSoundingLayer;
import com.raytheon.uf.common.dataplugin.acarssounding.ACARSSoundingRecord;
import com.raytheon.uf.common.pointdata.spatial.SurfaceObsLocation;
import com.raytheon.uf.common.sounding.SoundingLayer;
import com.raytheon.uf.common.sounding.VerticalSounding;
import com.raytheon.uf.common.sounding.adapter.AbstractVerticalSoundingAdapter;
import com.raytheon.uf.common.dataplugin.acarssounding.ACARSSoundingLayer;
import com.raytheon.uf.common.dataplugin.acarssounding.ACARSSoundingRecord;
import com.raytheon.uf.common.wxmath.ZToPsa;
/**
*
@ -38,7 +38,8 @@ import com.raytheon.uf.common.dataplugin.acarssounding.ACARSSoundingRecord;
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Dec 1, 2008 1747 jkorman Initial creation
* Dec 01, 2008 1747 jkorman Initial creation
* Aug 14, 2013 2262 dgilling Use new wxmath method for ztopsa.
*
* </pre>
*
@ -104,11 +105,9 @@ public class AcarsSoundingAdapter extends AbstractVerticalSoundingAdapter {
sndLayer.setWindSpeed(layer.getWindSpeed().floatValue());
}
if (layer.getPressure() != null) {
sndLayer
.setPressure(layer.getPressure().floatValue() / 100);
sndLayer.setPressure(layer.getPressure().floatValue() / 100);
} else if (layer.getFlightLevel() != null) {
sndLayer.setPressure(Controller.ztopsa(layer
.getFlightLevel()));
sndLayer.setPressure(ZToPsa.ztopsa(layer.getFlightLevel()));
}
if (layer.getFlightLevel() != null) {
sndLayer.setGeoHeight(layer.getFlightLevel().floatValue());

View file

@ -20,7 +20,17 @@
# Provide access to the meteolib functions through the java library
##
# SOFTWARE HISTORY
#
# Date Ticket# Engineer Description
# ------------ ---------- ----------- --------------------------
# Aug 13, 2013 2262 dgilling Use new wxmath routine ports.
########################################################################
from com.raytheon.uf.common.wxmath import PToZsa
from com.raytheon.uf.common.wxmath import ZToPsa
from com.raytheon.edex.meteoLib import Controller
from jep import jarray, JFLOAT_ID
import numpy
@ -29,7 +39,7 @@ import numpy
def ztopsa(Z):
if isinstance(Z, float) or isinstance(Z, numpy.float32):
if (Z > -9998):
return Controller.ztopsa(float(Z))
return ZToPsa.ZToPsa(float(Z))
elif isinstance(Z, numpy.ndarray):
result = numpy.ndarray(Z.shape, numpy.float32)
for i in range(len(Z)):
@ -41,7 +51,7 @@ def ztopsa(Z):
def ptozsa(P):
if isinstance(P, float) or isinstance(P, numpy.float32):
if (P > -9998):
return Controller.ptozsa(float(P))
return PToZsa.ptozsa(float(P))
elif isinstance(P, numpy.ndarray):
result = numpy.ndarray(P.shape, numpy.float32)
for i in range(len(P)):

View file

@ -14,11 +14,11 @@ Require-Bundle: org.eclipse.ui,
org.geotools;bundle-version="2.4.0",
com.raytheon.viz.alerts;bundle-version="1.10.13",
com.raytheon.viz.aviation;bundle-version="1.11.1",
com.raytheon.edex.meteolib;bundle-version="1.11.1",
com.raytheon.uf.edex.plugin.mesowest;bundle-version="1.0.0",
com.raytheon.uf.edex.decodertools;bundle-version="1.0.0",
com.raytheon.uf.common.monitor;bundle-version="1.11.17",
org.apache.commons.lang;bundle-version="2.3.0"
org.apache.commons.lang;bundle-version="2.3.0",
com.raytheon.uf.common.wxmath
Bundle-ActivationPolicy: lazy
Export-Package: com.raytheon.uf.viz.monitor,
com.raytheon.uf.viz.monitor.data,

View file

@ -31,6 +31,7 @@ import com.raytheon.uf.common.dataplugin.obs.metar.util.SkyCover;
import com.raytheon.uf.common.monitor.data.ObConst;
import com.raytheon.uf.common.monitor.data.ObConst.ThreatLevel;
import com.raytheon.uf.common.time.SimulatedTime;
import com.raytheon.uf.common.wxmath.CalcRH;
import com.raytheon.uf.viz.monitor.data.ObReport;
import com.raytheon.viz.aviation.model.CloudGroup;
@ -45,6 +46,7 @@ import com.raytheon.viz.aviation.model.CloudGroup;
* Feb 12, 2009 1999 grichard Initial creation.
* 2/25/2009 2047 grichard Added SNOW report generation method.
* Jan 19, 2010 4240 zhao Modified generateObReportSnow method
* Aug 14, 2013 2262 dgilling Use new wxmath method for calcrh.
*
* </pre>
*
@ -387,17 +389,20 @@ public final class ObUtil {
float spd;
/* arbitrarily do the calculation only for temps at or below 60F */
if (temp > 16.)
if (temp > 16.) {
return 1e37f;
}
/* no chilling if speed < 4 mph = 6.44km/h */
if (windSpd < 6.4)
if (windSpd < 6.4) {
return temp;
}
/* peg speed at 80 mph (= 128.75 km/h) */
if (windSpd > 128.75)
if (windSpd > 128.75) {
spd = 128.75f;
else
} else {
spd = windSpd;
}
spd = (float) Math.pow(spd, 0.16);
float windChillTemp = 13.12f + 0.6215f * temp - 11.37f * spd + 0.3965f
@ -421,16 +426,18 @@ public final class ObUtil {
// Temperature must be lower than -4.8C (23F) to avoid a calculation
// error (a negative number to -1.668 power is NAN)
if (temperatureC < -4.8)
if (temperatureC < -4.8) {
fbMinutes = ((-24.5f * ((0.667f * windspeedKPH) + 4.8f)) + 2111f)
* (float) Math.pow((-4.8 - temperatureC), -1.668);
else
} else {
return ObConst.MISSING;
}
// Check for frostbite boundaries
if (!(fbMinutes <= 30 && windspeedKPH > 25.0 && windspeedKPH <= 80.5))
if (!(fbMinutes <= 30 && windspeedKPH > 25.0 && windspeedKPH <= 80.5)) {
fbMinutes = ObConst.MISSING;
}
return fbMinutes;
}
@ -505,8 +512,7 @@ public final class ObUtil {
/**
* This method determines the RH from temperature and dew point in degrees
* celsius. It calls the "calcrh" Meteolib method that is wrapped by the
* "Controller" class.
* celsius.
*
* @param obReport
* -- the observation report
@ -521,28 +527,14 @@ public final class ObUtil {
&& obReport.getTemperature() < 1e30f
&& obReport.getDewpoint() != ObConst.MISSING
&& obReport.getDewpoint() < 1e30f) {
float[] tempC = { obReport.getTemperature() };
float[] dewptC = { obReport.getDewpoint() };
// Set up dimension values for impending calcrh() call
// (no arrays, just sending individual values, so
// set dims to 1)
int ndim1 = 1, idim = 1, jdim = 1;
float[] relHum = { ObConst.MISSING };
// Call calcrh from meteoLib.
// calcrh(&tempC, &dewptC, &ndim1, &idim, &jdim, &relHum);
relHum = com.raytheon.edex.meteoLib.Controller.calcrh(tempC,
dewptC, ndim1, idim, jdim);
if (relHum[0] < 0f || relHum[0] > 100f) {
float relHum = CalcRH.calcrh(obReport.getTemperature(),
obReport.getDewpoint());
if (Float.isNaN(relHum) || relHum < 0f || relHum > 100f) {
obReport.setRelativeHumidity(ObConst.MISSING);
} else {
obReport.setRelativeHumidity(relHum[0]);
obReport.setRelativeHumidity(relHum);
}
}
return true;

View file

@ -7,7 +7,8 @@ Bundle-Activator: com.raytheon.uf.viz.xy.crosssection.Activator
Bundle-Vendor: RAYTHEON
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui;bundle-version="3.4.1",
com.raytheon.uf.common.colormap;bundle-version="1.12.1174"
com.raytheon.uf.common.colormap;bundle-version="1.12.1174",
com.raytheon.uf.common.wxmath
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Eclipse-RegisterBuddy: com.raytheon.uf.viz.core, com.raytheon.viz.core

View file

@ -28,7 +28,6 @@ import java.util.Map;
import org.eclipse.swt.graphics.RGB;
import org.geotools.referencing.GeodeticCalculator;
import com.raytheon.edex.meteoLib.Controller;
import com.raytheon.uf.common.geospatial.ISpatialQuery.SearchMode;
import com.raytheon.uf.common.geospatial.SpatialException;
import com.raytheon.uf.common.geospatial.SpatialQueryFactory;
@ -37,6 +36,7 @@ import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.common.topo.TopoQuery;
import com.raytheon.uf.common.wxmath.Hgt2Pres;
import com.raytheon.uf.viz.core.DrawableString;
import com.raytheon.uf.viz.core.IGraphicsTarget;
import com.raytheon.uf.viz.core.IGraphicsTarget.HorizontalAlignment;
@ -78,6 +78,7 @@ import com.vividsolutions.jts.geom.Point;
* Jul 3, 2010 bsteffen Initial creation
* Feb 15, 2013 1638 mschenke Got rid of viz/edex topo classes
* and moved into common
* Aug 13, 2013 2262 dgilling Use new wxmath hgt2pres method.
*
* </pre>
*
@ -428,7 +429,7 @@ public class CrossSectionGraph extends AbstractGraph {
}
if (csDesc.getHeightScale().getHeightType() == LevelType.PRESSURE) {
for (int i = 0; i < heights.length; i++) {
heights[i] = Controller.hgt2pres((float) heights[i]);
heights[i] = Hgt2Pres.hgt2pres((float) heights[i]);
}
} else {
for (int i = 0; i < heights.length; i++) {

View file

@ -19,15 +19,15 @@ Require-Bundle: org.apache.batik,
com.raytheon.uf.common.python;bundle-version="1.12.1161",
com.raytheon.uf.common.pointdata;bundle-version="1.12.1174",
com.raytheon.uf.common.dataplugin.level;bundle-version="1.12.1174",
com.raytheon.uf.common.colormap;bundle-version="1.12.1174"
com.raytheon.uf.common.colormap;bundle-version="1.12.1174",
com.raytheon.uf.common.wxmath
Bundle-ActivationPolicy: lazy
Export-Package: com.raytheon.viz.pointdata,
com.raytheon.viz.pointdata.drawables,
com.raytheon.viz.pointdata.rsc,
com.raytheon.viz.pointdata.rsc.retrieve,
com.raytheon.viz.pointdata.util
Import-Package: com.raytheon.edex.meteoLib,
com.raytheon.uf.common.comm,
Import-Package: com.raytheon.uf.common.comm,
com.raytheon.uf.common.dataplugin.grid,
com.raytheon.uf.common.derivparam.tree,
com.raytheon.uf.common.message.response,

View file

@ -29,7 +29,6 @@ import javax.measure.unit.SI;
import org.geotools.coverage.grid.GridGeometry2D;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import com.raytheon.edex.meteoLib.Controller;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.dataplugin.grid.GridConstants;
import com.raytheon.uf.common.dataplugin.level.Level;
@ -42,6 +41,7 @@ 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.time.DataTime;
import com.raytheon.uf.common.wxmath.PToZsa;
import com.raytheon.uf.viz.core.catalog.LayerProperty;
import com.raytheon.uf.viz.core.datastructure.DataCubeContainer;
import com.raytheon.uf.viz.core.exception.VizException;
@ -57,6 +57,7 @@ import com.vividsolutions.jts.geom.Coordinate;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 14, 2010 bsteffen Initial creation
* Aug 14, 2013 #2262 dgilling Use new wxmath method for ptozsa.
*
* </pre>
*
@ -120,10 +121,10 @@ public class HeightOfRequestableData extends AbstractRequestableData {
try {
gribRec = getGribRec(time);
} catch (VizException e1) {
return Controller.ptozsa((float) level.getLevelonevalue());
return PToZsa.ptozsa((float) level.getLevelonevalue());
}
if (gribRec == null) {
return Controller.ptozsa((float) level.getLevelonevalue());
return PToZsa.ptozsa((float) level.getLevelonevalue());
} else {
ISpatialObject spatialObject = ((ISpatialEnabled) gribRec)
.getSpatialObject();
@ -135,11 +136,11 @@ public class HeightOfRequestableData extends AbstractRequestableData {
position = PointUtil.determineIndex(new Coordinate(lon, lat),
crs, mapGeometry);
} catch (Exception e) {
return Controller.ptozsa((float) level.getLevelonevalue());
return PToZsa.ptozsa((float) level.getLevelonevalue());
}
if (position.y < 0 || position.y >= spatialObject.getNy()
|| position.x < 0 || position.x >= spatialObject.getNx()) {
return Controller.ptozsa((float) level.getLevelonevalue());
return PToZsa.ptozsa((float) level.getLevelonevalue());
}
int index = position.y * spatialObject.getNx() + position.x;

View file

@ -43,8 +43,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0",
com.raytheon.uf.viz.points;bundle-version="1.0.0",
com.raytheon.uf.viz.ui.menus;bundle-version="1.12.1174",
com.raytheon.viz.awipstools;bundle-version="1.12.1174",
com.raytheon.edex.meteolib;bundle-version="1.12.1174",
org.apache.batik;bundle-version="1.6.0"
org.apache.batik;bundle-version="1.6.0",
com.raytheon.uf.common.wxmath
Import-Package: com.raytheon.viz.core.contours.util,
com.raytheon.viz.core.drawables,
com.raytheon.viz.core.rsc,

View file

@ -28,7 +28,6 @@ import java.util.Map;
import javax.measure.unit.Unit;
import javax.measure.unit.UnitFormat;
import com.raytheon.edex.meteoLib.Controller;
import com.raytheon.uf.common.dataplugin.radar.RadarDataKey;
import com.raytheon.uf.common.dataplugin.radar.RadarDataPoint;
import com.raytheon.uf.common.dataplugin.radar.RadarRecord;
@ -39,9 +38,27 @@ import com.raytheon.uf.common.dataplugin.radar.util.RadarRecordUtil;
import com.raytheon.uf.common.datastorage.DataStoreFactory;
import com.raytheon.uf.common.datastorage.IDataStore;
import com.raytheon.uf.common.datastorage.StorageException;
import com.raytheon.uf.common.wxmath.ZToPsa;
import com.raytheon.uf.viz.core.HDF5Util;
import com.raytheon.uf.viz.core.exception.VizException;
/**
* TODO Add Description
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* ??? ??, ???? xxxxxxxx Initial creation
* Aug 14, 2013 #2262 dgilling Use new wxmath method for ztopsa.
*
* </pre>
*
* @author xxxxxxxx
* @version 1.0
*/
public class DmdTools {
public static final String[] levels3d = { "LowLyr", "MaxShear", "MaxWind",
@ -87,7 +104,7 @@ public class DmdTools {
}
}
if (parameter.equals("P") && value != null) {
value = Controller.ztopsa(value);
value = ZToPsa.ztopsa(value);
}
if (value == null) {
return -9999;

View file

@ -0,0 +1,72 @@
/**
* 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.wxmath;
/**
* Calculate relative humidity from temperature and dewpoint.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 13, 2013 #2262 dgilling Ported from calcrh.f.
*
* </pre>
*
* @author dgilling
* @version 1.0
*/
public class CalcRH {
private static final double flg = 99998.0;
// Never allow this class to be directly instantiated
private CalcRH() {
throw new AssertionError();
}
/**
* Routine to calculate relative humidity from temperature and dewpoint.
*
* @param temperature
* Temperature (in C or K)
* @param dewpoint
* Dewpoint (same as temp)
* @return Relative humidity [range: 0. - 100.]
*/
public static float calcrh(float temperature, float dewpoint) {
float rh;
if (temperature > flg || dewpoint > flg) {
rh = Float.NaN;
} else {
double t1 = (temperature < 80.0) ? temperature + Constants.k0
: temperature;
double td1 = (temperature < 80.0) ? dewpoint + Constants.k0
: dewpoint;
rh = (float) (100.0 * Math.exp(Constants.b * (t1 - td1)
+ Constants.c / t1 - Constants.c / td1));
}
return rh;
}
}

View file

@ -30,6 +30,8 @@ package com.raytheon.uf.common.wxmath;
* ------------ ---------- ----------- --------------------------
* Jun 06, 2013 2043 bsteffen Ported from meteolib C
* Aug 13, 2013 2262 njensen Moved from deriv params
* Aug 13, 2013 2262 dgilling Adding additional constants from
* calcrh.f, hgt2pres.f, ztopsa.f, ptozsa.f
*
* </pre>
*
@ -39,14 +41,20 @@ package com.raytheon.uf.common.wxmath;
public class Constants {
// from meteoLib calcrh.f
public static final double b = 0.0091379024;
// from meteoLib calcrh.f
public static final double c = 6106.396;
// from meteoLib capeFunc.c
public static final double c0 = 26.66082;
// from meteoLib capeFunc.c
public static final double c1 = 0.0091379024;
public static final double c1 = b;
// from meteoLib capeFunc.c
public static final double c2 = 6106.396;
public static final double c2 = c;
// from meteoLib capeFunc.c
public static final double c_1 = 223.1986;
@ -54,6 +62,9 @@ public class Constants {
// from meteoLib capeFunc.c
public static final double c_2 = 0.0182758048;
// from meteoLib calcrh.f
public static final double k0 = 273.15;
// from meteoLib capeFunc.c
public static final double kapa = 0.286;
@ -62,4 +73,30 @@ public class Constants {
// from meteoLib calctw.f
public static final double f = 0.0006355;
// from meteoLib hgt2pres.f, ztopsa.f, ptozsa.f
public static final double T0 = 288.0;
// from meteoLib hgt2pres.f, ztopsa.f, ptozsa.f
public static final double gamma = 0.0065;
// from meteoLib hgt2pres.f, ztopsa.f, ptozsa.f
public static final double p0 = 1013.2;
// from meteoLib hgt2pres.f, ztopsa.f, ptozsa.f
public static final double p11 = 226.0971;
// from meteoLib hgt2pres.f, ztopsa.f, ptozsa.f
public static final double z11 = 11000.0;
// from meteoLib hgt2pres.f, ztopsa.f, ptozsa.f
public static final double HGT_PRES_c1 = 5.256;
// from meteoLib hgt2pres.f, ztopsa.f, ptozsa.f
public static final double HGT_PRES_c2 = 14600.0;
// Never allow this class to be directly instantiated
private Constants() {
throw new AssertionError();
}
}

View file

@ -0,0 +1,70 @@
/**
* 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.wxmath;
/**
* Calculate pressure from height based on a standard atmosphere.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 13, 2013 #2262 dgilling Ported from hgt2pres.f.
*
* </pre>
*
* @author dgilling
* @version 1.0
*/
public class Hgt2Pres {
private static final double bad = 1e06 - 2;
// Never allow this class to be directly instantiated
private Hgt2Pres() {
throw new AssertionError();
}
/**
* Routine to calculate pressure from height based on a standard atmosphere.
*
* @param height
* Height (in m)
* @return Pressure (in mb)
*/
public static float hgt2pres(float height) {
float pres;
if (height > bad) {
pres = Float.NaN;
} else if (height < Constants.z11) {
pres = (float) (Constants.p0 * Math.pow(
((Constants.T0 - Constants.gamma * height) / Constants.T0),
Constants.HGT_PRES_c1));
} else {
pres = (float) (Constants.p11 * Math.pow(10,
((Constants.z11 - height) / Constants.HGT_PRES_c2)));
}
return pres;
}
}

View file

@ -0,0 +1,71 @@
/**
* 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.wxmath;
/**
* Converts a pressure in milibars into a height in a standard atmosphere in
* meters.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 13, 2013 #2262 dgilling Ported from ptozsa.f.
*
* </pre>
*
* @author dgilling
* @version 1.0
*/
public class PToZsa {
private static final double Flg = 1e10;
// Never allow this class to be directly instantiated
private PToZsa() {
throw new AssertionError();
}
/**
* This routine converts a pressure in milibars into a height in a standard
* atmosphere in meters.
*
* @param pressure
* Pressure (in mb)
* @return Height (in m)
*/
public static float ptozsa(float pressure) {
float PtoZsa;
if (pressure > Flg || pressure < 1.0) {
PtoZsa = Float.NaN;
} else if (pressure > Constants.p11) {
PtoZsa = (float) ((Constants.T0 - (Constants.T0 * Math.pow(
(pressure / Constants.p0), (1 / Constants.HGT_PRES_c1)))) / Constants.gamma);
} else {
PtoZsa = (float) (Constants.HGT_PRES_c2
* Math.log10(Constants.p11 / pressure) + Constants.z11);
}
return PtoZsa;
}
}

View file

@ -0,0 +1,72 @@
/**
* 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.wxmath;
/**
* Converts a height in meters into a pressure in a standard atmosphere in
* milibars.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 13, 2013 #2262 dgilling Ported from ztopsa.f.
*
* </pre>
*
* @author dgilling
* @version 1.0
*/
public class ZToPsa {
private static final double Flg = 1e10;
// Never allow this class to be directly instantiated
private ZToPsa() {
throw new AssertionError();
}
/**
* This routine converts a height in meters into a pressure in a standard
* atmosphere in milibars.
*
* @param height
* Height (in m)
* @return Pressure (in mb)
*/
public static float ztopsa(float height) {
float ZtoPsa;
if (height > Flg) {
ZtoPsa = Float.NaN;
} else if (height < Constants.z11) {
ZtoPsa = (float) (Constants.p0 * Math.pow(
((Constants.T0 - Constants.gamma * height) / Constants.T0),
Constants.HGT_PRES_c1));
} else {
ZtoPsa = (float) (Constants.p11 * Math.pow(10,
((Constants.z11 - height) / Constants.HGT_PRES_c2)));
}
return ZtoPsa;
}
}

View file

@ -154,5 +154,11 @@
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="lib/swt_gtk_linux_x86_64.jar"/>
<classpathentry kind="lib" path="lib/swt_gtk_linux_x86.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.wxmath"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/libmeteoLib.so">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="/awips2/edex/lib/dependencies/meteolib.jni.linux32"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1,115 @@
/**
* 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.wxmath;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.BeforeClass;
import org.junit.Test;
import com.raytheon.edex.meteoLib.Controller;
/**
* Test for {@link com.raytheon.uf.common.wxmath.CalcRH}
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 14, 2013 #2262 dgilling Initial creation
*
* </pre>
*
* @author dgilling
* @version 1.0
*/
public class TestCalcRH {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
System.loadLibrary("meteoLib");
}
@Test
public void testDegreesC() {
float[] tempArray = new float[1];
float[] dewptArray = new float[1];
int iDim = 1;
int jDim = 1;
int nDim = 1;
for (float temp = -10.0f; temp <= 80.0f; temp += 5.5f) {
for (float dewpoint = 0.0f; dewpoint <= 80.0f; dewpoint += 1.25f) {
tempArray[0] = temp;
dewptArray[0] = dewpoint;
float[] legacyResult = Controller.calcrh(tempArray, dewptArray,
nDim, iDim, jDim);
float portResult = CalcRH.calcrh(temp, dewpoint);
assertEquals("Ported calcrh does not match legacy for temp= "
+ temp + ", dewpt= " + dewpoint, legacyResult[0],
portResult, 0.005f);
}
}
}
@Test
public void testDegreesK() {
float[] tempArray = new float[1];
float[] dewptArray = new float[1];
int iDim = 1;
int jDim = 1;
int nDim = 1;
for (float temp = 263.15f; temp <= 373.15f; temp += 5.5f) {
for (float dewpoint = 273.15f; dewpoint <= 333.15f; dewpoint += 1.25f) {
tempArray[0] = temp;
dewptArray[0] = dewpoint;
float[] legacyResult = Controller.calcrh(tempArray, dewptArray,
nDim, iDim, jDim);
float portResult = CalcRH.calcrh(temp, dewpoint);
assertEquals("Ported calcrh does not match legacy for temp= "
+ temp + ", dewpt= " + dewpoint, legacyResult[0],
portResult, 0.005f);
}
}
}
@Test
public void testTempOutsideRange() {
float temperature = 1.0e06f;
float dewpoint = 40f;
float portResult = CalcRH.calcrh(temperature, dewpoint);
assertTrue(Float.isNaN(portResult));
}
@Test
public void testDewPtOutsideRange() {
float temperature = 40f;
float dewpoint = 1.0e06f;
float portResult = CalcRH.calcrh(temperature, dewpoint);
assertTrue(Float.isNaN(portResult));
}
}

View file

@ -0,0 +1,70 @@
/**
* 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.wxmath;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.BeforeClass;
import org.junit.Test;
import com.raytheon.edex.meteoLib.Controller;
/**
* Test for {@link com.raytheon.uf.common.wxmath.Hgt2Pres}
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 14, 2013 #2262 dgilling Initial creation
*
* </pre>
*
* @author dgilling
* @version 1.0
*/
public class TestHgt2Pres {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
System.loadLibrary("meteoLib");
}
@Test
public void testHgt2PresInRange() {
for (float height = -1000; height < 1.0e06f; height += 12.25f) {
float legacyResult = Controller.hgt2pres(height);
float portResult = Hgt2Pres.hgt2pres(height);
assertEquals("Ported hgt2pres does not match legacy for height= "
+ height, legacyResult, portResult, 0.05f);
}
}
@Test
public void testHgt2PresOutRange() {
float result = Hgt2Pres.hgt2pres(1.0e06f);
assertTrue(Float.isNaN(result));
}
}

View file

@ -0,0 +1,84 @@
/**
* 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.wxmath;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.BeforeClass;
import org.junit.Test;
import com.raytheon.edex.meteoLib.Controller;
/**
* Test for {@link com.raytheon.uf.common.wxmath.PToZsa}
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 14, 2013 #2262 dgilling Initial creation
*
* </pre>
*
* @author dgilling
* @version 1.0
*/
public class TestPToZsa {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
System.loadLibrary("meteoLib");
}
@Test
public final void testPToZsaInRangeLow() {
for (float pressure = 1.0f; pressure <= 1e05f; pressure += 12.25f) {
float legacyResult = Controller.ptozsa(pressure);
float portResult = PToZsa.ptozsa(pressure);
assertEquals("Ported ptozsa does not match legacy for pressure= "
+ pressure, legacyResult, portResult, 0.05f);
}
}
@Test
public final void testPToZsaInRangeHigh() {
for (float pressure = 1e05f; pressure <= 1e10f; pressure += 2253.33f) {
float legacyResult = Controller.ptozsa(pressure);
float portResult = PToZsa.ptozsa(pressure);
assertEquals("Ported ptozsa does not match legacy for pressure= "
+ pressure, legacyResult, portResult, 0.5f);
}
}
@Test
public void testPToZsaOutRange() {
float result = PToZsa.ptozsa(1.01e10f);
assertTrue("PToZsa failed upper limit check.", Float.isNaN(result));
result = PToZsa.ptozsa(0.999f);
assertTrue("PToZsa failed lower limit check.", Float.isNaN(result));
}
}

View file

@ -0,0 +1,81 @@
/**
* 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.wxmath;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.BeforeClass;
import org.junit.Test;
import com.raytheon.edex.meteoLib.Controller;
/**
* Test for {@link com.raytheon.uf.common.wxmath.ZToPsa}
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 14, 2013 #2262 dgilling Initial creation
*
* </pre>
*
* @author dgilling
* @version 1.0
*/
public class TestZToPsa {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
System.loadLibrary("meteoLib");
}
@Test
public final void testZToPsaInRangeLow() {
for (float height = -1000; height < 1.0e06f; height += 12.25f) {
float legacyResult = Controller.ztopsa(height);
float portResult = ZToPsa.ztopsa(height);
assertEquals("Ported ptozsa does not match legacy for height= "
+ height, legacyResult, portResult, 0.05f);
}
}
@Test
public final void testZToPsaInRangeHigh() {
for (float height = 1.0e06f; height < 1.0e10f; height += 2253.33f) {
float legacyResult = Controller.ztopsa(height);
float portResult = ZToPsa.ztopsa(height);
assertEquals("Ported ptozsa does not match legacy for height= "
+ height, legacyResult, portResult, 0.5f);
}
}
@Test
public void testZToPsaOutRange() {
float result = ZToPsa.ztopsa(1.01e10f);
assertTrue(Float.isNaN(result));
}
}

View file

@ -0,0 +1,45 @@
/**
* 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.
**/
/**
* Junit tests for <code>com.raytheon.uf.common.wxmath</code>.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 14, 2013 dgilling Initial creation
*
* </pre>
*
* @author dgilling
* @version 1.0
*/
package com.raytheon.uf.common.wxmath;
// TODO
// FIXME: Because this common plugin is only part of a viz feature at the
// moment, it does not work with the current auto-test framework, which only
// tests EDEX plugins and plugins referenced by EDEX features. If either this
// plugin becomes part of an EDEX feature or the auto test framework is able to
// test viz code, this package should be moved to /tests/unit/.