Matching
A Comparer/ComparerCollection can be created in one of the following ways:
match()
- match observations and model resultsfrom_matched()
- create a Comparer from matched datafrom_config()
- create a ComparerCollection from a config file
modelskill.match
match(obs, mod, *, obs_item=None, mod_item=None, gtype=None, max_model_gap=None, spatial_method=None)
Match observation and model result data in space and time
NOTE: In case of multiple model results with different time coverage, only the overlapping time period will be used! (intersection)
NOTE: In case of multiple observations, multiple models can only be matched if they are all of SpatialField type, e.g. DfsuModelResult or GridModelResult.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obs |
(str, Path, DataFrame, Observation, Sequence[Observation])
|
Observation(s) to be compared |
required |
mod |
(str, Path, DataFrame, ModelResult, Sequence[ModelResult])
|
Model result(s) to be compared |
required |
obs_item |
int or str
|
observation item if obs is a file/dataframe, by default None |
None
|
mod_item |
(int, str)
|
model item if mod is a file/dataframe, by default None |
None
|
gtype |
(str, optional)
|
Geometry type of the model result (if mod is a file/dataframe). If not specified, it will be guessed. |
None
|
max_model_gap |
(float, optional)
|
Maximum time gap (s) in the model result (e.g. for event-based model results), by default None |
None
|
spatial_method |
str
|
For Dfsu- and GridModelResult, spatial interpolation/selection method.
|
None
|
Returns:
Type | Description |
---|---|
Comparer
|
In case of a single observation |
ComparerCollection
|
In case of multiple observations |
See Also
from_matched Create a Comparer from observation and model results that are already matched
Source code in modelskill/matching.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
|
modelskill.from_matched
from_matched(data, *, obs_item=0, mod_items=None, aux_items=None, quantity=None, name=None, weight=1.0, x=None, y=None, z=None, x_item=None, y_item=None)
Create a Comparer from observation and model results that are already matched (aligned)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
[DataFrame, str, Path, Dfs0, Dataset]
|
DataFrame (or object that can be converted to a DataFrame e.g. dfs0) with columns obs_item, mod_items, aux_items |
required |
obs_item |
[str, int]
|
Name or index of observation item, by default first item |
0
|
mod_items |
Iterable[str, int]
|
Names or indicies of model items, if None all remaining columns are model items, by default None |
None
|
aux_items |
Iterable[str, int]
|
Names or indicies of auxiliary items, by default None |
None
|
quantity |
Quantity
|
Quantity of the observation and model results, by default Quantity(name="Undefined", unit="Undefined") |
None
|
name |
str
|
Name of the comparer, by default None (will be set to obs_item) |
None
|
x |
float
|
x-coordinate of observation, by default None |
None
|
y |
float
|
y-coordinate of observation, by default None |
None
|
z |
float
|
z-coordinate of observation, by default None |
None
|
x_item |
str | int | None
|
Name of x item, only relevant for track data |
None
|
y_item |
str | int | None
|
Name of y item, only relevant for track data |
None
|
Examples:
>>> import pandas as pd
>>> import modelskill as ms
>>> df = pd.DataFrame({'stn_a': [1,2,3], 'local': [1.1,2.1,3.1]}, index=pd.date_range('2010-01-01', periods=3))
>>> cmp = ms.from_matched(df, obs_item='stn_a') # remaining columns are model results
>>> cmp
<Comparer>
Quantity: Undefined [Undefined]
Observation: stn_a, n_points=3
Model: local, rmse=0.100
>>> df = pd.DataFrame({'stn_a': [1,2,3], 'local': [1.1,2.1,3.1], 'global': [1.2,2.2,3.2], 'nonsense':[1,2,3]}, index=pd.date_range('2010-01-01', periods=3))
>>> cmp = ms.from_matched(df, obs_item='stn_a', mod_items=['local', 'global'])
>>> cmp
<Comparer>
Quantity: Undefined [Undefined]
Observation: stn_a, n_points=3
Model: local, rmse=0.100
Model: global, rmse=0.200
Source code in modelskill/matching.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
modelskill.from_config
Load ComparerCollection from a config file (or dict)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conf |
Union[str, Path, dict]
|
path to config file or dict with configuration |
required |
relative_path |
True: file paths are relative to configuration file, False: file paths are absolute (relative to the current directory), by default True |
True
|
Returns:
Type | Description |
---|---|
ComparerCollection
|
A ComparerCollection object from the given configuration |
Examples: