From 39940d9eb848cf46e705cbe00ce042467b60d9d5 Mon Sep 17 00:00:00 2001 From: Bryan Cazabonne <bryan.cazabonne@c-s.fr> Date: Mon, 14 Jan 2019 16:04:21 +0100 Subject: [PATCH] Changed API for angle unit. --- .../GlobalPressureTemperature2Model.java | 37 ++++++++++--------- .../GlobalPressureTemperature2ModelTest.java | 23 ++++++------ 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/orekit/models/earth/GlobalPressureTemperature2Model.java b/src/main/java/org/orekit/models/earth/GlobalPressureTemperature2Model.java index 12f5dba8b..138887182 100644 --- a/src/main/java/org/orekit/models/earth/GlobalPressureTemperature2Model.java +++ b/src/main/java/org/orekit/models/earth/GlobalPressureTemperature2Model.java @@ -89,10 +89,10 @@ public class GlobalPressureTemperature2Model implements DataLoader, WeatherModel /** The hydrostatic and wet a coefficients loaded. */ private double[] coefficientsA; - /** Geodetic site latitude, degrees.*/ + /** Geodetic site latitude, radians.*/ private double latitude; - /** Geodetic site longitude, degrees.*/ + /** Geodetic site longitude, radians.*/ private double longitude; /** Temperature site, in kelvins. */ @@ -115,8 +115,8 @@ public class GlobalPressureTemperature2Model implements DataLoader, WeatherModel /** Constructor with supported names given by user. * @param supportedNames supported names - * @param latitude geodetic latitude of the station, in degrees - * @param longitude longitude geodetic latitude of the station, in degrees + * @param latitude geodetic latitude of the station, in radians + * @param longitude longitude geodetic latitude of the station, in radians * @param geoid level surface of the gravity potential of a body */ public GlobalPressureTemperature2Model(final String supportedNames, final double latitude, @@ -129,14 +129,13 @@ public class GlobalPressureTemperature2Model implements DataLoader, WeatherModel this.geoid = geoid; this.latitude = latitude; - // Normalize longitude between 0° and 360° - final double lon = MathUtils.normalizeAngle(FastMath.toRadians(longitude), FastMath.PI); - this.longitude = FastMath.toDegrees(lon); + // Normalize longitude between 0 and 2π + this.longitude = MathUtils.normalizeAngle(longitude, FastMath.PI); } /** Constructor with default supported names. - * @param latitude geodetic latitude of the station, in degrees - * @param longitude geodetic latitude of the station, in degrees + * @param latitude geodetic latitude of the station, in radians + * @param longitude geodetic latitude of the station, in radians * @param geoid level surface of the gravity potential of a body */ public GlobalPressureTemperature2Model(final double latitude, final double longitude, final Geoid geoid) { @@ -307,30 +306,34 @@ public class GlobalPressureTemperature2Model implements DataLoader, WeatherModel final BilinearInterpolatingFunction functionAH = new BilinearInterpolatingFunction(xVal, yVal, fvalAH); final BilinearInterpolatingFunction functionAW = new BilinearInterpolatingFunction(xVal, yVal, fvalAW); + // Convert geodetic coordinates to degrees + final double lat = FastMath.toDegrees(latitude); + final double lon = FastMath.toDegrees(longitude); + // ah and aw coefficients coefficientsA = new double[2]; - coefficientsA[0] = functionAH.value(latitude, longitude) * 0.001; - coefficientsA[1] = functionAW.value(latitude, longitude) * 0.001; + coefficientsA[0] = functionAH.value(lat, lon) * 0.001; + coefficientsA[1] = functionAW.value(lat, lon) * 0.001; // Corrected height (can be negative) - final double undu = geoid.getUndulation(latitude, longitude, date); - final double correctedheight = height - undu - functionHS.value(latitude, longitude); + final double undu = geoid.getUndulation(lat, lon, date); + final double correctedheight = height - undu - functionHS.value(lat, lon); // Temperature gradient [K/m] - final double dTdH = functiondT.value(latitude, longitude) * 0.001; + final double dTdH = functiondT.value(lat, lon) * 0.001; // Specific humidity - final double qv = functionqv0.value(latitude, longitude) * 0.001; + final double qv = functionqv0.value(lat, lon) * 0.001; // For the computation of the temperature and the pressure, we use // the standard ICAO atmosphere formulas. // Temperature [K] - final double t0 = functionTemperature0.value(latitude, longitude); + final double t0 = functionTemperature0.value(lat, lon); this.temperature = t0 + dTdH * correctedheight; // Pressure [hPa] - final double p0 = functionPressure0.value(latitude, longitude); + final double p0 = functionPressure0.value(lat, lon); final double exponent = G / (dTdH * R); this.pressure = p0 * FastMath.pow(1 - (dTdH / t0) * correctedheight, exponent) * 0.01; diff --git a/src/test/java/org/orekit/models/earth/GlobalPressureTemperature2ModelTest.java b/src/test/java/org/orekit/models/earth/GlobalPressureTemperature2ModelTest.java index d570997d7..9faf63756 100644 --- a/src/test/java/org/orekit/models/earth/GlobalPressureTemperature2ModelTest.java +++ b/src/test/java/org/orekit/models/earth/GlobalPressureTemperature2ModelTest.java @@ -16,6 +16,7 @@ */ package org.orekit.models.earth; +import org.hipparchus.util.FastMath; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -58,8 +59,8 @@ public class GlobalPressureTemperature2ModelTest { // We test the fiability of our implementation by comparing our output values with // the ones obtained by the Vienna University. - final double latitude = 48.20; - final double longitude = 16.37; + final double latitude = FastMath.toRadians(48.20); + final double longitude = FastMath.toRadians(16.37); final double height = 156.0; final AbsoluteDate date = AbsoluteDate.createMJDDate(56141, 0.0, TimeScalesFactory.getUTC()); final Geoid geoid = new Geoid(GravityFieldFactory.getNormalizedProvider(12, 12), @@ -90,7 +91,7 @@ public class GlobalPressureTemperature2ModelTest { ReferenceEllipsoid.getWgs84(FramesFactory.getITRF(IERSConventions.IERS_2010, true))); final AbsoluteDate date = AbsoluteDate.createMJDDate(56141, 0.0, TimeScalesFactory.getUTC()); - final double latitude = 45.0; + final double latitude = FastMath.toRadians(45.0); final double height = 0.0; double longitude1; @@ -100,8 +101,8 @@ public class GlobalPressureTemperature2ModelTest { GlobalPressureTemperature2Model model2; // Test longitude = 181° and longitude = -179° - longitude1 = 181.0; - longitude2 = -179.0; + longitude1 = FastMath.toRadians(181.0); + longitude2 = FastMath.toRadians(-179.0); model1 = new GlobalPressureTemperature2Model(latitude, longitude1, geoid); model2 = new GlobalPressureTemperature2Model(latitude, longitude2, geoid); @@ -117,8 +118,8 @@ public class GlobalPressureTemperature2ModelTest { Assert.assertEquals(model1.getA()[1], model2.getA()[1], epsilon); // Test longitude = 180° and longitude = -180° - longitude1 = 180.0; - longitude2 = -180.0; + longitude1 = FastMath.toRadians(180.0); + longitude2 = FastMath.toRadians(-180.0); model1 = new GlobalPressureTemperature2Model(latitude, longitude1, geoid); model2 = new GlobalPressureTemperature2Model(latitude, longitude2, geoid); @@ -133,8 +134,8 @@ public class GlobalPressureTemperature2ModelTest { Assert.assertEquals(model1.getA()[1], model2.getA()[1], epsilon); // Test longitude = 0° and longitude = 360° - longitude1 = 0.0; - longitude2 = 360.0; + longitude1 = FastMath.toRadians(0.0); + longitude2 = FastMath.toRadians(360.0); model1 = new GlobalPressureTemperature2Model(latitude, longitude1, geoid); model2 = new GlobalPressureTemperature2Model(latitude, longitude2, geoid); @@ -153,8 +154,8 @@ public class GlobalPressureTemperature2ModelTest { @Test public void testCorruptedFileBadData() { - final double latitude = 14.0; - final double longitude = 67.5; + final double latitude = FastMath.toRadians(14.0); + final double longitude = FastMath.toRadians(67.5); final double height = 0.0; // Date is not used here -- GitLab