text#

swmmio.utils.text.extract_section_of_file(file_path, start_strings, end_strings, comment=';', **kwargs)[source]#

Extract a portion of a file found between one or more start strings and the first encountered end string.

Parameters:
file_pathstr

Path to the source file.

start_stringsstr or list of str

String or list of strings from which to start extracting.

end_stringsstr or list of str

String or list of strings at which to stop extracting.

commentstr, optional

Comment string used to ignore parts of the source file. Defaults to ‘;’.

**kwargs

Other keyword arguments.

Returns:
str

String extracted from source file.

Examples

>>> from swmmio.tests.data import MODEL_FULL_FEATURES_XY
>>> s = extract_section_of_file(MODEL_FULL_FEATURES_XY, '[EVAPORATI', '[', comment=None)
>>> print(s.strip())
[EVAPORATION]
;;Data Source    Parameters
;;-------------- ----------------
CONSTANT         0.0
DRY_ONLY         NO
swmmio.utils.text.find_byte_range_of_section(path, start_string)[source]#

returns the start and end “byte” location of substrings in a text file

swmmio.utils.text.get_inp_sections_details(inp_path, include_brackets=False)[source]#

Creates a dictionary with all the headers found in an INP file (which varies based on what the user has defined in a given model) and updates them based on the definitions in inp_header_dict to ensure the list is comprehensive.

Parameters:
inp_pathstr

Path to the INP file.

include_bracketsbool, optional

Whether to parse sections including the brackets ([]). Default is False.

Returns:
OrderedDict

An ordered dictionary with section headers as keys and their corresponding details.

Examples

>>> from swmmio.tests.data import MODEL_FULL_FEATURES_XY
>>> headers = get_inp_sections_details(MODEL_FULL_FEATURES_XY)
>>> [header for header, cols in headers.items()][:4]
['TITLE', 'OPTIONS', 'EVAPORATION', 'RAINGAGES']
>>> headers['SUBCATCHMENTS']['columns']
['Name', 'Raingage', 'Outlet', 'Area', 'PercImperv', 'Width', 'PercSlope', 'CurbLength', 'SnowPack']
swmmio.utils.text.get_rpt_metadata(file_path)[source]#

Scan rpt file and extract meta data

Parameters:

file_path – path to rpt file

Returns:

dict of metadata

swmmio.utils.text.get_rpt_sections_details(rpt_path: str)[source]#

Extracts and returns the details of sections from a SWMM report file.

Parameters:
rpt_pathstr

The file path to the SWMM report file.

Returns:
OrderedDict

An ordered dictionary where the keys are section headers found in the report file and the values are the corresponding details as defined in the RPT_OBJECTS.

swmmio.utils.text.get_rpt_value(file_path, value_type)[source]#

scan rpt file and find the line starting with value_type and return the last numeric value

swmmio.utils.text.inline_comments_in_inp(filepath, overwrite=False)[source]#

with an existing INP file, shift any comments that have been placed above the element (behavoir from saving in GUI) and place them to the right, inline with the element. To improve readability