Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"source.organizeImports": true
}
},
"python.formatting.provider": "black"
"python.formatting.provider": "charliermarsh.ruff",
}
}
}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/full_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
- uses: actions/checkout@v3
- uses: chartboost/ruff-action@v1 # Fail fast if there are any linting errors
with:
version: 0.6.2
src: "modelskill"
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true
},
"python.testing.pytestArgs": [
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
2. Install package in editable mode `pip install -e .[dev]`, including development dependencies
3. Make changes
4. Verify that all tests passes by running `pytest` from the package root directory
5. Format the code by running [black](https://black.readthedocs.io/en/stable/) e.g. `black nameofthefiletoformat.py`
5. Format the code by running [`ruff format`](https://docs.astral.sh/ruff/formatter/)
6. Make a pull request with a summary of the changes
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ build: typecheck test
lint:
ruff check $(LIB)

format:
ruff format $(LIB)

test:
pytest --disable-warnings

Expand Down
3 changes: 2 additions & 1 deletion modelskill/comparison/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""The `comparison` module contains different types of classes for single
"""The `comparison` module contains different types of classes for single
observation comparison (Comparer), and collections of Comparers (ComparerCollection).
"""

from ._comparison import Comparer
from ._collection import ComparerCollection

Expand Down
11 changes: 8 additions & 3 deletions modelskill/comparison/_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ def _validate_metrics(metrics: Iterable[Any]) -> None:
@dataclass
class ItemSelection:
"Utility class to keep track of observation, model and auxiliary items"

obs: str
model: Sequence[str]
aux: Sequence[str]
Expand Down Expand Up @@ -793,7 +794,8 @@ def __iadd__(self, other: Comparer): # type: ignore
else:
self.raw_mod_data.update(other.raw_mod_data)
matched = match_space_time(
observation=self._to_observation(), raw_mod_data=self.raw_mod_data # type: ignore
observation=self._to_observation(),
raw_mod_data=self.raw_mod_data, # type: ignore
)
self.data = matched

Expand Down Expand Up @@ -821,7 +823,8 @@ def __add__(
raw_mod_data = self.raw_mod_data.copy()
raw_mod_data.update(other.raw_mod_data) # TODO!
matched = match_space_time(
observation=self._to_observation(), raw_mod_data=raw_mod_data # type: ignore
observation=self._to_observation(),
raw_mod_data=raw_mod_data, # type: ignore
)
cmp = Comparer(matched_data=matched, raw_mod_data=raw_mod_data)

Expand Down Expand Up @@ -879,7 +882,9 @@ def sel(
d = d.sel(time=d.time.to_index().to_frame().loc[start:end].index) # type: ignore

# Note: if user asks for a specific time, we also filter raw
raw_mod_data = {k: v.sel(time=slice(start, end)) for k, v in raw_mod_data.items()} # type: ignore
raw_mod_data = {
k: v.sel(time=slice(start, end)) for k, v in raw_mod_data.items()
} # type: ignore
if time is not None:
d = d.sel(time=time)

Expand Down
4 changes: 3 additions & 1 deletion modelskill/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ def match(
if isinstance(obs, Collection):
assert all(isinstance(o, get_args(ObsInputType)) for o in obs)
else:
raise TypeError(f"Obs is not the correct type: it is {type(obs)}. Check the order of the arguments (obs, mod).")
raise TypeError(
f"Obs is not the correct type: it is {type(obs)}. Check the order of the arguments (obs, mod)."
)

if len(obs) > 1 and isinstance(mod, Collection) and len(mod) > 1:
if not all(isinstance(m, (DfsuModelResult, GridModelResult)) for m in mod):
Expand Down
6 changes: 3 additions & 3 deletions modelskill/metrics.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""The `metrics` module contains different skill metrics for evaluating the
difference between a model and an observation.
"""The `metrics` module contains different skill metrics for evaluating the
difference between a model and an observation.

* [bias][modelskill.metrics.bias]
* [max_error][modelskill.metrics.max_error]
* [root_mean_squared_error (rmse)][modelskill.metrics.root_mean_squared_error]
* [root_mean_squared_error (rmse)][modelskill.metrics.root_mean_squared_error]
* [urmse][modelskill.metrics.urmse]
* [mean_absolute_error (mae)][modelskill.metrics.mean_absolute_error]
* [mean_absolute_percentage_error (mape)][modelskill.metrics.mean_absolute_percentage_error]
Expand Down
1 change: 0 additions & 1 deletion modelskill/model/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def _extract_track(


class Alignable(Protocol):

@property
def time(self) -> pd.DatetimeIndex: ...

Expand Down
1 change: 0 additions & 1 deletion modelskill/model/dfsu.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def __init__(
quantity: Optional[Quantity] = None,
aux_items: Optional[list[int | str]] = None,
) -> None:

filename = None

assert isinstance(
Expand Down
3 changes: 2 additions & 1 deletion modelskill/model/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ def _extract_point(
# TODO: avoid runtrip to pandas if possible (potential loss of metadata)
if "z" in self.data.dims and z is not None:
ds = self.data.interp(
coords=dict(x=float(x), y=float(y), z=float(z)), method=method # type: ignore
coords=dict(x=float(x), y=float(y), z=float(z)),
method=method, # type: ignore
)
else:
ds = self.data.interp(coords=dict(x=float(x), y=float(y)), method=method) # type: ignore
Expand Down
4 changes: 1 addition & 3 deletions modelskill/model/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def interp_time(self, observation: Observation, **kwargs: Any) -> PointModelResu
**kwargs

Additional keyword arguments passed to xarray.interp

Returns
-------
PointModelResult
Expand Down Expand Up @@ -158,5 +158,3 @@ def _get_valid_times(
# valid query times where time delta is less than max_gap
valid_idx = df.dt <= max_gap
return df[valid_idx].index


9 changes: 6 additions & 3 deletions modelskill/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
plot.scatter.oneone_line.color : blue
plot.scatter.oneone_line.label : 1:1
plot.scatter.points.alpha : 0.5
plot.scatter.points.label :
plot.scatter.points.label :
plot.scatter.points.size : 20
plot.scatter.quantiles.color : darkturquoise
plot.scatter.quantiles.kwargs : {}
Expand All @@ -50,7 +50,7 @@
plot.scatter.quantiles.markeredgewidth : 0.5
plot.scatter.quantiles.markersize : 3.5
plot.scatter.reg_line.kwargs : {'color': 'r'}
>>> ms.set_option("plot.scatter.points.size", 4)
>>> ms.set_option("plot.scatter.points.size", 4)
>>> plot.scatter.points.size
4
>>> ms.get_option("plot.scatter.points.size")
Expand Down Expand Up @@ -414,7 +414,10 @@ def register_option(

# save the option metadata
_registered_options[key] = RegisteredOption(
key=key, defval=defval, doc=doc, validator=validator # , cb=cb
key=key,
defval=defval,
doc=doc,
validator=validator, # , cb=cb
)


Expand Down
6 changes: 2 additions & 4 deletions modelskill/skill_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,10 @@ def __repr__(self) -> str:
return "\n".join(out)

@overload
def __getitem__(self, key: Hashable) -> SkillGridArray:
...
def __getitem__(self, key: Hashable) -> SkillGridArray: ...

@overload
def __getitem__(self, key: Iterable[Hashable]) -> SkillGrid:
...
def __getitem__(self, key: Iterable[Hashable]) -> SkillGrid: ...

def __getitem__(
self, key: Hashable | Iterable[Hashable]
Expand Down
4 changes: 1 addition & 3 deletions modelskill/timeseries/_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ class TimeSeries:
"""Time series data"""

data: xr.Dataset
plotter: ClassVar = (
MatplotlibTimeSeriesPlotter # TODO is this the best option to choose a plotter? Can we use the settings module?
)
plotter: ClassVar = MatplotlibTimeSeriesPlotter # TODO is this the best option to choose a plotter? Can we use the settings module?

def __init__(self, data: xr.Dataset) -> None:
self.data = data if self._is_input_validated(data) else _validate_dataset(data)
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ dev = ["pytest",
"mkdocs-material==9.5.32",
"mkdocstrings==0.25.2",
"mkdocstrings-python==1.10.8",
"black==22.3.0",
"plotly >= 4.5",
"ruff",]
"ruff==0.6.2",]

test = [
"pytest",
"pytest-cov",
"netCDF4",
"openpyxl",
"dask",
Expand Down
Loading