diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 97d06a34..49541542 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,7 @@ repos: types: [text] files: \.(json|ipynb)$ - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.3 + rev: v0.9.6 hooks: - id: ruff args: [--fix, --show-fixes] @@ -22,6 +22,6 @@ repos: - id: ruff-format types_or: [python, jupyter] - repo: https://github.com/rbubley/mirrors-prettier # Update mirror as official mirror is deprecated - rev: v3.4.2 + rev: v3.5.0 hooks: - id: prettier diff --git a/docs/user-guide/tutorials/ADCP_data_tutorial.ipynb b/docs/user-guide/tutorials/ADCP_data_tutorial.ipynb index a85bb986..3700d699 100644 --- a/docs/user-guide/tutorials/ADCP_data_tutorial.ipynb +++ b/docs/user-guide/tutorials/ADCP_data_tutorial.ipynb @@ -128,7 +128,7 @@ " {\"long_name\": \"distance to coast\", \"units\": \"m\", \"positive\": \"shoreward\"}\n", ")\n", "peru = peru.set_coords(\"s\").sortby(\"s\")\n", - "print(f\"max distance from coast: {abs(peru.s.min()).data/1000:.2f} km\")" + "print(f\"max distance from coast: {abs(peru.s.min()).data / 1000:.2f} km\")" ] }, { diff --git a/docs/user-guide/tutorials/CTD_data_tutorial.ipynb b/docs/user-guide/tutorials/CTD_data_tutorial.ipynb index f7a8f0e7..da832695 100644 --- a/docs/user-guide/tutorials/CTD_data_tutorial.ipynb +++ b/docs/user-guide/tutorials/CTD_data_tutorial.ipynb @@ -263,12 +263,12 @@ "source": [ "# Fill the dataset with values from the csv files.\n", "for ob in range(5): # loop through files\n", - " header = pd.read_csv(f\"Japan/CTD_Japan_station_{ob+1}.csv\", nrows=7, header=None)\n", + " header = pd.read_csv(f\"Japan/CTD_Japan_station_{ob + 1}.csv\", nrows=7, header=None)\n", " ctd.lon[ob] = header.iloc[0, 1]\n", " ctd.lat[ob] = header.iloc[1, 1]\n", " ctd.start_time[ob] = header.iloc[2, 1]\n", " ctd.end_time[ob] = header.iloc[3, 1]\n", - " data = pd.read_csv(f\"Japan/CTD_Japan_station_{ob+1}.csv\", skiprows=4)\n", + " data = pd.read_csv(f\"Japan/CTD_Japan_station_{ob + 1}.csv\", skiprows=4)\n", " ctd.P[:, ob] = data[\"pressure [hPa]\"]\n", " ctd.T[:, ob] = data[\"temperature [degC]\"]\n", " ctd.S[:, ob] = data[\"salinity [g kg-1]\"]" diff --git a/docs/user-guide/tutorials/Drifter_data_tutorial.ipynb b/docs/user-guide/tutorials/Drifter_data_tutorial.ipynb index be8f0ac4..6aa055e4 100755 --- a/docs/user-guide/tutorials/Drifter_data_tutorial.ipynb +++ b/docs/user-guide/tutorials/Drifter_data_tutorial.ipynb @@ -84,7 +84,7 @@ " Drifter(\n", " Spacetime(\n", " Location(latitude=-30, longitude=lon),\n", - " time=np.datetime64(f\"2023-07-{i+2:02d} 00:00:00\"),\n", + " time=np.datetime64(f\"2023-07-{i + 2:02d} 00:00:00\"),\n", " ),\n", " depth=0.0,\n", " lifetime=timedelta(days=90),\n", diff --git a/src/virtualship/expedition/do_expedition.py b/src/virtualship/expedition/do_expedition.py index 1846ea14..0f32d7b5 100644 --- a/src/virtualship/expedition/do_expedition.py +++ b/src/virtualship/expedition/do_expedition.py @@ -85,9 +85,9 @@ def do_expedition(expedition_dir: str | Path, input_data: Path | None = None) -> os.makedirs(expedition_dir.joinpath("results")) # calculate expedition cost in US$ - assert ( - schedule.waypoints[0].time is not None - ), "First waypoint has no time. This should not be possible as it should have been verified before." + assert schedule.waypoints[0].time is not None, ( + "First waypoint has no time. This should not be possible as it should have been verified before." + ) time_past = schedule_results.time - schedule.waypoints[0].time cost = expedition_cost(schedule_results, time_past) with open(expedition_dir.joinpath("results", "cost.txt"), "w") as file: diff --git a/src/virtualship/expedition/simulate_schedule.py b/src/virtualship/expedition/simulate_schedule.py index 85df8696..1ca4e5ef 100644 --- a/src/virtualship/expedition/simulate_schedule.py +++ b/src/virtualship/expedition/simulate_schedule.py @@ -83,9 +83,9 @@ def __init__( self._ship_config = ship_config self._schedule = schedule - assert ( - self._schedule.waypoints[0].time is not None - ), "First waypoint must have a time. This should have been verified before calling this function." + assert self._schedule.waypoints[0].time is not None, ( + "First waypoint must have a time. This should have been verified before calling this function." + ) self._time = schedule.waypoints[0].time self._location = schedule.waypoints[0].location diff --git a/tests/instruments/test_adcp.py b/tests/instruments/test_adcp.py index 118ac21f..f32014c8 100644 --- a/tests/instruments/test_adcp.py +++ b/tests/instruments/test_adcp.py @@ -107,12 +107,12 @@ def test_simulate_adcp(tmpdir) -> None: for var in ["lat", "lon"]: obs_value = obs[var].values.item() exp_value = exp[var] - assert np.isclose( - obs_value, exp_value - ), f"Observation incorrect {vert_loc=} {obs_i=} {var=} {obs_value=} {exp_value=}." + assert np.isclose(obs_value, exp_value), ( + f"Observation incorrect {vert_loc=} {obs_i=} {var=} {obs_value=} {exp_value=}." + ) for var in ["V", "U"]: obs_value = obs[var].values.item() exp_value = exp[var][vert_loc] - assert np.isclose( - obs_value, exp_value - ), f"Observation incorrect {vert_loc=} {i=} {var=} {obs_value=} {exp_value=}." + assert np.isclose(obs_value, exp_value), ( + f"Observation incorrect {vert_loc=} {i=} {var=} {obs_value=} {exp_value=}." + ) diff --git a/tests/instruments/test_ctd.py b/tests/instruments/test_ctd.py index 12619edf..f1fc26a6 100644 --- a/tests/instruments/test_ctd.py +++ b/tests/instruments/test_ctd.py @@ -132,6 +132,6 @@ def test_simulate_ctds(tmpdir) -> None: for var in ["salinity", "temperature", "lat", "lon"]: obs_value = obs[var].values.item() exp_value = exp[var] - assert np.isclose( - obs_value, exp_value - ), f"Observation incorrect {ctd_i=} {loc=} {var=} {obs_value=} {exp_value=}." + assert np.isclose(obs_value, exp_value), ( + f"Observation incorrect {ctd_i=} {loc=} {var=} {obs_value=} {exp_value=}." + ) diff --git a/tests/instruments/test_drifter.py b/tests/instruments/test_drifter.py index 86e313e5..c62b5d60 100644 --- a/tests/instruments/test_drifter.py +++ b/tests/instruments/test_drifter.py @@ -73,14 +73,14 @@ def test_simulate_drifters(tmpdir) -> None: # Check if drifters are moving # lat, lon, should be increasing values (with the above positive VU fieldset) dlat = np.diff(results.sel(trajectory=traj)["lat"].values) - assert np.all( - dlat[np.isfinite(dlat)] > 0 - ), f"Drifter is not moving over y {drifter_i=}" + assert np.all(dlat[np.isfinite(dlat)] > 0), ( + f"Drifter is not moving over y {drifter_i=}" + ) dlon = np.diff(results.sel(trajectory=traj)["lon"].values) - assert np.all( - dlon[np.isfinite(dlon)] > 0 - ), f"Drifter is not moving over x {drifter_i=}" + assert np.all(dlon[np.isfinite(dlon)] > 0), ( + f"Drifter is not moving over x {drifter_i=}" + ) temp = results.sel(trajectory=traj)["temperature"].values - assert np.all( - temp[np.isfinite(temp)] == CONST_TEMPERATURE - ), f"measured temperature does not match {drifter_i=}" + assert np.all(temp[np.isfinite(temp)] == CONST_TEMPERATURE), ( + f"measured temperature does not match {drifter_i=}" + ) diff --git a/tests/instruments/test_ship_underwater_st.py b/tests/instruments/test_ship_underwater_st.py index 89a37227..210e7340 100644 --- a/tests/instruments/test_ship_underwater_st.py +++ b/tests/instruments/test_ship_underwater_st.py @@ -97,6 +97,6 @@ def test_simulate_ship_underwater_st(tmpdir) -> None: for var in ["S", "T", "lat", "lon"]: obs_value = obs[var].values.item() exp_value = exp[var] - assert np.isclose( - obs_value, exp_value - ), f"Observation incorrect {i=} {var=} {obs_value=} {exp_value=}." + assert np.isclose(obs_value, exp_value), ( + f"Observation incorrect {i=} {var=} {obs_value=} {exp_value=}." + ) diff --git a/tests/instruments/test_xbt.py b/tests/instruments/test_xbt.py index d674127a..232e0c8b 100644 --- a/tests/instruments/test_xbt.py +++ b/tests/instruments/test_xbt.py @@ -126,6 +126,6 @@ def test_simulate_xbts(tmpdir) -> None: for var in ["temperature", "lat", "lon"]: obs_value = obs[var].values.item() exp_value = exp[var] - assert np.isclose( - obs_value, exp_value - ), f"Observation incorrect {xbt_i=} {loc=} {var=} {obs_value=} {exp_value=}." + assert np.isclose(obs_value, exp_value), ( + f"Observation incorrect {xbt_i=} {loc=} {var=} {obs_value=} {exp_value=}." + )