Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RamiALBASHA committed Jun 27, 2023
1 parent d50f600 commit 5536311
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 39 deletions.
2 changes: 2 additions & 0 deletions test/data/reference_time_series.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Rg;An;E;Tleaf;psi_soil;psi_collar;psi_leaf;theta_soil
69.8278284128148;8.038509067043373;183.83694927361498;25.9860765072961;-0.2;-0.22715047303262692;-0.23648594239929285;0.05731273956258906
2 changes: 0 additions & 2 deletions test/data/reference_time_series.output

This file was deleted.

2 changes: 1 addition & 1 deletion test/non_regression_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ def json_parameters():

def reference_time_series_output():
"""Returns a `pandas.DataFrame` containing reference hydroshoot time-series output."""
path = join(sources_dir, 'reference_time_series.output')
path = join(sources_dir, 'reference_time_series.csv')
return read_csv(path, sep=';', decimal='.')
65 changes: 30 additions & 35 deletions test/test_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,18 @@ def setup_default_stomatal_conductance_params():


def setup_leaf_local_weather():
return Series({'time': datetime(2012, 8, 1, 11),
'Tac': 26.84,
'hs': 43.77,
'Rg': 300.28742,
'u': 2.17,
'Ca': 400,
'Pa': 101.3,
'PPFD': 663.035})
res = Series({'time': datetime(2012, 8, 1, 11),
'Tac': 26.84,
'Tlc': 26.84,
'hs': 43.77,
'Rg': 300.28742,
'u': 2.17,
'Ca': 400,
'Pa': 101.3,
'PPFD': 663.035})
res['vpd'] = utilities.vapor_pressure_deficit(temp_air=res['Tac'], temp_leaf=res['Tlc'], rh=res['hs'])

return res


