Res1D

Res1D API

class mikeio1d.Res1D(file_path=None, lazy_load=False, header_load=False, reaches=None, nodes=None, catchments=None, col_name_delimiter=':', put_chainage_in_col_name=True, clear_queue_after_reading=True, result_reader_type='copier')[source]

Class for reading data from 1D network result files into Pandas data frame. Currently supported formats are:

  • MIKE 1D network and catchment res1d files

  • MIKE 1D Long Term Statistics res1d files

  • MOUSE legacy PRF and CRF files

  • EPANET res and resx files generated by MIKE+

  • SWMM out files

Parameters:
  • file_path (str) – Relative or absolute path of the relevant result file.

  • lazy_load (bool) – Flag specifying to load the file using lazy loading bridge of MIKE 1D. This typically is useful if only a few time steps need to be read for the whole network.

  • header_load (bool) – Flag specifying to load just a header of the result file.

  • reaches (list of str) – Filter list of reach ID strings, which will be included when loading the result file.

  • nodes (list of str) – Filter list of node ID strings, which will be included when loading the result file.

  • catchments (list of str) – Filter list of catchment ID strings, which will be included when loading the result file.

  • col_name_delimiter (str) – String to delimit the quantity ID with location ID (and optionally chainage) in the data frame label.

  • put_chainage_in_col_name (bool) – Flag specifying to add chainage into data frame column label.

  • clear_queries_after_reading (bool) – Flag specifying to clear active queries after reading/processing them.

Examples

An example of reading the res1d file only for nodes with ID ‘node1’, ‘node2’ and reaches with ID ‘reach1’, ‘reach2’:

>>> nodes = ['node1', 'node2']
>>> reaches = ['reach1', 'reach2']
>>> res1d = Res1D('MyRes1D.res1d', nodes=nodes, reaches=reaches)
>>> res1d.read()
catchments

Catchments of the result file.

clear_queue()[source]

Clear the current active list of queries.

property data

.NET object ResultData with the loaded res1d data.

More information about ResultData class see: https://manuals.mikepoweredbydhi.help/latest/General/Class_Library/DHI_MIKE1D/html/T_DHI_Mike1D_ResultDataAccess_ResultData.htm

property end_time

End time of the result file.

extract(file_path, queries=None, time_step_skipping_number=1, ext=None)[source]

Extract given queries to provided file. File type is determined from file_path extension. The supported formats are: * csv * dfs0 * txt

Parameters:
  • file_path (str) – Output file path.

  • queries (list) – List of queries.

  • time_step_skipping_number (int) – Number specifying the time step frequency to output.

  • ext (str) – Output file type to use instead of determining it from extension. Can be ‘csv’, ‘dfs0’, ‘txt’.

property file_path

File path of the result file.

global_data

Global data of the result file.

info()[source]

Prints information about the result file.

static merge(file_names, merged_file_name)[source]

Merges 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:
  • file_names (list of str or Res1D objects) – List of res1d file names to merge.

  • merged_file_name (str) – File name of the res1d file to store the merged data.

modify(data_frame, file_path=None)[source]

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

Parameters:
  • data_frame (pandas.DataFrame) – Pandas data frame object with column names based on query labels

  • file_path (str) – File path for the new res1d file. Optional.

network

Network of the result file.

nodes

Nodes of the result file.

property projection_string

Projection string of the result file.

property quantities

Quantities in res1d file.

property query

.NET object ResultDataQuery to use for querying the loaded res1d data.

More information about ResultDataQuery class see: https://manuals.mikepoweredbydhi.help/latest/General/Class_Library/DHI_MIKE1D/html/T_DHI_Mike1D_ResultDataAccess_ResultDataQuery.htm

reaches

Reaches of the result file.

read(queries=None, column_mode=None)[source]

Read loaded .res1d file data based on queries. Currently the supported query classes are

  • query.QueryDataNode

  • query.QueryDataReach

  • query.QueryDataCatchment

Parameters:
  • queries (A single query or a list of queries.) – Default is None = reads all data.

  • 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

Returns:

pd.DataFrame

Examples

An example of reading res1d file with queries:

>>> res1d = Res1D('MyRes1D.res1d')
>>> queries = [
        QueryDataNode('WaterLevel', 'node1'),
        QueryDataReach('Discharge', 'reach1', 50.0)
    ]
>>> res1d.read(queries)
read_all(column_mode=None)[source]

Read all data from res1d file to dataframe.

Parameters:

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

Returns:

pd.DataFrame

save(file_path)[source]

Saves the ResultData to a new res1d file.

Parameters:

file_path (str) – File path for the new res1d file.

property searcher

.NET object ResultDataSearcher to use for searching res1d data items on network.

More information about ResultDataSearcher class see: https://manuals.mikepoweredbydhi.help/latest/General/Class_Library/DHI_MIKE1D/html/T_DHI_Mike1D_ResultDataAccess_ResultDataQuery.htm

property start_time

Start time of the result file.

structures

Structures of the result file.

property time_index

pandas.DatetimeIndex of the time index.

to_csv(file_path, queries=None, time_step_skipping_number=1)[source]

Extract to csv file.

to_dfs0(file_path, queries=None, time_step_skipping_number=1)[source]

Extract to dfs0 file.

to_txt(file_path, queries=None, time_step_skipping_number=1)[source]

Extract to txt file.