Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
58fca42
wip drifters
surgura May 28, 2024
3524ab3
drifters instrument. just missing test
surgura May 28, 2024
9c00fcf
drifter test
surgura May 28, 2024
695c73e
Remove old drifter file and fix errors
surgura May 28, 2024
42cd06e
codetools
surgura May 28, 2024
ffbc702
outputdf wherever i forgot to use it
surgura May 29, 2024
02a8b3c
added todo list
surgura May 29, 2024
f7917b3
ctd instrument
surgura May 29, 2024
8209396
CTDtest
surgura May 29, 2024
1b30b0d
use new ctd instrument in sailship
surgura May 29, 2024
af9536e
fix typo
surgura May 29, 2024
fe47b0c
codetools
surgura May 29, 2024
4956494
use new parcels api for particle class
surgura May 29, 2024
e33c045
add ctd to init
surgura May 29, 2024
2fd0169
comments
surgura Jun 2, 2024
98b17c7
first try adcp
surgura Jun 2, 2024
f9df8bc
adcp test
surgura Jun 2, 2024
9ded5e2
use adcp instrument in sailship
surgura Jun 3, 2024
4e57117
cleanup
surgura Jun 3, 2024
0eaaff1
instrument ship s t
surgura Jun 3, 2024
0ae0776
use ship st in sailship
surgura Jun 3, 2024
9d6b0c5
cleanup
surgura Jun 3, 2024
b06ce7d
refactor sailship ctd cast
surgura Jun 3, 2024
1716df2
cleanup
surgura Jun 3, 2024
78872ed
large cleanup
surgura Jun 4, 2024
087371d
add checks that all drifter and argo floats are deployed
surgura Jun 4, 2024
3e10d46
comments
surgura Jun 4, 2024
47c7e05
docstrings and other codetools fixes
surgura Jun 4, 2024
072437c
rename SamplePoint to Spacetime and move them one dir up
surgura Jun 4, 2024
c717f5c
rm todo
surgura Jun 4, 2024
1241f70
run pydocstyle on tests
surgura Jun 4, 2024
55c290d
fix some names
surgura Jun 4, 2024
ae077e6
Update virtual_ship/instruments/ctd.py
surgura Jun 5, 2024
b7ee4ff
removed comment about ctd
surgura Jun 5, 2024
dfe461d
fix incorrect docstring
surgura Jun 5, 2024
4b065a5
renamed ship_st to ship_underwater_st
surgura Jun 5, 2024
23a0b31
remove sailship create fieldset commented out function
surgura Jun 5, 2024
06092b0
ship underway st docstring improvement
surgura Jun 5, 2024
ced9221
minor docstring change
surgura Jun 5, 2024
e50ca96
minor docstring change
surgura Jun 5, 2024
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
2 changes: 1 addition & 1 deletion codetools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ flake8 ./$PACKAGE ./$TESTS
echo "--------------"
echo "pydocstyle"
echo "--------------"
pydocstyle ./$PACKAGE
pydocstyle ./$PACKAGE ./$TESTS

echo "--------------"
echo "sort-all"
Expand Down
9 changes: 8 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
"""Test configuration that is ran for every test."""

import pytest


