Skip to content

Commit

Permalink
add test for MWL24 model
Browse files Browse the repository at this point in the history
  • Loading branch information
whitetuft committed Jul 24, 2024
1 parent 936e86c commit 25138af
Show file tree
Hide file tree
Showing 8 changed files with 423 additions and 375 deletions.
3 changes: 1 addition & 2 deletions pyrtlib/absorption_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def n2_absorption(t: np.ndarray, p: np.ndarray, f: np.ndarray) -> np.ndarray:
'[AbsN2] No model available with this name: {} . Sorry...'.format(N2AbsModel.model))

if N2AbsModel.model == 'MWL24':
bf = N2AbsModel.n2_absorption_mwl24(f, p, t) * 1.E5
bf = N2AbsModel.n2_absorption_mwl24(t, p, f) * 1.E5
else:
bf = l * fdepen * p * p * f * f * th ** m

Expand Down Expand Up @@ -533,7 +533,6 @@ def h2o_absorption(self, pdrykpa: np.ndarray, vx: np.ndarray, ekpa: np.ndarray,
con_frgn = 7.1e-10 * (300./t)**4.4 * f**1.96 * pda * pvap
con = con_self + con_frgn
else:

con = (self.h2oll.cf * pda * ti ** self.h2oll.xcf + self.h2oll.cs * pvap * ti ** self.h2oll.xcs) * \
pvap * f * f
# 2019/03/18 *********************************************************
Expand Down
6 changes: 1 addition & 5 deletions pyrtlib/rt_equation.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,14 +554,10 @@ def clearsky_absorption(p: np.ndarray, t: np.ndarray, e: np.ndarray, frq: np.nda
npp, ncpp = O2AbsModel().o2_absorption(pdrykpa, v, ekpa, frq, amu)
aO2[i] = factor * (npp + ncpp) * db2np
# add N2 term
if N2AbsModel.model not in ['R03', 'R16', 'R17', 'R18', 'R98']:
if N2AbsModel.model:
aN2[i] = N2AbsModel.n2_absorption(
t[i], np.dot(pdrykpa, 10), frq)

if not N2AbsModel.model:
raise ValueError(
'No model avalaible with this name: {} . Sorry...'.format('model'))

if isinstance(o3n, np.ndarray) and O3AbsModel.model in ['R18', 'R21', 'R21SD', 'R22', 'R22SD', 'R23', 'R23SD', 'R24']:
aO3[i] = O3AbsModel().o3_absorption(
t[i], p[i], frq, o3n[i], amu)
Expand Down
364 changes: 182 additions & 182 deletions pyrtlib/tests/data/tb_tot_ground_ros03_19sd_21sd_era5.csv

Large diffs are not rendered by default.

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions pyrtlib/tests/test_absorption_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,12 @@ def test_h20continum(self):

cs = H2OAbsModel().h2o_continuum(183, 1.09, 1)
assert_allclose(cs, np.array([3.724996e-08]))

def test_h20continum_mwl24(self):
H2OAbsModel.model = 'MWL24'
H2OAbsModel.set_ll()
assert H2OAbsModel.h2oll.ctr[0] == 300.0

cs = H2OAbsModel().h2o_continuum_mwl24(22, 1.09)
assert_allclose(cs, np.array([4.370745e-05]))

22 changes: 21 additions & 1 deletion pyrtlib/tests/test_main_ground.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from numpy.testing import assert_allclose
from pyrtlib.climatology import AtmosphericProfiles as atmp
from pyrtlib.tb_spectrum import TbCloudRTE
from pyrtlib.absorption_model import H2OAbsModel, O2AbsModel
from pyrtlib.absorption_model import H2OAbsModel, N2AbsModel, O2AbsModel
from pyrtlib.apiwebservices import ERA5Reanalysis
from pyrtlib.utils import ppmv2gkg, mr2rh

Expand Down Expand Up @@ -72,6 +72,25 @@ def test_pyrtlib_ground_R24(self):
df_expected = pd.read_csv(os.path.join(
THIS_DIR, "data", "tb_tot_ground_ros03_19sd_21sd_era5.csv"))
assert_allclose(df.tbtotal, df_expected.r24, atol=0)

def test_pyrtlib_ground_MWL24(self):
z, p, _, t, md = atmp.gl_atm(atmp.TROPICAL)

gkg = ppmv2gkg(md[:, atmp.H2O], atmp.H2O)
rh = mr2rh(p, t, gkg)[0] / 100

frq = np.arange(20, 201, 1)

rte = TbCloudRTE(z, p, t, rh, frq)
rte.satellite = False
rte.init_absmdl('MWL24')
O2AbsModel.model = 'R22'
O2AbsModel.set_ll()
df = rte.execute()

df_expected = pd.read_csv(os.path.join(
THIS_DIR, "data", "tb_tot_ground_ros03_19sd_21sd_era5.csv"))
assert_allclose(df.tbtotal, df_expected.mwl24, atol=0)


# @pytest.mark.datafiles(DATA_DIR)
Expand All @@ -87,6 +106,7 @@ def test_pyrtlib_ground_R03(self):
rte = TbCloudRTE(z, p, t, rh, frq)
rte.satellite = False
rte.init_absmdl('R03')
N2AbsModel.model = None
df = rte.execute()

df_expected = pd.read_csv(os.path.join(
Expand Down
28 changes: 26 additions & 2 deletions pyrtlib/tests/test_main_sat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pandas as pd
from datetime import datetime
from numpy.testing import assert_allclose
from pyrtlib.absorption_model import H2OAbsModel, O2AbsModel, O3AbsModel
from pyrtlib.absorption_model import H2OAbsModel, N2AbsModel, O2AbsModel, O3AbsModel
from pyrtlib.climatology import AtmosphericProfiles as atmp
from pyrtlib.tb_spectrum import TbCloudRTE
from pyrtlib.apiwebservices import WyomingUpperAir, ERA5Reanalysis, IGRAUpperAir
Expand Down Expand Up @@ -89,6 +89,7 @@ def test_pyrtlib_sat_R16(self):

rte = TbCloudRTE(z, p, t, rh, frq, ang)
rte.init_absmdl('R16')
N2AbsModel.model = None
df = rte.execute()

df_expected = pd.read_csv(
Expand All @@ -107,6 +108,7 @@ def test_pyrtlib_sat_R03(self):

rte = TbCloudRTE(z, p, t, rh, frq, ang)
rte.init_absmdl('R03')
N2AbsModel.model = None
df = rte.execute()

df_expected = pd.read_csv(
Expand All @@ -125,6 +127,7 @@ def test_pyrtlib_sat_R17(self):

rte = TbCloudRTE(z, p, t, rh, frq, ang)
rte.init_absmdl('R17')
N2AbsModel.model = None
df = rte.execute()

df_expected = pd.read_csv(
Expand Down Expand Up @@ -197,6 +200,7 @@ def test_pyrtlib_sat_R18(self):

rte = TbCloudRTE(z, p, t, rh, frq, ang)
rte.init_absmdl('R18')
N2AbsModel.model = None
df = rte.execute()

df_expected = pd.read_csv(
Expand All @@ -214,6 +218,7 @@ def test_pyrtlib_sat_R98(self):

rte = TbCloudRTE(z, p, t, rh, frq, ang)
rte.init_absmdl('R98')
N2AbsModel.model = None
df = rte.execute()

df_expected = pd.read_csv(
Expand Down Expand Up @@ -245,6 +250,7 @@ def test_pyrtlib_sat_R98_cloudy(self):

rte = TbCloudRTE(z, p, t, rh, frq, ang)
rte.init_absmdl('R98')
N2AbsModel.model = None
rte.cloudy = True
rte.init_cloudy(cldh, denice, denliq)
df = rte.execute()
Expand Down Expand Up @@ -449,4 +455,22 @@ def test_pyrtlib_sat_R24(self):

df_expected = pd.read_csv(
os.path.join(THIS_DIR, "data", "tb_tot_ros03_16_17_18_19_19sd_20_20sd_98_mak11_21sd.csv"))
assert_allclose(df.tbtotal, df_expected.r24)
assert_allclose(df.tbtotal, df_expected.r24)

def test_pyrtlib_sat_MWL24(self):
z, p, _, t, md = atmp.gl_atm(atmp.TROPICAL)

gkg = ppmv2gkg(md[:, atmp.H2O], atmp.H2O)
rh = mr2rh(p, t, gkg)[0] / 100

frq = np.arange(20, 201, 1)

rte = TbCloudRTE(z, p, t, rh, frq)
rte.init_absmdl('MWL24')
O2AbsModel.model = 'R22'
O2AbsModel.set_ll()
df = rte.execute()

df_expected = pd.read_csv(
os.path.join(THIS_DIR, "data", "tb_tot_ros03_16_17_18_19_19sd_20_20sd_98_mak11_21sd.csv"))
assert_allclose(df.tbtotal, df_expected.mwl24)
3 changes: 2 additions & 1 deletion pyrtlib/tests/test_uncertainty.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import pandas as pd
from numpy.testing import assert_allclose, assert_equal
from pyrtlib.absorption_model import H2OAbsModel, O2AbsModel, O3AbsModel
from pyrtlib.absorption_model import H2OAbsModel, N2AbsModel, O2AbsModel, O3AbsModel
from pyrtlib.uncertainty import AbsModUncertainty, SpectroscopicParameter
from pyrtlib.uncertainty import covariance_matrix
from pyrtlib.climatology import AtmosphericProfiles as atmp
Expand Down Expand Up @@ -73,6 +73,7 @@ def test_pyrtlib_uncertainty_gamma_a(self):

rte = TbCloudRTE(z, p, t, rh, frq, amu=amu)
rte.init_absmdl('R17')
N2AbsModel.model = None
O2AbsModel.model = 'R18'
O2AbsModel.set_ll()
df = rte.execute()
Expand Down

0 comments on commit 25138af

Please sign in to comment.