Skip to content

Commit

Permalink
improve comments in test
Browse files Browse the repository at this point in the history
  • Loading branch information
surgura committed Jun 5, 2024
1 parent 8184c74 commit 68db417
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions tests/instruments/test_ship_underwater_st.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@
from virtual_ship.instruments.ship_underwater_st import simulate_ship_underwater_st
import xarray as xr
from typing import Callable
from datetime import timedelta


def test_simulate_ship_underwater_st(tmp_dir_factory: Callable[[str], str]) -> None:
# depth at which the sampling will be done
DEPTH = -2

# arbitrary time offset for the dummy fieldset
base_time = np.datetime64("1950-01-01")

# variabes we are going to compare between expected and actual observations
variables = ["salinity", "temperature", "lat", "lon"]

# were to sample
sample_points = [
Spacetime(Location(3, 0), base_time + np.timedelta64(0, "s")),
Spacetime(Location(7, 0), base_time + np.timedelta64(1, "s")),
]

# expected observations at sample points
expected_obs = [
{"salinity": 1, "temperature": 2, "lat": 3, "lon": 0, "time": base_time},
{
Expand All @@ -32,6 +37,7 @@ def test_simulate_ship_underwater_st(tmp_dir_factory: Callable[[str], str]) -> N
},
]

# create fieldset based on the expected observations
fieldset = FieldSet.from_data(
{
"U": np.zeros((2, 2)),
Expand Down Expand Up @@ -63,10 +69,14 @@ def test_simulate_ship_underwater_st(tmp_dir_factory: Callable[[str], str]) -> N

results = xr.open_zarr(out_file_name)

assert len(results.trajectory) == 1
# below we assert if output makes sense
assert len(results.trajectory) == 1 # expect a singe trajectory
traj = results.trajectory.item()
assert len(results.sel(trajectory=traj).obs) == len(sample_points)
assert len(results.sel(trajectory=traj).obs) == len(
sample_points
) # expect as many obs as sample points

# for every obs, check if the variables match the expected observations
for i, (obs_i, exp) in enumerate(
zip(results.sel(trajectory=traj).obs, expected_obs, strict=True)
):
Expand Down

0 comments on commit 68db417

Please sign in to comment.