def test_conduit_section(self): """Test CONDUIT section using Project class, data from Example 7""" from_text = Project() source_text = "[CONDUITS]\n" \ " ;; Inlet Outlet Manning Inlet Outlet Init. Max.\n" \ " ;;Name Node Node Length N Offset Offset Flow Flow\n" \ " ;;-------------- ---------------- ---------------- ---------- ---------- ---------- ---------- ---------- ----------\n" \ " C2a J2a J2 157.48 0.016 4 4 0 0\n" \ " C2 J2 J11 526.0 0.016 4 6 0 0\n" \ " C3 J3 J4 109.0 0.016 0 6 0 0\n" \ " C4 J4 J5 133.0 0.05 6 4 0 0\n" \ " C5 J5 J6 207.0 0.05 4 0 0 0\n" \ " C6 J7 J6 140.0 0.05 8 0 0 0\n" \ " C7 J6 J8 95.0 0.016 0 0 0 0\n" \ " C8 J8 J9 166.0 0.05 0 0 0 0\n" \ " C9 J9 J10 320.0 0.05 0 6 0 0\n" \ " C10 J10 J11 145.0 0.05 6 6 0 0\n" \ " C11 J11 O1 89.0 0.016 0 0 0 0\n" \ " C_Aux1 Aux1 J1 377.31 0.016 0 4 0 0\n" \ " C_Aux2 Aux2 J2a 239.41 0.016 0 4 0 0\n" \ " C_Aux1to2 J1 Aux2 286.06 0.016 4 0 0 0\n" \ " C_Aux3 Aux3 J3 444.75 0.05 6 0 0 0\n" \ " P1 J1 J5 185.39 0.016 0 0 0 0\n" \ " P2 J2a J2 157.48 0.016 0 0 0 0\n" \ " P3 J2 J11 529.22 0.016 0 0 0 0\n" \ " P4 Aux3 J4 567.19 0.016 0 0 0 0\n" \ " P5 J5 J4 125.98 0.016 0 0 0 0\n" \ " P6 J4 J7 360.39 0.016 0 0 0 0\n" \ " P7 J7 J10 507.76 0.016 0 0 0 0\n" \ " P8 J10 J11 144.50 0.016 0 0 0 0" from_text.set_text(source_text) project_section = from_text.conduits assert Section.match_omit(project_section.get_text(), source_text, " \t-;\n")
def test_xsections_section(self): """Test XSECTIONS: example 3""" test_text = """[XSECTIONS] ;;Link Shape Geom1 Geom2 Geom3 Geom4 Barrels ;;-------------- ------------ ---------------- ---------- ---------- ---------- ---------- C1 TRAPEZOIDAL 3 5 5 5 1 C2 TRAPEZOIDAL 1 0 0.0001 25 1 C3 CIRCULAR 2.25 0 0 0 1 C4 TRAPEZOIDAL 3 5 5 5 1 C5 TRAPEZOIDAL 3 5 5 5 1 C6 TRAPEZOIDAL 3 5 5 5 1 C7 CIRCULAR 3.5 0 0 0 1 C8 TRAPEZOIDAL 3 5 5 5 1 C9 TRAPEZOIDAL 3 5 5 5 1 C10 TRAPEZOIDAL 3 5 5 5 1 C11 CIRCULAR 4.75 0 0 0 1 C_out CIRCULAR 4.75 0 0 0 1 Or1 RECT_CLOSED 0.3 0.25 0 0 Or2 RECT_CLOSED 0.5 2 0 0 Or3 RECT_CLOSED 0.25 0.35 0 0 W1 RECT_OPEN 2.83 1.75 0 0 ;;Link Shape Geom1 Geom2 Geom3 Geom4 Barrels Culvert ;;-------------- ------------ ---------------- ---------- ---------- ---------- ---------- ---------- Culvert CIRCULAR 3 0 0 0 2 4 Channel TRAPEZOIDAL 9 10 2 2 1 Roadway RECT_OPEN 50 200 0 0 """ from_text = Project() from_text.set_text(test_text) project_section = from_text.xsections actual_text = project_section.get_text() msg = '\nSet:'+test_text+'\nGet:'+actual_text self.assertTrue(project_section.matches(test_text), msg)
def test_junctions(self): """Test JUNCTIONS section through Project class""" test_text = r""" [JUNCTIONS] ;; Invert Max. Init. Surcharge Ponded ;;Name Elev. Depth Depth Depth Area ;;-------------- ---------- ---------- ---------- ---------- ---------- J1 4973 0 0 0 0 J2 4969 0 0 0 0 J3 4973 0 0 0 0 J4 4971 0 0 0 0 J5 4969.8 0 0 0 0 J6 4969 0 0 0 0 J7 4971.5 0 0 0 0 J8 4966.5 0 0 0 0 J9 4964.8 0 0 0 0 J10 4963.8 0 0 0 0 J11 4963 0 0 0 0 J12 4973.8 0 0 0 0 J13 4970.7 0 0 0 0 J14 4972.9 0 0 0 0 J15 4974.5 0 0 0 0 J16 4973.5 0 0 0 0 J17 4973.5 0 0 0 0 """ from_text = Project() from_text.set_text(test_text) project_section = from_text.junctions assert Section.match_omit(project_section.get_text(), test_text, " \t-;\n")
def test_xsections_section(self): """Test XSECTIONS: example 3""" test_text = """[XSECTIONS] ;;Link Shape Geom1 Geom2 Geom3 Geom4 Barrels ;;-------------- ------------ ---------------- ---------- ---------- ---------- ---------- C1 TRAPEZOIDAL 3 5 5 5 1 C2 TRAPEZOIDAL 1 0 0.0001 25 1 C3 CIRCULAR 2.25 0 0 0 1 C4 TRAPEZOIDAL 3 5 5 5 1 C5 TRAPEZOIDAL 3 5 5 5 1 C6 TRAPEZOIDAL 3 5 5 5 1 C7 CIRCULAR 3.5 0 0 0 1 C8 TRAPEZOIDAL 3 5 5 5 1 C9 TRAPEZOIDAL 3 5 5 5 1 C10 TRAPEZOIDAL 3 5 5 5 1 C11 CIRCULAR 4.75 0 0 0 1 C_out CIRCULAR 4.75 0 0 0 1 Or1 RECT_CLOSED 0.3 0.25 0 0 Or2 RECT_CLOSED 0.5 2 0 0 Or3 RECT_CLOSED 0.25 0.35 0 0 W1 RECT_OPEN 2.83 1.75 0 0 ;;Link Shape Geom1 Geom2 Geom3 Geom4 Barrels Culvert ;;-------------- ------------ ---------------- ---------- ---------- ---------- ---------- ---------- Culvert CIRCULAR 3 0 0 0 2 4 Channel TRAPEZOIDAL 9 10 2 2 1 Roadway RECT_OPEN 50 200 0 0 """ from_text = Project() from_text.set_text(test_text) project_section = from_text.xsections actual_text = project_section.get_text() msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(project_section.matches(test_text), msg)
def test_dividers(self): """Test DIVIDERS section from Example-1b""" from_text = Project() source_text = "[DIVIDERS]\n" \ ";;Name Elevation Diverted Link Type Parameters\n" \ ";;-------------- ---------- ---------------- ---------- ----------\n" \ "10 0 * CUTOFF 0 0 0" from_text.set_text(source_text) project_section = from_text.dividers assert Section.match_omit(project_section.get_text(), source_text, " \t-;\n")
def test_outfall_section(self): """Test OUTFALLS section""" test_text = r""" [OUTFALLS] ;;Name Elevation Type Stage Data Gated Route To ;;-------------- ---------- ---------- ---------------- -------- ---------------- 18 975 FREE NO 18 975 FREE NO xxx """ from_text = Project() from_text.set_text(test_text) project_section = from_text.outfalls assert Section.match_omit(project_section.get_text(), test_text, " \t-;\n")
def test_groundwater_section(self): """Test GROUNDWATER section through Project Class""" # -- Failed Empty string get_text from_text = Project() test_text =" [GROUNDWATER]\n" \ ";;Subcatchment Aquifer Node Elev A1 B1 A2 B2 A3 Hsw Hcb BEL WTEL UZM\n" \ ";;-------------- ---------------- ---------------- ------ ------ ------ ------ ------ ------ ------ ------ ------ ------ ------\n" \ "1 1 2 6 0.1 1 0 0 0 0 4" from_text.set_text(test_text) project_section = from_text.groundwater actual_text = project_section.get_text() msg = '\nSet:'+test_text+'\nGet:'+actual_text self.assertTrue(project_section.matches(test_text), msg)
def test_groundwater_section(self): """Test GROUNDWATER section through Project Class""" # -- Failed Empty string get_text from_text = Project() test_text =" [GROUNDWATER]\n" \ ";;Subcatchment Aquifer Node Elev A1 B1 A2 B2 A3 Hsw Hcb BEL WTEL UZM\n" \ ";;-------------- ---------------- ---------------- ------ ------ ------ ------ ------ ------ ------ ------ ------ ------ ------\n" \ "1 1 2 6 0.1 1 0 0 0 0 4" from_text.set_text(test_text) project_section = from_text.groundwater actual_text = project_section.get_text() msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(project_section.matches(test_text), msg)
def test_rdii_section(self): test_text = r""" [RDII] ;;Node UHgroup SewerArea ;;---------------------------------------------------------------------- 80408 FLOW 80408 81009 FLOW 81009 82309 FLOW 82309 """ from_text = Project() from_text.set_text(test_text) project_section = from_text.rdii assert Section.match_omit(project_section.get_text(), test_text, " \t-;\n")
def test_inflows_flowts(self): """Test INFLOWS section with FLOW TS type""" test_text=r""" [INFLOWS] ;;Node Constituent Time Series Type Mfactor Sfactor Baseline Pattern ;;-------------- ---------------- ---------------- -------- -------- -------- -------- -------- Inlet FLOW Inflow FLOW 1.0 1.0 """ from_text = Project() from_text.set_text(test_text) project_section = from_text.inflows actual_text = project_section.get_text() msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(project_section.matches(test_text), msg)
def test_loading_section(self): """Test LOADINGS section""" test_text = r""" [LOADINGS] ;;Subcatchment Pollutant Loading Pollutant Loading ;;---------------------------------------------------------- SB1 TSS 0.1 Lead 0.01 """ from_text = Project() from_text.set_text(test_text) project_section = from_text.loadings actual_text = project_section.get_text() msg = '\nSet:'+test_text+'\nGet:'+actual_text self.assertTrue(project_section.matches(test_text), msg) # assert Section.match_omit(project_section.get_text(), test_text, " \t-;\n")
def test_treatment_section(self): """Test TREATMENT section""" test_text = r""" [TREATMENT] ;; Results: R or C ;; R-Fraction removal ;; C-efflument concentration ;;Node Pollutant Result = Func ;;---------------------------------------------------------------------- Node23 BOD C = BOD * exp(-0.05*HRT) Node24 Lead R = 0.2 * R_TSS """ from_text = Project() from_text.set_text(test_text) project_section = from_text.treatment assert Section.match_omit(project_section.get_text(), test_text, " \t-;\n")
def test_washoff_section(self): """Test WASHOFF section""" test_text = r""" [WASHOFF] ;; Clean. BMP ;;LandUse Pollutant Function Coeff1 Coeff2 Effic. Effic. ;;------------------------------------------------------------------------------ Residential TSS EXP 0.1 1 0 0 Residential Lead EMC 0 0 0 0 Undeveloped TSS EXP 0.1 0.7 0 0 Undeveloped Lead EMC 0 0 0 0 """ from_text = Project() from_text.set_text(test_text) project_section = from_text.washoff assert Section.match_omit(project_section.get_text(), test_text, " \t-;\n")
def test_pollutant_section(self): """Test POLLUTANTS section through Project""" test_text = r""" [POLLUTANTS] ;; Mass Rain GW I&I Decay Snow ;;Name Units Conc. Conc. Conc. Coeff. Only Co-Pollutant ;;------------------------------------------------------------------------------------------ TSS MG/L 0.0 0.0 0 0.0 NO Lead UG/L 0.0 0.0 0 0.0 NO TSS 0.2 """ from_text = Project() from_text.set_text(test_text) project_section = from_text.pollutants actual_text = project_section.get_text() msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(project_section.matches(test_text), msg)
def test_curves_section(self): # TODO: check the match_omit method """Test CURVES section using Project class, Example6-Initial""" from_text = Project() # test_text = '\n'.join(self.TEST_TEXT) test_text = "[CURVES]\n" \ ";;Name Type X-Value Y-Value\n" \ ";;-------------- ---------- ---------- ----------\n" \ "SU2 Storage 0 10368\n" \ "SU2 2.2 14512\n" \ "SU2 2.3 32000\n" \ "SU2 6 50000" from_text.set_text(test_text) project_section = from_text.curves actual_text = project_section.get_text() msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(project_section.matches(test_text), msg)
def test_inflows_flow(self): """Test INFLOWS section with flow type""" test_text = r""" [INFLOWS] ;; Concen Conversion ;;Node Parameter Time Series /Mass Factor ;;---------------------------------------------------------------------- 80408 FLOW 80408 81009 FLOW 81009 82309 FLOW 82309""" from_text = Project() from_text.set_text(test_text) project_section = from_text.inflows actual_text = project_section.get_text() msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(project_section.matches(test_text), msg)
def test_dwf_section_example8(self): """Test DWF section from example 8""" from_text = Project() source_text = r"""[DWF] ;; Average Time ;;Node Parameter Value Patterns ;;-------------- ---------------- ---------- ---------- J1 FLOW 0.008 J2a FLOW 0.01 J12 FLOW 0.0125 J13 FLOW 0.0123 Aux3 FLOW 0.004 """ # --Test set_text from_text.set_text(source_text) project_section = from_text.dwf assert Section.match_omit(project_section.get_text(), source_text, " \t-;\n")
def test_buildup_section(self): """Test BUILDUP section using Project class""" from_text = Project() # source_text = '\n'.join(self.TEST_TEXT) test_text = "[BUILDUP]\n" \ ";;LandUse Pollutant Function Coeff1 Coeff2 Coeff3 Normalizer\n" \ ";;-----------------------------------------------------------------------------------\n" \ " Residential TSS SAT 50 0 2 AREA\n" \ " Residential Lead NONE 0 0 0 AREA\n" \ " Undeveloped TSS SAT 100 0 3 AREA\n" \ " Undeveloped Lead NONE 0 0 0 AREA" from_text.set_text(test_text) project_section = from_text.buildup actual_text = project_section.get_text() msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(project_section.matches(test_text), msg)
def test_landuses(self): """Test LANDUSES section""" test_text = r""" [LANDUSES] ;; Cleaning Fraction Last ;;Name Interval Available Cleaned ;;-------------- ---------- ---------- ---------- Residential_1 0 0 0 Residential_2 0 0 0 Commercial 0 0 0 LID 0 0 0 """ from_text = Project() from_text.set_text(test_text) project_section = from_text.landuses assert Section.match_omit(project_section.get_text(), test_text, " \t-;\n")
def test_lid_usage_section(self): """Test LIDUSAGE section through Project class Test failed as current LID usage only contains one line of LID usage Also code compained when I have special character in the comment lines""" test_text = r""" [LID_USAGE] ;34 rain barrels of 12 sq ft each are placed in ;subcatchment S1. They are initially empty and treat 17 ;The outflow from the barrels is returned to the ;subcatchments pervious area. S1 RB14 34 12 0 0 17 1 S2 Swale 1 10000 50 0 0 0 swale.rpt """ from_text = Project() from_text.set_text(test_text) project_section = from_text.lid_usage assert Section.match_omit(project_section.get_text(), test_text, " \t-;\n")
def test_aquifers(self): """Test AQUIFERS section using the Project class""" from_text = Project() source_text = '\n'.join(self.TEST_TEXT) from_text.set_text(source_text) project_section = from_text.aquifers assert Section.match_omit(project_section.get_text(), source_text, " \t-;\n") val = project_section.value[0] assert val.name == "1" assert val.porosity == "0.5" assert val.wilting_point == "0.15" assert val.field_capacity == "0.30" assert val.conductivity == "0.1" assert val.conductivity_slope == "12" assert val.tension_slope == "15.0" assert val.upper_evaporation_fraction == "0.35" assert val.lower_evaporation_depth == "14.0" assert val.lower_groundwater_loss_rate == "0.002" assert val.bottom_elevation == "0.0" assert val.water_table_elevation == "3.5" assert val.unsaturated_zone_moisture == "0.40" assert val.upper_evaporation_pattern == "" val = project_section.value[1] assert val.name == "1" assert val.porosity == "2" assert val.wilting_point == "3" assert val.field_capacity == "4" assert val.conductivity == "5" assert val.conductivity_slope == "6" assert val.tension_slope == "7" assert val.upper_evaporation_fraction == "8" assert val.lower_evaporation_depth == "9" assert val.lower_groundwater_loss_rate == "10" assert val.bottom_elevation == "11" assert val.water_table_elevation == "12" assert val.unsaturated_zone_moisture == "13" assert val.upper_evaporation_pattern == "14" assert Aquifer.metadata.label_of("name") == "Aquifer Name" assert Aquifer.metadata.hint_of("name") == "User-assigned aquifer name."
def test_dwf_section_example3(self): """Test DWF section from example 3""" from_text = Project() source_text = r""" [DWF] ;; Average Time ;;Node Parameter Value Patterns ;;----------------------------------------------------- KRO3001 FLOW 1 "" "" "DWF" "" "" "" "" KRO6015 FLOW 1 "" "" "DWF" "" "" "" "" KRO6016 FLOW 1 "" "" "DWF" "" "" "" "" KRO6017 FLOW 1 "" "" "DWF" "" "" "" "" KRO1002 FLOW 1 "" "" "DWF" "" "" "" "" KRO1003 FLOW 1 "" "" "DWF" "" "" "" "" KRO1004 FLOW 1 "" "" "DWF" "" "" "" "" KRO1005 FLOW 1 "" "" "DWF" "" "" "" "" KRO1006 FLOW 1 "" "" "DWF" "" "" "" "" KRO1007 FLOW 1 "" "" "DWF" "" "" "" "" KRO1008 FLOW 1 "" "" "DWF" "" "" "" "" KRO1009 FLOW 1 "" "" "DWF" "" "" "" "" KRO1010 FLOW 1 "" "" "DWF" "" "" "" "" KRO1012 FLOW 1 "" "" "DWF" "" "" "" "" KRO1013 FLOW 1 "" "" "DWF" "" "" "" "" KRO1015 FLOW 1 "" "" "DWF" "" "" "" "" KRO2001 FLOW 1 "" "" "DWF" "" "" "" "" KRO4004 FLOW 1 "" "" "DWF" "" "" "" "" KRO4008 FLOW 1 "" "" "DWF" "" "" "" "" KRO4009 FLOW 1 "" "" "DWF" "" "" "" "" KRO4010 FLOW 1 "" "" "DWF" "" "" "" "" KRO4011 FLOW 1 "" "" "DWF" "" "" "" "" KRO4012 FLOW 1 "" "" "DWF" "" "" "" "" KRO4013 FLOW 1 "" "" "DWF" "" "" "" "" KRO4014 FLOW 1 "" "" "DWF" "" "" "" "" KRO4015 FLOW 1 "" "" "DWF" "" "" "" "" KRO4017 FLOW 1 "" "" "DWF" "" "" "" "" KRO4018 FLOW 1 "" "" "DWF" "" "" "" "" KRO4019 FLOW 1 "" "" "DWF" "" "" "" "" SU1 FLOW 1 "" "" "DWF" "" "" "" "" """ from_text.set_text(source_text) project_section = from_text.dwf assert Section.match_omit(project_section.get_text(), source_text, " \t-;\n")
def test_snowpacks_section(self): """Test SNOWPACKS section""" test_text = r""" [SNOWPACKS] ;;Name Surface Parameters ;;-------------- ---------- ---------- sno PLOWABLE 0.001 0.001 32.0 0.10 0.00 0.00 0.0 sno IMPERVIOUS 0.001 0.001 32.0 0.10 0.00 0.00 0.00 sno PERVIOUS 0.001 0.001 32.0 0.10 0.00 0.00 0.00 sno REMOVAL 1.0 0.0 0.0 0.0 0.0 0.0 s PLOWABLE 0.001 0.001 32.0 0.10 0.00 0.00 0.0 s IMPERVIOUS 0.001 0.001 32.0 0.10 0.00 0.00 0.00 s PERVIOUS 0.001 0.001 32.0 0.10 0.00 0.00 0.00 s REMOVAL 1.0 0.0 0.0 0.0 0.0 0.0 w """ from_text = Project() from_text.set_text(test_text) project_section = from_text.snowpacks assert Section.match_omit(project_section.get_text(), test_text, " \t-;\n")
def test_subcatchments(self): """Test SUBCATCHMENTS section from Example 1""" test_text = """[SUBCATCHMENTS] ;; Total Pcnt. Pcnt. Curb Snow ;;Name Raingage Outlet Area Imperv Width Slope Length Pack ;;---------------------------------------------------------------------------------------------------- 1 RG1 9 10 50 500 0.01 0 2 RG1 10 10 50 500 0.01 0 3 RG1 13 5 50 500 0.01 0 4 RG1 22 5 50 500 0.01 0 5 RG1 15 15 50 500 0.01 0 6 RG1 23 12 10 500 0.01 0 7 RG1 19 4 10 500 0.01 0 8 RG1 18 10 10 500 0.01 0 """ from_text = Project() from_text.set_text(test_text) project_section = from_text.subcatchments assert Section.match_omit(project_section.get_text(), test_text, " \t-;\n")
def test_curvenumber_infiltration_section(self): """Test INFILTRATION section curve_number type""" test_text = """[INFILTRATION] ;;Subcatchment CurveNo Ksat DryTime ;;-------------- ---------- ---------- ---------- S1 3.5 0.2 2 S2 3.5 0.2 2 S3 3.5 0.2 2 S4 3.5 0.2 2 S5 3.5 0.2 2 S6 3.5 0.2 2 Swale3 3.5 0.2 2 Swale4 3.5 0.2 2 Swale6 3.5 0.2 2 """ from_text = Project() from_text.set_text(test_text) project_section = from_text.infiltration actual_text = project_section.get_text() assert project_section.matches(test_text)
def test_greenampt_infiltration_section(self): """Test INFILTRATION section Example 4a Green Ampt type""" test_text = """[INFILTRATION] ;;Subcatchment Suction Ksat IMD ;;-------------- ---------- ---------- ---------- S1 3.5 0.2 0.2 S2 3.5 0.2 0.2 S3 3.5 0.2 0.2 S4 3.5 0.2 0.2 S5 3.5 0.2 0.2 S6 3.5 0.2 0.2 Swale3 3.5 0.2 0.2 Swale4 3.5 0.2 0.2 Swale6 3.5 0.2 0.2 """ from_text = Project() from_text.set_text(test_text) project_section = from_text.infiltration actual_text = project_section.get_text() assert project_section.matches(test_text)
def test_greenampt_infiltration_section(self): """Test INFILTRATION section Example 4a Green Ampt type""" test_text ="""[INFILTRATION] ;;Subcatchment Suction Ksat IMD ;;-------------- ---------- ---------- ---------- S1 3.5 0.2 0.2 S2 3.5 0.2 0.2 S3 3.5 0.2 0.2 S4 3.5 0.2 0.2 S5 3.5 0.2 0.2 S6 3.5 0.2 0.2 Swale3 3.5 0.2 0.2 Swale4 3.5 0.2 0.2 Swale6 3.5 0.2 0.2 """ from_text = Project() from_text.set_text(test_text) project_section = from_text.infiltration actual_text = project_section.get_text() assert project_section.matches(test_text)
def test_transect_section(self): """Test transects: using Project # -- Output does not match input, only one transect was kept and GRs gets combined""" test_text = r"""[TRANSECTS] NC 0.015 0.015 0.015 X1 Full_Street 7 0.0 0.0 0.0 0.0 0.0 0.0 0.0 GR 1.3 -40 0.5 -20 0 -20 0.8 0 0 20 GR 0.5 20 1.3 40 NC 0.016 0.016 0.016 X1 Half_Street 5 0.0 0.0 0.0 0.0 0.0 0.0 0.0 GR 1.3 -40 0.5 -20 0 -20 0.8 0 1.3 0 """ from_text = Project() from_text.set_text(test_text) project_section = from_text.transects # assert Section.match_omit(project_section.get_text(), test_text, " \t-;\n") actual_text = project_section.get_text() msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(project_section.matches(test_text), msg)
def test_timeseries_section(self): """Test Example in SWMM 5.1 manual Page335""" # -- Failed because of SECTION name and # -- Data structure # self.my_options = TimeSeries() test_text = r""" [TIMESERIES] ;Rainfall time series with dates specified TS1 6-15-2001 7:00 0.1 8:00 0.2 9:00 0.05 10:00 0 TS1 6-21-2001 4:00 0.2 5:00 0 14:00 0.1 15:00 0 ;Inflow hydrograph - time relative to start of simulation HY1 0 0 1.25 100 2:30 150 3.0 120 4.5 0 HY1 32:10 0 34.0 57 35.33 85 48.67 24 50 0 """ from_text = Project() from_text.set_text(test_text) project_section = from_text.timeseries actual_text = project_section.get_text() msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(project_section.matches(test_text), msg)
def std_openproj(self): file_name = QtGui.QFileDialog.getOpenFileName(self, "Open Project...", "", "Inp files (*.inp);;All files (*.*)") if file_name: self.project = Project() try: self.project.read_file(file_name) self.setWindowTitle(self.model + " - " + os.path.split(file_name)[1]) except: self.project = None self.setWindowTitle(self.model) pass
def test_horton_infiltration_section(self): """Test INFILTRATION section Horton type""" test_text = r""" [INFILTRATION] ;;Subcatchment MaxRate MinRate Decay DryTime MaxInfil ;;----------------------------------------------------------------------- 1 0.35 0.25 4.14 0.50 2 0.7 0.3 4.14 0.50 3 0.7 0.3 4.14 0.50 4 0.7 0.3 4.14 0.50 5 0.7 0.3 4.14 0.50 6 0.7 0.3 4.14 0.50 7 0.7 0.3 4.14 0.50 8 0.7 0.3 4.14 0.50 """ from_text = Project() from_text.set_text(test_text) # from_text.infiltration.set_text('HORTON') project_section = from_text.infiltration actual_text = project_section.get_text() assert project_section.matches(test_text)
def test_project_section(self): """Test EVAPORATION use project section""" test_text = ("[EVAPORATION]", ";;Type \tParameters", ";;----------\t----------", "CONSTANT \t0.2", "DRY_ONLY \tNO") from_text = Project() test_text = '\n'.join(test_text) from_text.set_text(test_text) project_section = from_text.evaporation assert Section.match_omit(project_section.get_text(), test_text, " \t-;\n") assert project_section.format == EvaporationFormat.CONSTANT assert project_section.constant == "0.2" assert project_section.monthly == () assert project_section.timeseries == '' assert project_section.monthly_pan_coefficients == () assert project_section.recovery_pattern == '' assert project_section.dry_only is False actual_text = project_section.get_text() msg = '\nSet:' + test_text + '\nGet:' + actual_text self.assertTrue(project_section.matches(test_text), msg)
def std_newproj(self): self.project = Project() self.setWindowTitle(self.model + " - New") self.project.file_name = "New.inp" pass
class frmMainSWMM(frmMain): def __init__(self, parent=None, *args): frmMain.__init__(self, parent) QtCore.QObject.connect(self.actionStdNewProjectMenu, QtCore.SIGNAL('triggered()'), self.std_newproj) QtCore.QObject.connect(self.actionStdNewProject, QtCore.SIGNAL('triggered()'), self.std_newproj) QtCore.QObject.connect(self.actionStdOpenProjMenu, QtCore.SIGNAL('triggered()'), self.std_openproj) QtCore.QObject.connect(self.actionStdOpenProj, QtCore.SIGNAL('triggered()'), self.std_openproj) QtCore.QObject.connect(self.actionStdExit, QtCore.SIGNAL('triggered()'), self.action_exit) self.model = 'SWMM' self.modelenv1 = 'EXE_SWMM' assembly_path = os.path.dirname(os.path.abspath(__file__)) exe_name = "swmm5.exe" pexe = os.path.join(assembly_path, exe_name) if not os.path.exists(pexe): pp = os.path.dirname(os.path.dirname(assembly_path)) pexe = os.path.join(pp, "Externals", exe_name) if not os.path.exists(pexe): pexe = QtGui.QFileDialog.getOpenFileName(self, 'Locate SWMM Executable', '/', 'exe files (*.exe)') if os.path.exists(pexe): os.environ[self.modelenv1] = pexe else: os.environ[self.modelenv1] = '' self.on_load(model=self.model) self._frmDates = None self._frmDynamicWave = None self._frmMapBackdropOptions = None self._frmGeneralOptions = None self._frmInterfaceFiles = None self._frmReportOptions = None self._frmTimeSteps = None self._frmTitle = None def std_newproj(self): self.project = Project() self.setWindowTitle(self.model + " - New") self.project.file_name = "New.inp" pass def std_openproj(self): file_name = QtGui.QFileDialog.getOpenFileName(self, "Open Project...", "", "Inp files (*.inp);;All files (*.*)") if file_name: self.project = Project() try: self.project.read_file(file_name) self.setWindowTitle(self.model + " - " + os.path.split(file_name)[1]) except: self.project = None self.setWindowTitle(self.model) pass def proj_save(self): self.project.write_file(self.project.file_name) def proj_save_as(self): file_name = QtGui.QFileDialog.getSaveFileName(self, "Save As...", "", "Inp files (*.inp)") if file_name: self.project.write_file(file_name) self.setWindowTitle(self.model + " - " + os.path.split(file_name)[1]) def edit_options(self, itm, column): if self.project == None: return if itm.data(0, 0) == 'Dates': self._frmDates = frmDates(self) self._frmDates.show() if itm.data(0, 0) == 'Dynamic Wave': self._frmDynamicWave = frmDynamicWave(self) self._frmDynamicWave.show() if itm.data(0, 0) == 'Map/Backdrop': self._frmMapBackdropOptions = frmMapBackdropOptions(self) self._frmMapBackdropOptions.show() if itm.data(0, 0) == 'General': self._frmGeneralOptions = frmGeneralOptions(self) self._frmGeneralOptions.show() if itm.data(0, 0) == 'Interface Files': self._frmInterfaceFiles = frmInterfaceFiles(self) self._frmInterfaceFiles.show() if itm.data(0, 0) == 'Reporting': self._frmReportOptions = frmReportOptions(self) self._frmReportOptions.show() if itm.data(0, 0) == 'Time Steps': self._frmTimeSteps = frmTimeSteps(self) self._frmTimeSteps.show() if itm.data(0, 0) == 'Title/Notes': self._frmTitle = frmTitle(self) self._frmTitle.show() def proj_run_simulation(self): run = 0 inp_dir = '' margs=[] prog = os.environ[self.modelenv1] if not os.path.exists(prog): QMessageBox.information(None, "SWMM", "SWMM Executable not found", QMessageBox.Ok) return -1 filename = '' if self.project is None: filename = QtGui.QFileDialog.getOpenFileName(self, 'Open Existing Project', '/', 'Inp files (*.inp)') else: filename = self.project.file_name if os.path.exists(filename): fpre, fext = os.path.splitext(filename) margs.append(filename) margs.append(fpre + '.out') margs.append(fpre + '.rpt') else: QMessageBox.information(None, "SWMM", "SWMM input file not found", QMessageBox.Ok) # running the Exe (modified version to rid of the \b printout status = StatusMonitor0(prog, margs, self, model='SWMM') status.show() def on_load(self, **kwargs): self.obj_tree = ObjectTreeView(model=kwargs['model']) self.obj_tree.itemDoubleClicked.connect(self.edit_options) layout = QVBoxLayout(self.tabProject) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.obj_tree) self.tabProject.setLayout(layout) self.setWindowTitle(self.model) self.obj_list = ObjectListView(model=kwargs['model'],ObjRoot='',ObjType='',ObjList=None) mlayout = self.dockw_more.layout() mlayout.addWidget(self.obj_list) self.dockw_more.setLayout(mlayout) def action_exit(self): # TODO: check project status and prompt if there are unsaved changed app.quit()
def __init__(self, q_application): frmMain.__init__(self, q_application) self.model = "SWMM" self.model_path = '' # Set this only if needed later when running model self.output = None # Set this when model output is available self.status_suffix = "_status.txt" self.status_file_name = '' # Set this when model status is available self.output_filename = '' # Set this when model output is available self.project_type = Project # Use the model-specific Project as defined in core.swmm.project self.project = Project() self.assembly_path = os.path.dirname(os.path.abspath(__file__)) self.on_load(tree_top_item_list=self.tree_top_items) HelpHandler.init_class(os.path.join(self.assembly_path, "swmm.qhc")) self.helper = HelpHandler(self) self.help_topic = "swmm/src/src/swmmsmainwindow.htm" self.actionStatus_ReportMenu = QtGui.QAction(self) self.actionStatus_ReportMenu.setObjectName(from_utf8("actionStatus_ReportMenu")) self.actionStatus_ReportMenu.setText(transl8("frmMain", "Status", None)) self.actionStatus_ReportMenu.setToolTip(transl8("frmMain", "Display Simulation Status", None)) self.menuReport.addAction(self.actionStatus_ReportMenu) QtCore.QObject.connect(self.actionStatus_ReportMenu, QtCore.SIGNAL('triggered()'), self.report_status) self.actionSummary_ReportMenu = QtGui.QAction(self) self.actionSummary_ReportMenu.setObjectName(from_utf8("actionSummary_ReportMenu")) self.actionSummary_ReportMenu.setText(transl8("frmMain", "Summary", None)) self.actionSummary_ReportMenu.setToolTip(transl8("frmMain", "Display Results Summary", None)) self.menuReport.addAction(self.actionSummary_ReportMenu) QtCore.QObject.connect(self.actionSummary_ReportMenu, QtCore.SIGNAL('triggered()'), self.report_summary) menu = QtGui.QMenu() submenuGraph = QtGui.QMenu(self.menuReport) submenuGraph.setTitle("Graph") self.menuReport.addMenu(submenuGraph) self.actionGraph_ProfileMenu = QtGui.QAction(self) self.actionGraph_ProfileMenu.setObjectName(from_utf8("actionGraph_ProfileMenu")) self.actionGraph_ProfileMenu.setText(transl8("frmMain", "Profile", None)) self.actionGraph_ProfileMenu.setToolTip(transl8("frmMain", "Display Profile Plot", None)) submenuGraph.addAction(self.actionGraph_ProfileMenu) QtCore.QObject.connect(self.actionGraph_ProfileMenu, QtCore.SIGNAL('triggered()'), self.report_profile) self.actionGraph_TimeSeriesMenu = QtGui.QAction(self) self.actionGraph_TimeSeriesMenu.setObjectName(from_utf8("actionGraph_TimeSeriesMenu")) self.actionGraph_TimeSeriesMenu.setText(transl8("frmMain", "Time Series", None)) self.actionGraph_TimeSeriesMenu.setToolTip(transl8("frmMain", "Display Time Series Plot", None)) submenuGraph.addAction(self.actionGraph_TimeSeriesMenu) QtCore.QObject.connect(self.actionGraph_TimeSeriesMenu, QtCore.SIGNAL('triggered()'), self.report_timeseries) self.actionGraph_ScatterMenu = QtGui.QAction(self) self.actionGraph_ScatterMenu.setObjectName(from_utf8("actionGraph_ScatterMenu")) self.actionGraph_ScatterMenu.setText(transl8("frmMain", "Scatter", None)) self.actionGraph_ScatterMenu.setToolTip(transl8("frmMain", "Display Scatter Plot", None)) submenuGraph.addAction(self.actionGraph_ScatterMenu) QtCore.QObject.connect(self.actionGraph_ScatterMenu, QtCore.SIGNAL('triggered()'), self.report_scatter) self.actionTable_VariableMenu = QtGui.QAction(self) self.actionTable_VariableMenu.setObjectName(from_utf8("actionTable_VariableMenu")) self.actionTable_VariableMenu.setText(transl8("frmMain", "Table", None)) self.actionTable_VariableMenu.setToolTip(transl8("frmMain", "Display Table", None)) self.menuReport.addAction(self.actionTable_VariableMenu) QtCore.QObject.connect(self.actionTable_VariableMenu, QtCore.SIGNAL('triggered()'), self.report_variable) self.actionStatistics_ReportMenu = QtGui.QAction(self) self.actionStatistics_ReportMenu.setObjectName(from_utf8("actionStatistics_ReportMenu")) self.actionStatistics_ReportMenu.setText(transl8("frmMain", "Statistics", None)) self.actionStatistics_ReportMenu.setToolTip(transl8("frmMain", "Display Results Statistics", None)) self.menuReport.addAction(self.actionStatistics_ReportMenu) QtCore.QObject.connect(self.actionStatistics_ReportMenu, QtCore.SIGNAL('triggered()'), self.report_statistics) self.Help_Topics_Menu = QtGui.QAction(self) self.Help_Topics_Menu.setObjectName(from_utf8("Help_Topics_Menu")) self.Help_Topics_Menu.setText(transl8("frmMain", "Help Topics", None)) self.Help_Topics_Menu.setToolTip(transl8("frmMain", "Display Help Topics", None)) self.menuHelp.addAction(self.Help_Topics_Menu) QtCore.QObject.connect(self.Help_Topics_Menu, QtCore.SIGNAL('triggered()'), self.help_topics) self.Help_About_Menu = QtGui.QAction(self) self.Help_About_Menu.setObjectName(from_utf8("Help_About_Menu")) self.Help_About_Menu.setText(transl8("frmMain", "About", None)) self.Help_About_Menu.setToolTip(transl8("frmMain", "About SWMM", None)) self.menuHelp.addAction(self.Help_About_Menu) QtCore.QObject.connect(self.Help_About_Menu, QtCore.SIGNAL('triggered()'), self.help_about)
def test_hydrographs(self): """Test HYDROGRAPHS section""" TEST_TEXT = ( "[HYDROGRAPHS]", ";;Hydrograph\tMonth\tResponse\tR\tT\tK\tDmax\tDrecov\tDinit", "UH101 RG1", "UH101 ALL SHORT 0.033 1.0 2.0", "UH101 ALL MEDIUM 0.300 3.0 2.0\t1\t2\t3", "UH101 ALL LONG 0.033 10.0 2.0", "UH101 JUL SHORT 0.033 0.5 2.0", "UH101 JUL MEDIUM 0.011 2.0 2.0") from_text = Project() source_text = '\n'.join(TEST_TEXT) from_text.set_text(source_text) project_hydrographs = from_text.hydrographs assert Section.match_omit(project_hydrographs.get_text(), source_text, " \t-;\n") assert len(project_hydrographs.value) == 1 val = project_hydrographs.value[0] assert val.group_name == "UH101" assert val.rain_gage_id == "RG1" assert len(val.value) == 5 hydrograph_item = val.value[0] assert hydrograph_item.hydrograph_month == "ALL" assert hydrograph_item.term == "SHORT" assert hydrograph_item.response_ratio == "0.033" assert hydrograph_item.time_to_peak == "1.0" assert hydrograph_item.recession_limb_ratio == "2.0" assert hydrograph_item.initial_abstraction_depth == '' assert hydrograph_item.initial_abstraction_rate == '' assert hydrograph_item.initial_abstraction_amount == '' hydrograph_item = val.value[1] assert hydrograph_item.hydrograph_month == "ALL" assert hydrograph_item.term == "MEDIUM" assert hydrograph_item.response_ratio == "0.300" assert hydrograph_item.time_to_peak == "3.0" assert hydrograph_item.recession_limb_ratio == "2.0" assert hydrograph_item.initial_abstraction_depth == '1' assert hydrograph_item.initial_abstraction_rate == '2' assert hydrograph_item.initial_abstraction_amount == '3' hydrograph_item = val.value[2] assert hydrograph_item.hydrograph_month == "ALL" assert hydrograph_item.term == "LONG" assert hydrograph_item.response_ratio == "0.033" assert hydrograph_item.time_to_peak == "10.0" assert hydrograph_item.recession_limb_ratio == "2.0" assert hydrograph_item.initial_abstraction_depth == '' assert hydrograph_item.initial_abstraction_rate == '' assert hydrograph_item.initial_abstraction_amount == '' hydrograph_item = val.value[4] assert hydrograph_item.hydrograph_month == "JUL" assert hydrograph_item.term == "MEDIUM" assert hydrograph_item.response_ratio == "0.011" assert hydrograph_item.time_to_peak == "2.0" assert hydrograph_item.recession_limb_ratio == "2.0" assert hydrograph_item.initial_abstraction_depth == '' assert hydrograph_item.initial_abstraction_rate == '' assert hydrograph_item.initial_abstraction_amount == ''