Skip to content

Conversation

@surgura
Copy link
Contributor

@surgura surgura commented May 24, 2024

  • 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.

@surgura surgura changed the base branch from main to development May 24, 2024 13:16
@surgura surgura marked this pull request as ready for review May 24, 2024 14:16
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
Contributor 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.

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?

Comment on lines 3 to 4
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
Contributor 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.

Comment on lines 34 to 45
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)
Copy link
Member

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 (Parcels-code/Parcels#1501), you can also make this cleaner as

Suggested change
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),
])

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

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

)

# get time when the fieldset ends
fieldset_endtime = fieldset.time_origin.fulltime(fieldset.U.grid.time_full[-1])
Copy link
Member

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?

Copy link
Collaborator

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

Copy link
Contributor Author

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?

Copy link
Collaborator

@ammedd ammedd left a 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

drift_days: float


class _ArgoParticle(JITParticle):
Copy link
Collaborator

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?

Copy link
Contributor Author

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

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)
Copy link
Collaborator

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

Copy link
Contributor Author

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?

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)
Copy link
Collaborator

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?

Copy link
Contributor Author

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?

"""
lon = [argo.location.lon for argo in argos]
lat = [argo.location.lat for argo in argos]
time = [argo.deployment_time for argo in argos]
Copy link
Collaborator

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?

Copy link
Contributor Author

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

)

# get time when the fieldset ends
fieldset_endtime = fieldset.time_origin.fulltime(fieldset.U.grid.time_full[-1])
Copy link
Collaborator

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 ...

@@ -0,0 +1,29 @@
"""Location class."""
Copy link
Collaborator

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?

Copy link
Contributor Author

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

)

# get time when the fieldset ends
fieldset_endtime = fieldset.time_origin.fulltime(fieldset.U.grid.time_full[-1])
Copy link
Collaborator

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

Copy link
Collaborator

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

surgura and others added 4 commits May 27, 2024 17:05
Co-authored-by: Erik van Sebille <erikvansebille@gmail.com>
Co-authored-by: Erik van Sebille <erikvansebille@gmail.com>
Co-authored-by: Erik van Sebille <erikvansebille@gmail.com>
@surgura surgura requested review from ammedd and erikvansebille May 28, 2024 14:25
Copy link
Member

@erikvansebille erikvansebille left a 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
Copy link
Member

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

Suggested change
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
Copy link
Member

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

Suggested change
pytest --cov=virtual_ship --cov-report=html tests
pytest -v --cov=virtual_ship --cov-report=html tests

Comment on lines 34 to 45
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)
Copy link
Member

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

@surgura surgura merged commit d6307b9 into development May 29, 2024
@surgura surgura deleted the basic_test branch May 29, 2024 15:03
surgura added a commit that referenced this pull request Aug 18, 2024
    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.
VeckoTheGecko pushed a commit that referenced this pull request Sep 25, 2024
    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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants