Res1D

Res1D(self, file_path=None, reaches=None, nodes=None, catchments=None, time=None, derived_quantities=None, **kwargs)

Class for reading data from 1D network result files.

Currently supported formats are:

  • MIKE 1D network and catchment res1d files
  • MIKE 1D Long Term Statistics (LTS) res1d files
  • EPANET res and resx files generated by MIKE+
  • SWMM out files
  • MOUSE legacy PRF and CRF files

Parameters

Name Type Description Default
file_path str | Path File path of the result file. None
reaches list[str] | None Reach IDs to include when pre-loading dynamic results. None includes all. None
nodes list[str] | None Node IDs to include when pre-loading dynamic results. None includes all. None
catchments list[str] | None Catchment IDs to include when pre-loading dynamic results. None includes all. None
time Union[tuple[str], list[str], slice, None] Start and end time of the data to read. Using None will read all data. None
derived_quantities list[str] | None Derived quantities to include when pre-loading dynamic results. None includes all. None

Examples

Read all data from a res1d file into a Pandas DataFrame:

>>> res = Res1D("results.res1d")
>>> res.read()

Read all available data for nodes:

>>> res1d.nodes.read()

Read data for a specific node:

>>> res.nodes['node1'].read()

Read data for a specific quantity:

>>> res.nodes['node1'].WaterLevel.read()

Filter which data is pre-loaded, typically used for large files:

>>> nodes = ['node1', 'node2']
>>> reaches = ['reach1', 'reach2']
>>> times = slice('2020-01-01', '2020-01-02')
>>> res1d = Res1D('MyRes1D.res1d', nodes=nodes, reaches=reaches, time=times)
>>> res1d.read()

Attributes

Name Description
catchments Catchments of the result file.
data .NET object ResultData with the loaded res1d data.
derived_quantities Derived quantities available for res1d file.
end_time End time of the result file.
file_path File path of the result file.
global_data Global data of the result file.
nodes Nodes of the result file.
number_of_time_steps Number of time steps in the result file.
projection_string Projection string of the result file.
quantities Quantities in res1d file.
query .NET object ResultDataQuery to use for querying the loaded res1d data.
reaches Reaches of the result file.
result_network Deprecated. Use network property instead.
searcher .NET object ResultDataSearcher to use for searching res1d data items on network.
start_time Start time of the result file.
structures Structures of the result file.
time_index pandas.DatetimeIndex of the time index.

Methods

Name Description
add_derived_quantity Add a derived quantity to the Res1D object, propogating changes to the network.
clear_queue Clear the current active list of queries.
extract Extract given queries to provided file.
get_catchment_values Get catchment values. Deprecated, use network.catchments instead.
get_node_values Get node values. Deprecated, use network.nodes instead.
get_reach_end_values Get reach end values. Deprecated, use network.reaches instead.
get_reach_start_values Get reach start values. Deprecated, use network.reaches instead.
get_reach_sum_values Get reach sum values. Deprecated, use network.reaches instead.
get_reach_value Get reach value. Deprecated, use network.reaches instead.
get_reach_values Get reach values. Deprecated, use network.reaches instead.
get_supported_file_extensions Get supported file extensions for Res1D.
info Print information about the result file.
merge Merge res1d files.
modify Modify the ResultData object TimeData based on the provided data frame.
read Read result data into a pandas DataFrame.
read_all Read all data from res1d file to dataframe. Deprecated, use read() instead.
remove_derived_quantity Remove a derived quantity from the Res1D object, propogating changes to the network.
save Save the ResultData to a new res1d file.
to_csv Extract to csv file.
to_dfs0 Extract to dfs0 file.
to_txt Extract to txt file.

add_derived_quantity

Res1D.add_derived_quantity(derived_quantity)

Add a derived quantity to the Res1D object, propogating changes to the network.

Parameters

Name Type Description Default
derived_quantity Type[DerivedQuantity] Derived quantity to be added required

clear_queue

Res1D.clear_queue()

Clear the current active list of queries.

extract

Res1D.extract(file_path, queries=None, time_step_skipping_number=1, ext=None)

Extract given queries to provided file.

File type is determined from file_path extension. The supported formats are: * csv * dfs0 * txt

Parameters

