Exemplo n.º 1
0
    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'))
Exemplo n.º 2
0
    def _print_array_stats(arr, file_output):
        """Print array stats.
        """

        Logger.info("Raster ASCII output file {} saved".format(file_output))
        Logger.info("\tArray stats: min={} max={} mean={}".format(
            np.min(arr), np.max(arr), np.mean(arr)))
Exemplo n.º 3
0
    def __init__(self):
        super(Cumulative, self).__init__()

        Logger.info('Save cumulative and maximum values from: Surface')

        # Dictionary stores the python arrays identification.
        self.data.update({
            # cumulative infiltrated volume [m3]
            'infiltration':
            CumulativeData('core', 'cInfil_m3'),  # 1
            # cumulative precipitation volume [m3]
            'precipitation':
            CumulativeData('core', 'cRain_m3'),  # 2
            # maximum surface water level [m]
            'h_sur_tot':
            CumulativeData('control', 'mWLevel_m'),  # 3
            # maximum sheet discharge [m3s-1]
            'q_sheet':
            CumulativeData('control', 'mQsheet_m3_s'),  # 4
            # cumulative sheet runoff volume [m3]
            'vol_sheet':
            CumulativeData('control', 'cSheetVOutM3'),  # 5
            # maximum sheet velocity [ms-1]
            'v_sheet':
            CumulativeData('control', 'mVel_m_s'),  # 6
            # maximum sheet shear stress [Pa]
            'shear_sheet':
            CumulativeData('control', 'mrSearStr_Pa'),  # 7
            # maximum water level in rills [m]
            'h_rill':
            CumulativeData('control', 'mWLevelRill_m'),  # 8
            # maximum discharge in rills [m3s-1]
            'q_rill':
            CumulativeData('control', 'mQRill_m3_s'),  # 9
            # cumulative runoff volume in rills [m3]
            'vol_rill':
            CumulativeData('control', 'cRillVOut_m3'),  # 10
            # maximum rill width [m]
            'b_rill':
            CumulativeData('control', 'widthRill'),  # 11
            # cumulative surface inflow volume [m3]
            'inflow_sur':
            CumulativeData('control', 'cVIn_M3'),  # 12
            # maximum surface retention [m]
            'sur_ret':
            CumulativeData('control', 'surRet_M'),  # 13
            # cumulative surface runoff volume [m3]
            'vol_sur_r':
            CumulativeData('control', 'CumVRestL3'),  # 14
            # maximal total surface flow [m3/s]
            'q_sur_tot':
            CumulativeData('core', 'mQsur_m3_s'),  # 15
            # cumulative total surface flow [m3/s]
            'vol_sur_tot':
            CumulativeData('core', 'cVsur_m3')  # 16
        })
        # define arrays class attributes
        for item in self.data.keys():
            setattr(self, item, np.zeros([GridGlobals.r, GridGlobals.c],
                                         float))
Exemplo n.º 4
0
    def __init__(self):
        super(Stream, self).__init__()
        Logger.info('Stream: ON')
        self.streams = Gl.streams

        self.nReaches = len(self.streams[0])

        self.cell_stream = Gl.cell_stream

        self.reach = []

        for i in range(self.nReaches):
            self.reach.append(
                Reach(self.streams[0][i], self.streams[1][i],
                      self.streams[2][i], self.streams[3][i],
                      self.streams[4][i], self.streams[5][i],
                      self.streams[6][i], self.streams[7][i],
                      self.streams[8][i], self.streams[9][i],
                      self.streams[10][i], self.streams[11][i],
                      self.streams[12][i], self.streams[13][i],
                      self.streams[14][i]))

        self.streams_loc = Gl.streams_loc
        self.mat_stream_reach = Gl.mat_stream_reach

        for i in self.rr:
            for j in self.rc[i]:
                self.arr[i][j].state += self.mat_stream_reach[i][j]

        self.STREAM_RATIO = Gl.STREAM_RATIO
Exemplo n.º 5
0
    def __init__(self):
        Logger.info("Diffuse approach")
        if (Globals.r is None or Globals.r is None):
            exit("Global variables are not assigned")
        r = Globals.r
        c = Globals.c

        self.H = np.zeros([r, c], float)
Exemplo n.º 6
0
    def __init__(self, L_sub, Ks, vg_n, vg_l):
        super(SubsurfacePass, self).__init__()
        # jj
        self.n = 0

        self.q_subsurface = None
        # self.arr = np.zeros([0],float)
        Logger.info("Subsurface: OFF")
