INP Class#

Summary#

The INP class is used to read and update Flood Modeller’s inp file format that is associated with 1D Urban models. The class is initiated with the full filepath of an INP file to load an existing drainage network.

Attention

The API functionality for Urban 1D INP files is currently in development and should be treated as experimental.

The API currently only supports reading/writing of a limited number of unit types. Furthermore, the API does not yet support adding/deleting units. Support of additional unit types, as well as functionality to create and build networks will be implemented in a future release.

from floodmodeller_api import INP

inp = INP('path/to/inpfile.inp') # Loads existing INP file into memory

Once you have initialised a INP class, the supported units can be accessed via the attributes:

In each, the individual units of each type are stored in a dictionary of unit names and unit classes. Only units which are supported in the API will be accesible via these attributes, all of which can be found in the Individual Urban 1D Unit Classes section.

# Print string representation of all units.
print(inp.junctions)
print(inp.raingauges)

Each individual unit class is somewhat unique in how they can be worked with in python. For each unit, the associated data can be accessed and edited via the unit’s class attributes. For example, for a JUNCTION the the invert elevation can be accessed via the .elevation attribute:

print(inp.junctions['MC0918'].elevation) # print the invert elevation for junction 'MC0918'
>>> 3.28

inp.junctions['MC0918'].elevation = 5 # Update the invert elevation to 5m

Although it is possible to rename units by passing a new name into the .name attribute, it is recommended to avoid this as it may cause label issues within the network. Currently the INP class only allows for editing existing units, however functionality to add/remove sections will be included in a future release. For full documentation on the available unit classes, please refer to the Individual Urban 1D Unit Classes section.

In addition to the units, the general options for the INP file can be accessed through the .options attribute. This contains a dictionary of all the general INP settings and can be edited by assigning them new values.

inp.general_parameters # Access dictionary of general INP parameters
>>> {
        "flow_units": "CFS",
        "infiltration": "HORTON",
        "flow_routing": "KINWAVE",
        "link_offsets": "DEPTH",
        "force_main_equation": "H-W",
        "ignore_rainfall": None,
        "ignore_snowmelt": None,
        "ignore_groundwater": None,
        "ignore_rdii": None,
        "ignore_routing": None,
        "ignore_quality": None,
        "allow_ponding": "NO",
        "skip_steady_state": "NO",
        "sys_flow_tol": "5",
        "lat_flow_tol": "5",
        "start_date": "09/13/2014",
        "start_time": "00:00:00",
        "end_date": "09/15/2014",
        "end_time": "00:00:00",
        "report_start_date": "09/13/2014",
        "report_start_time": "00:00:00",
        "sweep_start": "01/01",
        "sweep_end": "12/31",
        "dry_days": "0",
        "report_step": "00:15:00",
        "wet_step": "00:05:00",
        "dry_step": "00:05:00",
        "routing_step": "0:00:30",
        "lengthening_step": "0",
        "variable_step": "0.75",
        "minimum_step": "0.5",
        "inertial_damping": "PARTIAL",
        "normal_flow_limited": "BOTH",
        "min_surfarea": "12.557",
        "min_slope": "0",
        "max_trials": "8",
        "head_tolerance": "0.005",
        "threads": "1",
        "tempdir": None,
    }

Reference#

class floodmodeller_api.INP(inp_filepath: str | Path | None = None, from_json: bool = False)#

Reads and writes Flood Modeller 1DUrban file format ‘.inp’

Parameters:

inp_filepath (str, optional) – Full filepath to inp file. If not specified, a new INP class will be created. Defaults to None.

Output:

Initiates ‘INP’ class object

Raises:
  • TypeError – Raised if inp_filepath does not point to a .inp file

  • FileNotFoundError – Raised if inp_filepath points to a file which does not exist

update() None#

Updates the existing INP based on any altered attributes

save(filepath: str | Path) None#

Saves the INP to the given location, if pointing to an existing file it will be overwritten. Once saved, the INP() class will continue working from the saved location, therefore any further calls to INP.update() will update in the latest saved location rather than the original source INP used to construct the class

Parameters:

filepath (str) – Filepath to new save location including the name and ‘.inp’ extension

Raises:

TypeError – Raised if given filepath doesn’t point to a file suffixed ‘.inp’

diff(other: INP, force_print: bool = False) None#

Compares the INP class against another INP class to check whether they are equivalent, or if not, what the differences are. Two instances of an INP class are deemed equivalent if all of their attributes are equal except for the filepath and raw data. For example, two INP files from different filepaths that had the same data except maybe some differences in decimal places and some default parameters ommitted, would be classed as equaivalent as they would produce the same INP instance and write the exact same data.

The result is printed to the console. If you need to access the returned data, use the method INP._get_diff()

Parameters:
  • other (floodmodeller_api.INP) – Other instance of an INP class

  • force_print (bool) – Forces the API to print every difference found, rather than just the first 25 differences. Defaults to False.

to_json() str#

Converts the object instance into a JSON string representation.

Returns:

A JSON string representing the object instance.

Return type:

str

classmethod from_json(json_string: str)#

Creates an object instance from a JSON string.

Parameters:

json_string (str) – A JSON string representation of the object.

Returns:

An object instance of the class.

Examples#

Example 1 - Increase non-zero initial depths for all junctions

In this example, the the initial depth of all junctions is to be increased by 200m only where the exiting initial depth is non-zero. The updated INP file is saved to a new location rather than updating the original file.

# Import modules
from floodmodeller_api import INP

# Initialise INP class
inp = INP(
    r"C:\Projects\FloodModellerAPI\Development\Example Data\Oldsmar_50YR_1DAY.inp"
)

# Iterate through all junction units
for name, junction in inp.junctions.items():

    # Add 200mm to initial depth if not equal to 0
    if junction.initial_depth != 0:
        junction.initial_depth += 0.2

# Save update inp to new location
inp.save(
    r"C:\Projects\FloodModellerAPI\Development\Example Data\inpfile_increased_initial_depth.inp"
)  # Save to new location