Skip to content

Commit

Permalink
Merge pull request #269 from DHI/matching-refactor
Browse files Browse the repository at this point in the history
More work on internal data structures
  • Loading branch information
jsmariegaard authored Nov 19, 2023
2 parents cbf562d + 5bf3ea3 commit d09b54b
Show file tree
Hide file tree
Showing 46 changed files with 6,079 additions and 2,353 deletions.
2 changes: 1 addition & 1 deletion docs/simple-compare.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ c = ms.compare(fn_obs, fn_mod, mod_item=0)
### 4. Analysis and plotting

The returned
[PointComparer](modelskill.comparison.PointComparer) can make
[Comparer](modelskill.comparison.Comparer) can make
scatter plots, skill assessment, time series plots etc.

```python
Expand Down
10 changes: 1 addition & 9 deletions modelskill/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from .model import PointModelResult, TrackModelResult, GridModelResult, DfsuModelResult
from .observation import PointObservation, TrackObservation
from .matching import compare, from_matched
from .connection import Connector
from .connection import Connector, from_config
from .settings import options, get_option, set_option, reset_option, load_style
from . import plotting
from .comparison import ComparerCollection
Expand Down Expand Up @@ -77,11 +77,3 @@ def load(filename: Union[str, Path]) -> ComparerCollection:
"plotting",
"from_config",
]


def from_config(
configuration: Union[dict, str], *, validate_eum=True, relative_path=True
):
return Connector.from_config(
configuration, validate_eum=validate_eum, relative_path=relative_path
)
8 changes: 4 additions & 4 deletions modelskill/comparison/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""The `comparison` module contains different types of comparer classes for
fixed locations (PointComparer), or locations moving in space (TrackComparer).
"""The `comparison` module contains different types of classes for single
observation comparison (Comparer), and collections of Comparers (ComparerCollection).
"""
from ._comparison import Comparer, PointComparer, TrackComparer
from ._comparison import Comparer
from ._collection import ComparerCollection

__all__ = ["Comparer", "PointComparer", "TrackComparer", "ComparerCollection"]
__all__ = ["Comparer", "ComparerCollection"]
25 changes: 13 additions & 12 deletions modelskill/comparison/_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
from ..settings import options, reset_option

from ..utils import _get_idx, _get_name
from ._comparison import (
Comparer,
IdOrNameTypes,
TimeTypes,
from ._comparison import Comparer
from ._utils import (
_parse_metric,
_parse_groupby,
_groupby_df,
_add_spatial_grid_to_df,
_groupby_df,
_parse_groupby,
IdOrNameTypes,
TimeTypes,
)
from ._comparison import _get_deprecated_args # TODO remove in v 1.1

Expand Down Expand Up @@ -97,7 +97,7 @@ def add_comparer(self, comparer: Union["Comparer", "ComparerCollection"]) -> Non
Parameters
----------
comparer : (PointComparer, TrackComparer, ComparerCollection)
comparer : (Comparer, ComparerCollection)
Comparer to add to this collection
"""
if isinstance(comparer, (ComparerCollection, Sequence)):
Expand Down Expand Up @@ -181,7 +181,7 @@ def var_names(self) -> List[str]:
"""List of unique variable names"""
unique_names = []
for cmp in self.comparers.values():
n = cmp.quantity_name
n = cmp.quantity.name
if n not in unique_names:
unique_names.append(n)
return unique_names
Expand Down Expand Up @@ -211,12 +211,13 @@ def to_dataframe(self) -> pd.DataFrame:
for cmp in self.comparers.values():
for j in range(cmp.n_models):
mod_name = cmp.mod_names[j]
df = cmp.data[[mod_name]].to_dataframe().copy()
df.columns = ["mod_val"]
# drop "x", "y", ?
df = cmp.data.drop_vars(["z"])[[mod_name]].to_dataframe().copy()
df = df.rename(columns={mod_name: "mod_val"})
df["model"] = mod_name
df["observation"] = cmp.name
if self.n_variables > 1:
df["variable"] = cmp.quantity_name
df["variable"] = cmp.quantity.name
df["x"] = cmp.x
df["y"] = cmp.y
df["obs_val"] = cmp.obs
Expand Down Expand Up @@ -329,7 +330,7 @@ def sel(

cc = ComparerCollection()
for cmp in self.comparers.values():
if cmp.name in observation and cmp.quantity_name in variable:
if cmp.name in observation and cmp.quantity.name in variable:
thismodel = (
[m for m in mod_names if m in cmp.mod_names] if model else None
)
Expand Down
Loading

0 comments on commit d09b54b

Please sign in to comment.