def peakflow(self, catchment): filename = str(uuid.uuid4()) self.write_rain_file(filename, self.getRainVec(), 60 * 6) fo = open("/tmp/" + filename + ".inp", 'w') self.init_swmm_model(fo, rainfile='/tmp/' + filename + '.dat', start='01/01/2000', stop='01/02/2000', intervall='00:05:00', sub_satchment=catchment) fo.close() swmm = cdll.LoadLibrary(self.getSWMMLib()) if swmm.swmm_run("/tmp/" + filename + ".inp", "/tmp/" + filename + ".rep", "/tmp/" + filename + ".out") != 0: print "something went wrong" return -1 f = swmmread.open("/tmp/" + filename + ".out") natural_peaks = {} for c in catchment.keys(): timeseries = f.get_values('subcatchments', c) a = np.array([row[1][4] for row in timeseries]) natural_peaks[c] = a.max() #os.remove("/tmp/" + filename + ".inp") #os.remove("/tmp/" + filename + ".rep") #os.remove("/tmp/" + filename + ".out") #os.remove("/tmp/" + filename + ".dat") return natural_peaks
def peakflow(self, catchment): filename = str(uuid.uuid4()) self.write_rain_file(filename, self.getRainVec(), 60 * 5) fo = open("/tmp/" + filename + ".inp", "w") self.init_swmm_model( fo, rainfile="/tmp/" + filename + ".dat", start="01/01/2000", stop="01/02/2000", intervall="00:05:00", sub_satchment=catchment, ) fo.close() swmm = cdll.LoadLibrary(self.getSWMMLib()) if swmm.swmm_run("/tmp/" + filename + ".inp", "/tmp/" + filename + ".rep", "/tmp/" + filename + ".out") != 0: print "something went wrong" return -1 f = swmmread.open("/tmp/" + filename + ".out") natural_peaks = {} for c in catchment.keys(): timeseries = f.get_values("subcatchments", c) a = np.array([row[1][4] for row in timeseries]) natural_peaks[c] = a.max() os.remove("/tmp/" + filename + ".inp") os.remove("/tmp/" + filename + ".rep") os.remove("/tmp/" + filename + ".out") os.remove("/tmp/" + filename + ".dat") return natural_peaks
def SEI(self, catchment, thresholds): filename = str(uuid.uuid4()) fo = open("/tmp/" + filename + ".inp", 'w') intervall = ( datetime.datetime(2000, 1, 1) + datetime.timedelta(seconds=self.time_delta)).strftime('%H:%M:%S') dt = datetime.timedelta(seconds=self.time_delta) swmm_rain_filename = self.swmm_rain_file if self.rain_vector_from_city != "": self.city.reset_reading() for c in self.city: # print "wite",self.rain_vector_from_city import ogr # print c.GetGeomFieldCount() # print c.GetFieldDefnRef().GetType("data") #ogr.FieldDefn.GetType("data") # print c.GetFieldAsBinary("data") # print dm_get_double_list(c, self.rain_vector_from_city) self.write_rain_file( filename, dm_get_double_list(c, self.rain_vector_from_city), 60 * 6) swmm_rain_filename = "/tmp/" + filename + ".dat" self.init_swmm_model(fo, rainfile=swmm_rain_filename, start='01/01/2000', stop='12/30/2009', intervall=intervall, sub_satchment=catchment) fo.close() swmm = cdll.LoadLibrary(self.getSWMMLib()) e_code = swmm.swmm_run("/tmp/" + filename + ".inp", "/tmp/" + filename + ".rep", "/tmp/" + filename + ".out") if e_code != 0: print e_code, "something went wrong" return -1 f = swmmread.open("/tmp/" + filename + ".out") SEIs = {} for c in catchment.keys(): timeseries = f.get_values('subcatchments', c) sum = 0 threshold = thresholds[c] / 2.0 for row in timeseries: if row[1][4] > threshold: sum = sum + row[1][4] # print c, sum SEIs[c] = sum os.remove("/tmp/" + filename + ".inp") os.remove("/tmp/" + filename + ".rep") os.remove("/tmp/" + filename + ".out") if self.rain_vector_from_city != "": os.remove("/tmp/" + filename + ".dat") return SEIs
def SEI(self, catchment, thresholds): filename = str(uuid.uuid4()) fo = open("/tmp/" + filename + ".inp", "w") intervall = (datetime.datetime(2000, 1, 1) + datetime.timedelta(seconds=self.time_delta)).strftime("%H:%M:%S") dt = datetime.timedelta(seconds=self.time_delta) swmm_rain_filename = self.swmm_rain_file if self.rain_vector_from_city != "": self.city.reset_reading() for c in self.city: # s = str(c.GetFieldAsString(self.rain_vector_from_city)) self.write_rain_file(filename, dm_get_double_list(c, self.rain_vector_from_city), 60 * 5) swmm_rain_filename = "/tmp/" + filename + ".dat" self.init_swmm_model( fo, rainfile=swmm_rain_filename, start="01/01/2000", stop="12/30/2009", intervall=intervall, sub_satchment=catchment, ) fo.close() swmm = cdll.LoadLibrary(self.getSWMMLib()) e_code = swmm.swmm_run("/tmp/" + filename + ".inp", "/tmp/" + filename + ".rep", "/tmp/" + filename + ".out") if e_code != 0: print e_code, "something went wrong" return -1 f = swmmread.open("/tmp/" + filename + ".out") SEIs = {} for c in catchment.keys(): timeseries = f.get_values("subcatchments", c) sum = 0 threshold = thresholds[c] / 2.0 for row in timeseries: if row[1][4] > threshold: sum = sum + row[1][4] # print c, sum SEIs[c] = sum os.remove("/tmp/" + filename + ".inp") os.remove("/tmp/" + filename + ".rep") os.remove("/tmp/" + filename + ".out") if self.rain_vector_from_city != "": os.remove("/tmp/" + filename + ".dat") return SEIs