Exemplo n.º 7
0
def removeCellsWithSameHeightNeighborhood(
    mat_dem, mat_nan, rows, cols
):  # function determines if cell neighborhood has exactly same values of height a and than it save that cell as NoData
    "Returns an array with the values of heights, adjusted for the value of NoData cells"

    bad_cells = []

    # finding problem cells with same height neogborhood
    for i in range(rows):
        for j in range(cols):
            c = [i, j]
            count_nbrs = 0
            point_m = mat_dem[i][j]

            if i > 0 and i < (rows - 1) and j > 0 and j < (
                    cols - 1
            ):  # non edge cells - edge cells are excluded thanks to slope trimming

                nbrs = [
                    mat_dem[i - 1][j - 1], mat_dem[i - 1][j],
                    mat_dem[i - 1][j + 1], mat_dem[i][j - 1],
                    mat_dem[i][j + 1], mat_dem[i + 1][j - 1],
                    mat_dem[i + 1][j], mat_dem[i + 1][j + 1]
                ]

                for k in range(8):
                    if point_m > 0 and point_m == nbrs[k]:
                        count_nbrs = count_nbrs + 1
                if count_nbrs >= 7:  # compare number of neighbours with the same height
                    bad_cells.append(c)
                    bc = 1

    Logger.info(
        "Possible water circulation! Check the input DTM raster for flat areas with the same height neighborhood."
    )

    # all problem cells set as NoData
    if len(bad_cells) > 0:
        for i in range(rows):
            for j in range(cols):
                if bc == 1:
                    bc_i = bad_cells[0][0]
                    bc_j = bad_cells[0][1]

                    if bc_i == i and bc_j == j:
                        mat_dem[i][j] = -3.40282346639e+038
                        mat_nan[i][j] = -3.40282346639e+038
                        bad_cells.pop(0)
                        if len(bad_cells) == 0:
                            bc = 0
                else:
                    break

    return mat_dem, mat_nan
Exemplo n.º 8
0
    def _save_data(data, filename):
        """Save data into pickle.
        """
        if filename is None:
            raise ProviderError('Output file for saving data not defined')
        dirname = os.path.dirname(filename)
        if not os.path.exists(dirname):
            os.makedirs(dirname)

        with open(filename, 'wb') as fd:
            pickle.dump(data, fd, protocol=2)
        Logger.info('Pickle file created in <{}> ({} bytes)'.format(
            filename, sys.getsizeof(data)))
Exemplo n.º 9
0
    def __init__(self):
        super(CumulativeSubsurface, self).__init__()

        Logger.info('Subsurface')

        self.data.update({
            # cumulative exfiltration volume [m3]
            'exfiltration': CumulativeData('core', 'cExfiltr_m3'),  # 1
            # cumulative percolation volume [m3]
            'percolation': CumulativeData('core', 'cPercol_m3'),  # 2
            # maximum water level in the subsurface soil layer [m]
            'h_sub': CumulativeData('core', 'mWLevelSub_M'),  # 3
            # maximum subsurface flux [m3s-1]
            'q_sub': CumulativeData('core', 'mQSub_m3_s'),  # 4
            # cumulative outflow volume in subsurface soil layer [m3]
            'vol_sub': CumulativeData('core', 'cVOutSub_m3')  # 5
        })
Exemplo n.º 10
0
    def __init__(self, id_, point_x, point_y, point_x_1, point_y_1, to_node,
                 length, sklon, smoderp, number, shape, b, m, roughness, q365):

        self.id_ = id_
        self.pointsFrom = [point_x, point_y]
        self.pointsTo = [point_x_1, point_y_1]
        self.to_node = to_node
        self.length = length
        if sklon < 0:
            Logger.info(
                "Slope in reach part {} indicated minus slope in stream".
                format(id_))
        self.slope = abs(sklon)
        self.smoderp = smoderp
        self.no = number
        self.shape = shape

        self.b = b
        self.m = m
        self.roughness = roughness
        self.q365 = q365
        self.V_in_from_field = 0.0
        self.V_in_from_field_cum = 0.0
        self.V_in_from_reach = 0.0
        self.V_out_cum = 0.0  # L^3
        self.vol_rest = 0.0
        self.h = 0.0  # jj mozna pocatecni podminka? ikdyz to je asi q365 co...
        self.h_max = 0.0
        self.timeh_max = 0.0
        self.V_out = 0.0
        self.vs = 0.0
        self.Q_out = 0.0
        self.Q_max = 0.0
        self.timeQ_max = 0.0
        self.V_out_domain = 0.0

        if shape == 0:  # obdelnik
            self.outflow_method = stream_f.rectangle
        elif shape == 1:  # trapezoid
            self.outflow_method = stream_f.trapezoid
        elif shape == 2:  # triangle
            self.outflow_method = stream_f.triangle
        elif shape == 3:  # parabola
            self.outflow_method = stream_f.parabola
        else:
            self.outflow_method = stream_f.rectangle
Exemplo n.º 11
0
    def __init__(self):

        Logger.info("Multiflow direction algorithm")
        self.inflows, fd_rill = mfd.new_mfda(mat_dem, mat_nan, mat_fd, vpix,
                                             spix, rows, cols)
        self.inflowsRill = D8_.new_inflows(fd_rill)
Exemplo n.º 12
0
 def __init__(self):
     Logger.info("D8 flow algorithm")
     self.inflows = D8_.new_inflows(Globals.get_mat_fd())
Exemplo n.º 13
0
    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...")
Exemplo n.º 14
0
 def __init__(self):
     Logger.info("Kinematic approach")
     super(Kinematic, self).__init__()
Exemplo n.º 15
0
 def __init__(self):
     super(StreamPass, self).__init__()
     self.reach = None
     Logger.info('Stream: OFF')
Exemplo n.º 16
0
 def __init__(self, L_sub=0.010, Ks=0.001, vg_n=1.5, vg_l=0.5):
     Logger.info("Subsurface:")
     super(Subsurface, self).__init__(L_sub=L_sub,
                                      Ks=Ks,
                                      vg_n=vg_n,
                                      vg_l=vg_l)