From c17f8b4409c9b8ecf095b186ce5281fc4db15530 Mon Sep 17 00:00:00 2001 From: David Gillingham Date: Tue, 13 Aug 2013 18:23:40 -0500 Subject: [PATCH] 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: 40b5d54bf3cfedf2afa237d90ae79fe9fda037fa [formerly 5992197809236553e9c021526e42d28ed327b413] Former-commit-id: 0b6b0e06cccc203a7eb288adcfd0138a75bc94bc --- .../META-INF/MANIFEST.MF | 2 +- .../ACARSSoundingDataCubeAdapter.java | 5 +- .../acarssounding/AcarsSoundingAdapter.java | 15 ++- .../derivedParameters/functions/meteolib.py | 14 ++- .../META-INF/MANIFEST.MF | 4 +- .../raytheon/uf/viz/monitor/util/ObUtil.java | 48 +++----- .../META-INF/MANIFEST.MF | 3 +- .../crosssection/graph/CrossSectionGraph.java | 5 +- .../META-INF/MANIFEST.MF | 6 +- .../util/HeightOfRequestableData.java | 11 +- .../META-INF/MANIFEST.MF | 4 +- .../com/raytheon/viz/radar/util/DmdTools.java | 21 +++- .../com/raytheon/uf/common/wxmath/CalcRH.java | 72 +++++++++++ .../raytheon/uf/common/wxmath/Constants.java | 41 ++++++- .../raytheon/uf/common/wxmath/Hgt2Pres.java | 70 +++++++++++ .../com/raytheon/uf/common/wxmath/PToZsa.java | 71 +++++++++++ .../com/raytheon/uf/common/wxmath/ZToPsa.java | 72 +++++++++++ tests/.classpath | 6 + .../raytheon/uf/common/wxmath/TestCalcRH.java | 115 ++++++++++++++++++ .../uf/common/wxmath/TestHgt2Pres.java | 70 +++++++++++ .../raytheon/uf/common/wxmath/TestPToZsa.java | 84 +++++++++++++ .../raytheon/uf/common/wxmath/TestZToPsa.java | 81 ++++++++++++ .../uf/common/wxmath/package-info.java | 45 +++++++ 23 files changed, 805 insertions(+), 60 deletions(-) create mode 100644 edexOsgi/com.raytheon.uf.common.wxmath/src/com/raytheon/uf/common/wxmath/CalcRH.java create mode 100644 edexOsgi/com.raytheon.uf.common.wxmath/src/com/raytheon/uf/common/wxmath/Hgt2Pres.java create mode 100644 edexOsgi/com.raytheon.uf.common.wxmath/src/com/raytheon/uf/common/wxmath/PToZsa.java create mode 100644 edexOsgi/com.raytheon.uf.common.wxmath/src/com/raytheon/uf/common/wxmath/ZToPsa.java create mode 100644 tests/manual/com/raytheon/uf/common/wxmath/TestCalcRH.java create mode 100644 tests/manual/com/raytheon/uf/common/wxmath/TestHgt2Pres.java create mode 100644 tests/manual/com/raytheon/uf/common/wxmath/TestPToZsa.java create mode 100644 tests/manual/com/raytheon/uf/common/wxmath/TestZToPsa.java create mode 100644 tests/manual/com/raytheon/uf/common/wxmath/package-info.java diff --git a/cave/com.raytheon.uf.viz.acarssounding/META-INF/MANIFEST.MF b/cave/com.raytheon.uf.viz.acarssounding/META-INF/MANIFEST.MF index b56a499f3c..7edbca4e30 100644 --- a/cave/com.raytheon.uf.viz.acarssounding/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.uf.viz.acarssounding/META-INF/MANIFEST.MF @@ -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 diff --git a/cave/com.raytheon.uf.viz.acarssounding/src/com/raytheon/uf/viz/acarssounding/ACARSSoundingDataCubeAdapter.java b/cave/com.raytheon.uf.viz.acarssounding/src/com/raytheon/uf/viz/acarssounding/ACARSSoundingDataCubeAdapter.java index cb1aee5b46..7cd7d391ed 100644 --- a/cave/com.raytheon.uf.viz.acarssounding/src/com/raytheon/uf/viz/acarssounding/ACARSSoundingDataCubeAdapter.java +++ b/cave/com.raytheon.uf.viz.acarssounding/src/com/raytheon/uf/viz/acarssounding/ACARSSoundingDataCubeAdapter.java @@ -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. * * * @@ -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; diff --git a/cave/com.raytheon.uf.viz.acarssounding/src/com/raytheon/uf/viz/acarssounding/AcarsSoundingAdapter.java b/cave/com.raytheon.uf.viz.acarssounding/src/com/raytheon/uf/viz/acarssounding/AcarsSoundingAdapter.java index 72b19a605e..ec6297746e 100644 --- a/cave/com.raytheon.uf.viz.acarssounding/src/com/raytheon/uf/viz/acarssounding/AcarsSoundingAdapter.java +++ b/cave/com.raytheon.uf.viz.acarssounding/src/com/raytheon/uf/viz/acarssounding/AcarsSoundingAdapter.java @@ -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. * * * @@ -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()); diff --git a/cave/com.raytheon.uf.viz.derivparam.python/localization/derivedParameters/functions/meteolib.py b/cave/com.raytheon.uf.viz.derivparam.python/localization/derivedParameters/functions/meteolib.py index fcc45f7e0d..86c7b7bcb1 100644 --- a/cave/com.raytheon.uf.viz.derivparam.python/localization/derivedParameters/functions/meteolib.py +++ b/cave/com.raytheon.uf.viz.derivparam.python/localization/derivedParameters/functions/meteolib.py @@ -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)): diff --git a/cave/com.raytheon.uf.viz.monitor/META-INF/MANIFEST.MF b/cave/com.raytheon.uf.viz.monitor/META-INF/MANIFEST.MF index d7c1651bef..8d6e555393 100644 --- a/cave/com.raytheon.uf.viz.monitor/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.uf.viz.monitor/META-INF/MANIFEST.MF @@ -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, diff --git a/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/util/ObUtil.java b/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/util/ObUtil.java index 6d75d1580b..14eb46c206 100644 --- a/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/util/ObUtil.java +++ b/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/util/ObUtil.java @@ -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. * * * @@ -82,7 +84,7 @@ public final class ObUtil { dropTime.add(Calendar.HOUR, -(ObConst.THREAT_INTERVAL_HOURS)); return dropTime.getTime(); } - + /** * Method that gets the current time. * @@ -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; diff --git a/cave/com.raytheon.uf.viz.xy.crosssection/META-INF/MANIFEST.MF b/cave/com.raytheon.uf.viz.xy.crosssection/META-INF/MANIFEST.MF index 142970a922..19d8a466ce 100644 --- a/cave/com.raytheon.uf.viz.xy.crosssection/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.uf.viz.xy.crosssection/META-INF/MANIFEST.MF @@ -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 diff --git a/cave/com.raytheon.uf.viz.xy.crosssection/src/com/raytheon/uf/viz/xy/crosssection/graph/CrossSectionGraph.java b/cave/com.raytheon.uf.viz.xy.crosssection/src/com/raytheon/uf/viz/xy/crosssection/graph/CrossSectionGraph.java index 2219357488..c2736efb67 100644 --- a/cave/com.raytheon.uf.viz.xy.crosssection/src/com/raytheon/uf/viz/xy/crosssection/graph/CrossSectionGraph.java +++ b/cave/com.raytheon.uf.viz.xy.crosssection/src/com/raytheon/uf/viz/xy/crosssection/graph/CrossSectionGraph.java @@ -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. * * * @@ -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++) { diff --git a/cave/com.raytheon.viz.pointdata/META-INF/MANIFEST.MF b/cave/com.raytheon.viz.pointdata/META-INF/MANIFEST.MF index bdcf8ed7c0..d3282cf0cc 100644 --- a/cave/com.raytheon.viz.pointdata/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.viz.pointdata/META-INF/MANIFEST.MF @@ -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, diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/HeightOfRequestableData.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/HeightOfRequestableData.java index 69a468754e..070d6ae12f 100644 --- a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/HeightOfRequestableData.java +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/HeightOfRequestableData.java @@ -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. * * * @@ -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; diff --git a/cave/com.raytheon.viz.radar/META-INF/MANIFEST.MF b/cave/com.raytheon.viz.radar/META-INF/MANIFEST.MF index de6c909cce..b1c8b061f3 100644 --- a/cave/com.raytheon.viz.radar/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.viz.radar/META-INF/MANIFEST.MF @@ -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, diff --git a/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/util/DmdTools.java b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/util/DmdTools.java index fab62fbb98..f206f2682d 100644 --- a/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/util/DmdTools.java +++ b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/util/DmdTools.java @@ -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 + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * ??? ??, ????            xxxxxxxx     Initial creation
+ * Aug 14, 2013  #2262     dgilling     Use new wxmath method for ztopsa.
+ * 
+ * 
+ * + * @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; diff --git a/edexOsgi/com.raytheon.uf.common.wxmath/src/com/raytheon/uf/common/wxmath/CalcRH.java b/edexOsgi/com.raytheon.uf.common.wxmath/src/com/raytheon/uf/common/wxmath/CalcRH.java new file mode 100644 index 0000000000..1e2cf99bc8 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.common.wxmath/src/com/raytheon/uf/common/wxmath/CalcRH.java @@ -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. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Aug 13, 2013  #2262     dgilling     Ported from calcrh.f.
+ * 
+ * 
+ * + * @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; + } +} diff --git a/edexOsgi/com.raytheon.uf.common.wxmath/src/com/raytheon/uf/common/wxmath/Constants.java b/edexOsgi/com.raytheon.uf.common.wxmath/src/com/raytheon/uf/common/wxmath/Constants.java index 130783b4b6..6dc1109f70 100644 --- a/edexOsgi/com.raytheon.uf.common.wxmath/src/com/raytheon/uf/common/wxmath/Constants.java +++ b/edexOsgi/com.raytheon.uf.common.wxmath/src/com/raytheon/uf/common/wxmath/Constants.java @@ -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 * * * @@ -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(); + } } diff --git a/edexOsgi/com.raytheon.uf.common.wxmath/src/com/raytheon/uf/common/wxmath/Hgt2Pres.java b/edexOsgi/com.raytheon.uf.common.wxmath/src/com/raytheon/uf/common/wxmath/Hgt2Pres.java new file mode 100644 index 0000000000..30fc530cfe --- /dev/null +++ b/edexOsgi/com.raytheon.uf.common.wxmath/src/com/raytheon/uf/common/wxmath/Hgt2Pres.java @@ -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. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Aug 13, 2013  #2262     dgilling     Ported from hgt2pres.f.
+ * 
+ * 
+ * + * @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; + } +} diff --git a/edexOsgi/com.raytheon.uf.common.wxmath/src/com/raytheon/uf/common/wxmath/PToZsa.java b/edexOsgi/com.raytheon.uf.common.wxmath/src/com/raytheon/uf/common/wxmath/PToZsa.java new file mode 100644 index 0000000000..713586a99c --- /dev/null +++ b/edexOsgi/com.raytheon.uf.common.wxmath/src/com/raytheon/uf/common/wxmath/PToZsa.java @@ -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. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Aug 13, 2013  #2262     dgilling     Ported from ptozsa.f.
+ * 
+ * 
+ * + * @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; + } +} diff --git a/edexOsgi/com.raytheon.uf.common.wxmath/src/com/raytheon/uf/common/wxmath/ZToPsa.java b/edexOsgi/com.raytheon.uf.common.wxmath/src/com/raytheon/uf/common/wxmath/ZToPsa.java new file mode 100644 index 0000000000..a6deabbe03 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.common.wxmath/src/com/raytheon/uf/common/wxmath/ZToPsa.java @@ -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. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Aug 13, 2013  #2262     dgilling     Ported from ztopsa.f.
+ * 
+ * 
+ * + * @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; + } +} diff --git a/tests/.classpath b/tests/.classpath index 1c6a328254..49efdea148 100644 --- a/tests/.classpath +++ b/tests/.classpath @@ -154,5 +154,11 @@ + + + + + + diff --git a/tests/manual/com/raytheon/uf/common/wxmath/TestCalcRH.java b/tests/manual/com/raytheon/uf/common/wxmath/TestCalcRH.java new file mode 100644 index 0000000000..aa18dc38ff --- /dev/null +++ b/tests/manual/com/raytheon/uf/common/wxmath/TestCalcRH.java @@ -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} + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Aug 14, 2013  #2262     dgilling     Initial creation
+ * 
+ * 
+ * + * @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)); + } +} diff --git a/tests/manual/com/raytheon/uf/common/wxmath/TestHgt2Pres.java b/tests/manual/com/raytheon/uf/common/wxmath/TestHgt2Pres.java new file mode 100644 index 0000000000..685b12719c --- /dev/null +++ b/tests/manual/com/raytheon/uf/common/wxmath/TestHgt2Pres.java @@ -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} + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Aug 14, 2013  #2262     dgilling     Initial creation
+ * 
+ * 
+ * + * @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)); + } +} diff --git a/tests/manual/com/raytheon/uf/common/wxmath/TestPToZsa.java b/tests/manual/com/raytheon/uf/common/wxmath/TestPToZsa.java new file mode 100644 index 0000000000..48b1bc5d49 --- /dev/null +++ b/tests/manual/com/raytheon/uf/common/wxmath/TestPToZsa.java @@ -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} + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Aug 14, 2013  #2262     dgilling     Initial creation
+ * 
+ * 
+ * + * @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)); + } +} diff --git a/tests/manual/com/raytheon/uf/common/wxmath/TestZToPsa.java b/tests/manual/com/raytheon/uf/common/wxmath/TestZToPsa.java new file mode 100644 index 0000000000..5aa42846e3 --- /dev/null +++ b/tests/manual/com/raytheon/uf/common/wxmath/TestZToPsa.java @@ -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} + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Aug 14, 2013  #2262     dgilling     Initial creation
+ * 
+ * 
+ * + * @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)); + } +} diff --git a/tests/manual/com/raytheon/uf/common/wxmath/package-info.java b/tests/manual/com/raytheon/uf/common/wxmath/package-info.java new file mode 100644 index 0000000000..bcc47ef88b --- /dev/null +++ b/tests/manual/com/raytheon/uf/common/wxmath/package-info.java @@ -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 com.raytheon.uf.common.wxmath. + * + *
+ *
+ * SOFTWARE HISTORY
+ *
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Aug 14, 2013            dgilling     Initial creation
+ *
+ * 
+ * + * @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/. \ No newline at end of file