def __init__(self): """The constructor Make all numpy arrays and establish the inflow procedure based on D8 or Multi Flow Direction Algorithm method. """ GridGlobals.__init__(self) Logger.info("Surface: ON") self.n = 15 # assign array objects for i in range(self.r): for j in range(self.c): self.arr[i][j] = SurArrs(Globals.get_mat_reten(i, j), Globals.get_mat_inf_index(i, j), Globals.get_mat_hcrit(i, j), Globals.get_mat_aa(i, j), Globals.get_mat_b(i, j)) Stream.__init__(self) Logger.info( "\tRill flow: {}".format('ON' if Globals.isRill else 'OFF'))
def rill_runoff(i, j, sur, dt, efect_vrst, ratio): """TODO. :param i: row index :param j: col index :param sur: TODO :param dt: TODO :param efect_vrst: TODO :param ratio: TODO :return: TODO """ ppp = False n = Globals.get_mat_n(i, j) slope = Globals.get_mat_slope(i, j) vol_to_rill = sur.h_rill * GridGlobals.get_pixel_area() h, b = rill.update_hb(vol_to_rill, RILL_RATIO, efect_vrst, sur.rillWidth, ratio, ppp) r_rill = (h * b) / (b + 2 * h) v_rill = math.pow(r_rill, (2.0 / 3.0)) * \ 1. / n * math.pow(slope / 100, 0.5) q_rill = v_rill * h * b vol_rill = q_rill * dt # original based on speed courant = (v_rill * dt) / efect_vrst # celerita # courant = (1 + s*b/(3*(b+2*h))) * q_rill/(b*h) sur.vol_to_rill = vol_to_rill sur.rillWidth = b if courant <= courantMax: if vol_rill > vol_to_rill: sur.v_rill_rest = 0 sur.vol_runoff_rill = vol_to_rill else: sur.v_rill_rest = vol_to_rill - vol_rill sur.vol_runoff_rill = vol_rill else: return q_rill, v_rill, ratio, courant return q_rill, v_rill, ratio, courant
def do_flow(self, surface, subsurface, delta_t, flow_control, courant): rr, rc = GridGlobals.get_region_dim() mat_efect_cont = Globals.get_mat_efect_cont() fc = flow_control sr = Globals.get_sr() itera = Globals.get_itera() potRain, fc.tz = rain_f.timestepRainfall(itera, fc.total_time, delta_t, fc.tz, sr) for i in rr: for j in rc[i]: # TODO: variable not used. Should we delete it? h_total_pre = surface.arr[i][j].h_total_pre surface_state = surface.arr[i][j].state if surface_state >= 1000: q_sheet = 0.0 v_sheet = 0.0 q_rill = 0.0 v_rill = 0.0 rill_courant = 0.0 else: q_sheet, v_sheet, q_rill, v_rill, fc.ratio, rill_courant = runoff( i, j, surface.arr[i][j], delta_t, mat_efect_cont[i][j], fc.ratio) subsurface.runoff(i, j, delta_t, mat_efect_cont[i][j]) # TODO: variable not used. Should we delete it? q_surface = q_sheet + q_rill # print v_sheet,v_rill v = max(v_sheet, v_rill) co = 'sheet' courant.CFL(i, j, surface.arr[i][j].h_total_pre, v, delta_t, mat_efect_cont[i][j], co, rill_courant) # TODO: variable not used. Should we delet it? rill_courant = 0. # w1 = surface.arr[i][j].vol_runoff_rill # w2 = surface.arr[i][j].v_rill_rest # print surface.arr[i][j].h_total_pre # if (w1 > 0 and w2 == 0) : # print 'asdf', w1, w2 return potRain
def __init__(self): """TODO.""" super(Vegetation, self).__init__() mat_pi = Globals.get_mat_pi() / 1000.0 self.n = 3 # TODO ? for i in range(self.r): for j in range(self.c): self.arr[i][j] = VegArrs(False, DataGlobals.get_mat_ppl(i, j), mat_pi[i][j])
def output_filepath(self, name, item='temp'): """Get ArcGIS data path. TODO: item needs to be set for each raster reparatelly. Now all is in temp dir. :param name: layer name :return: full path """ #try: # item = self._data[name] #except: # item = 'temp' path = os.path.join(Globals.get_outdir(), item, 'data.gdb', name) Logger.debug('File path: {}'.format(path)) return path
def _handler(self, request, response): # lazy import sys.path.insert( 0, os.path.join(os.path.dirname(__file__), '..', '..', '..')) from smoderp2d import WpsRunner from smoderp2d.exceptions import ProviderError, ConfigError from smoderp2d.core.general import Globals # input data indata = self.process_input(request.inputs['input'][0].data) if not indata: raise Exception("Input ini file not found") # run computation runner = WpsRunner() runner.set_options({'typecomp': 'roff', 'indata': indata}) runner.run() # output data response.outputs['output'].file = self.process_output( Globals.get_outdir()) return response
def __init__(self): Logger.info("D8 flow algorithm") self.inflows = D8_.new_inflows(Globals.get_mat_fd())
def __init__(self): points = Globals.get_array_points() ipi = points.shape[0] jpj = 5 point_int = [[0] * jpj for i in range(ipi)] rr, rc = GridGlobals.get_region_dim() pixel_area = GridGlobals.get_pixel_area() self.inSurface = [] self.inStream = [] for ip in range(ipi): for jp in [0, 1, 2]: point_int[ip][jp] = int(points[ip][jp]) for ip in range(ipi): for jp in [3, 4]: point_int[ip][jp] = points[ip][jp] # tento cylkus meze budy, ktere jsou # v i,j cylku o jednu vedle rrows a rcols outsideDomain = False del_ = [] for ip in range(ipi): l = point_int[ip][1] m = point_int[ip][2] for ipp in rr: if l == ipp: for jpp in rc[ipp]: if m == jpp: outsideDomain = True if not (outsideDomain): del_.append(ip) outsideDomain = False point_int = [i for j, i in enumerate(point_int) if j not in del_] ipi -= len(del_) counter = 0 # mat_stream_seg is alway presented if stream == True # if (mat_stream_seg != None) and (stream == True): if Globals.isStream: for ip in range(ipi): l = point_int[ip][1] m = point_int[ip][2] if Globals.get_mat_stream_reach(l, m) >= 1000: self.inStream.append(counter) counter += 1 else: self.inSurface.append(counter) counter += 1 else: self.inSurface = [i for i in range(ipi)] self.inStream.append(-99) self.inSurface.append(-99) self.n = ipi self.point_int = point_int self.subflow = Globals.subflow self.rill = Globals.isRill self.stream = Globals.isStream self.pixel_area = pixel_area iStream = 0 iSurface = 0 self.header = [] for i in range(self.n): if i == self.inStream[iStream]: header = '# Hydrograph at the point with coordinates: {} {}{}'.format( self.point_int[i][3], self.point_int[i][4], os.linesep) header += '# A pixel size is [m2]:{}'.format(os.linesep) header += '# {}{}'.format(self.pixel_area, os.linesep) if not Globals.extraOut: header += '# time[s];deltaTime[s];rainfall[m];reachWaterLevel[m];reachFlow[m3/s];reachVolRunoff[m3]' else: header += '# time[s];deltaTime[s];Rainfall[m];Waterlevel[m];V_runoff[m3];Q[m3/s];V_from_field[m3];V_rests_in_stream[m3]' header += os.linesep iStream += 1 self.header.append(header) elif i == self.inSurface[iSurface]: header = '# Hydrograph at the point with coordinates: {} {}{}'.format( self.point_int[i][3], self.point_int[i][4], os.linesep) header += '# A pixel size is [m2]:{}'.format(os.linesep) header += '# {}{}'.format(self.pixel_area, os.linesep) if not Globals.extraOut: header += '# time[s];deltaTime[s];rainfall[m];totalWaterLevel[m];surfaceFlow[m3/s];surfaceVolRunoff[m3]' else: header += '# time[s];deltaTime[s];Rainfall[m];Water_level_[m];Sheet_Flow[m3/s];Sheet_V_runoff[m3];Sheet_V_rest[m3];Infiltration[m];Surface_retetion[m];State;V_inflow[m3];WlevelTotal[m]{}' if Globals.isRill: header += ';WlevelRill[m];Rill_width[m];Rill_flow[m3/s];Rill_V_runoff[m3];Rill_V_rest;Surface_Flow[m3/s];Surface_V_runoff[m3]' header += ';SurfaceBil[m3]' if Globals.subflow: header += ';Sub_Water_level_[m];Sub_Flow_[m3/s];Sub_V_runoff[m3];Sub_V_rest[m3];Percolation[];exfiltration[]' if Globals.extraOut: header += ';V_to_rill.m3.;ratio;courant;courantrill;iter' header += os.linesep iSurface += 1 self.header.append(header) self.files = [] for i in range(self.n): filename = 'point{}.dat'.format(str(self.point_int[i][0]).zfill(3)) fd = open(os.path.join(Globals.get_outdir(), filename), 'w') fd.writelines(self.header[i]) self.files.append(fd) del self.inStream[-1] del self.inSurface[-1] Logger.info("Hydrographs files has been created...")
def do_next_h(self, surface, subsurface, rain_arr, cumulative, hydrographs, flow_control, courant, potRain, delta_t): global infilt_capa global max_infilt_capa global infilt_time rr, rc = GridGlobals.get_region_dim() pixel_area = GridGlobals.get_pixel_area() fc = flow_control combinatIndex = Globals.get_combinatIndex() NoDataValue = GridGlobals.get_no_data() infilt_capa += potRain if (infilt_capa < max_infilt_capa): infilt_time += delta_t actRain = 0.0 # TODO: variable not used. Should we delete it? potRain = 0.0 for i in rr: for j in rc[i]: hydrographs.write_hydrographs_record( i, j, flow_control, courant, delta_t, surface, subsurface, actRain) return actRain for iii in combinatIndex: # TODO: variable not used. Should we delete it? index = iii[0] k = iii[1] s = iii[2] # jj * 100.0 !!! smazat iii[3] = infilt.phlilip(k, s, delta_t, fc.total_time - infilt_time, NoDataValue) # print total_time-infilt_time, iii[3]*1000, k, s infilt.set_combinatIndex(combinatIndex) # # nulovani na zacatku kazdeho kola # surface.reset_inflows() surface.new_inflows() subsurface.fill_slope() subsurface.new_inflows() # print 'bbilll' for i in rr: for j in rc[i]: # print i,j, surface.arr[i][j].h_total_pre, surface.arr[i][j].vol_runoff # # current cell precipitation # actRain, fc.sum_interception, rain_arr.arr[i][ j].veg_true = rain_f.current_rain(rain_arr.arr[i][j], potRain, fc.sum_interception) surface.arr[i][j].cur_rain = actRain # # Inflows from surroundings cells # surface.arr[i][j].inflow_tm = surface.cell_runoff(i, j) # # Surface BILANCE # surBIL = surface.arr[i][j].h_total_pre + actRain + surface.arr[ i][j].inflow_tm / pixel_area - ( surface.arr[i][j].vol_runoff / pixel_area + surface.arr[i][j].vol_runoff_rill / pixel_area) # # surface retention # surBIL = surface_retention(surBIL, surface.arr[i][j]) # # infiltration # if subsurface.get_exfiltration(i, j) > 0: surface.arr[i][j].infiltration = 0.0 infiltration = 0.0 else: surBIL, infiltration = infilt.philip_infiltration( surface.arr[i][j].soil_type, surBIL) surface.arr[i][j].infiltration = infiltration # surface retention surBIL += subsurface.get_exfiltration(i, j) surface_state = surface.arr[i][j].state if surface_state >= 1000: # toto je pripraveno pro odtok v ryhach surface.arr[i][j].h_total_new = 0.0 h_sub = subsurface.runoff_stream_cell(i, j) inflowToReach = h_sub * pixel_area + surBIL * pixel_area surface.reach_inflows(id_=int(surface_state - 1000), inflows=inflowToReach) else: surface.arr[i][j].h_total_new = surBIL surface_state = surface.arr[i][j].state # subsurface inflow """ inflow_sub = subsurface.cell_runoff(i,j,False) subsurface.bilance(i,j,infiltration,inflow_sub/pixel_area,delta_t) subsurface.fill_slope() """ cumulative.update_cumulative(i, j, surface.arr[i][j], subsurface.arr[i][j], delta_t) hydrographs.write_hydrographs_record(i, j, flow_control, courant, delta_t, surface, subsurface, actRain) return actRain