VerticalModelResult

VerticalModelResult(
    data,
    *,
    name=None,
    item=None,
    quantity=None,
    z_item=0,
    x=None,
    y=None,
    aux_items=None,
)

Model result for a vertical profile at a fixed (x, y) location.

Construct a VerticalModelResult from a dfs0 file, mikeio.Dataset, pandas.DataFrame or xarray.Dataset in long format: one row per (time, z) pair, with one item/column holding the vertical coordinate and another holding the modelled value. At least two items are required (z + value); if more are present, item must be given.

Parameters

Name Type Description Default
data (str, Path, pd.DataFrame, mikeio.Dfs0, mikeio.Dataset, xr.Dataset) Input data or path to a dfs0 file. required
name str Name of the model result, by default the file or item name. None
item str or int Index or name of the value item. Required if the input has more than two items. None
quantity Quantity Model quantity, for MIKE files this is inferred from the EUM information None
z_item str or int Index or name of the item holding the vertical coordinate, by default 0. 0
x float x-coordinate of the profile location, inferred from data when possible. None
y float y-coordinate of the profile location, inferred from data when possible. None
aux_items list[int | str] Auxiliary items to keep alongside the value item, by default None. None

Notes

A dfs0 with N depth levels has its profile timestamps repeated N times on a non-equidistant time axis. Duplicate (time, z) pairs are not allowed and will raise a ValueError.

Examples

From a pandas.DataFrame in long format:

import modelskill as ms
import pandas as pd

times = pd.to_datetime(["2010-01-01 01:00"] * 3 + ["2010-01-01 02:00"] * 3)
df = pd.DataFrame(
    {
        "z": [0.0, -5.0, -10.0, 0.0, -5.0, -10.0],
        "Salinity": [30.1, 30.3, 30.4, 30.5, 30.3, 30.3],
    },
    index=times,
)
ms.VerticalModelResult(
    df,
    item="Salinity",
    z_item="z",
    x=12.0,
    y=55.0,
    quantity=ms.Quantity("Salinity", "PSU"),
)
<VerticalModelResult>: Salinity
Time: 2010-01-01 01:00:00 - 2010-01-01 02:00:00
Quantity: Salinity [PSU]

From a dfs0 file (with z, Salinity and Temperature items):

ms.VerticalModelResult(
    "../data/vertical/VerticalModel_at_obs.dfs0",
    item="Salinity",
    z_item="z",
    x=657500,
    y=6553600,
)
<VerticalModelResult>: VerticalModel_at_obs
Time: 2022-06-12 00:00:00 - 2022-06-20 22:00:00
Quantity: Salinity [PSU]

Attributes

Name Description
gtype Geometry type
n_points Number of data points
name Name of time series (value item name)
node node-coordinate
plot Plot using the ComparerPlotter
quantity Quantity of time series
time Time index
values Values as numpy array
x x-coordinate
y y-coordinate
z z-coordinate

Methods

Name Description
align Align model result to observation by matching nearest times and interpolating to observation depths.
copy Create a deep copy of the TimeSeries.
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

align

VerticalModelResult.align(vo, temporal_tolerance=None)

Align model result to observation by matching nearest times and interpolating to observation depths.

Observation depths outside the model depth range are assigned NaN values; no extrapolation is performed.

Parameters

Name Type Description Default
vo VerticalObservation Vertical observation to align with required
temporal_tolerance pd.Timedelta Maximum allowed time difference for matching, by default None None

Returns

Name Type Description
xr.Dataset Aligned model result

copy

VerticalModelResult.copy()

Create a deep copy of the TimeSeries.

Returns

Name Type Description
TimeSeries Deep copy of the TimeSeries object

equals

VerticalModelResult.equals(other)

Check if two TimeSeries are equal

sel

VerticalModelResult.sel(**kwargs)

Select data by label

to_dataframe

VerticalModelResult.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

VerticalModelResult.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'