swmmio.version_control package

Submodules

swmmio.version_control.inp module

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

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 file (human readable)

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

swmmio.version_control.utils module

swmmio.version_control.utils.bi_is_current(build_instr_file)[source]

check if a given build instruction file has any parent models whose date modified does not match the date modified of the parent INP file

swmmio.version_control.utils.bi_latest_parent_date_modified(vc_dir, parentname)[source]

given a path to a version control directory of build instructions and the name of the parent model, return the parent model’s revision date

swmmio.version_control.utils.copy_rpts_hsf(from_dir, to_dir, search_dir)[source]

walk through a directory and find all rpts and hot start files and copy to another location based on the relative path from the to_dir.

ex:

to_directory = r’P:_ProjectsSouthPhilaSE_SFRMasterModels’ from_dir = r’F:modelsSPhilaMasterModels_170104’ search_dir = r’F:modelsSPhilaMasterModels_170104Combinations’ copy_rpts_hsf(from_dir, to_dir, search_dir)

Good for model results written on a local drive to a network drive

swmmio.version_control.utils.modification_date(filename, string=True)[source]

get modification datetime of a file credit: Christian Oudard ‘stackoverflow.com/questions/237079/how-to-get-file-creation-modification- date-times-in-python’

swmmio.version_control.utils.newest_file(directory)[source]

return the newest file (most recent) in a given directory. Beware that people report the min / max to do different things per OS…

swmmio.version_control.utils.read_meta_data(filepath)[source]
swmmio.version_control.utils.write_inp_section(file_object, allheaders, sectionheader, section_data, pad_top=True, na_fill='')[source]

given an open file object, list of header sections, the current section header, and the section data in a Pandas Dataframe format, this function writes the data to the file object.

swmmio.version_control.utils.write_meta_data(file_object, metadicts)[source]

swmmio.version_control.version_control module

swmmio.version_control.version_control.create_combinations(baseline_dir, rsn_dir, combi_dir, version_id='', comments='')[source]

Generate SWMM5 models of each logical combination of all implementation phases (IP) across all relief sewer networks (RSN).

Inputs:

baseline_dir -> path to directory containing the baseline SWMM5 model rsn_dir -> path to directory containing subdirectories for each RSN

containing directories for each IP within the network

combi_dir -> target directory in which child models will be created version_id -> identifier for a given version (optional) comments -> comments tracked within build instructions log for

each model scenario (optional)

Calling create_combinations will update child models if parent models have been changed.

swmmio.version_control.version_control.propagate_changes_from_baseline(baseline_dir, alternatives_dir, combi_dir, version_id='', comments='')[source]

if the baseline model has changes that need to be propagated to all models, iterate through each model and rebuild the INPs with the new baseline and existing build instructions. update the build instructions to reflect the revision date of the baseline.

Module contents

class swmmio.version_control.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

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 file (human readable)

class swmmio.version_control.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.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.create_combinations(baseline_dir, rsn_dir, combi_dir, version_id='', comments='')[source]

Generate SWMM5 models of each logical combination of all implementation phases (IP) across all relief sewer networks (RSN).

Inputs:

baseline_dir -> path to directory containing the baseline SWMM5 model rsn_dir -> path to directory containing subdirectories for each RSN

containing directories for each IP within the network

combi_dir -> target directory in which child models will be created version_id -> identifier for a given version (optional) comments -> comments tracked within build instructions log for

each model scenario (optional)

Calling create_combinations will update child models if parent models have been changed.

swmmio.version_control.propagate_changes_from_baseline(baseline_dir, alternatives_dir, combi_dir, version_id='', comments='')[source]

if the baseline model has changes that need to be propagated to all models, iterate through each model and rebuild the INPs with the new baseline and existing build instructions. update the build instructions to reflect the revision date of the baseline.