PfsSection

PfsSection(self, dictionary, **kwargs)

Methods

Name Description
clear Remove all items from the PfsSection.
copy Return a copy of the PfsSection.
find_replace Update recursively all old_value with new_value.
from_dataframe Create a PfsSection from a DataFrame.
get Return the value for key if key is in the PfsSection,
items Return a new view of the PfsSection’s items ((key, value) pairs).
keys Return a new view of the PfsSection’s keys.
pop If key is in the dictionary, remove it and return its
search Find recursively all keys, sections or parameters
to_dataframe Output enumerated subsections to a DataFrame.
to_dict Convert to (nested) dict (as a copy).
update_recursive Update recursively all matches of key with value.
values Return a new view of the PfsSection’s values.

clear

PfsSection.clear()

Remove all items from the PfsSection.

copy

PfsSection.copy()

Return a copy of the PfsSection.

find_replace

PfsSection.find_replace(old_value, new_value)

Update recursively all old_value with new_value.

from_dataframe

PfsSection.from_dataframe(df, prefix)

Create a PfsSection from a DataFrame.

Parameters

Name Type Description Default
df pd.DataFrame data required
prefix str section header prefix required

Examples

import pandas as pd
import mikeio
df = pd.DataFrame(dict(station=["Foo", "Bar"],include=[0,1]), index=[1,2])
df
station include
1 Foo 0
2 Bar 1
mikeio.PfsSection.from_dataframe(df,"STATION_")
[STATION_1]
   station = 'Foo'
   include = 0
EndSect  // STATION_1
[STATION_2]
   station = 'Bar'
   include = 1
EndSect  // STATION_2

get

PfsSection.get(key, default=None)

Return the value for key if key is in the PfsSection, else default. If default is not given, it defaults to None, so that this method never raises a KeyError.

items

PfsSection.items()

Return a new view of the PfsSection’s items ((key, value) pairs).

keys

PfsSection.keys()

Return a new view of the PfsSection’s keys.

pop

PfsSection.pop(key, default=None)

If key is in the dictionary, remove it and return its value, else return default. If default is not given and key is not in the dictionary, a KeyError is raised.

search

PfsSection.search(text=None, *, key=None, section=None, param=None, case=False)

Find recursively all keys, sections or parameters matching a pattern.

NOTE: logical OR between multiple conditions

Parameters

Name Type Description Default
text str Search for text in either key, section or parameter, by default None None
key str text pattern to seach for in keywords, by default None None
section str text pattern to seach for in sections, by default None None
param (str, bool, float, int) text or value in a parameter, by default None None
case bool should the text search be case-sensitive?, by default False False

Returns

Name Type Description
PfsSection Search result as a nested PfsSection

to_dataframe

PfsSection.to_dataframe(prefix=None)

Output enumerated subsections to a DataFrame.

Parameters

Name Type Description Default
prefix str The prefix of the enumerated sections, e.g. “OUTPUT_”, which can be supplied if it fails without this argument, by default None (will try to “guess” the prefix) None

Returns

Name Type Description
pd.DataFrame The enumerated subsections as a DataFrame

Examples

pfs = mikeio.read_pfs("../data/pfs/lake.sw")
pfs.SW.OUTPUTS.to_dataframe(prefix="OUTPUT_")
Touched include title file_name type format flood_and_dry coordinate_type zone input_file_name ... last_time_step time_step_frequency number_of_points POINT_1 LINE AREA INTEGRAL_WAVE_PARAMETERS INPUT_PARAMETERS MODEL_PARAMETERS SPECTRAL_PARAMETERS
1 1 1 Wave parameters in domain Wave_parameters.dfsu 1 2 2 UTM-32 0 || ... 450 10 1 {'name': 'POINT_1', 'x': 20000.0, 'y': 20000.0} {'npoints': 3, 'x_first': 0.0, 'y_first': 0.0,... {'number_of_points': 4, 'POINT_1': {'x': -400.... {'Touched': 1, 'type_of_spectrum': 1, 'minimum... {'Touched': 1, 'Surface_elevation': 0, 'Water_... {'Touched': 1, 'Wind_friction_speed': 0, 'Roug... {'Touched': 1, 'separation_of_wind_sea_and_swe...
2 1 0 Wave parameters along line Wave_line.dfs1 1 1 2 UTM-32 0 || ... 450 10 1 {'name': 'POINT_1', 'x': 20000.0, 'y': 20000.0} {'npoints': 41, 'x_first': 0.0, 'y_first': 200... {'number_of_points': 4, 'POINT_1': {'x': -400.... {'Touched': 1, 'type_of_spectrum': 1, 'minimum... {'Touched': 1, 'Surface_elevation': 0, 'Water_... {'Touched': 1, 'Wind_friction_speed': 0, 'Roug... {'Touched': 1, 'separation_of_wind_sea_and_swe...
3 1 1 Wave parameters in a point Waves_x20km_y20km.dfs0 1 0 2 UTM-32 0 || ... 450 1 1 {'name': 'POINT_1', 'x': 38000.0, 'y': 20000.0} {'npoints': 3, 'x_first': 0.0, 'y_first': 0.0,... {'number_of_points': 4, 'POINT_1': {'x': -400.... {'Touched': 1, 'type_of_spectrum': 1, 'minimum... {'Touched': 1, 'Surface_elevation': 0, 'Water_... {'Touched': 1, 'Wind_friction_speed': 0, 'Roug... {'Touched': 1, 'separation_of_wind_sea_and_swe...
4 1 1 Spectrum in a point spectrum_x20km_y20km.dfsu 4 0 2 UTM-32 0 || ... 450 10 1 {'name': 'POINT_1', 'x': 38000.0, 'y': 20000.0} {'npoints': 3, 'x_first': 0.0, 'y_first': 0.0,... {'number_of_points': 4, 'POINT_1': {'x': -400.... {'Touched': 1, 'type_of_spectrum': 1, 'minimum... {'Touched': 1, 'Surface_elevation': 0, 'Water_... {'Touched': 1, 'Wind_friction_speed': 0, 'Roug... {'Touched': 1, 'separation_of_wind_sea_and_swe...

4 rows × 24 columns

to_dict

PfsSection.to_dict()

Convert to (nested) dict (as a copy).

update_recursive

PfsSection.update_recursive(key, value)

Update recursively all matches of key with value.

values

PfsSection.values()

Return a new view of the PfsSection’s values.