class Reach(Element): def __init__(self): super(Reach, self).__init__('Reach', None) self.downstream = Property('Downstream') self.staticProperties = [self.downstream.getName()] @classmethod def readReach(cls, currentLine, basinsrc, basinsink): r = Reach() super(Reach, r).deserialize(currentLine, basinsrc) r.serialize(basinsink) return r def add(self, a): if isinstance(a,Property): if a.getName() == self.downstream.getName(): self.downstream.setValue(a.getValue()) super(Reach, self).add(self.downstream) else: super(Reach, self).add(a) else: print(a, "is not an instance of Property class. Cannot be added.") def remove(self, a): if isinstance(a,Property): if a.getName() == self.downstream.getName(): self.downstream.setValue(None) else: try: super(Reach, self).remove(a) except LookupError: print("Property not found.")
class Reach(Element): def __init__(self): super(Reach, self).__init__('Reach', None) self.downstream = Property('Downstream') self.staticProperties = [self.downstream.getName()] @classmethod def readReach(cls, currentLine, basinsrc, basinsink): r = Reach() super(Reach, r).deserialize(currentLine, basinsrc) r.serialize(basinsink) return r def add(self, a): if isinstance(a, Property): if a.getName() == self.downstream.getName(): self.downstream.setValue(a.getValue()) super(Reach, self).add(self.downstream) else: super(Reach, self).add(a) else: print(a, "is not an instance of Property class. Cannot be added.") def remove(self, a): if isinstance(a, Property): if a.getName() == self.downstream.getName(): self.downstream.setValue(None) else: try: super(Reach, self).remove(a) except LookupError: print("Property not found.")
class Junction(Element): def __init__(self): super(Junction, self).__init__('Junction', None) self.downstream = Property('Downstream') self.staticProperties = [self.downstream.getName()] @classmethod def readJunction(cls, currentLine, basinsrc, basinsink): j = Junction() super(Junction, j).deserialize(currentLine, basinsrc) j.serialize(basinsink) return j def add(self, a): if isinstance(a, Property): if a.getName() == self.downstream.getName(): self.downstream.setValue(a.getValue()) super(Junction, self).add(self.downstream) else: super(Junction, self).add(a) else: print(a, "is not an instance of Property class. Cannot be added.") def remove(self, a): if isinstance(a, Property): if a.getName() == self.downstream.getName(): self.downstream.setValue(None) else: try: super(Junction, self).remove(a) except LookupError: print("Property not found.") @classmethod def newJunction(cls, s, basinsink): j = Junction() j.setIdentifier('JN ' + str(s.getIdentifier())) j.downstream = s.downstream p = Property.newProperty('Canvas X', s.canvasx.getValue()) super(Junction, j).add(Property.newProperty('Canvas X', s.canvasx.getValue())) super(Junction, j).add(Property.newProperty('Canvas Y', s.canvasy.getValue())) super(Junction, j).add(j.downstream) j.serialize(basinsink) return j
class Reservoir(Element): def __init__(self): super(Reservoir, self).__init__('Reservoir', None) self.downstream = Property('Downstream') self.storageoutflow = Property('Storage-Outflow Table') self.staticProperties = [self.downstream.getName(), self.storageoutflow.getName()] @classmethod def readReservoir(cls, currentLine, basinsrc, basinsink): r = Reservoir() super(Reservoir, r).deserialize(currentLine, basinsrc) r.serialize(basinsink) return r def add(self, a): if isinstance(a,Property): if a.getName() == self.downstream.getName(): self.downstream.setValue(a.getValue()) super(Reservoir, self).add(self.downstream) elif a.getName() == self.storageoutflow.getName(): self.storageoutflow.setValue(a.getValue()) super(Reservoir, self).add(self.storageoutflow) else: super(Reservoir, self).add(a) else: print(a, "is not an instance of Property class. Cannot be added.") def remove(self, a): if isinstance(a,Property): if a.getName() == self.downstream.getName(): self.downstream.setValue(None) elif a.getName() == self.storageoutflow.getName(): self.storageoutflow.setValue(None) else: try: super(Reservoir, self).remove(a) except LookupError: print("Property not found.") @classmethod def newReservoir(cls, s, basinsink, redevel, rlsrate): r = Reservoir() r.setIdentifier('Reservoir ' + s.getIdentifier()) r.downstream = Property.newProperty('Downstream', 'J ' + s.getIdentifier()) r.storageoutflow = Property.newProperty('Storage-Outflow Table', s.getIdentifier() + 'MWRD_' + str(redevel) + '_' + str(rlsrate)) super(Reservoir, r).add(Property.newProperty('Canvas X', s.canvasx.getValue())) super(Reservoir, r).add(Property.newProperty('Canvas Y', s.canvasy.getValue())) super(Reservoir, r).add(r.downstream) super(Reservoir, r).add(Property.newProperty('Route', 'Modified Puls')) super(Reservoir, r).add(Property.newProperty('Routing Curve', 'Storage-Outflow')) super(Reservoir, r).add(Property.newProperty('Initial Outflow Equals Inflow', 'Yes')) super(Reservoir, r).add(r.storageoutflow) r.serialize(basinsink) return r
class Junction(Element): def __init__(self): super(Junction, self).__init__("Junction", None) self.downstream = Property("Downstream") self.staticProperties = [self.downstream.getName()] @classmethod def readJunction(cls, currentLine, basinsrc, basinsink): j = Junction() super(Junction, j).deserialize(currentLine, basinsrc) j.serialize(basinsink) return j def add(self, a): if isinstance(a, Property): if a.getName() == self.downstream.getName(): self.downstream.setValue(a.getValue()) super(Junction, self).add(self.downstream) else: super(Junction, self).add(a) else: print(a, "is not an instance of Property class. Cannot be added.") def remove(self, a): if isinstance(a, Property): if a.getName() == self.downstream.getName(): self.downstream.setValue(None) else: try: super(Junction, self).remove(a) except LookupError: print("Property not found.") @classmethod def newJunction(cls, s, basinsink): j = Junction() j.setIdentifier("JN " + str(s.getIdentifier())) j.downstream = s.downstream p = Property.newProperty("Canvas X", s.canvasx.getValue()) super(Junction, j).add(Property.newProperty("Canvas X", s.canvasx.getValue())) super(Junction, j).add(Property.newProperty("Canvas Y", s.canvasy.getValue())) super(Junction, j).add(j.downstream) j.serialize(basinsink) return j
def deserialize(self, currentLine, infile): lineList = currentLine.strip('\n').strip().split(': ') try: self.setIdentifier(lineList[1]) except IndexError: print(lineList) self.setIdentifier('') # Read a single line and add the info to a new Property of an Element child class as long it is not an 'End:' # line. This is intended to be used only in the child classes in super() or overridden in the child class. currentLine = infile.readline() while not currentLine.startswith('End:'): if not currentLine == '\n': # p = Property(None) lineList = currentLine.strip('\n').strip().split(': ') p = Property(lineList[0]) try: p.setValue(lineList[1]) except IndexError: p.setValue('') self.__class__.add(self, p) currentLine = infile.readline() else: currentLine = infile.readline()
class Diversion(Element): def __init__(self): super(Diversion, self).__init__('Diversion', None) self.downstream = Property('Downstream') self.divertto = Property('Divert To') self.staticProperties = [ self.downstream.getName(), self.divertto.getName() ] @classmethod def readDiversion(cls, currentLine, basinsrc, basinsink): d = Diversion() super(Diversion, d).deserialize(currentLine, basinsrc) d.serialize(basinsink) return d def add(self, a): if isinstance(a, Property): if a.getName() == self.downstream.getName(): self.downstream.setValue(a.getValue()) super(Diversion, self).add(self.downstream) elif a.getName() == self.divertto.getName(): self.divertto.setValue(a.getValue()) super(Diversion, self).add(self.divertto) else: super(Diversion, self).add(a) def remove(self, a): if isinstance(a, Property): if a.getName() == self.downstream.getName(): self.downstream.setValue(None) elif a.getName() == self.divertto.getName(): self.divertto.setValue(None) else: try: super(Diversion, self).remove(a) except LookupError: print("Property not found.")
class Diversion(Element): def __init__(self): super(Diversion, self).__init__('Diversion', None) self.downstream = Property('Downstream') self.divertto = Property('Divert To') self.staticProperties = [self.downstream.getName(), self.divertto.getName()] @classmethod def readDiversion(cls, currentLine, basinsrc, basinsink): d = Diversion() super(Diversion, d).deserialize(currentLine, basinsrc) d.serialize(basinsink) return d def add(self, a): if isinstance(a,Property): if a.getName() == self.downstream.getName(): self.downstream.setValue(a.getValue()) super(Diversion, self).add(self.downstream) elif a.getName() == self.divertto.getName(): self.divertto.setValue(a.getValue()) super(Diversion, self).add(self.divertto) else: super(Diversion, self).add(a) def remove(self, a): if isinstance(a,Property): if a.getName() == self.downstream.getName(): self.downstream.setValue(None) elif a.getName() == self.divertto.getName(): self.divertto.setValue(None) else: try: super(Diversion, self).remove(a) except LookupError: print("Property not found.")
class Reservoir(Element): def __init__(self): super(Reservoir, self).__init__('Reservoir', None) self.downstream = Property('Downstream') self.storageoutflow = Property('Storage-Outflow Table') self.staticProperties = [ self.downstream.getName(), self.storageoutflow.getName() ] @classmethod def readReservoir(cls, currentLine, basinsrc, basinsink): r = Reservoir() super(Reservoir, r).deserialize(currentLine, basinsrc) r.serialize(basinsink) return r def add(self, a): if isinstance(a, Property): if a.getName() == self.downstream.getName(): self.downstream.setValue(a.getValue()) super(Reservoir, self).add(self.downstream) elif a.getName() == self.storageoutflow.getName(): self.storageoutflow.setValue(a.getValue()) super(Reservoir, self).add(self.storageoutflow) else: super(Reservoir, self).add(a) else: print(a, "is not an instance of Property class. Cannot be added.") def remove(self, a): if isinstance(a, Property): if a.getName() == self.downstream.getName(): self.downstream.setValue(None) elif a.getName() == self.storageoutflow.getName(): self.storageoutflow.setValue(None) else: try: super(Reservoir, self).remove(a) except LookupError: print("Property not found.") @classmethod def newReservoir(cls, s, basinsink, redevel, rlsrate): r = Reservoir() r.setIdentifier('Reservoir ' + s.getIdentifier()) r.downstream = Property.newProperty('Downstream', 'JN ' + s.getIdentifier()) soString = s.getIdentifier() + 'MWRD_' + str(redevel) + '_' + str( rlsrate) r.storageoutflow = Property.newProperty('Storage-Outflow Table', soString[:27]) super(Reservoir, r).add(Property.newProperty('Canvas X', s.canvasx.getValue())) super(Reservoir, r).add(Property.newProperty('Canvas Y', s.canvasy.getValue())) super(Reservoir, r).add(r.downstream) super(Reservoir, r).add(Property.newProperty('Route', 'Modified Puls')) super(Reservoir, r).add(Property.newProperty('Routing Curve', 'Storage-Outflow')) super(Reservoir, r).add( Property.newProperty('Initial Outflow Equals Inflow', 'Yes')) super(Reservoir, r).add(r.storageoutflow) r.serialize(basinsink) return r
class Subbasin(Element): def __init__(self): super(Subbasin, self).__init__('Subbasin', None) self.area = Property('Area') self.downstream = Property('Downstream') self.curvenum = Property('Curve Number') self.impervious = Property('Percent Impervious Area') self.canvasx = Property('Canvas X') self.canvasy = Property('Canvas Y') self.canopy = Property('Canopy') self.rlsrate = Property('Release Rate') self.redevel = Property('Percent Redevelopment') self.staticProperties = [self.area.getName(), self.downstream.getName(), self.curvenum.getName(), self.impervious.getName(), self.canvasx.getName(), self.canvasy.getName(), self.canopy.getName(), self.rlsrate.getName(), self.redevel.getName()] @classmethod def readSubbasin(cls, currentLine, basinsrc, basinsink, redevel, altRDdict, curvenum, rlsrate, altRRdict, canopyrate, altCANdict): s = Subbasin() super(Subbasin, s).deserialize(currentLine, basinsrc) ID = s.getIdentifier() if ID in altRDdict: RDrate = altRDdict[ID] else: RDrate = redevel if ID in altRRdict: RRrate = altRRdict[ID] else: RRrate = rlsrate if ID in altCANdict: CANrate = altCANdict[ID] else: CANrate = canopyrate sNew, soname = s.divideSubbasin(basinsink, RDrate, curvenum, RRrate, CANrate) s.rlsrate.setValue(RRrate) s.redevel.setValue(RDrate) s.serialize(basinsink) return s, sNew, soname def add(self, a): if isinstance(a,Property): if a.getName() == self.area.getName(): self.area.setValue(a.getAsFloat()) super(Subbasin, self).add(self.area) elif a.getName() == self.downstream.getName(): self.downstream.setValue(a.getValue()) super(Subbasin, self).add(self.downstream) elif a.getName() == self.curvenum.getName(): self.curvenum.setValue(a.getAsFloat()) super(Subbasin, self).add(self.curvenum) elif a.getName() == self.impervious.getName(): self.impervious.setValue(a.getAsFloat()) super(Subbasin, self).add(self.impervious) elif a.getName() == self.canvasx.getName(): self.canvasx.setValue(a.getValue()) super(Subbasin, self).add(self.canvasx) elif a.getName() == self.canvasy.getName(): self.canvasy.setValue(a.getValue()) super(Subbasin, self).add(self.canvasy) elif a.getName() == self.canopy.getName(): self.canopy.setValue(a.getValue()) super(Subbasin, self).add(self.canopy) else: super(Subbasin, self).add(a) else: print(a, "is not an instance of Property class. Cannot be added.") def remove(self, a): if isinstance(a,Property): if a.getName() == self.area.getName(): self.area.setValue(None) elif a.getName() == self.downstream.getName(): self.downstream.setValue(None) elif a.getName() == self.curvenum.getName(): self.curvenum.setValue(None) elif a.getName() == self.impervious.getName(): self.impervious.setValue(None) elif a.getName() == self.canvasx.getName(): self.canvasx.setValue(None) elif a.getName() == self.canvasy.getName(): self.canvasy.setValue(None) elif a.getName() == self.canopy.getName(): self.canopy.setValue(None) else: try: super(Subbasin, self).remove(a) except LookupError: print("Property not found.") def divideSubbasin(self, basinsink, redevel, curvenum, rlsrate, canrate): j = Junction.newJunction(self, basinsink) r = Reservoir.newReservoir(self, basinsink, redevel, rlsrate) sNew = Subbasin.newSubbasin(self, basinsink, redevel, curvenum, canrate) self.area.setValue(self.area.getAsFloat() - sNew.area.getAsFloat()) self.downstream.setValue('JN ' + self.getIdentifier()) sNew.rlsrate.setValue(rlsrate) sNew.redevel.setValue(redevel) return sNew, r.storageoutflow.getAsString() @classmethod def newSubbasin(cls, s, basinsink, redevel, curvenum, canrate): sNew = copy.deepcopy(s) sNew.setIdentifier(s.getIdentifier() + 'MWRD') sNew.area.setValue((redevel / 100.) * s.area.getAsFloat()) sNew.downstream.setValue('Reservoir ' + s.getIdentifier()) sNew.canopy.setValue('SMA') # Define new canopy properties initCanopy = Property.newProperty('Initial Canopy Storage Percent', 0) maxCanopy = Property.newProperty('Canopy Maximum Storage', canrate) endCanopy = Property.newProperty('End Canopy', '') super(Subbasin, sNew).insert(super(Subbasin, sNew).index(sNew.canopy) + 1, endCanopy) super(Subbasin, sNew).insert(super(Subbasin, sNew).index(sNew.canopy) + 1, maxCanopy) super(Subbasin, sNew).insert(super(Subbasin, sNew).index(sNew.canopy) + 1, initCanopy) sNew.curvenum.setValue(curvenum) sNew.serialize(basinsink) return sNew
class Subbasin(Element): def __init__(self): super(Subbasin, self).__init__('Subbasin', None) self.area = Property('Area') self.downstream = Property('Downstream') self.curvenum = Property('Curve Number') self.impervious = Property('Percent Impervious Area') self.canvasx = Property('Canvas X') self.canvasy = Property('Canvas Y') self.canopy = Property('Canopy') self.rlsrate = Property('Release Rate') self.redevel = Property('Percent Redevelopment') self.staticProperties = [ self.area.getName(), self.downstream.getName(), self.curvenum.getName(), self.impervious.getName(), self.canvasx.getName(), self.canvasy.getName(), self.canopy.getName(), self.rlsrate.getName(), self.redevel.getName() ] @classmethod def readSubbasin(cls, currentLine, basinsrc, basinsink, redevel, altRDdict, curvenum, rlsrate, altRRdict, canopyrate, altCANdict): s = Subbasin() super(Subbasin, s).deserialize(currentLine, basinsrc) ID = s.getIdentifier() if ID in altRDdict: RDrate = altRDdict[ID] else: RDrate = redevel if ID in altRRdict: RRrate = altRRdict[ID] else: RRrate = rlsrate if ID in altCANdict: CANrate = altCANdict[ID] else: CANrate = canopyrate sNew, soname = s.divideSubbasin(basinsink, RDrate, curvenum, RRrate, CANrate) s.rlsrate.setValue(RRrate) s.redevel.setValue(RDrate) s.serialize(basinsink) return s, sNew, soname def add(self, a): if isinstance(a, Property): if a.getName() == self.area.getName(): self.area.setValue(a.getAsFloat()) super(Subbasin, self).add(self.area) elif a.getName() == self.downstream.getName(): self.downstream.setValue(a.getValue()) super(Subbasin, self).add(self.downstream) elif a.getName() == self.curvenum.getName(): self.curvenum.setValue(a.getAsFloat()) super(Subbasin, self).add(self.curvenum) elif a.getName() == self.impervious.getName(): self.impervious.setValue(a.getAsFloat()) super(Subbasin, self).add(self.impervious) elif a.getName() == self.canvasx.getName(): self.canvasx.setValue(a.getValue()) super(Subbasin, self).add(self.canvasx) elif a.getName() == self.canvasy.getName(): self.canvasy.setValue(a.getValue()) super(Subbasin, self).add(self.canvasy) elif a.getName() == self.canopy.getName(): self.canopy.setValue(a.getValue()) super(Subbasin, self).add(self.canopy) else: super(Subbasin, self).add(a) else: print(a, "is not an instance of Property class. Cannot be added.") def remove(self, a): if isinstance(a, Property): if a.getName() == self.area.getName(): self.area.setValue(None) elif a.getName() == self.downstream.getName(): self.downstream.setValue(None) elif a.getName() == self.curvenum.getName(): self.curvenum.setValue(None) elif a.getName() == self.impervious.getName(): self.impervious.setValue(None) elif a.getName() == self.canvasx.getName(): self.canvasx.setValue(None) elif a.getName() == self.canvasy.getName(): self.canvasy.setValue(None) elif a.getName() == self.canopy.getName(): self.canopy.setValue(None) else: try: super(Subbasin, self).remove(a) except LookupError: print("Property not found.") def divideSubbasin(self, basinsink, redevel, curvenum, rlsrate, canrate): j = Junction.newJunction(self, basinsink) r = Reservoir.newReservoir(self, basinsink, redevel, rlsrate) sNew = Subbasin.newSubbasin(self, basinsink, redevel, curvenum, canrate) self.area.setValue(self.area.getAsFloat() - sNew.area.getAsFloat()) self.downstream.setValue('JN ' + self.getIdentifier()) sNew.rlsrate.setValue(rlsrate) sNew.redevel.setValue(redevel) return sNew, r.storageoutflow.getAsString() @classmethod def newSubbasin(cls, s, basinsink, redevel, curvenum, canrate): sNew = copy.deepcopy(s) sNew.setIdentifier(s.getIdentifier() + 'MWRD') sNew.area.setValue((redevel / 100.) * s.area.getAsFloat()) print("================= create Reservoir " + s.getIdentifier() + " ===================") sNew.downstream.setValue('Reservoir ' + s.getIdentifier()) print(sNew.downstream) sNew.canopy.setValue('SMA') # Define new canopy properties initCanopy = Property.newProperty('Initial Canopy Storage Percent', 0) maxCanopy = Property.newProperty('Canopy Maximum Storage', canrate) endCanopy = Property.newProperty('End Canopy', '') super(Subbasin, sNew).insert( super(Subbasin, sNew).index(sNew.canopy) + 1, endCanopy) super(Subbasin, sNew).insert( super(Subbasin, sNew).index(sNew.canopy) + 1, maxCanopy) super(Subbasin, sNew).insert( super(Subbasin, sNew).index(sNew.canopy) + 1, initCanopy) sNew.curvenum.setValue(curvenum) sNew.serialize(basinsink) return sNew