Ejemplo n.º 1
0
    "15_perc", "16_maxbas", "17_K_muskingum", "18_x_muskingum"
]
SaveTo = Comp + "01Algorithms/HAPI/Hapi/Parameters/"
# par = "UZL"
for i in range(len(ParamList)):
    Path = list()
    for j in range(0, 10):
        if j < 9:
            folder = "0" + str(j + 1)
        else:
            folder = str(j + 1)

        Path.append(Comp + "01Algorithms/HAPI/Hapi/Parameters/" + folder +
                    "/" + ParamList[i] + ".tif")

    parameters = R.ReadRastersFolder(Path, WithOrder=False)
    MaxValue = parameters.max(axis=2)
    MinValue = parameters.min(axis=2)
    MeanValue = parameters.mean(axis=2)

    # Path1 = path + "/" + ParamList[i] + "-1.tif"
    src = gdal.Open(Path[0])

    Saveto1 = SaveTo + "/max/" + ParamList[i] + ".tif"
    Saveto2 = SaveTo + "/min/" + ParamList[i] + ".tif"
    Saveto3 = SaveTo + "/avg/" + ParamList[i] + ".tif"

    R.RasterLike(src, MaxValue, Saveto1, pixel_type=1)
    R.RasterLike(src, MinValue, Saveto2, pixel_type=1)
    R.RasterLike(src, MeanValue, Saveto3, pixel_type=1)
Ejemplo n.º 2
0
    def DeleteBasins(basins, pathout):
        """
        ===========================================================
             DeleteBasins(basins,pathout)
        ===========================================================
        this function deletes all the basins in a basin raster created when delineating
        a catchment and leave only the first basin which is the biggest basin in the raster

        Inputs:
        ----------
            1- basins:
                [gdal.dataset] raster you create during delineation of a catchment
                values of its cells are the number of the basin it belongs to
            2- pathout:
                [String] path you want to save the resulted raster to it should include
                the extension ".tif"
        Outputs:
        ----------
            1- raster with only one basin (the basin that its name is 1 )

        Example:
        ----------
            basins=gdal.Open("Data/basins.tif")
            pathout="mask.tif"
            DeleteBasins(basins,pathout)
        """
        # input data validation
        # data type
        assert type(pathout) == str, "A_path input should be string type"
        assert type(
            basins
        ) == gdal.Dataset, "basins raster should be read using gdal (gdal dataset please read it using gdal library) "

        # input values
        # check wether the user wrote the extension of the raster or not
        ext = pathout[-4:]
        assert ext == ".tif", "please add the extension at the end of the path input"

        # get number of rows
        rows = basins.RasterYSize
        # get number of columns
        cols = basins.RasterXSize
        # array
        basins_A = basins.ReadAsArray()
        # no data value
        no_val = np.float32(basins.GetRasterBand(1).GetNoDataValue())
        # get number of basins and there names
        basins_val = list(
            set([
                int(basins_A[i, j]) for i in range(rows) for j in range(cols)
                if basins_A[i, j] != no_val
            ]))

        # keep the first basin and delete the others by filling their cells by nodata value
        for i in range(rows):
            for j in range(cols):
                if basins_A[i, j] != no_val and basins_A[i,
                                                         j] != basins_val[0]:
                    basins_A[i, j] = no_val

        raster.RasterLike(basins, basins_A, pathout)