def test_leaf_na_is_as_expected():
Expand Down Expand Up @@ -309,10 +313,9 @@ def test_an_gs_ci_reduces_gas_exchange_rates_as_leaf_water_potential_decreases(
leaf_local_weather=setup_leaf_local_weather()):
an, _, _, gs = zip(
*[exchange.an_gs_ci(
air_temperature=leaf_local_weather['Tac'],
absorbed_ppfd=leaf_local_weather['PPFD'],
relative_humidity=leaf_local_weather['hs'],
leaf_temperature=25.,
vapor_pressure_deficit=leaf_local_weather['vpd'],
leaf_temperature=leaf_local_weather['Tac'],
leaf_water_potential=psi,
photo_params=setup_default_photosynthesis_params(),
gs_params=setup_default_stomatal_conductance_params(),
Expand All @@ -327,9 +330,8 @@ def test_an_gs_ci_reduces_gas_exchange_rates_as_leaf_water_potential_decreases(
def test_an_gs_ci_changes_gas_exchange_rates_as_leaf_temperature_changes(leaf_local_weather=setup_leaf_local_weather()):
an, _, _, gs = zip(
*[exchange.an_gs_ci(
air_temperature=leaf_local_weather['Tac'],
absorbed_ppfd=leaf_local_weather['PPFD'],
relative_humidity=leaf_local_weather['hs'],
vapor_pressure_deficit=leaf_local_weather['vpd'],
leaf_temperature=t,
leaf_water_potential=0,
photo_params=setup_default_photosynthesis_params(),
Expand All @@ -345,9 +347,8 @@ def test_an_gs_ci_changes_gas_exchange_rates_as_leaf_temperature_changes(leaf_lo
def test_an_gs_ci_yields_maximum_net_photosynthesis_at_31_degrees_celsius(
leaf_local_weather=setup_leaf_local_weather()):
an_max, *_ = exchange.an_gs_ci(
air_temperature=leaf_local_weather['Tac'],
absorbed_ppfd=leaf_local_weather['PPFD'],
relative_humidity=leaf_local_weather['hs'],
vapor_pressure_deficit=leaf_local_weather['vpd'],
leaf_temperature=31,
leaf_water_potential=0,
photo_params=setup_default_photosynthesis_params(),
Expand All @@ -357,9 +358,8 @@ def test_an_gs_ci_yields_maximum_net_photosynthesis_at_31_degrees_celsius(

an, *_ = zip(
*[exchange.an_gs_ci(
air_temperature=leaf_local_weather['Tac'],
absorbed_ppfd=leaf_local_weather['PPFD'],
relative_humidity=leaf_local_weather['hs'],
vapor_pressure_deficit=leaf_local_weather['vpd'],
leaf_temperature=t,
leaf_water_potential=0,
photo_params=setup_default_photosynthesis_params(),
Expand All @@ -374,9 +374,8 @@ def test_an_gs_ci_yields_maximum_net_photosynthesis_at_31_degrees_celsius(
def test_an_gs_ci_yields_maximum_stomatal_conductance_at_34_degrees_celsius(
leaf_local_weather=setup_leaf_local_weather()):
*_, gs_max = exchange.an_gs_ci(
air_temperature=leaf_local_weather['Tac'],
absorbed_ppfd=leaf_local_weather['PPFD'],
relative_humidity=leaf_local_weather['hs'],
vapor_pressure_deficit=leaf_local_weather['vpd'],
leaf_temperature=34,
leaf_water_potential=0,
photo_params=setup_default_photosynthesis_params(),
Expand All @@ -386,9 +385,8 @@ def test_an_gs_ci_yields_maximum_stomatal_conductance_at_34_degrees_celsius(

*_, gs = zip(
*[exchange.an_gs_ci(
air_temperature=leaf_local_weather['Tac'],
absorbed_ppfd=leaf_local_weather['PPFD'],
relative_humidity=leaf_local_weather['hs'],
vapor_pressure_deficit=leaf_local_weather['vpd'],
leaf_temperature=t,
leaf_water_potential=0,
photo_params=setup_default_photosynthesis_params(),
Expand All @@ -404,9 +402,8 @@ def test_an_gs_ci_yields_more_severe_stress_when_temperature_and_water_stresses_
leaf_local_weather=setup_leaf_local_weather()):
an_t, *_, gs_t = zip(
*[exchange.an_gs_ci(
air_temperature=leaf_local_weather['Tac'],
absorbed_ppfd=leaf_local_weather['PPFD'],
relative_humidity=leaf_local_weather['hs'],
vapor_pressure_deficit=leaf_local_weather['vpd'],
leaf_temperature=t,
leaf_water_potential=0,
photo_params=setup_default_photosynthesis_params(),
Expand All @@ -417,9 +414,8 @@ def test_an_gs_ci_yields_more_severe_stress_when_temperature_and_water_stresses_

an_t_psi, *_, gs_t_psi = zip(
*[exchange.an_gs_ci(
air_temperature=leaf_local_weather['Tac'],
absorbed_ppfd=leaf_local_weather['PPFD'],
relative_humidity=leaf_local_weather['hs'],
vapor_pressure_deficit=leaf_local_weather['vpd'],
leaf_temperature=t,
leaf_water_potential=-2,
photo_params=setup_default_photosynthesis_params(),
Expand All @@ -433,24 +429,23 @@ def test_an_gs_ci_yields_more_severe_stress_when_temperature_and_water_stresses_


def test_transpiration_rate_incrases_as_vapor_pressure_deficit_increases(leaf_local_weather=setup_leaf_local_weather()):
air_temp = 25.
leaf_temp = 25.
atmospheric_pressure = leaf_local_weather['Pa']
air_temp = leaf_local_weather['Tac']
leaf_temp = air_temp
gb = exchange.boundary_layer_conductance(leaf_length=0.1, wind_speed=leaf_local_weather['u'],
atm_pressure=leaf_local_weather['Pa'], air_temp=air_temp,
atm_pressure=atmospheric_pressure, air_temp=air_temp,
ideal_gas_cst=constants.ideal_gaz_cst)
es = utilities.saturated_air_vapor_pressure(leaf_temp)
vpd = utilities.vapor_pressure_deficit(temp_air=air_temp, temp_leaf=leaf_temp, rh=leaf_local_weather['hs'])
*_, gs = exchange.an_gs_ci(
air_temperature=leaf_local_weather['Tac'],
absorbed_ppfd=leaf_local_weather['PPFD'],
relative_humidity=leaf_local_weather['hs'],
leaf_temperature=34,
vapor_pressure_deficit=vpd,
leaf_temperature=leaf_temp,
leaf_water_potential=0,
photo_params=setup_default_photosynthesis_params(),
gs_params=setup_default_stomatal_conductance_params(),
rbt=2. / 3.,
ca=400.)

transpiration = [exchange.calc_transpiration_rate(leaf_temp, ea, gs, gb, atmospheric_pressure)
for ea in linspace(es, 0, 10)]
assert all(x <= y for x, y in zip(transpiration, transpiration[1:]))
transpiration = [exchange.calc_transpiration_rate(vpd=vpd, gs=gs, gb=gb, atm_pressure=atmospheric_pressure)
for vpd in linspace(vpd, 0, 10)]
assert all(x >= y for x, y in zip(transpiration, transpiration[1:]))
2 changes: 1 addition & 1 deletion test/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def test_potted_grapevine():
gdd_since_budbreak=100.)
ref = non_regression_data.reference_time_series_output()
# do not compare date index
assert_array_almost_equal(ref.iloc[0, 1:], results.reset_index(drop=True).iloc[0, :], decimal=0)
assert_array_almost_equal(ref.iloc[0, :], results.reset_index(drop=True).iloc[0, :], decimal=0)

0 comments on commit 5536311

Please sign in to comment.