-
Notifications
You must be signed in to change notification settings - Fork 4
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
Basic test #33
Conversation
…ata directory a parameter instead of hardcoded
…sed through the config object. Create test that runs a very simple cruise
tests/conftest.py
Outdated
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
tests/sailship_config.json
Outdated
There was a problem hiding this comment.
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?
tests/test_sailship.py
Outdated
from virtual_ship.virtual_ship_configuration import VirtualShipConfiguration | ||
from virtual_ship.sailship import sailship |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
virtual_ship/instruments/argo.py
Outdated
class _ArgoParticle(JITParticle): | ||
cycle_phase = Variable("cycle_phase", dtype=np.int32, initial=0.0) | ||
cycle_age = Variable("cycle_age", dtype=np.float32, initial=0.0) | ||
drift_age = Variable("drift_age", dtype=np.float32, initial=0.0) | ||
salinity = Variable("salinity", initial=np.nan) | ||
temperature = Variable("temperature", initial=np.nan) | ||
min_depth = Variable("min_depth", dtype=np.float32) | ||
max_depth = Variable("max_depth", dtype=np.float32) | ||
drift_depth = Variable("drift_depth", dtype=np.float32) | ||
vertical_speed = Variable("vertical_speed", dtype=np.float32) | ||
cycle_days = Variable("cycle_days", dtype=np.int32) | ||
drift_days = Variable("drift_days", dtype=np.int32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Parcels v3.0.2 (OceanParcels/Parcels#1501), you can also make this cleaner as
class _ArgoParticle(JITParticle): | |
cycle_phase = Variable("cycle_phase", dtype=np.int32, initial=0.0) | |
cycle_age = Variable("cycle_age", dtype=np.float32, initial=0.0) | |
drift_age = Variable("drift_age", dtype=np.float32, initial=0.0) | |
salinity = Variable("salinity", initial=np.nan) | |
temperature = Variable("temperature", initial=np.nan) | |
min_depth = Variable("min_depth", dtype=np.float32) | |
max_depth = Variable("max_depth", dtype=np.float32) | |
drift_depth = Variable("drift_depth", dtype=np.float32) | |
vertical_speed = Variable("vertical_speed", dtype=np.float32) | |
cycle_days = Variable("cycle_days", dtype=np.int32) | |
drift_days = Variable("drift_days", dtype=np.int32) | |
class _ArgoParticle = JITParticle.add_variables([ | |
Variable("cycle_phase", dtype=np.int32, initial=0.0), | |
Variable("cycle_age", dtype=np.float32, initial=0.0), | |
Variable("drift_age", dtype=np.float32, initial=0.0), | |
Variable("salinity", initial=np.nan), | |
Variable("temperature", initial=np.nan), | |
Variable("min_depth", dtype=np.float32), | |
Variable("max_depth", dtype=np.float32), | |
Variable("drift_depth", dtype=np.float32), | |
Variable("vertical_speed", dtype=np.float32), | |
Variable("cycle_days", dtype=np.int32), | |
Variable("drift_days", dtype=np.int32), | |
]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if this is cleaner. If we later introduce a type checker this is probably harder to check than the original class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's cleaner because users can easily create bugs/issues when the varname on the left side of the equal sign is not the same as the varname in the Variable object; that is why I want to move away from the varname = Variable(varname)
way of declaring. So I would strongly advice to change to the new way of creating a new Particle Class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing duplication makes sense, I replaced. Regarding parcels, you could also look at the dataclass and fields API and try do something similar: https://www.studytonight.com/post/python-dataclass-field-function-part-3
virtual_ship/instruments/argo.py
Outdated
) | ||
|
||
# get time when the fieldset ends | ||
fieldset_endtime = fieldset.time_origin.fulltime(fieldset.U.grid.time_full[-1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we run to the end of the fieldset?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We allowed 6 max weeks of floating time, 3 week ship time + 3 weeks after cruise ended, but since they are deployed at different times end times would also have been different if set at 6 weeks, this was our workaround
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can discuss. Right now I attempted to reproduce the original code as much as possible. Maybe we can have an end time for every argo? I assume that if the end time of the argo is later than the end time of the fieldset that is an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Left some comments about documentation and questions
virtual_ship/instruments/argo.py
Outdated
drift_days: float | ||
|
||
|
||
class _ArgoParticle(JITParticle): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a next step you will test for JIT and SciPy right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the tests will be expanded later
virtual_ship/instruments/argo.py
Outdated
max_depth = Variable("max_depth", dtype=np.float32) | ||
drift_depth = Variable("drift_depth", dtype=np.float32) | ||
vertical_speed = Variable("vertical_speed", dtype=np.float32) | ||
cycle_days = Variable("cycle_days", dtype=np.int32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I would use float ipv int for flexibility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean that you want fractional days?
virtual_ship/instruments/argo.py
Outdated
drift_age = Variable("drift_age", dtype=np.float32, initial=0.0) | ||
salinity = Variable("salinity", initial=np.nan) | ||
temperature = Variable("temperature", initial=np.nan) | ||
min_depth = Variable("min_depth", dtype=np.float32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you being so explicit about defining these instead of letting parcels create them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what you mean?
virtual_ship/instruments/argo.py
Outdated
""" | ||
lon = [argo.location.lon for argo in argos] | ||
lat = [argo.location.lat for argo in argos] | ||
time = [argo.deployment_time for argo in argos] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any check if Lon, lat and time have the same length? Otherwise it fails? or cycles through the shorter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All three loops cycle over the the same argo float array
virtual_ship/instruments/argo.py
Outdated
) | ||
|
||
# get time when the fieldset ends | ||
fieldset_endtime = fieldset.time_origin.fulltime(fieldset.U.grid.time_full[-1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future it would be good to have multiple reasons to end the simulation, not just the end of the fieldset, but also a predefined time, or ...
virtual_ship/instruments/location.py
Outdated
@@ -0,0 +1,29 @@ | |||
"""Location class.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not clear to me yet how you will use this class. Can you explain? or is this for later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The discription for the class is in the docstring of the class. I did not want to repeat the description, so this docstring is fairly useless. It is used in the instruments to define a location on the globe
virtual_ship/instruments/argo.py
Outdated
) | ||
|
||
# get time when the fieldset ends | ||
fieldset_endtime = fieldset.time_origin.fulltime(fieldset.U.grid.time_full[-1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We allowed 6 max weeks of floating time, 3 week ship time + 3 weeks after cruise ended, but since they are deployed at different times end times would also have been different if set at 6 weeks, this was our workaround
virtual_ship/sailship.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file changed too much from my file for me to oversee the differences. I'll leave it to Erik or until we discuss
Co-authored-by: Erik van Sebille <[email protected]>
Co-authored-by: Erik van Sebille <[email protected]>
Co-authored-by: Erik van Sebille <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved, except for changing the custom Particle Class (see comment above about the ArgoParticle)
- name: install | ||
run: pip install ".[dev]" | ||
- name: run_tests | ||
run: pytest --cov=virtual_ship tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add extra verbose/debug output to pytest
run: pytest --cov=virtual_ship tests | |
run: pytest -v --cov=virtual_ship tests |
|
||
# Runs the tests and creates a code coverage report. | ||
|
||
pytest --cov=virtual_ship --cov-report=html tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here add extra verbose/debug output
pytest --cov=virtual_ship --cov-report=html tests | |
pytest -v --cov=virtual_ship --cov-report=html tests |
virtual_ship/instruments/argo.py
Outdated
class _ArgoParticle(JITParticle): | ||
cycle_phase = Variable("cycle_phase", dtype=np.int32, initial=0.0) | ||
cycle_age = Variable("cycle_age", dtype=np.float32, initial=0.0) | ||
drift_age = Variable("drift_age", dtype=np.float32, initial=0.0) | ||
salinity = Variable("salinity", initial=np.nan) | ||
temperature = Variable("temperature", initial=np.nan) | ||
min_depth = Variable("min_depth", dtype=np.float32) | ||
max_depth = Variable("max_depth", dtype=np.float32) | ||
drift_depth = Variable("drift_depth", dtype=np.float32) | ||
vertical_speed = Variable("vertical_speed", dtype=np.float32) | ||
cycle_days = Variable("cycle_days", dtype=np.int32) | ||
drift_days = Variable("drift_days", dtype=np.int32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's cleaner because users can easily create bugs/issues when the varname on the left side of the equal sign is not the same as the varname in the Variable object; that is why I want to move away from the varname = Variable(varname)
way of declaring. So I would strongly advice to change to the new way of creating a new Particle Class
Created test framework Added test that runs sail_ship complete. No assertions yet; just to see if it runs. Seperated Argo simulation as a seperate module in instruments/argo. Created test for it; similarly without assertions. Added tests to CI. Full code coverage is not generated or uploaded anywhere yet. Just runs the tests and sees how that goes.
Created test framework Added test that runs sail_ship complete. No assertions yet; just to see if it runs. Seperated Argo simulation as a seperate module in instruments/argo. Created test for it; similarly without assertions. Added tests to CI. Full code coverage is not generated or uploaded anywhere yet. Just runs the tests and sees how that goes.
sail_ship
complete. No assertions yet; just to see if it runs.instruments/argo
. Created test for it; similarly without assertions.