Skip to content

Commit

Permalink
depreciate the atmosphere argument in Model.run
Browse files Browse the repository at this point in the history
  • Loading branch information
ghislainp committed Aug 27, 2020
1 parent 192a7eb commit 368b4db
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
16 changes: 8 additions & 8 deletions smrt/atmosphere/test_atmosphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import numpy as np

from smrt import make_snowpack, make_model, sensor, make_soil
from smrt import sensor_list
from smrt import make_snowpack, make_model, sensor_list
from smrt.atmosphere.simple_isotropic_atmosphere import SimpleIsotropicAtmosphere, make_atmosphere


Expand All @@ -14,33 +13,34 @@ def test_simple_isotropic_atmosphere():
temperature = [265, 265]
thickness = [0.4, 10]
radius = [200e-6, 400e-6]
#stickiness = [1000, 1000]
stickiness = [0.2, 0.2]

rads = sensor_list.amsre('36V')

atmos = SimpleIsotropicAtmosphere(30., 6., 0.90)

snowpack = make_snowpack(thickness, "sticky_hard_spheres",
density=density, temperature=temperature, radius=radius, stickiness=stickiness)
snowpack = make_snowpack(thickness, "sticky_hard_spheres", density=density,
temperature=temperature, radius=radius, stickiness=stickiness)

# create the EM Model - Equivalent DMRTML
iba = make_model("iba", "dort")

res1 = iba.run(rads, snowpack)
res2 = iba.run(rads, snowpack, atmosphere=atmos)

snowpack.atmosphere = atmos
res2 = iba.run(rads, snowpack)

print('TB 1: ', res1.TbV(), 'TB2: ', res2.TbV())

#absorption with effective permittivity
# absorption with effective permittivity
assert abs(res1.TbV() - 227.61318467710458) < 1e-2
assert abs(res2.TbV() - 214.66092232541834) < 1e-2


def test_frequency_dependent_atmosphere():

mu = np.cos(np.arange(0, 90))
atmos = make_atmosphere(tbdown={10e9: 15, 21e9: 23}, tbup={10e9:5, 21e9:6}, trans={10e9:1, 21e9:0.95})
atmos = make_atmosphere(tbdown={10e9: 15, 21e9: 23}, tbup={10e9: 5, 21e9: 6}, trans={10e9: 1, 21e9: 0.95})

