Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions tests/models/abiotic/test_abiotic_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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],
]
)

Expand Down
15 changes: 5 additions & 10 deletions virtual_ecosystem/models/abiotic/abiotic_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
}

Expand Down