Skip to content

Commit

Permalink
still trying to fix windows error
Browse files Browse the repository at this point in the history
  • Loading branch information
kthyng committed Jan 17, 2024
1 parent 3b4e520 commit a5222dd
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 36 deletions.
2 changes: 1 addition & 1 deletion 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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
if "default" in config_model[key] and is_None(config_model[key]["default"]):
config_model[key]["default"] = None


# logger = logging.getLogger("opendrift")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ def __init__(
kwargs_xarray=None,
):
"""Initialize ROMS model reader."""

import pdb; pdb.set_trace()

if filename is None:
raise ValueError("Need filename as argument to constructor")
Expand Down
16 changes: 12 additions & 4 deletions particle_tracking_manager/the_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ 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__
Expand Down Expand Up @@ -202,14 +202,22 @@ def __setattr__(self, name: str, value) -> None:

# check start_time relative to ocean_model selection
if name in ["ocean_model", "start_time"]:
if hasattr(self, "start_time") and self.start_time is not None and \
hasattr(self, "ocean_model") and self.ocean_model is not None:
if (
hasattr(self, "start_time")
and self.start_time is not None
and hasattr(self, "ocean_model")
and self.ocean_model is not None
):
if value == "NWGOA":
assert overall_start_time <= value <= nwgoa_end_time
elif value == "CIOFS":
assert overall_start_time <= value <= ciofs_end_time
elif value == "CIOFS_NOW":
assert ciofs_operational_start_time <= value <= ciofs_operational_end_time
assert (
ciofs_operational_start_time
<= value
<= ciofs_operational_end_time
)

# deal with if input longitudes need to be shifted due to model
if name == "oceanmodel_lon0_360" and value:
Expand Down
17 changes: 12 additions & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import os

from datetime import datetime

import pytest
from datetime import datetime

import particle_tracking_manager as ptm

Expand All @@ -14,13 +15,19 @@ def test_setup():
No drifters are run due to oceanmodel=None
"""
ret_value = os.system(
f"python {ptm.__path__[0]}/cli.py ocean_model='test' lon=-151 lat=59 use_auto_landmask=True start_time='2000-1-1'"
f"python {ptm.__path__[0]}/cli.py ocean_model=test lon=-151 lat=59 use_auto_landmask=True start_time='2000-1-1'"
)
assert ret_value == 0


def test_setup_library():
"""Same test but with library"""

m = ptm.OpenDriftModel(ocean_model='test', lon=-151, lat=59, use_auto_landmask=True, start_time=datetime(2000,1,1))
m.run_all()

m = ptm.OpenDriftModel(
ocean_model="test",
lon=-151,
lat=59,
use_auto_landmask=True,
start_time=datetime(2000, 1, 1),
)
m.run_all()
91 changes: 70 additions & 21 deletions tests/test_opendrift_init.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
"""From Copilot"""

import unittest
from particle_tracking_manager.models.opendrift.model_opendrift import OpenDriftModel, config_model

from particle_tracking_manager.models.opendrift.model_opendrift import (
OpenDriftModel,
config_model,
)


class TestOpenDriftModel(unittest.TestCase):
def setUp(self):
Expand All @@ -12,35 +17,79 @@ def test_init(self):
self.assertEqual(self.odm.radius, config_model["radius"]["default"])
self.assertEqual(self.odm.radius_type, config_model["radius_type"]["default"])
# self.assertEqual(self.odm.horizontal_diffusivity, config_model["horizontal_diffusivity"]["default"])
self.assertEqual(self.odm.use_auto_landmask, config_model["use_auto_landmask"]["default"])
self.assertEqual(self.odm.diffusivitymodel, config_model["diffusivitymodel"]["default"])
self.assertEqual(
self.odm.use_auto_landmask, config_model["use_auto_landmask"]["default"]
)
self.assertEqual(
self.odm.diffusivitymodel, config_model["diffusivitymodel"]["default"]
)
self.assertEqual(self.odm.stokes_drift, config_model["stokes_drift"]["default"])
self.assertEqual(self.odm.mixed_layer_depth, config_model["mixed_layer_depth"]["default"])
self.assertEqual(self.odm.coastline_action, config_model["coastline_action"]["default"])
self.assertEqual(
self.odm.mixed_layer_depth, config_model["mixed_layer_depth"]["default"]
)
self.assertEqual(
self.odm.coastline_action, config_model["coastline_action"]["default"]
)
self.assertEqual(self.odm.max_speed, config_model["max_speed"]["default"])
self.assertEqual(self.odm.wind_drift_factor, config_model["wind_drift_factor"]["default"])
self.assertEqual(self.odm.wind_drift_depth, config_model["wind_drift_depth"]["default"])
self.assertEqual(self.odm.vertical_mixing_timestep, config_model["vertical_mixing_timestep"]["default"])
self.assertEqual(
self.odm.wind_drift_factor, config_model["wind_drift_factor"]["default"]
)
self.assertEqual(
self.odm.wind_drift_depth, config_model["wind_drift_depth"]["default"]
)
self.assertEqual(
self.odm.vertical_mixing_timestep,
config_model["vertical_mixing_timestep"]["default"],
)
self.assertEqual(self.odm.object_type, config_model["object_type"]["default"])
self.assertEqual(self.odm.diameter, config_model["diameter"]["default"])
self.assertEqual(self.odm.neutral_buoyancy_salinity, config_model["neutral_buoyancy_salinity"]["default"])
self.assertEqual(self.odm.stage_fraction, config_model["stage_fraction"]["default"])
self.assertEqual(
self.odm.neutral_buoyancy_salinity,
config_model["neutral_buoyancy_salinity"]["default"],
)
self.assertEqual(
self.odm.stage_fraction, config_model["stage_fraction"]["default"]
)
self.assertEqual(self.odm.hatched, config_model["hatched"]["default"])
self.assertEqual(self.odm.length, config_model["length"]["default"])
self.assertEqual(self.odm.weight, config_model["weight"]["default"])
self.assertEqual(self.odm.oil_type, config_model["oil_type"]["default"])
self.assertEqual(self.odm.m3_per_hour, config_model["m3_per_hour"]["default"])
self.assertEqual(self.odm.oil_film_thickness, config_model["oil_film_thickness"]["default"])
self.assertEqual(self.odm.droplet_size_distribution, config_model["droplet_size_distribution"]["default"])
self.assertEqual(self.odm.droplet_diameter_mu, config_model["droplet_diameter_mu"]["default"])
self.assertEqual(self.odm.droplet_diameter_sigma, config_model["droplet_diameter_sigma"]["default"])
self.assertEqual(self.odm.droplet_diameter_min_subsea, config_model["droplet_diameter_min_subsea"]["default"])
self.assertEqual(self.odm.droplet_diameter_max_subsea, config_model["droplet_diameter_max_subsea"]["default"])
self.assertEqual(self.odm.emulsification, config_model["emulsification"]["default"])
self.assertEqual(
self.odm.oil_film_thickness, config_model["oil_film_thickness"]["default"]
)
self.assertEqual(
self.odm.droplet_size_distribution,
config_model["droplet_size_distribution"]["default"],
)
self.assertEqual(
self.odm.droplet_diameter_mu, config_model["droplet_diameter_mu"]["default"]
)
self.assertEqual(
self.odm.droplet_diameter_sigma,
config_model["droplet_diameter_sigma"]["default"],
)
self.assertEqual(
self.odm.droplet_diameter_min_subsea,
config_model["droplet_diameter_min_subsea"]["default"],
)
self.assertEqual(
self.odm.droplet_diameter_max_subsea,
config_model["droplet_diameter_max_subsea"]["default"],
)
self.assertEqual(
self.odm.emulsification, config_model["emulsification"]["default"]
)
self.assertEqual(self.odm.dispersion, config_model["dispersion"]["default"])
self.assertEqual(self.odm.evaporation, config_model["evaporation"]["default"])
self.assertEqual(self.odm.update_oilfilm_thickness, config_model["update_oilfilm_thickness"]["default"])
self.assertEqual(self.odm.biodegradation, config_model["biodegradation"]["default"])
self.assertEqual(
self.odm.update_oilfilm_thickness,
config_model["update_oilfilm_thickness"]["default"],
)
self.assertEqual(
self.odm.biodegradation, config_model["biodegradation"]["default"]
)


if __name__ == '__main__':
unittest.main()
if __name__ == "__main__":
unittest.main()
10 changes: 8 additions & 2 deletions tests/test_ptm_init.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
"""From Co-pilot"""

import unittest

from datetime import datetime, timedelta

import particle_tracking_manager as ptm


# from ptm.the_manager import ParticleTrackingManager


class TestParticleTrackingManager(unittest.TestCase):
def setUp(self):
self.ptm = ptm.ParticleTrackingManager(model="opendrift")
Expand Down Expand Up @@ -74,5 +79,6 @@ def test_set_end_time(self):
self.ptm.end_time = end_time
self.assertEqual(self.ptm.end_time, end_time)

if __name__ == '__main__':
unittest.main()

if __name__ == "__main__":
unittest.main()
1 change: 1 addition & 0 deletions tests/test_realistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def test_run():
"""Set up and run."""

import xroms

seeding_kwargs = dict(lon=-90, lat=28.7, number=1)
manager = ptm.OpenDriftModel(**seeding_kwargs)

Expand Down

0 comments on commit a5222dd

Please sign in to comment.