assert np.all(atmos.tbup(frequency=10e9, costheta=mu, npol=2) == 5)
assert np.all(atmos.tbdown(frequency=21e9, costheta=mu, npol=2) == 23)
Expand Down
6 changes: 5 additions & 1 deletion smrt/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
The :py:mod:`smrt.rtsolver` is responsible for propagation of the incident or emitted energy through the layers, up to the surface, and eventually
through the atmosphere.
To build a model, use the :py:func:`make_model` function with the type of emmodel and type of rtsolver as arguments.
To build a model, use the :py:meth:`make_model` function with the type of emmodel and type of rtsolver as arguments.
Then call the :py:meth:`Model.run` method of the model instance by specifying the sensor (:py:class:`smrt.core.sensor.Sensor`),
snowpack (:py:class:`smrt.core.snowpack.Snowpack`) and optionally atmosphere (see :py:mod:`smrt.atmosphere`).
The results are returned as a :py:class:`~smrt.core.result.Result` which can then been interrogated to retrieve brightness temperature,
Expand Down Expand Up @@ -172,6 +172,10 @@ def run(self, sensor, snowpack, atmosphere=None, snowpack_dimension=None, progre
:returns: result of the calculation(s) as a :py:class:`Results` instance
"""

if atmosphere is not None:
raise DeprecationWarning("The atmosphere argument of the run method is going to be depreciated."
" Setting the 'atmosphere' with make_snowpack (and similar functions) is now the recommended way.")

if not isinstance(sensor, SensorBase):
raise SMRTError("the first argument of 'run' must be a sensor")

Expand Down
29 changes: 18 additions & 11 deletions smrt/test/test_physics_law.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@
def test_isothermal_universe_highscatt():
_do_test_isothermal_universe(0.8e-3, 10)


def test_isothermal_universe_lowscatt():
_do_test_isothermal_universe(0.05e-3, 10)


def test_isothermal_universe_shallow():
_do_test_isothermal_universe(0.8e-3, 0.1)


def test_kirchoff_law_highscatt():
_do_test_kirchoff_law(0.8e-3, 10)


def test_kirchoff_law_lowscatt():
_do_test_kirchoff_law(0.05e-3, 10)


def test_kirchoff_law_shallow():
_do_test_kirchoff_law(0.8e-3, 0.1)

Expand All @@ -31,13 +35,14 @@ def _do_test_isothermal_universe(pc, thickness_1):

T = 265

substrate = make_soil('soil_wegmuller',permittivity_model=complex(10,1), roughness_rms=0.001, temperature=T)

snowpack = make_snowpack([0.3, thickness_1], "exponential",
density=[200, 300], temperature=T, corr_length=pc, substrate=substrate)
substrate = make_soil('soil_wegmuller', permittivity_model=complex(10,1), roughness_rms=0.001, temperature=T)

atmosphere = SimpleIsotropicAtmosphere(tbdown=T, tbup=0, trans=1)

snowpack = make_snowpack([0.3, thickness_1], "exponential",
density=[200, 300], temperature=T, corr_length=pc,
substrate=substrate, atmosphere=atmosphere)

# create the sensor
theta = range(10, 80, 5)
radiometer = sensor_list.passive(37e9, theta)
Expand All @@ -46,7 +51,7 @@ def _do_test_isothermal_universe(pc, thickness_1):
m = make_model("iba", "dort")

# run the model
sresult = m.run(radiometer, snowpack, atmosphere)
sresult = m.run(radiometer, snowpack)

np.testing.assert_allclose(sresult.TbV(), T, atol=0.01)
np.testing.assert_allclose(sresult.TbH(), T, atol=0.01)
Expand All @@ -58,11 +63,12 @@ def _do_test_kirchoff_law(pc, thickness_1):

substrate = make_soil('soil_wegmuller', permittivity_model=complex(10, 1), roughness_rms=0.001, temperature=T)

snowpack = make_snowpack([0.3, thickness_1], "exponential",
density=[200, 300], temperature=T, corr_length=pc, substrate=substrate)

atmosphere1K = SimpleIsotropicAtmosphere(tbdown=1, tbup=0, trans=1)

snowpack = make_snowpack([0.3, thickness_1], "exponential",
density=[200, 300], temperature=T, corr_length=pc,
substrate=substrate)

# create the sensor
theta = range(10, 80, 5)
radiometer = sensor_list.passive(37e9, theta)
Expand All @@ -72,17 +78,18 @@ def _do_test_kirchoff_law(pc, thickness_1):

# run the model
sresult_0 = m.run(radiometer, snowpack)
sresult_1 = m.run(radiometer, snowpack, atmosphere1K)
snowpack.atmosphere = atmosphere1K
sresult_1 = m.run(radiometer, snowpack)

# V-pol
emissivity_V = (sresult_0.TbV() + sresult_1.TbV())/2/T
emissivity_V = (sresult_0.TbV() + sresult_1.TbV()) / 2 / T
reflectivity_V = (sresult_1.TbV() - sresult_0.TbV())

print(emissivity_V, 1 - reflectivity_V)
np.testing.assert_allclose(emissivity_V, 1 - reflectivity_V, atol=0.002)

# H-pol
emissivity_H = (sresult_0.TbH() + sresult_1.TbH())/2/T
emissivity_H = (sresult_0.TbH() + sresult_1.TbH()) / 2 / T
reflectivity_H = (sresult_1.TbH() - sresult_0.TbH())

print(emissivity_H, 1 - reflectivity_H)
Expand Down

0 comments on commit 368b4db

Please sign in to comment.