Skip to content

Commit

Permalink
integrated into opendrift logging, moved xroms to pip
Browse files Browse the repository at this point in the history
  • Loading branch information
kthyng committed Jan 16, 2024
1 parent 62dac7d commit 67a1c47
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 17 deletions.
3 changes: 2 additions & 1 deletion ci/environment-py3.10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ dependencies:
- opendrift
- scipy
- xarray
- xroms
# - xroms
##############
- pytest
- pip:
- codecov
- pytest-cov
- coverage[toml]
- xroms # can't be found on conda-forge for CI
3 changes: 2 additions & 1 deletion ci/environment-py3.11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ dependencies:
- opendrift
- scipy
- xarray
- xroms
# - xroms
##############
- pytest
- pip:
- codecov
- pytest-cov
- coverage[toml]
- xroms # can't be found on conda-forge for CI
3 changes: 2 additions & 1 deletion ci/environment-py3.9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ dependencies:
- opendrift
- scipy
- xarray
- xroms
# - xroms
##############
- pytest
- pip:
- codecov
- pytest-cov
- coverage[toml]
- xroms # can't be found on conda-forge for CI
26 changes: 24 additions & 2 deletions docs/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ kernelspec:

+++

The simplest way to run `particle-tracking-manager` is to choose a built-in ocean model and select a location to initialize drifters, then use the built-in defaults for everything else (including start time which defaults to the first time step in the model output). You can do this interacting with the software as a Python library or using a command line interface.
The simplest way to run `particle-tracking-manager` is to choose a built-in ocean model and select a location to initialize drifters, then use the built-in defaults for everything else (including start time which defaults to the first time step in the model output). You can do this interacting with the software as a Python library or using a command line interface.

Alternatively, you can run the package with new model output by inputting the necessary information into the `Manager`.

Expand Down Expand Up @@ -88,6 +88,28 @@ m.seed()
m.run()
```

```{code-cell} ipython3
## Ways to Get Information

Check drifter initialization properties:

```
m.initial_drifters
```

Look at reader/ocean model properties:

```
m.reader
```

Get reader/ocean model properties (gathered metadata about model):

```
m.reader_metadata(key)
```

Show configuration details — many more details on this in {doc}`configuration`:

```
m.show_config()
```
16 changes: 10 additions & 6 deletions particle_tracking_manager/models/opendrift/model_opendrift.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Using OpenDrift for particle tracking."""
import copy
import datetime
import logging
import pathlib

import pandas as pd
Expand Down Expand Up @@ -42,6 +43,9 @@
overall_start_time = datetime.datetime(1999, 1, 1, 0, 0, 0)
overall_end_time = ciofs_operational_end_time


# logger = logging.getLogger("opendrift")


# @copydocstring( ParticleTrackingManager )
class OpenDriftModel(ParticleTrackingManager):
Expand Down Expand Up @@ -271,7 +275,7 @@ def __setattr_model__(self, name: str, value) -> None:
self, "horizontal_diffusivity"
):

print(
self.logger.info(
"overriding horizontal_diffusivity parameter with one tuned to reader model"
)

Expand All @@ -296,7 +300,7 @@ def __setattr_model__(self, name: str, value) -> None:
and self.horizontal_diffusivity is None
):

print(
self.logger.info(
"changing horizontal_diffusivity parameter from None to 0.0. Otherwise set it to a specific value."
)

Expand All @@ -311,7 +315,7 @@ def __setattr_model__(self, name: str, value) -> None:
"CIOFS_now",
]:

print(
self.logger.info(
"overriding horizontal_diffusivity parameter with one tuned to reader model"
)

Expand Down Expand Up @@ -341,7 +345,7 @@ def __setattr_model__(self, name: str, value) -> None:
"CIOFS_now",
]:

print(
self.logger.info(
"changing horizontal_diffusivity parameter from None to 0.0. Otherwise set it to a specific value."
)

Expand All @@ -367,15 +371,15 @@ def __setattr_model__(self, name: str, value) -> None:
and hasattr(self, "o")
):
if self.surface_only and self.drift_model != "Leeway":
print("Truncating model output below 0.5 m.")
self.logger.info("Truncating model output below 0.5 m.")
self.o.set_config("drift:truncate_ocean_model_below_m", 0.5)
elif (
not self.surface_only
and self.drift_model != "Leeway"
and self.show_config(key="drift:truncate_ocean_model_below_m")["value"]
is not None
):
print("Un-truncating model output below 0.5 m.")
self.logger.info("Un-truncating model output below 0.5 m.")
self.o.set_config("drift:truncate_ocean_model_below_m", None)

# Leeway doesn't have this option available
Expand Down
15 changes: 9 additions & 6 deletions particle_tracking_manager/the_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# from docstring_inheritance import NumpyDocstringInheritanceMeta
import datetime
import logging
import pathlib
import warnings

Expand Down Expand Up @@ -142,6 +143,8 @@ def __init__(
sig = signature(ParticleTrackingManager)

self.config_ptm = config_ptm

self.logger = logging.getLogger(model)

# Set all attributes which will trigger some checks and changes in __setattr__
# these will also update "value" in the config dict
Expand Down Expand Up @@ -198,7 +201,7 @@ def __setattr__(self, name: str, value) -> None:
self.__dict__["lon"] += 360

if name == "surface_only" and value:
print(
self.logger.info(
"overriding values for `do3D`, `z`, and `vertical_mixing` because `surface_only` True"
)
self.do3D = False
Expand All @@ -208,7 +211,7 @@ def __setattr__(self, name: str, value) -> None:
# in case any of these are reset by user after surface_only is already set
if name in ["do3D", "z", "vertical_mixing"]:
if hasattr(self, "surface_only") and self.surface_only:
print(
self.logger.info(
"overriding values for `do3D`, `z`, and `vertical_mixing` because `surface_only` True"
)
if name == "do3D":
Expand All @@ -222,19 +225,19 @@ def __setattr__(self, name: str, value) -> None:

# if not 3D turn off vertical_mixing
if hasattr(self, "do3D") and not self.do3D:
print("turning off vertical_mixing since do3D is False")
self.logger.info("turning off vertical_mixing since do3D is False")
self.__dict__["vertical_mixing"] = False
self.config_ptm["vertical_mixing"]["value"] = False
# self.vertical_mixing = False # this is recursive

# set z to None if seed_seafloor is True
if name == "seed_seafloor" and value:
print("setting z to None since being seeded at seafloor")
self.logger.info("setting z to None since being seeded at seafloor")
self.z = None

# in case z is changed back after initialization
if name == "z" and value is not None and hasattr(self, "seed_seafloor"):
print(
self.logger.info(
"setting `seed_seafloor` to False since now setting a non-None z value"
)
self.seed_seafloor = False
Expand All @@ -260,7 +263,7 @@ def __setattr__(self, name: str, value) -> None:

# use reader start time if not otherwise input
if name == "has_added_reader" and value and self.start_time is None:
print("setting reader start_time as simulation start_time")
self.logger.info("setting reader start_time as simulation start_time")
self.start_time = self.reader_metadata("start_time")

# if reader, lon, and lat set, check inputs
Expand Down

0 comments on commit 67a1c47

Please sign in to comment.