TrackObservation
TrackObservation(
data,
*,
item=None,
name=None,
weight=1.0,
x_item=0,
y_item=1,
keep_duplicates='first',
quantity=None,
aux_items=None,
attrs=None,
)Class for observation with locations moving in space, e.g. satellite altimetry
The data needs in addition to the datetime of each single observation point also, x and y coordinates.
Create TrackObservation from dfs0 or DataFrame
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| data | (str, Path, mikeio.Dataset, pd.DataFrame, xr.Dataset) | path to dfs0 file or object with track data | required |
| item | (str, int) | item name or index of values, by default None if data contains more than one item, item must be given | None |
| name | str | user-defined name for easy identification in plots etc, by default file basename | None |
| x_item | (str, int) | item name or index of x-coordinate, by default 0 | 0 |
| y_item | (str, int) | item name or index of y-coordinate, by default 1 | 1 |
| keep_duplicates | (str, bool) | strategy for handling duplicate timestamps (xarray.Dataset.drop_duplicates): “first” to keep first occurrence, “last” to keep last occurrence, False to drop all duplicates, “offset” to add milliseconds to consecutive duplicates, by default “first” | 'first' |
| quantity | Quantity | The quantity of the observation, for validation with model results For MIKE dfs files this is inferred from the EUM information | None |
| aux_items | list | list of names or indices of auxiliary items, by default None | None |
| attrs | dict | additional attributes to be added to the data, by default None | None |
| weight | float | weighting factor for skill scores, by default 1.0 | 1.0 |
Examples
>>> import modelskill as ms
>>> o1 = ms.TrackObservation("track.dfs0", item=2, name="c2")>>> o1 = ms.TrackObservation("track.dfs0", item="wind_speed", name="c2")>>> o1 = ms.TrackObservation("lon_after_lat.dfs0", item="wl", x_item=1, y_item=0)>>> o1 = ms.TrackObservation("track_wl.dfs0", item="wl", x_item="lon", y_item="lat")>>> df = pd.DataFrame(
... {
... "t": pd.date_range("2010-01-01", freq="10s", periods=n),
... "x": np.linspace(0, 10, n),
... "y": np.linspace(45000, 45100, n),
... "swh": [0.1, 0.3, 0.4, 0.5, 0.3],
... }
... )
>>> df = df.set_index("t")
>>> df
x y swh
t
2010-01-01 00:00:00 0.0 45000.0 0.1
2010-01-01 00:00:10 2.5 45025.0 0.3
2010-01-01 00:00:20 5.0 45050.0 0.4
2010-01-01 00:00:30 7.5 45075.0 0.5
2010-01-01 00:00:40 10.0 45100.0 0.3
>>> t1 = TrackObservation(df, name="fake")
>>> t1.n_points
5
>>> t1.values
array([0.1, 0.3, 0.4, 0.5, 0.3])
>>> t1.time
DatetimeIndex(['2010-01-01 00:00:00', '2010-01-01 00:00:10',
'2010-01-01 00:00:20', '2010-01-01 00:00:30',
'2010-01-01 00:00:40'],
dtype='datetime64[ns]', name='t', freq=None)
>>> t1.x
array([ 0. , 2.5, 5. , 7.5, 10. ])
>>> t1.y
array([45000., 45025., 45050., 45075., 45100.])Attributes
| Name | Description |
|---|---|
| attrs | Attributes of the observation |
| gtype | Geometry type |
| n_points | Number of data points |
| name | Name of time series (value item name) |
| plot | Plot using the ComparerPlotter |
| quantity | Quantity of time series |
| time | Time index |
| values | Values as numpy array |
| weight | Weighting factor for skill scores |
| x | x-coordinate |
| y | y-coordinate |
Methods
| Name | Description |
|---|---|
| equals | Check if two TimeSeries are equal |
| sel | Select data by label |
| to_dataframe | Convert matched data to pandas DataFrame |
| trim | Trim observation data to a given time interval |
equals
TrackObservation.equals(other)Check if two TimeSeries are equal
sel
TrackObservation.sel(**kwargs)Select data by label
to_dataframe
TrackObservation.to_dataframe()Convert matched data to pandas DataFrame
Include x, y coordinates only if gtype=track
Returns
| Name | Type | Description |
|---|---|---|
| pd.DataFrame | data as a pandas DataFrame |
trim
TrackObservation.trim(
start_time=None,
end_time=None,
buffer='1s',
no_overlap='error',
)Trim observation data to a given time interval
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| start_time | pd.Timestamp | start time | None |
| end_time | pd.Timestamp | end time | None |
| buffer | str | buffer time around start and end time, by default “1s” | '1s' |
| no_overlap | Literal['ignore', 'error', 'warn'] | Empty data handling. | 'error' |