Skip to content

Commit 3e02b94

Browse files
committed
just wrapping up
1 parent dfb34c5 commit 3e02b94

17 files changed

+1643
-47
lines changed

docs/environment.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@ channels:
33
- conda-forge
44
- nodefaults
55
dependencies:
6-
- python=3.10
6+
- python>=3.11
77
# If your docs code examples depend on other packages add them here
88
- adios_db
99
- aiohttp
1010
- appdirs
1111
- cmocean
1212
- fastparquet
13-
- geojson_pydantic
1413
- numpy
1514
- xarray
16-
- kerchunk
15+
- kerchunk==0.2.7
1716
- numpydoc
1817
- opendrift==1.13.0
1918
# These are needed for the docs themselves

docs/tutorial.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ There are also specific seeding options for this model:
211211

212212
```{code-cell} ipython3
213213
m = ptm.OpenDriftModel(drift_model="OpenOil", lon=-89.85, lat=28.08, number=10, steps=45,
214-
z=-10, do3D=True, oil_type='Cook Inlet [2003] (EC00561)',
214+
z=-10, do3D=True, oil_type='Cook Inlet [2003]',
215215
start_time="2009-11-19T12:00", ocean_model="TXLA",
216216
ocean_model_local=False,
217217
)
@@ -220,12 +220,14 @@ m.o.set_config('environment:constant:x_wind', -1)
220220
m.o.set_config('environment:constant:y_wind', 1)
221221
```
222222

223-
List available oil types from NOAA's ADIOS database:
223+
List available oil types from NOAA's ADIOS database (or check the database online):
224224

225225
```{code-cell} ipython3
226226
ptm.OpenOilModelConfig.model_json_schema()["$defs"]["OilTypeEnum"]["enum"]
227227
```
228228

229+
You can instead refer to the `oil_type` by its id, for example in this case `oil_tye='EC00561'` would work.
230+
229231
The configuration parameters for this simulation are:
230232

231233
```{code-cell} ipython3

docs/whats_new.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# What's New
22

3-
## Unreleased
3+
## v0.12.0 (April 9, 2025)
44

55
* Suffix for parquet file format is now ".parquet" instead of ".parq".
66
* Added a method to run plots from saved OpenDrift output file; also available in CLI. Updated docs.
@@ -16,8 +16,11 @@
1616
* can run plots from a parquet or netcdf output file now
1717
* can't run idealized simulations using `OpenDrift` directly in PTM anymore but this could be added back in if needed
1818
* updated docs
19-
* property plot now requires keyword "variable" instead of "prop"
19+
* property plot now requires keyword "variable" instead of "prop" (this change is from `OpenDrift`)
2020
* most configuration parameters are under `m.config` now instead of just `m`, if `m` represents a Manager instance.
21+
* a geojson dict can be input but it is not fully working at the moment
22+
* `oil_type` can be input as the name or the id from the adios database.
23+
* `.model_json_schema()` is overridden in `OpenDriftConfig` to include a bit of custom code to modify the `oil_type` output in the JSON schema "properties" area. This shouldn't affect anything other than it being available if people want that.
2124

2225

2326
## v0.11.1 (February 4, 2025)

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies:
99
- aiohttp
1010
- appdirs
1111
- fastparquet
12-
- geojson_pydantic
12+
# - geojson_pydantic
1313
- jupyter
1414
- jupyterlab
1515
- kerchunk

particle_tracking_manager/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
OpenDriftConfig,
1818
OpenOilModelConfig,
1919
)
20+
from .models.opendrift.enums import ModifyOilTypeJsonSchema
2021
from .models.opendrift.opendrift import OpenDriftModel

particle_tracking_manager/config_misc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def assign_output_file_if_needed(value: str | None) -> str:
6565
@field_validator("output_file", mode="after")
6666
def clean_output_file(value: str) -> str:
6767
"""Clean the output file name by removing extensions."""
68-
value = value.replace(".nc", "").replace(".parquet", "").replace(".parq", "")
68+
value = (
69+
str(value).replace(".nc", "").replace(".parquet", "").replace(".parq", "")
70+
)
6971
return value
7072

7173
@model_validator(mode="after")

particle_tracking_manager/config_the_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# Third-party imports
1212
import pandas as pd
1313

14-
from geojson import GeoJSON
14+
# from geojson import GeoJSON
1515
from pydantic import BaseModel, Field, computed_field, model_validator
1616

1717
# Local imports

particle_tracking_manager/models/opendrift/config_opendrift.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pathlib import Path
88

99
# Third-party imports
10-
from pydantic import Field, model_validator
10+
from pydantic import Field, field_validator, model_validator
1111
from pydantic.fields import FieldInfo
1212
from typing_extensions import Self
1313

@@ -18,6 +18,7 @@
1818
DiffusivityModelEnum,
1919
DriftModelEnum,
2020
DropletSizeDistributionEnum,
21+
ModifyOilTypeJsonSchema,
2122
ObjectTypeEnum,
2223
OilTypeEnum,
2324
PlotTypeEnum,
@@ -165,6 +166,13 @@ class OpenDriftConfig(TheManagerConfig):
165166
"extra": "forbid",
166167
}
167168

169+
@classmethod
170+
def model_json_schema(cls, **kwargs) -> dict:
171+
"""Override the method to customize the JSON schema to include customization of oil_type."""
172+
return super().model_json_schema(
173+
schema_generator=ModifyOilTypeJsonSchema, **kwargs
174+
)
175+
168176
@model_validator(mode="after")
169177
def check_interpolator_filename(self) -> Self:
170178
"""Check if interpolator_filename is set correctly."""
@@ -479,7 +487,7 @@ class OpenOilModelConfig(OceanDriftModelConfig):
479487
drift_model: DriftModelEnum = DriftModelEnum.OpenOil # .value
480488

481489
oil_type: OilTypeEnum = Field(
482-
default=OilTypeEnum.GENERIC_BUNKER_C_AD04012, # .value,
490+
default=OilTypeEnum("GENERIC BUNKER C"), # .value,
483491
description="Oil type to be used for the simulation, from the NOAA ADIOS database.",
484492
title="Oil Type",
485493
json_schema_extra={"od_mapping": "seed:oil_type", "ptm_level": 1},
@@ -650,6 +658,24 @@ class OpenOilModelConfig(OceanDriftModelConfig):
650658
# self.oil_type = self.oil_type_input.split(" (")[0]
651659
# return self
652660

661+
# @model_validator(mode="before")
662+
# def validate_oil_type_by_id_from_name(cls, values):
663+
# """Validate oil type by id from name."""
664+
# name_id = values.get('oil_type')
665+
# if name_id not in OceanModelEnum.__members__:
666+
# raise ValueError(f"Invalid ocean model name_id: {name_id}")
667+
# return values
668+
669+
@field_validator("oil_type", mode="before")
670+
def map_oil_type_to_id(cls, v):
671+
"""Map oil type to enum name (which is the oil type id)."""
672+
if v in OilTypeEnum.__members__: # Check if it matches a name
673+
return OilTypeEnum[v]
674+
for enum_member in OilTypeEnum: # Check if it matches a value
675+
if enum_member.value == v:
676+
return enum_member
677+
raise ValueError(f"Invalid value or name '{v}' for OilTypeEnum")
678+
653679

654680
class LarvalFishModelConfig(OceanDriftModelConfig):
655681
"""Larval fish model configuration for OpenDrift."""

0 commit comments

Comments
 (0)