dfsu.Dfsu2DH

dfsu.Dfsu2DH(self, filename)

Attributes

Name Description
deletevalue File delete value.
end_time File end time.
items List of items.
n_items Number of items.
n_timesteps Number of time steps.
start_time File start time.
timestep Time step size in seconds.

Methods

Name Description
append Append data to an existing dfsu file.
extract_track Extract track data from a dfsu file.
get_overset_grid get a 2d grid that covers the domain by specifying spacing or shape.
read Read data from a dfsu file.

append

dfsu.Dfsu2DH.append(ds, validate=True)

Append data to an existing dfsu file.

Parameters

Name Type Description Default
ds Dataset Dataset to be appended required
validate bool Validate that the items and geometry match, by default True True

extract_track

dfsu.Dfsu2DH.extract_track(
    track,
    items=None,
    method='nearest',
    dtype=np.float32,
)

Extract track data from a dfsu file.

Parameters

Name Type Description Default
track pd.DataFrame with DatetimeIndex and (x, y) of track points as first two columns x,y coordinates must be in same coordinate system as dfsu required
track pd.DataFrame filename of csv or dfs0 file containing t,x,y required
items int | str | Sequence[int | str] | None Extract only selected items, by number (0-based), or by name None
method Literal['nearest', 'inverse_distance'] Spatial interpolation method (‘nearest’ or ‘inverse_distance’) default=‘nearest’ 'nearest'
dtype Any Data type to read, by default np.float32 np.float32

Returns

Name Type Description
Dataset A dataset with data dimension t The first two items will be x- and y- coordinates of track

Examples

>>> dfsu = mikeio.open("tests/testdata/NorthSea_HD_and_windspeed.dfsu")
>>> ds = dfsu.extract_track("tests/testdata/altimetry_NorthSea_20171027.csv")
>>> ds
<mikeio.Dataset>
dims: (time:1115)
time: 2017-10-26 04:37:37 - 2017-10-30 20:54:47 (1115 non-equidistant records)
geometry: GeometryUndefined()
items:
  0:  Longitude <Undefined> (undefined)
  1:  Latitude <Undefined> (undefined)
  2:  Surface elevation <Surface Elevation> (meter)
  3:  Wind speed <Wind speed> (meter per sec)

get_overset_grid

dfsu.Dfsu2DH.get_overset_grid(dx=None, dy=None, nx=None, ny=None, buffer=0.0)

get a 2d grid that covers the domain by specifying spacing or shape.

Parameters

Name Type Description Default
dx float grid resolution in x-direction (or in x- and y-direction) None
dy float grid resolution in y-direction None
nx int number of points in x-direction, by default None (the value will be inferred) None
ny int number of points in y-direction, by default None (the value will be inferred) None
buffer float positive to make the area larger, default=0 can be set to a small negative value to avoid NaN values all around the domain. 0.0

Returns

Name Type Description
<mikeio.Grid2D> 2d grid

read

dfsu.Dfsu2DH.read(
    items=None,
    time=None,
    elements=None,
    area=None,
    x=None,
    y=None,
    keepdims=False,
    dtype=np.float32,
    error_bad_data=True,
    fill_bad_data_value=np.nan,
)

Read data from a dfsu file.

Parameters

Name Type Description Default
items str | int | Sequence[str | int] | None Read only selected items, by number (0-based), or by name None
time int | str | slice | None Read only selected time steps, by default None (=all) None
keepdims bool When reading a single time step only, should the time-dimension be kept in the returned Dataset? by default: False False
area tuple[float, float, float, float] | None Read only data inside (horizontal) area given as a bounding box (tuple with left, lower, right, upper) or as list of coordinates for a polygon, by default None None
x float | None Read only data for elements containing the (x,y) points(s), by default None None
y float | None Read only data for elements containing the (x,y) points(s), by default None None
elements Sequence[int] | np.ndarray | None Read only selected element ids, by default None None
error_bad_data bool raise error if data is corrupt, by default True, True
fill_bad_data_value float fill value for to impute corrupt data, used in conjunction with error_bad_data=False default np.nan np.nan
dtype Any Data type to read, by default np.float32 np.float32

Returns

Name Type Description
Dataset A Dataset with data dimensions [t,elements]