From c1f55485adcf2c477c6e9f8fad103c3a57aeb733 Mon Sep 17 00:00:00 2001 From: arofarn Date: Mon, 28 Jun 2021 17:55:09 +0200 Subject: [PATCH] Check and fix all constants and units compare to MetPy results --- tests/metpy_simpletest.py | 14 +++++++ umetpy/constants.py | 81 ++++++++++++++++++++------------------- 2 files changed, 55 insertions(+), 40 deletions(-) create mode 100644 tests/metpy_simpletest.py diff --git a/tests/metpy_simpletest.py b/tests/metpy_simpletest.py new file mode 100644 index 0000000..0c42e35 --- /dev/null +++ b/tests/metpy_simpletest.py @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# SPDX-FileCopyrightText: Copyright (c) 2021 Arofarn +# +# SPDX-License-Identifier: BSD-3-Clause + +"""Same as umetpy_simpletest but for original MetPy module, to compare and validate results""" + +import metpy.constants as mpconsts + +# pylint: disable=eval-used +print("List of all constants:\n") +for cst in dir(mpconsts): + if cst[0] != "_" and cst not in ["exporter", "units"]: + print("{:30s} = {:.12f}".format(cst, eval("{}.{}".format("mpconsts", cst)))) diff --git a/umetpy/constants.py b/umetpy/constants.py index 10774e5..544369c 100644 --- a/umetpy/constants.py +++ b/umetpy/constants.py @@ -71,10 +71,9 @@ molecular_weight_ratio :math:`\epsilon` epsilon :math:`\text{None}` .. [7] [WMO1966]_ .. [8] [Picard2008]_ """ # noqa: E501 - # pylint: enable=line-too-long - # pylint: disable=invalid-name + from .package_tools import Exporter exporter = Exporter(globals()) @@ -82,53 +81,55 @@ exporter = Exporter(globals()) # Export all the variables defined in this block with exporter: # Earth - earth_gravity = g = 9.80665 # 'm / s^2' - Re = earth_avg_radius = 6371008.7714 # 'm' - G = gravitational_constant = 6.67430e-11 # 'm^3 / kg / s^2' - GM = geocentric_gravitational_constant = 3986005e8 # 'm^3 / s^2' - omega = earth_avg_angular_vel = 7292115e-11 # 'rad / s' - d = earth_sfc_avg_dist_sun = 149597870700.0 # 'm' - S = earth_solar_irradiance = 1360.8 # 'W / m^2' - delta = earth_max_declination = 23.45 # 'degrees' - earth_orbit_eccentricity = 0.0167 # 'dimensionless' - earth_mass = me = geocentric_gravitational_constant / gravitational_constant + earth_gravity = g = 9.80665 # 'm / s^2' x + Re = earth_avg_radius = 6371008.7714 # 'm' x + G = gravitational_constant = 6.67430e-11 # 'm^3 / kg / s^2' x + GM = geocentric_gravitational_constant = 3986005e8 # 'm^3 / s^2' x + omega = earth_avg_angular_vel = 7292115e-11 # 'rad / s' x + d = earth_sfc_avg_dist_sun = 149597870700.0 # 'm' x + S = earth_solar_irradiance = 1360.8 # 'W / m^2' x + delta = earth_max_declination = 23.45 # 'degrees' x + earth_orbit_eccentricity = 0.0167 # 'dimensionless' x + earth_mass = me = 5972169366075843731783680 # 'kg' x # molar gas constant - R = 8.314462618 # 'J / mol / K' + R = 8.314462618 # 'J / mol / K' x # Water - Mw = water_molecular_weight = 18.015268 # 'g / mol' - Rv = water_gas_constant = R / Mw - rho_l = density_water = 999.97495 # 'kg / m^3' - wv_specific_heat_ratio = 1.330 # 'dimensionless' - Cp_v = wv_specific_heat_press = ( - wv_specific_heat_ratio * Rv / (wv_specific_heat_ratio - 1) - ) - Cv_v = wv_specific_heat_vol = Cp_v / wv_specific_heat_ratio - Cp_l = water_specific_heat = 4.2194 # 'kJ / kg / K' - Lv = water_heat_vaporization = 2.50084e6 # 'J / kg' - Lf = water_heat_fusion = 3.337e5 # 'J / kg' - Cp_i = ice_specific_heat = 2090 # 'J / kg / K' - rho_i = density_ice = 917 # 'kg / m^3' + Mw = water_molecular_weight = 18.015268 # 'g / mol' x + Rv = water_gas_constant = 0.461523115726 # 'J / g / K' x + rho_l = density_water = 999.97495 # 'kg / m^3' x + wv_specific_heat_ratio = 1.330 # 'dimensionless' x + # Cp_v = (wv_specific_heat_ratio * Rv / (wv_specific_heat_ratio - 1)) + Cp_v = wv_specific_heat_press = 1.860078011866 # 'J / g / K' x + # Cv_v = Cp_v / wv_specific_heat_ratio + Cv_v = wv_specific_heat_vol = 1.398554896140 # 'J / g / K' x + Cp_l = water_specific_heat = 4.2194 # 'kJ / kg / K' x + Lv = water_heat_vaporization = 2500840 # 'J / kg' x + Lf = water_heat_fusion = 333700.0 # 'J / kg' x + Cp_i = ice_specific_heat = 2090 # 'J / kg / K' x + rho_i = density_ice = 917 # 'kg / m^3' x # Dry air - Md = dry_air_molecular_weight = 28.96546e-3 # 'kg / mol' - Rd = dry_air_gas_constant = R / Md + Md = dry_air_molecular_weight = 0.02896546 # 'kg / mol' x + # Rd = dry_air_gas_constant = R / Md + Rd = dry_air_gas_constant = 287.047490977185 # 'J / K / kg` x dry_air_spec_heat_ratio = 1.4 # 'dimensionless' - Cp_d = dry_air_spec_heat_press = ( - dry_air_spec_heat_ratio * Rd / (dry_air_spec_heat_ratio - 1) - ) - Cv_d = dry_air_spec_heat_vol = Cp_d / dry_air_spec_heat_ratio - # TODO : check unit conversion - rho_d = dry_air_density_stp = 1000.0 / (Rd * 273.15) # 'kg / m^3' + # Cp_d = (dry_air_spec_heat_ratio * Rd / (dry_air_spec_heat_ratio - 1)) + Cp_d = dry_air_spec_heat_press = 1004.666218420146 # 'J / K / kg` x + # Cv_d = dry_air_spec_heat_vol = Cp_d / dry_air_spec_heat_ratio + Cv_d = dry_air_spec_heat_vol = 717.618727442962 # 'J / K / kg` x + # rho_d = dry_air_density_stp = 1000.0 mbar / (Rd * 273.15 K) + rho_d = dry_air_density_stp = 1.275395968940 # 'kg / m^3' x # General meteorology constants - P0 = pot_temp_ref_press = 1000.0 # 'mbar' - # TODO : check unit conversion - kappa = poisson_exponent = Rd / Cp_d # 'dimensionless' - gamma_d = dry_adiabatic_lapse_rate = g / Cp_d - # TODO : check unit conversion - epsilon = molecular_weight_ratio = Mw / Md # 'dimensionless' + P0 = pot_temp_ref_press = 1000.0 # 'mbar' x + # kappa = poisson_exponent = Rd / Cp_d + kappa = poisson_exponent = 0.285714285714 # 'dimensionless' x + # gamma_d = dry_adiabatic_lapse_rate = g / Cp_d + gamma_d = dry_adiabatic_lapse_rate = 0.009761102563 # 'K * kg * m / J / s^2' x + # epsilon = molecular_weight_ratio = Mw / Md + epsilon = molecular_weight_ratio = 0.621956910058 # 'dimensionless' del exporter del Exporter