diff --git a/tests/models/abiotic/test_abiotic_tools.py b/tests/models/abiotic/test_abiotic_tools.py index 2eb1f11eb..d7452cc10 100644 --- a/tests/models/abiotic/test_abiotic_tools.py +++ b/tests/models/abiotic/test_abiotic_tools.py @@ -338,9 +338,20 @@ def test_calculate_atmospheric_layer_geometry( layer_structure=lyr_str, ) - for var in ["heights", "thickness", "layer_top", "layer_midpoints"]: + for var in ["heights", "thickness", "layer_midpoints"]: assert var in result + exp_heights = np.array( + [ + [32.0, 32.0, 32.0, 32.0], + [30.0, 30.0, 30.0, np.nan], + [20.0, 20.0, np.nan, np.nan], + [10.0, np.nan, np.nan, np.nan], + [0.1, 0.1, 0.1, 0.1], + ] + ) + np.testing.assert_allclose(result["heights"], exp_heights, rtol=1e-04, atol=1e-04) + exp_thickness = np.array( [ [2.0, 2.0, 2.0, 31.9], @@ -356,11 +367,11 @@ def test_calculate_atmospheric_layer_geometry( exp_midpoints = np.array( [ - [1.0, 1.0, 1.0, 15.95], - [7.0, 7.0, 16.95, np.nan], - [17, 21.95, np.nan, np.nan], - [26.95, np.nan, np.nan, np.nan], - [31.95, 31.95, 31.95, 31.95], + [31.0, 31.0, 31.0, 16.05], + [25.0, 25.0, 15.05, np.nan], + [15.0, 10.05, np.nan, np.nan], + [5.05, np.nan, np.nan, np.nan], + [0.05, 0.05, 0.05, 0.05], ] ) diff --git a/virtual_ecosystem/models/abiotic/abiotic_tools.py b/virtual_ecosystem/models/abiotic/abiotic_tools.py index 47383d648..015a5191d 100644 --- a/virtual_ecosystem/models/abiotic/abiotic_tools.py +++ b/virtual_ecosystem/models/abiotic/abiotic_tools.py @@ -305,10 +305,9 @@ def update_profile_from_reference( def calculate_atmospheric_layer_geometry(data: Data, layer_structure: LayerStructure): - """Calculate heights, thickness, layer tops, and midpoints for atmospheric layers. + """Calculate heights, layer thickness, and midpoints for atmospheric layers. - The layer top and midpoint values are distances in metres below the above canopy - reference height for each cell. + The midpoint values are distances in metres above ground for each cell. Args: data: Data object @@ -324,17 +323,13 @@ def calculate_atmospheric_layer_geometry(data: Data, layer_structure: LayerStruc # Compute thickness thickness = compute_layer_thickness_for_varying_canopy(heights=heights) - # Compute the top of each layer below the above canopy reference height - layer_top = np.abs(heights - heights[0, :]) - - # Compute the midpoint of each layer as the distance below the above canopy - # reference height - midpoints = layer_top + thickness / 2 + # Compute the midpoint of each layer as the height above ground minus half the layer + # thickness + midpoints = heights - thickness / 2 return { "heights": heights, "thickness": thickness, - "layer_top": layer_top, "layer_midpoints": midpoints, }