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) atmosphere = SimpleIsotropicAtmosphere(tbdown=T, tbup=0, trans=1) # create the sensor theta = range(10, 80, 5) radiometer = sensor_list.passive(37e9, theta) # create the EM Model m = make_model("iba", "dort") # run the model sresult = m.run(radiometer, snowpack, atmosphere) np.testing.assert_allclose(sresult.TbV(), T, atol=0.01) np.testing.assert_allclose(sresult.TbH(), T, atol=0.01)
def test_snowpack_with_coherent_layer(): # this test is only here to avoid regression, it is not scientifically validated density = [300, 917, 400, 500] thickness = [0.10, 0.01, 0.20, 1000] temperature = 270 corr_length = [200e-6, 0, 200e-6, 200e-6] theta = 60 radiometer = sensor_list.passive(5e9, theta) sp = make_snowpack(thickness, "exponential", density=density, temperature=temperature, corr_length=corr_length) # create the EM Model - Equivalent DMRTML m = make_model("iba", "dort", rtsolver_options={'n_max_stream': 64, 'process_coherent_layers': True}) res = m.run(radiometer, sp) print(res.TbV(), res.TbH()) assert abs(res.TbV() - 261.1994214138529) < 1e-4 assert abs(res.TbH() - 201.1848483718344) < 1e-4
def test_oneconfig_for_multiyear_sea_ice(): # prepare inputs l, n_max_stream, thickness, temperature, salinity = setup_seaice() p_ex = np.array([1000e-6] * l) # correlation length porosity = 0.08 # ice porosity, in fraction # create an ice column with assumption of spherical brine inclusions (inclusion_shape="spheres"): ice_column = make_ice_column(ice_type="multiyear", thickness=thickness, temperature=temperature, microstructure_model="exponential", brine_inclusion_shape="spheres", salinity=salinity, porosity=porosity, corr_length=p_ex, add_water_substrate="ocean") # create the sensor sensor = sensor_list.passive(1.4e9, 40.) n_max_stream = 128 m = make_model("iba", "dort", rtsolver_options={"n_max_stream": n_max_stream}) # run the model res = m.run(sensor, ice_column) print(res.TbV(), res.TbH()) # absorption with effective permittivity assert abs(res.TbV() - 257.5689162188296) < 1e-4 assert abs(res.TbH() - 232.03924683304172) < 1e-4
def test_oneconfig_for_firstyear_sea_ice(): # prepare inputs l, n_max_stream, thickness, temperature, salinity = setup_seaice() p_ex = np.array([500e-6] * l) # correlation length # create an ice column with assumption of spherical brine inclusions (brine_inclusion_shape="spheres"): ice_column = make_ice_column( ice_type="firstyear", thickness=thickness, temperature=temperature, microstructure_model="exponential", brine_inclusion_shape= "spheres", #inclusion_shape can be "spheres" or "random_needles", or "mix_spheres_needles" salinity= salinity, #either 'salinity' or 'brine_volume_fraction' should be given for sea ice; if salinity is given, brine volume fraction is calculated in the model; if none is given, ice is treated as fresh water ice corr_length=p_ex, add_water_substrate="ocean") # create the sensor sensor = sensor_list.passive(1.4e9, 40.) n_max_stream = 128 m = make_model("iba", "dort", rtsolver_options={"n_max_stream": n_max_stream}) # run the model res = m.run(sensor, ice_column) print(res.TbV(), res.TbH()) #absorption with effective permittivity assert abs(res.TbV() - 256.01165061598317) < 1e-4 assert abs(res.TbH() - 228.47447378338745) < 1e-4
def _do_test_kirchoff_law(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) atmosphere1K = SimpleIsotropicAtmosphere(tbdown=1, tbup=0, trans=1) # create the sensor theta = range(10, 80, 5) radiometer = sensor_list.passive(37e9, theta) # create the EM Model m = make_model("iba", "dort") # run the model sresult_0 = m.run(radiometer, snowpack) sresult_1 = m.run(radiometer, snowpack, atmosphere1K) # V-pol 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 reflectivity_H = (sresult_1.TbH() - sresult_0.TbH()) print(emissivity_H, 1 - reflectivity_H) np.testing.assert_allclose(emissivity_H, 1 - reflectivity_H, atol=0.002)
def test_snowpack_with_coherent_layer(): # this test is only here to avoid regression, it is not scientifically validated density = [300, 916.7, 400, 500] thickness = [0.10, 0.01, 0.20, 1000] temperature = 270 corr_length = [200e-6, 0, 200e-6, 200e-6] theta = 60 radiometer = sensor_list.passive(5e9, theta) sp = make_snowpack(thickness, "exponential", density=density, temperature=temperature, corr_length=corr_length) # create the EM Model - Equivalent DMRTML m = make_model("iba", "dort", rtsolver_options={ 'n_max_stream': 64, 'process_coherent_layers': True }) res = m.run(radiometer, sp) print(res.TbV(), res.TbH()) #assert abs(res.TbV() - 261.1994214138529) < 1e-4 #assert abs(res.TbH() - 201.1848483718344) < 1e-4 # the new values may come from the correction of the bug in dort which limited # the streams to the non-total reflection ones. This is not all clear yet... #assert abs(res.TbV() - 261.05630770071855) < 1e-4 #assert abs(res.TbH() - 196.83495992559307) < 1e-4 # the new values come form the correction of 917->916.7 assert abs(res.TbV() - 261.06421847662216) < 1e-4 assert abs(res.TbH() - 196.8660443556061) < 1e-4
l_s = 2 #2 snow layers thickness_s = np.array([0.05, 0.2]) p_ex_s = np.array([5e-5] * l_s) temperature_s = np.linspace(273.15 - 25., 273.15 - 20, l_s) density_s = [200, 340] # create the snowpack snowpack = make_snowpack(thickness=thickness_s, microstructure_model="exponential", density=density_s, temperature=temperature_s, corr_length=p_ex_s) #add snowpack on top of ice column: medium = snowpack + ice_column # create the sensor sensor = sensor_list.passive(1.4e9, 40.) n_max_stream = 128 #TB calculation is more accurate if number of streams is increased (currently: default = 32); #needs to be increased when using > 1 snow layer on top of sea ice! m = make_model("iba", "dort", rtsolver_options={"n_max_stream": n_max_stream}) # run the model for bare sea ice: res1 = m.run(sensor, ice_column) # run the model for snow-covered sea ice: res2 = m.run(sensor, medium) # print TBs at horizontal and vertical polarization: print(res1.TbH(), res1.TbV()) print(res2.TbH(), res2.TbV())
from smrt import make_snowpack, make_model, sensor_list # import for memls from smrt.utils import memls_legacy # prepare snowpack pc = 0.2e-3 snowpack = make_snowpack(thickness=[10], microstructure_model="exponential", density=[300], temperature=[265], corr_length=pc) # create the sensor theta = range(10, 80, 5) radiometer = sensor_list.passive(37e9, theta) # create the EM Model m = make_model("iba", "dort") # run the model sresult = m.run(radiometer, snowpack) # run MEMLS matlab code mresult = memls_legacy.run(radiometer, snowpack) # outputs plt.plot(theta, sresult.TbV(), 'r-', label='SMRT V') plt.plot(theta, sresult.TbH(), 'r--', label='SMRT H') plt.plot(theta, mresult.TbV(), 'b-', label='MEMLS V') plt.plot(theta, mresult.TbH(), 'b--', label='MEMLS H')
def test_equivalence_porosity_density(): l, n_max_stream, thickness, temperature, salinity = setup_seaice() p_ex = np.array([1.0e-3] * (l)) # correlation length ice_type = 'multiyear' # first-year (FY) or multi-year (MY) sea ice porosity = 0.08 # ice porosity, in fraction ice_column1 = make_ice_column( ice_type, thickness=thickness, temperature=temperature, microstructure_model="exponential", brine_inclusion_shape="spheres", # brine_inclusion_shape can be "spheres", "random_needles" or "mix" (a mix of spheres and needles) salinity=salinity, # either 'salinity' or 'brine_volume_fraction' should be given for sea ice; if salinity is given, brine volume fraction is calculated in the model; if none is given, ice is treated as fresh water ice porosity=porosity, # either density or 'porosity' should be set for sea ice. If porosity is given, density is calculated in the model. If none is given, ice is treated as having a porosity of 0% (no air inclusions) # density = density, corr_length=p_ex, add_water_substrate="ocean" # see comment below ) # Same, but giving the density instead: density = [ bulk_ice_density(temp, salt, porosity) for temp, salt in zip(temperature, salinity) ] ice_column2 = make_ice_column( ice_type, thickness=thickness, temperature=temperature, microstructure_model="exponential", brine_inclusion_shape="spheres", # brine_inclusion_shape can be "spheres", "random_needles" or "mix" (a mix of spheres and needles) salinity=salinity, # either 'salinity' or 'brine_volume_fraction' should be given for sea ice; if salinity is given, brine volume fraction is calculated in the model; if none is given, ice is treated as fresh water ice # porosity = porosity, # either density or 'porosity' should be set for sea ice. If porosity is given, density is calculated in the model. If none is given, ice is treated as having a porosity of 0% (no air inclusions) density=density, corr_length=p_ex, add_water_substrate="ocean" # see comment below ) sensor = sensor_list.passive(1.4e9, 40.) n_max_stream = 128 # TB calculation is more accurate if number of streams is increased (currently: default = 32); # needs to be increased when using > 1 snow layer on top of sea ice! m = make_model("iba", "dort", rtsolver_options={"n_max_stream": n_max_stream}) # run the model for sea ice with porosity / density res1 = m.run(sensor, ice_column1) res2 = m.run(sensor, ice_column2) print(res1.TbV(), res1.TbH()) print(res2.TbV(), res2.TbH()) # The two should be similar assert abs(res1.TbV() - res2.TbV()) < 1e-4 assert abs(res1.TbH() - res2.TbH()) < 1e-4