# Set the working directory for each test to the directory of that test.
@pytest.fixture(autouse=True)
def change_test_dir(request, monkeypatch):
"""
Set the working directory for each test to the directory of that test.

:param request: -
:param monkeypatch: -
"""
monkeypatch.chdir(request.fspath.dirname)
33 changes: 33 additions & 0 deletions tests/instruments/test_adcp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Test the simulation of ADCP instruments."""

import numpy as np
from parcels import FieldSet

from virtual_ship import Location, Spacetime
from virtual_ship.instruments.adcp import simulate_adcp


def test_simulate_adcp() -> None:
MAX_DEPTH = -1000
MIN_DEPTH = -5
BIN_SIZE = 24

fieldset = FieldSet.from_data(
{"U": 0, "V": 0},
{
"lon": 0,
"lat": 0,
"time": [np.datetime64("1950-01-01") + np.timedelta64(632160, "h")],
},
)

sample_points = [Spacetime(Location(0, 0), 0)]

simulate_adcp(
fieldset=fieldset,
out_file_name="test",
max_depth=MAX_DEPTH,
min_depth=MIN_DEPTH,
bin_size=BIN_SIZE,
sample_points=sample_points,
)
9 changes: 4 additions & 5 deletions tests/instruments/test_argo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import numpy as np
from parcels import FieldSet

from virtual_ship.instruments import Location
from virtual_ship import Location, Spacetime
from virtual_ship.instruments.argo_float import ArgoFloat, simulate_argo_floats


def test_simulate_argo_floats() -> None:
DRIFT_DEPTH = -1000
MAX_DEPTH = -2000
VERTICLE_SPEED = -0.10
VERTICAL_SPEED = -0.10
CYCLE_DAYS = 10
DRIFT_DAYS = 9

Expand All @@ -29,12 +29,11 @@ def test_simulate_argo_floats() -> None:

argo_floats = [
ArgoFloat(
location=Location(latitude=0, longitude=0),
deployment_time=0,
spacetime=Spacetime(location=Location(latitude=0, longitude=0), time=0),
min_depth=min_depth,
max_depth=MAX_DEPTH,
drift_depth=DRIFT_DEPTH,
vertical_speed=VERTICLE_SPEED,
vertical_speed=VERTICAL_SPEED,
cycle_days=CYCLE_DAYS,
drift_days=DRIFT_DAYS,
)
Expand Down
38 changes: 38 additions & 0 deletions tests/instruments/test_ctd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Test the simulation of CTD instruments."""

from datetime import timedelta

import numpy as np
from parcels import FieldSet

from virtual_ship import Location, Spacetime
from virtual_ship.instruments.ctd import CTD, simulate_ctd


def test_simulate_ctds() -> None:
fieldset = FieldSet.from_data(
{"U": 0, "V": 0, "T": 0, "S": 0, "bathymetry": 100},
{
"lon": 0,
"lat": 0,
"time": [np.datetime64("1950-01-01") + np.timedelta64(632160, "h")],
},
)

min_depth = -fieldset.U.depth[0]
max_depth = -fieldset.U.depth[-1]

ctds = [
CTD(
spacetime=Spacetime(location=Location(latitude=0, longitude=0), time=0),
min_depth=min_depth,
max_depth=max_depth,
)
]

simulate_ctd(
ctds=ctds,
fieldset=fieldset,
out_file_name="test",
outputdt=timedelta(seconds=10),
)
36 changes: 36 additions & 0 deletions tests/instruments/test_drifters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Test the simulation of drifters."""

from datetime import timedelta

import numpy as np
from parcels import FieldSet

from virtual_ship import Location, Spacetime
from virtual_ship.instruments.drifter import Drifter, simulate_drifters


def test_simulate_drifters() -> None:
fieldset = FieldSet.from_data(
{"U": 0, "V": 0, "T": 0},
{
"lon": 0,
"lat": 0,
"time": [np.datetime64("1950-01-01") + np.timedelta64(632160, "h")],
},
)

min_depth = -fieldset.U.depth[0]

drifters = [
Drifter(
spacetime=Spacetime(location=Location(latitude=0, longitude=0), time=0),
min_depth=min_depth,
)
]

simulate_drifters(
drifters=drifters,
fieldset=fieldset,
out_file_name="test",
outputdt=timedelta(minutes=5),
)
29 changes: 29 additions & 0 deletions tests/instruments/test_ship_underwater_st.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Test the simulation of ship salinity temperature measurements."""

import numpy as np
from parcels import FieldSet

from virtual_ship import Location, Spacetime
from virtual_ship.instruments.ship_underwater_st import simulate_ship_underwater_st


def test_simulate_ship_underwater_st() -> None:
DEPTH = -2

