class SimpleTransectTest(unittest.TestCase):
    """Test TRANSECTS section"""

    def test_one_transect(self):
        """Test one transect from Example-7-final"""
        test_text ="NC\t0.016\t0.016\t0.016\n" \
                   "X1\tFull_Street\t7\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" \
                   "GR\t1.3\t-40\t0.5\t-20\t0\t-20\t0.8\t0\t0\t20\n" \
                   "GR\t0.5\t20\t1.3\t40"
        self.my_options = Transect()
        self.my_options.set_text(test_text)
        actual_text = self.my_options.get_text() #Check this
        new_text = actual_text.replace(" ","")
        #assert new_text == actual_text
        msg = '\nSet:'+test_text+'\nGet:'+actual_text
        self.assertTrue(self.my_options.matches(test_text), msg)

    def test_transects(self):
        """Test transects:Example-7-final inp
        # -- 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
        """
        self.my_options = Transects()
        self.my_options.set_text(test_text)
        actual_text = self.my_options.get_text() #Check this
        msg = '\nSet:' + test_text + '\nGet:' + actual_text
        self.assertTrue(self.my_options.matches(test_text), msg)

    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_transects(self):
        """Test transects:Example-7-final inp
        # -- 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
        """
        self.my_options = Transects()
        self.my_options.set_text(test_text)
        actual_text = self.my_options.get_text() #Check this
        msg = '\nSet:' + test_text + '\nGet:' + actual_text
        self.assertTrue(self.my_options.matches(test_text), msg)
 def test_one_transect(self):
     """Test one transect from Example-7-final"""
     test_text ="NC\t0.016\t0.016\t0.016\n" \
                "X1\tFull_Street\t7\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" \
                "GR\t1.3\t-40\t0.5\t-20\t0\t-20\t0.8\t0\t0\t20\n" \
                "GR\t0.5\t20\t1.3\t40"
     self.my_options = Transect()
     self.my_options.set_text(test_text)
     actual_text = self.my_options.get_text() #Check this
     new_text = actual_text.replace(" ","")
     #assert new_text == actual_text
     msg = '\nSet:'+test_text+'\nGet:'+actual_text
     self.assertTrue(self.my_options.matches(test_text), msg)
    def __init__(self):
        """Define the fields of a SWMM Project by creating an empty placeholder for each section"""

        ProjectBase.__init__(self)

        self.title = Title()  # TITLE         project title
        self.options = General()  # OPTIONS       analysis options
        self.report = Report()  # REPORT        output reporting instructions
        self.files = Files()  # FILES         interface file options
        self.backdrop = BackdropOptions(
        )  # BACKDROP      bounding rectangle and file name of backdrop image
        self.map = MapOptions(
        )  # MAP           map's bounding rectangle and units
        self.raingages = SectionAsList(
            "[RAINGAGES]"
        )  # (list of RainGage)  # RAINGAGES  rain gage information

        self.hydrographs = SectionAsList(
            "[HYDROGRAPHS]")  # (list of UnitHydrograph)
        # unit hydrograph data used to construct RDII inflows

        self.evaporation = Evaporation()  # EVAPORATION   evaporation data
        self.temperature = Temperature(
        )  # TEMPERATURE   air temperature and snow melt data
        self.adjustments = Adjustments(
        )  # ADJUSTMENTS   monthly climate adjustments
        self.subcatchments = SectionAsList(
            "[SUBCATCHMENTS]")  # (list of Subcatchment)
        # basic subcatchment information

        # self.subareas = [Section]               # SUBAREAS      subcatchment impervious/pervious sub-area data

        self.infiltration = SectionAsList("[INFILTRATION]")  # (list of str)
        # subcatchment infiltration parameters

        self.lid_controls = SectionAsList(
            "[LID_CONTROLS]")  # (list of LIDControl)
        # low impact development control information

        self.lid_usage = SectionAsList("[LID_USAGE]")  # (list of LIDUsage)
        # assignment of LID controls to subcatchments

        self.aquifers = SectionAsList("[AQUIFERS]")  # (list of Aquifer)
        # groundwater aquifer parameters

        self.groundwater = SectionAsList(
            "[GROUNDWATER]")  # (list of Groundwater)
        # subcatchment groundwater parameters

        self.snowpacks = SectionAsList("[SNOWPACKS]")  # (list of SnowPack)
        # subcatchment snow pack parameters

        self.junctions = SectionAsList("[JUNCTIONS]")  # (list of Junction)
        # junction node information

        self.outfalls = SectionAsList("[OUTFALLS]")  # (list of Outfall)
        #  outfall node information

        self.dividers = SectionAsList("[DIVIDERS]")  # (list of Divider)
        #  flow divider node information

        self.storage = SectionAsList("[STORAGE]")  # (list of StorageUnit)
        #  storage node information

        self.conduits = SectionAsList("[CONDUITS]")  # (list of Conduit)
        # conduit link information

        self.pumps = SectionAsList("[PUMPS]")  # (list of Pump)
        # pump link information

        self.orifices = SectionAsList("[ORIFICES]")  # (list of Orifice)
        # orifice link information

        self.weirs = SectionAsList("[WEIRS]")  # (list of Weir)
        # weir link information

        self.outlets = SectionAsList("[OUTLETS]")  # (list of Outlet)
        # outlet link information

        self.xsections = SectionAsList("[XSECTIONS]")  # (list of CrossSection)
        # conduit, orifice, and weir cross-section geometry

        self.transects = Transects(
        )  # transect geometry for conduits with irregular cross-sections

        self.controls = Controls()
        # rules that control pump and regulator operation

        self.events = SectionAsList("[EVENTS]")  # (list of Events)

        self.landuses = SectionAsList(
            "[LANDUSES]")  # (list of Landuse)     # land use categories

        self.buildup = SectionAsList("[BUILDUP]")  # (list of Buildup)
        # buildup functions for pollutants and land uses

        self.washoff = SectionAsList("[WASHOFF]")  # (list of Washoff)
        # washoff functions for pollutants and land uses

        self.pollutants = SectionAsList("[POLLUTANTS]")  # (list of Pollutant)
        # pollutant information

        self.coverages = Coverages(
        )  # COVERAGES   assignment of land uses to subcatchments
        self.treatment = SectionAsList("[TREATMENT]")  # (list of Treatment)
        # pollutant removal functions at conveyance system nodes

        self.inflows = SectionAsList("[INFLOWS]")  # (list of DirectInflow)
        # INFLOWS # external hydrograph/pollutograph inflow at nodes

        self.dwf = SectionAsList("[DWF]")  # (list of DryWeatherInflow)
        # baseline dry weather sanitary inflow at nodes

        self.patterns = SectionAsList("[PATTERNS]")  # (list of Pattern)
        # periodic variation in dry weather inflow

        self.rdii = SectionAsList("[RDII]")  # (list of RDIInflow)
        # rainfall-dependent I/I information at nodes

        self.loadings = InitialLoadings()
        # initial pollutant loads on subcatchments

        self.curves = SectionAsList("[CURVES]")  # (list of Curve)
        # CURVES        x-y tabular data referenced in other sections

        self.timeseries = SectionAsList("[TIMESERIES]")  # (list of TimeSeries)
        # time series data referenced in other sections

        self.labels = SectionAsList("[LABELS]")  # (list of Label)
        # X, Y coordinates and text of labels

        self.subcentroids = SectionAsList(
            "[SUBCENTROIDS]")  # (list of subcentroids)
        # X, Y coordinates and text of subcentroids

        self.sublinks = SectionAsList("[SUBLINKS]")  # (list of sublinks)
        # sublinks information

        self.sections = [
            self.title, self.options, self.evaporation, self.raingages,
            self.subcatchments, self.infiltration, self.junctions,
            self.dividers, self.storage, self.outfalls, self.conduits,
            self.pumps, self.orifices, self.weirs, self.outlets,
            self.xsections, self.landuses, self.coverages, self.pollutants,
            self.timeseries, self.patterns, self.curves, self.dwf, self.rdii,
            self.loadings, self.buildup, self.washoff, self.report,
            self.events, self.files, self.backdrop, self.map, self.hydrographs,
            self.temperature, self.adjustments, self.lid_controls,
            self.lid_usage, self.aquifers, self.groundwater, self.snowpacks,
            self.transects, self.controls, self.treatment, self.inflows,
            self.labels, self.subcentroids, self.sublinks
        ]  # Start with a sensible order of sections.
        self.add_sections_from_attributes(
        )  # Add any sections not added in the line above, should not be any left.
