inp#

class swmmio.version_control.inp.BuildInstructions(build_instr_file=None)[source]#

Bases: object

similar to the INPSectionDiff object, this object contains information used to generate an inp based on ‘serialized’ (though human readable, inp-esque) build instructions files. This object is meant to neatly encapsulate things.

self.instructions attribute contains a dictionary with keys of the headers that have changes i.e. build instructions w.r.t baseline model

Methods

build(baseline_dir, target_path)

build a complete INP file with the build instructions committed to a baseline model.

save(dir, filename)

Save the current BuildInstructions instance to a file in a human-readable format.

build(baseline_dir, target_path)[source]#

build a complete INP file with the build instructions committed to a baseline model.

save(dir, filename)[source]#

Save the current BuildInstructions instance to a file in a human-readable format.

Parameters:
dirstr

The directory where the file will be saved. If the directory does not exist, it will be created.

filenamestr

The name of the file to save the BuildInstructions instance to.

Notes

This method writes metadata and instructions to the specified file. The instructions are written by concatenating the removed, altered, and added changes for each section and then writing them to the file.

class swmmio.version_control.inp.INPDiff(model1=None, model2=None)[source]#

Bases: object

Diff of all INP sections between two models

Parameters:
  • model1 – base model for diff

  • model2 – target model for diff

>>> from swmmio.tests.data import MODEL_FULL_FEATURES_XY, MODEL_FULL_FEATURES_XY_B
>>> mydiff = INPDiff(MODEL_FULL_FEATURES_XY, MODEL_FULL_FEATURES_XY_B)
>>> print(mydiff.diffs['XSECTIONS'])

         Shape  Geom1  Geom2  Geom3  Geom4  Barrels  XX  ;  Comment                     Origin
Link                                                                                          
1:4   CIRCULAR      1      0      0      0      1.0 NaN  ;  Removed  model_full_features_b.inp
2:5   CIRCULAR      1      0      0      0      1.0 NaN  ;  Removed  model_full_features_b.inp
3:4   CIRCULAR      1      0      0      0      1.0 NaN  ;  Removed  model_full_features_b.inp
4:5   CIRCULAR      1      0      0      0      1.0 NaN  ;  Removed  model_full_features_b.inp
5:J1  CIRCULAR      1      0      0      0      1.0 NaN  ;  Removed  model_full_features_b.inp
class swmmio.version_control.inp.INPSectionDiff(model1=None, model2=None, section='JUNCTIONS', build_instr_file=None)[source]#

Bases: object

This object represents the ‘changes’ of a given section of a INP file with respect to another INP. Three main dataframes are attributes: - added: includes elements that are new in model2 (compare to model1) - removed: elements that do not exist in model2, that were found to model1 - altered: elements whose attributes have changes from model1 to model2

Parameters:
  • model1 – base model for diff

  • model2 – target model for diff

  • section – section of the inp used for comparison

  • build_instr_file – optionally instantiate an INPSectionDiff from an existing Build Instructions file

>>> from swmmio.examples import jersey, jerzey
>>> mydiff = INPSectionDiff(jersey, jerzey, section='JUNCTIONS')
>>> print(mydiff)

      InvertElev  MaxDepth  InitDepth  SurchargeDepth  PondedArea  ;  Comment                     Origin
Name                                                                                                    
1           17.0         0          0               0           0  ;  Removed  model_full_features_b.inp
2           17.0         0          0               0           0  ;  Removed  model_full_features_b.inp
3           16.5         0          0               0           0  ;  Removed  model_full_features_b.inp
4           16.0         0          0               0           0  ;  Removed  model_full_features_b.inp
5           15.0         0          0               0           0  ;  Removed  model_full_features_b.inp
swmmio.version_control.inp.create_inp_build_instructions(inpA, inpB, path, filename, comments='')[source]#

pass in two inp file paths and produce a spreadsheet showing the differences found in each of the INP sections. These differences should then be used whenever we need to rebuild this model from the baseline reference model.

Note: this should be split into a func that creates a overall model “diff” that can then be written as a BI file or used programmatically

swmmio.version_control.inp.merge_models(inp1, inp2, target='merged_model.inp')[source]#

Merge two separate swmm models into one model. This creates a diff, ignores removed sections, and uses inp1 settings where conflicts exist (altered sections in diff) :param inp1: swmmio.Model.inp object to be combined with inp2 :param inp2: swmmio.Model.inp object to be combined with inp1 :param target: path of new model :return: path to target