fieldset = FieldSet.from_data(
{"U": 0, "V": 0, "S": 0, "T": 0},
{
"lon": 0,
"lat": 0,
"time": [np.datetime64("1950-01-01") + np.timedelta64(632160, "h")],
},
)

sample_points = [Spacetime(Location(0, 0), 0)]

simulate_ship_underwater_st(
fieldset=fieldset,
out_file_name="test",
depth=DEPTH,
sample_points=sample_points,
)
4 changes: 2 additions & 2 deletions tests/sailship_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
"bin_size_m": 24
},
"CTD_locations": [
[-23.071289, 63.743631]
[-23.081289, 63.743631]
],
"CTD_settings": {
"max_depth": "max"
},
"drifter_deploylocations": [

[-23.081289, 63.743631]
],
"argo_deploylocations": [
[-23.081289, 63.743631]
Expand Down
22 changes: 16 additions & 6 deletions tests/test_sailship.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,28 @@


def test_sailship() -> None:
adcp_fieldset = FieldSet.from_data(
{"U": 0, "V": 0},
{"lon": 0, "lat": 0},
)

ship_underwater_st_fieldset = FieldSet.from_data(
{"U": 0, "V": 0, "S": 0, "T": 0},
{"lon": 0, "lat": 0},
)

ctd_fieldset = FieldSet.from_data(
{"U": 0, "V": 0, "S": 0, "T": 0, "bathymetry": 0},
{"lon": 0, "lat": 0},
)
ctd_fieldset.add_constant("maxtime", ctd_fieldset.U.grid.time_full[-1])
ctd_fieldset.add_constant("mindepth", -ctd_fieldset.U.depth[0])
ctd_fieldset.add_constant("max_depth", -ctd_fieldset.U.depth[-1])

drifter_fieldset = FieldSet.from_data(
{"U": 0, "V": 0, "T": 0},
{
"U": 0,
"V": 0,
"lon": 0,
"lat": 0,
"time": [np.datetime64("1950-01-01") + np.timedelta64(632160, "h")],
},
{"lon": 0, "lat": 0},
)

argo_float_fieldset = FieldSet.from_data(
Expand All @@ -35,6 +43,8 @@ def test_sailship() -> None:

config = VirtualShipConfiguration(
"sailship_config.json",
adcp_fieldset=adcp_fieldset,
ship_underwater_st_fieldset=ship_underwater_st_fieldset,
ctd_fieldset=ctd_fieldset,
drifter_fieldset=drifter_fieldset,
argo_float_fieldset=argo_float_fieldset,
Expand Down
4 changes: 3 additions & 1 deletion virtual_ship/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Code for the Virtual Ship Classroom, where Marine Scientists can combine Copernicus Marine Data with an OceanParcels ship to go on a virtual expedition."""

from . import instruments, sailship
from .location import Location
from .spacetime import Spacetime

__all__ = ["instruments", "sailship"]
__all__ = ["Location", "Spacetime", "instruments", "sailship"]
10 changes: 7 additions & 3 deletions virtual_ship/costs.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
"""costs function."""

from datetime import timedelta

def costs(config, total_time):
from .virtual_ship_configuration import VirtualShipConfiguration


def costs(config: VirtualShipConfiguration, total_time: timedelta):
"""
Calculate the cost of the virtual ship (in US$).

:param config: The cruise configuration.
:param total_time: Time cruised in seconds.
:param total_time: Time cruised.
:returns: The calculated cost of the cruise.
"""
ship_cost_per_day = 30000
drifter_deploy_cost = 2500
argo_deploy_cost = 15000

ship_cost = ship_cost_per_day / 24 * total_time // 3600
ship_cost = ship_cost_per_day / 24 * total_time.total_seconds() // 3600
argo_cost = len(config.argo_deploylocations) * argo_deploy_cost
drifter_cost = len(config.drifter_deploylocations) * drifter_deploy_cost

Expand Down
Loading