예제 #5
0
    def __init__(self):
        """Define the fields of a SWMM Project by creating an empty placeholder for each section"""

        self.title = Title()  # TITLE         project title
        self.options = General()  # OPTIONS       analysis options
        self.report = Report()  # REPORT        output reporting instructions
        self.files = Files()  # FILES         interface file options
        self.backdrop = BackdropOptions(
        )  # BACKDROP      bounding rectangle and file name of backdrop image
        self.map = MapOptions(
        )  # MAP           map's bounding rectangle and units
        # self.raingages = [RainGage]             # RAINGAGES     rain gage information
        self.hydrographs = SectionAsListGroupByID(
            "[HYDROGRAPHS]", UnitHydrograph,
            ";;Hydrograph    \tRain Gage/Month \tResponse\tR       \tT       \tK       \tDmax    \tDrecov  \tDinit   \n"
            ";;--------------\t----------------\t--------\t--------\t--------\t--------\t--------\t--------\t--------"
        )
        # unit hydrograph data used to construct RDII inflows

        self.evaporation = Evaporation()  # EVAPORATION   evaporation data
        self.temperature = Temperature(
        )  # TEMPERATURE   air temperature and snow melt data
        self.adjustments = Adjustments(
        )  # ADJUSTMENTS   monthly climate adjustments
        self.subcatchments = SectionAsListOf(
            "[SUBCATCHMENTS]", Subcatchment,
            ";;Name          \tRain Gage       \tOutlet          \tArea    \t%Imperv \tWidth   \t%Slope  \tCurbLen \tSnowPack        \n"
            ";;--------------\t----------------\t----------------\t--------\t--------\t--------\t--------\t--------\t----------------"
        )
        # basic subcatchment information

        # self.subareas = [Section]               # SUBAREAS      subcatchment impervious/pervious sub-area data

        self.infiltration = SectionAsListOf("[INFILTRATION]", basestring)
        # This is set to SectionAsListOf HortonInfiltration or GreenAmptInfiltration or CurveNumberInfiltration on read
        # subcatchment infiltration parameters

        self.lid_controls = SectionAsListGroupByID(
            "[LID_CONTROLS]", LIDControl,
            ";;Name          \tType/Layer\tParameters\n"
            ";;--------------\t----------\t----------")
        # low impact development control information

        self.lid_usage = SectionAsListOf(
            "[LID_USAGE]", LIDUsage,
            ";;Subcatchment  \tLID Process     \tNumber \tArea      \tWidth     \tInitSat   \tFromImp   \tToPerv    \tRptFile                 \tDrainTo\n"
            ";;--------------\t----------------\t-------\t----------\t----------\t----------\t----------\t----------\t------------------------\t----------------"
        )
        # assignment of LID controls to subcatchments

        self.aquifers = SectionAsListOf(
            "[AQUIFERS]", Aquifer,
            ";;Aquifer       \tPhi   \tWP    \tFC    \tHydCon\tKslope\tTslope\tUEF   \tLED   \tLGLR  \tBEL   \tWTEL  \tUZM   \tUEF Pat\n"
            ";;--------------\t------\t------\t------\t------\t------\t------\t------\t------\t------\t------\t------\t------\t-------"
        )
        # groundwater aquifer parameters

        self.groundwater = SectionAsListOf(
            "[GROUNDWATER]", Groundwater,
            ";;Subcatchment  \tAquifer         \tNode            \tEsurf \tA1    \tB1    \tA2    \tB2    \tA3    \tDsw   \tEgwt  \tEbot  \tWgr   \tUmc   \n"
            ";;--------------\t----------------\t----------------\t------\t------\t------\t------\t------\t------\t------\t------\t------\t------\t------"
        )
        # subcatchment groundwater parameters

        self.snowpacks = SectionAsListGroupByID(
            "[SNOWPACKS]", SnowPack,
            ";;Name          \tSurface   \tParameters\n"
            ";;--------------\t----------\t----------")
        # subcatchment snow pack parameters

        self.junctions = SectionAsListOf(
            "[JUNCTIONS]", Junction,
            ";;Name          \tElevation \tMaxDepth  \tInitDepth \tSurDepth  \tAponded\n"
            ";;--------------\t----------\t----------\t----------\t----------\t----------"
        )
        # junction node information

        # self.outfalls = [Outfall] # OUTFALLS # outfall node information
        # self.dividers = [Divider] # DIVIDERS # flow divider node information
        # self.storage = [StorageUnit] # STORAGE # storage node information

        self.conduits = SectionAsListOf(
            "[CONDUITS]", Conduit,
            ";;Name          \tFrom Node       \tTo Node         \tLength    \tRoughness \tInOffset  \tOutOffset \tInitFlow  \tMaxFlow   \n"
            ";;--------------\t----------------\t----------------\t----------\t----------\t----------\t----------\t----------\t----------"
        )
        # conduit link information

        self.pumps = SectionAsListOf(
            "[PUMPS]", Pump,
            ";;Name          \tFrom Node       \tTo Node         \tPump Curve      \tStatus  \tStartup \tShutoff \n"
            ";;--------------\t----------------\t----------------\t----------------\t--------\t--------\t--------"
        )
        # pump link information

        # self.orifices = [Orifice] # ORIFICES # orifice link information
        # self.weirs = [Weir] # WEIRS # weir link information
        # self.outlets = [Outlet] # OUTLETS # outlet link information

        self.xsections = SectionAsListOf(
            "[XSECTIONS]", CrossSection,
            ";;Link          \tShape       \tGeom1           \tGeom2     \tGeom3     \tGeom4     \tBarrels   \tCulvert   \n"
            ";;--------------\t------------\t----------------\t----------\t----------\t----------\t----------\t----------"
        )
        # conduit, orifice, and weir cross-section geometry

        self.transects = Transects(
        )  # TRANSECTS # transect geometry for conduits with irregular cross-sections
        # self.losses = [Section] # LOSSES # conduit entrance/exit losses and flap valves
        self.controls = SectionAsListOf(
            "[CONTROLS]",
            basestring)  # rules that control pump and regulator operation
        self.landuses = SectionAsListOf(
            "[LANDUSES]", Landuse,
            ";;              \tSweeping  \tFraction  \tLast\n"
            ";;Name          \tInterval  \tAvailable \tSwept\n"
            ";;--------------\t----------\t----------\t----------")
        # land use categories

        self.buildup = SectionAsListOf(
            "[BUILDUP]", Buildup,
            ";;Land Use      \tPollutant       \tFunction  \tCoeff1    \tCoeff2    \tCoeff3    \tPer Unit\n"
            ";;--------------\t----------------\t----------\t----------\t----------\t----------\t----------"
        )
        # buildup functions for pollutants and land uses

        self.washoff = SectionAsListOf(
            "[WASHOFF]", Washoff,
            ";;Land Use      \tPollutant       \tFunction  \tCoeff1    \tCoeff2    \tSweepRmvl \tBmpRmvl\n"
            ";;--------------\t----------------\t----------\t----------\t----------\t----------\t----------"
        )
        # washoff functions for pollutants and land uses

        self.pollutants = SectionAsListOf(
            "[POLLUTANTS]", Pollutant,
            ";;Name          \tUnits \tCrain     \tCgw       \tCrdii     \tKdecay    \tSnowOnly  \tCo-Pollutant    \tCo-Frac   \tCdwf      \tCinit\n"
            ";;--------------\t------\t----------\t----------\t----------\t----------\t----------\t----------------\t----------\t----------\t----------"
        )
        # pollutant information

        self.coverages = Coverages(
        )  # COVERAGES # assignment of land uses to subcatchments
        self.treatment = SectionAsListOf(
            "[TREATMENT]", Treatment,
            ";;Node          \tPollutant       \tFunction\n"
            ";;--------------\t----------------\t--------")

        # pollutant removal functions at conveyance system nodes

        self.inflows = SectionAsListOf(
            "[INFLOWS]", DirectInflow,
            ";;Node          \tConstituent     \tTime Series     \tType    \tMfactor \tSfactor \tBaseline\tPattern\n"
            ";;--------------\t----------------\t----------------\t--------\t--------\t--------\t--------\t--------"
        )
        # INFLOWS # external hydrograph/pollutograph inflow at nodes

        self.dwf = SectionAsListOf(
            "[DWF]", DryWeatherInflow,
            ";;Node          \tConstituent     \tBaseline  \tPatterns  \n"
            ";;--------------\t----------------\t----------\t----------")
        # baseline dry weather sanitary inflow at nodes

        self.patterns = SectionAsListGroupByID(
            "[PATTERNS]", Pattern,
            ";;Name          \tType      \tMultipliers\n"
            ";;--------------\t----------\t-----------")
        # PATTERNS      periodic variation in dry weather inflow

        self.rdii = SectionAsListOf(
            "[RDII]", RDIInflow,
            ";;Node          \tUnit Hydrograph \tSewer Area\n"
            ";;--------------\t----------------\t----------")
        # rainfall-dependent I/I information at nodes

        self.loadings = SectionAsListOf(
            "[LOADINGS]", InitialLoading,
            ";;Subcatchment  \tPollutant       \tBuildup\n"
            ";;--------------\t----------------\t----------")
        # initial pollutant loads on subcatchments

        self.curves = SectionAsListGroupByID(
            "[CURVES]", Curve,
            ";;Name          \tType      \tX-Value   \tY-Value   \n"
            ";;--------------\t----------\t----------\t----------")
        # CURVES        x-y tabular data referenced in other sections

        self.timeseries = SectionAsListGroupByID(
            "[TIMESERIES]", TimeSeries,
            ";;Name          \tDate      \tTime      \tValue\n"
            ";;--------------\t----------\t----------\t----------")
        # time series data referenced in other sections

        # self.polygons = [Section] # POLYGONS # X,Y coordinates for each vertex of subcatchment polygons
        # self.coordinates = [Section] # COORDINATES # X,Y coordinates for nodes
        # self.vertices = [Section] # VERTICES # X,Y coordinates for each interior vertex of polyline links
        # self.labels = [Section] # LABELS # X,Y coordinates and text of labels
        # self.symbols = [Section] # SYMBOLS # X,Y coordinates for rain gages
        #  X,Y coordinates of the bounding rectangle and file name of the backdrop image.
        # [TAGS]
        InputFile.__init__(
            self
        )  # Do this after setting attributes so they will all get added to sections[]