Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic test #33

Merged
merged 29 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
16159dc
Move deployments and postprocessing into sailship function and make d…
surgura Apr 30, 2024
a41afab
ignore .vscode/
surgura Apr 30, 2024
dbb7f0d
ignore .vscode/
surgura Apr 30, 2024
34a44a7
Crudely move fieldset creation out of sailship and onto the user, pas…
surgura Apr 30, 2024
56f44b5
Create sensors module, starting with argos. create basic test for argos.
surgura May 22, 2024
fd6f84e
Use argo sensor in sailship function
surgura May 22, 2024
17948e1
rename sensors to instruments
surgura May 24, 2024
0a6ab7a
rename sensors to instruments
surgura May 24, 2024
c2bb72f
Resolved codetools errors
surgura May 24, 2024
528d1b3
Make constants individual parameters for argos
surgura May 24, 2024
02ee54d
update sailship to use new argo function
surgura May 24, 2024
a694733
whitespace
surgura May 24, 2024
635110e
whitespace
surgura May 24, 2024
72a83cd
comment
surgura May 24, 2024
ad173e2
Add running tests with codecov
surgura May 24, 2024
89f88a6
Add missing dependency
surgura May 24, 2024
49c7d50
Add missing dependencies
surgura May 24, 2024
e566bdb
fix dependency?
surgura May 24, 2024
9ad6008
fix dependency?
surgura May 24, 2024
c4d4555
Add missing newline
surgura May 27, 2024
87b040f
Comments update
surgura May 27, 2024
3e42563
Docstring update
surgura May 27, 2024
01ffb83
Rename argos to argo floats
surgura May 28, 2024
1e1267f
Create proper init.py
surgura May 28, 2024
3b65eca
make outputdf a parameters for argos
surgura May 28, 2024
36ead1b
Minor docstring update
surgura May 28, 2024
5186d7e
minor variable renaming
surgura May 28, 2024
8bb7ee2
Run codetools on tests
surgura May 28, 2024
1cf2082
Use new parcels particle api
surgura May 29, 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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,5 @@ cython_debug/

# Auto generated by setuptools scm
virtual_ship/_version_setup.py

.vscode/
Empty file modified codetools.sh
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dev = [
"isort == 5.13.2",
"pydocstyle == 6.3.0",
"sort-all == 1.2.0",
"pytest == 8.2.0",
]

[tool.isort]
Expand Down
7 changes: 7 additions & 0 deletions tests/conftest.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? We don't have this in parcels. What does this file do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ran for every test. It chanced the working directory of the test to the directory of the test itself. The reason I did this is because the config json is next to the test, and since the working directory was at the project root I had to type the path to the file.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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):
monkeypatch.chdir(request.fspath.dirname)
40 changes: 40 additions & 0 deletions tests/instruments/test_argo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Test the simulation of argos."""

from virtual_ship.instruments.argo import simulate_argos, Argo
from virtual_ship.instruments.location import Location
from parcels import FieldSet
import numpy as np


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

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

min_depth = -fieldset.U.depth[0]

argos = [
Argo(
location=Location(latitude=0, longitude=0),
deployment_time=0,
min_depth=min_depth,
max_depth=MAX_DEPTH,
drift_depth=DRIFT_DEPTH,
vertical_speed=VERTICLE_SPEED,
cycle_days=CYCLE_DAYS,
drift_days=DRIFT_DAYS,
)
]

simulate_argos(argos=argos, fieldset=fieldset, out_file_name="test")
40 changes: 40 additions & 0 deletions tests/sailship_config.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR, but at some point we should reconsider whether we want to keep using json files. We could also move to yaml-files (with the advantage of allowing comments) or another format?

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"region_of_interest": {
"North": 64,
"East": -23,
"South": 59,
"West": -43
},
"requested_ship_time": {
"start": "2022-01-01T00:00:00",
"end": "2022-01-2T00:00:00"
},
"route_coordinates": [
[-23.071289, 63.743631], [-23.081289, 63.743631], [-23.091289, 63.743631]
],
"underway_data": true,
"ADCP_data": false,
"ADCP_settings": {
"max_depth": -1000,
"bin_size_m": 24
},
"CTD_locations": [
[-23.071289, 63.743631]
],
"CTD_settings": {
"max_depth": "max"
},
"drifter_deploylocations": [

],
"argo_deploylocations": [
[-23.081289, 63.743631]
],
"argo_characteristics": {
"driftdepth": -1000,
"maxdepth": -2000,
"vertical_speed": -0.10,
"cycle_days" : 10,
"drift_days": 9
}
}
42 changes: 42 additions & 0 deletions tests/test_sailship.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Performs a complete cruise with virtual ship."""

from virtual_ship.virtual_ship_configuration import VirtualShipConfiguration
from virtual_ship.sailship import sailship
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In plasticparcels, we've started to move to a API that is more like numpy etc, where we use an abbreviation (vship?) for all functions. E.g.

import virtualship as vship

config = vship.Configuration(...)
vship.sailship(config)

Should we start doing that here too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me. Regarding the API(what is exported where in which modules), I will look at that after I've finished the first cleanup round.

from parcels import FieldSet
import numpy as np


def test_sailship() -> None:
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,
},
{"lon": 0, "lat": 0},
)

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

config = VirtualShipConfiguration(
"sailship_config.json",
ctd_fieldset=ctd_fieldset,
drifter_fieldset=drifter_fieldset,
argo_fieldset=argo_fieldset,
)

sailship(config)
189 changes: 0 additions & 189 deletions virtual_ship/argo_deployments.py

This file was deleted.

16 changes: 9 additions & 7 deletions virtual_ship/drifter_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import numpy as np
from parcels import AdvectionRK4, FieldSet, JITParticle, ParticleSet, Variable

from .virtual_ship_configuration import VirtualShipConfiguration

def drifter_deployments(config, drifter_time):

def drifter_deployments(config: VirtualShipConfiguration, drifter_time):
"""
Deploy drifters.

Expand All @@ -17,7 +19,7 @@ def drifter_deployments(config, drifter_time):
"""
if len(config.drifter_deploylocations) > 0:

fieldset = create_drifter_fieldset(config)
fieldset = config.drifter_fieldset

# Create particle to sample water underway
class DrifterParticle(JITParticle):
Expand Down Expand Up @@ -74,18 +76,18 @@ def CheckError(particle, fieldset, time):
)


def create_drifter_fieldset(config):
def create_drifter_fieldset(config, data_dir: str):
"""
Create a fieldset from netcdf files for drifters, returns fieldset with negative depth values.

:param config: The cruise configuration.
:param data_dir: TODO
:returns: The fieldset.
"""
datadirname = os.path.dirname(__file__)
filenames = {
"U": os.path.join(datadirname, "drifterdata_UV.nc"),
"V": os.path.join(datadirname, "drifterdata_UV.nc"),
"T": os.path.join(datadirname, "drifterdata_T.nc"),
"U": os.path.join(data_dir, "drifterdata_UV.nc"),
"V": os.path.join(data_dir, "drifterdata_UV.nc"),
"T": os.path.join(data_dir, "drifterdata_T.nc"),
}
variables = {"U": "uo", "V": "vo", "T": "thetao"}
dimensions = {
Expand Down
Loading