Name Type Description Default
file_path str Output file path. required
queries list List of queries. None
time_step_skipping_number int Number specifying the time step frequency to output. 1
ext str Output file type to use instead of determining it from extension. Can be ‘csv’, ‘dfs0’, ‘txt’. None

get_catchment_values

Res1D.get_catchment_values(catchment_id, quantity)

Get catchment values. Deprecated, use network.catchments instead.

get_node_values

Res1D.get_node_values(node_id, quantity)

Get node values. Deprecated, use network.nodes instead.

get_reach_end_values

Res1D.get_reach_end_values(reach_name, quantity)

Get reach end values. Deprecated, use network.reaches instead.

get_reach_start_values

Res1D.get_reach_start_values(reach_name, quantity)

Get reach start values. Deprecated, use network.reaches instead.

get_reach_sum_values

Res1D.get_reach_sum_values(reach_name, quantity)

Get reach sum values. Deprecated, use network.reaches instead.

get_reach_value

Res1D.get_reach_value(reach_name, chainage, quantity, time)

Get reach value. Deprecated, use network.reaches instead.

get_reach_values

Res1D.get_reach_values(reach_name, chainage, quantity)

Get reach values. Deprecated, use network.reaches instead.

get_supported_file_extensions

Res1D.get_supported_file_extensions()

Get supported file extensions for Res1D.

info

Res1D.info()

Print information about the result file.

merge

Res1D.merge(file_names, merged_file_name)

Merge res1d files.

It is possible to merge three kinds of result files: * Regular res1d (HD, RR, etc.) * LTS extreme statistics * LTS chronological statistics

For regular res1d files the requirement is that the simulation start time of the first file matches the simulation end time of the second file (the same principle for subsequent files).

For LTS result files, meaningful merged result file is obtained when simulation periods for the files do not overlap.

Parameters

Name Type Description Default
file_names list of str or Res1D objects List of res1d file names to merge. required
merged_file_name str File name of the res1d file to store the merged data. required

modify

Res1D.modify(data_frame, file_path=None)

Modify the ResultData object TimeData based on the provided data frame.

Parameters

Name Type Description Default
data_frame pandas.DataFrame Pandas data frame object with column names based on query labels required
file_path str File path for the new res1d file. Optional. None

read

Res1D.read(queries=None, column_mode=None)

Read result data into a pandas DataFrame.

Parameters

Name Type Description Default
queries Optional[list[TimeSeriesId] | TimeSeriesId | list[QueryData] | QueryData] For internal use by mikeio1d. If None, reads all data. None
column_mode str | ColumnMode(optional) Specifies the type of column index of returned DataFrame. ‘all’ - column MultiIndex with levels matching TimeSeriesId objects. ‘compact’ - same as ‘all’, but removes levels with default values. ‘timeseries’ - column index of TimeSeriesId objects ‘str’ - column index of str representations of QueryData objects None

Returns

Type Description
pd.DataFrame

Notes

The queries parameter is intended for internal use by mikeio1d. It mainly exists for historical reasons and is not recommended for general use. The preferred way to query data is via the fluent API, e.g. res.nodes['node1'].WaterLevel.read().

Examples

>>> res = Res1D('results.res1d')
>>> res1d.read()

read_all

Res1D.read_all(column_mode=None)

Read all data from res1d file to dataframe. Deprecated, use read() instead.

remove_derived_quantity

Res1D.remove_derived_quantity(derived_quantity)

Remove a derived quantity from the Res1D object, propogating changes to the network.

Parameters

Name Type Description Default
derived_quantity DerivedQuantity | str Derived quantity to be removed. Either DerivedQuantity class or its name. required

save

Res1D.save(file_path)

Save the ResultData to a new res1d file.

Useful for persisting modified data, as well as converting supported result file types (e.g. res11) into res1d.

Parameters

Name Type Description Default
file_path str File path for the new res1d file. required

Examples

>>> res11_data = Res1D('results.res11')
>>> res11_data.save('results.res1d')

to_csv

Res1D.to_csv(file_path, queries=None, time_step_skipping_number=1)

Extract to csv file.

to_dfs0

Res1D.to_dfs0(file_path, queries=None, time_step_skipping_number=1)

Extract to dfs0 file.

to_txt

Res1D.to_txt(file_path, queries=None, time_step_skipping_number=1)

Extract to txt file.