示例#1
0
    def step_inputs(self):
        """
        Return
        ------
            the return could be and iterable or a callable
        """
        from simplification import MergeTileRasters as mtr
        from simplification import VectAndSimp as vas
        from Common import FileUtils as fut

        if os.path.exists(self.grid):
            return mtr.getListVectToClip(self.outmos, self.clipfield,
                                         self.outfilevect)
        else:
            params = []
            if not self.clipvalue:
                valsfield = vas.getFieldValues(self.clipfile, self.clipfield)
                for val in valsfield:
                    params.append([
                        fut.FileSearch_AND(self.outmos, True, ".shp",
                                           "hermite")[0], val
                    ])
            else:
                params = [
                    fut.FileSearch_AND(self.outmos, True, ".shp", "hermite"),
                    self.clipvalue
                ]
                print(params)
            return params
示例#2
0
文件: GridFit.py 项目: pageoty/code
def getAllDatasByDate(currentTile, rasterPatterns, masksPatterns, arboRaster,
                      arboMask, TileFolder, rasterInitValue, masksInitValues):

    #get all raster into the current tile and store it with init value
    buf = []
    r = []
    for currentPattern in rasterPatterns:
        r += fu.fileSearchRegEx(TileFolder + currentTile + arboRaster +
                                currentPattern)
    for currentR in r:
        buf.append((currentR, rasterInitValue))

    for currentPattern, currentMaskInit in zip(masksPatterns, masksInitValues):
        m = []
        m += fu.fileSearchRegEx(TileFolder + currentTile + arboMask +
                                currentPattern)
        for currentM in m:
            buf.append((currentM, currentMaskInit))
    #sort it by date
    buff = [(getDateFromRaster(currentRaster[0]), currentRaster)
            for currentRaster in buf]
    buff = fu.sortByFirstElem(buff)
    allDates = []
    allRasters = []
    for date, rasters in buff:
        allDates.append(date)
        allRasters.append(rasters)
    return allRasters, allDates
示例#3
0
def extraction(vectorFill, vectorSource, field, field_val, driversFill,
               driversSource):

    ogrDriversSource = ogr.GetDriverByName(driversSource)
    dataSourceSource = ogrDriversSource.Open(vectorSource, 0)

    layerSource = dataSourceSource.GetLayer()

    print("RECHERCHE DES FIDs")
    All_FID = [(currentFeat.GetField(field), str(currentFeat.GetFID()))
               for currentFeat in layerSource
               if currentFeat.GetField(field) in field_val]
    print("FIDs trouvée")
    layerSource.ResetReading()

    All_FID = fu.sortByFirstElem(All_FID)

    for currentClass, FID in All_FID:
        splits = fu.splitList(FID, len(vectorFill))
        for currentSplit, currentVectorFill in zip(splits, vectorFill):
            cmd = "ogr2ogr -append " + currentVectorFill + " " + vectorSource + " -where \" fid in (" + ",".join(
                currentSplit) + ")\""
            print(cmd)
            print("Ajout de " + str(currentClass) + " dans " +
                  currentVectorFill.split("/")[-1])
            os.system(cmd)
示例#4
0
def DataAugmentationSynthetic(samples,
                              groundTruth,
                              dataField,
                              strategies,
                              workingDirectory=None):
    """Compute how many samples should be add in the sample set and launch data augmentation method

    Parameters
    ----------
    samples : string
        path to a vector file to augment samples
    groundTruth : string
        path to the original ground truth vector file, in order to list interger / float fields
    dataField : string
        data field's name in samples
    strategies : dict
        dictionary
    workingDirectory : string
        path to a working directory
    """

    if GetRegionFromSampleName(samples) in strategies[
            "target_models"] or "all" in strategies["target_models"]:
        from collections import Counter
        class_count = Counter(
            fut.getFieldElement(samples,
                                driverName="SQLite",
                                field=dataField,
                                mode="all",
                                elemType="int"))

        class_augmentation = SamplesAugmentationCounter(
            class_count,
            mode=strategies["samples.strategy"],
            minNumber=strategies.get("samples.strategy.minNumber", None),
            byClass=strategies.get("samples.strategy.byClass", None))

        fields_types = GetFieldsType(groundTruth)

        excluded_fields_origin = [
            field_name.lower()
            for field_name, field_type in list(fields_types.items())
            if "int" in field_type or "flaot" in field_type
        ]
        samples_fields = fut.get_all_fields_in_shape(samples, driver='SQLite')
        excluded_fields = list(
            set(excluded_fields_origin).intersection(samples_fields))
        excluded_fields.append("originfid")

        DoAugmentation(samples,
                       class_augmentation,
                       strategy=strategies["strategy"],
                       field=dataField,
                       excluded_fields=excluded_fields,
                       Jstdfactor=strategies.get("strategy.jitter.stdfactor",
                                                 None),
                       Sneighbors=strategies.get("strategy.smote.neighbors",
                                                 None),
                       workingDirectory=workingDirectory)
示例#5
0
文件: GridFit.py 项目: pageoty/code
def launchFit(sensorName, cmdPath, workingDirectory, outDirectory, outGridPath,
              outputGrid_tileNameField, outPixRes, outputProjection,
              interpolator, inputGrid_tileNameField, inputGRID, arboMask,
              masksInitValues, masksPatterns, arboRaster, rasterInitValue,
              rasterPatterns, TileFolder):

    createOutGrid(TileFolder, rasterPatterns[0], outputProjection,
                  outputGrid_tileNameField, outGridPath)
    intersections = getIntersections(inputGRID, outGridPath,
                                     inputGrid_tileNameField,
                                     outputGrid_tileNameField)
    allCmd = []
    for refTile, tiles in intersections:
        outFolder_tile = outDirectory + "/" + refTile
        if not os.path.exists(outFolder_tile):
            os.mkdir(outFolder_tile)
        minX_ref, maxX_ref, minY_ref, maxY_ref = getTileEnvelope(
            inputGRID, inputGrid_tileNameField, refTile)
        for currentTile in tiles:
            datas, dates = getAllDatasByDate(currentTile, rasterPatterns,
                                             masksPatterns, arboRaster,
                                             arboMask, TileFolder,
                                             rasterInitValue, masksInitValues)
            for currentDatas, currentDate in zip(datas, dates):
                outFolderDate = outFolder_tile + "/" + sensorName + "_" + refTile + "_" + currentDate + "_" + currentTile
                outFolderDateMask = outFolderDate + "/MASKS"
                if not os.path.exists(outFolderDate):
                    os.mkdir(outFolderDate)
                    os.mkdir(outFolderDateMask)
                for currentRaster in currentDatas:
                    folder = outFolderDate
                    print currentRaster
                    if checkMaskFromRaster(currentRaster[0], masksPatterns):
                        folder = outFolderDateMask
                    outFolder = folder
                    if workingDirectory:
                        folder = workingDirectory + "/"
                    outName = currentRaster[0].split("/")[-1].replace(
                        currentTile,
                        refTile).replace(".tif", "_" + currentTile + ".tif")
                    out = folder + "/" + outName
                    cmd = "gdalwarp -t_srs EPSG:" + outputProjection + " -wo INIT_DEST=" + currentRaster[
                        1] + " -te " + str(minX_ref) + " " + str(
                            minY_ref
                        ) + " " + str(maxX_ref) + " " + str(
                            maxY_ref
                        ) + " -tr " + outPixRes + " -" + outPixRes + " -r " + interpolator + " " + currentRaster[
                            0] + " " + out
                    if not os.path.exists(outFolder + "/" + outName):
                        allCmd.append(cmd)
                        run(cmd)
                        if workingDirectory:
                            shutil.copy(out, outFolder + "/" + outName)
                            os.remove(out)
    fu.writeCmds(cmdPath, allCmd)
示例#6
0
def computeStats(pathConf, wD=None):

    dataField = Config(file(pathConf)).chain.dataField
    iota2Folder = Config(file(pathConf)).chain.outputPath
    runs = Config(file(pathConf)).chain.runs
    workingDirectory = iota2Folder + "/final/TMP"
    if wD:
        workingDirectory = wD

    statsBySeed = []
    for seed in range(runs):
        #Get sqlites
        dataBase = fut.FileSearch_AND(iota2Folder + "/final/TMP", True,
                                      ".sqlite", "extraction",
                                      "learn")  #stats only on learnt polygons
        #dataBase = fut.FileSearch_AND("/work/OT/theia/oso/TMP/sampleExtraction", True, ".sqlite", "extraction")
        finalDataBaseName = "statsDataBase_run_" + str(
            seed) + ".sqlite"  #will contain all data base
        finalDataBasePath = workingDirectory + "/" + finalDataBaseName

        if os.path.exists(finalDataBasePath):
            os.remove(finalDataBasePath)

        shutil.copy(dataBase[0], finalDataBasePath)
        del dataBase[0]
        fields = "GEOMETRY," + ",".join(
            fut.getAllFieldsInShape(finalDataBasePath, driver='SQLite'))

        conn = lite.connect(finalDataBasePath)
        cursor = conn.cursor()
        cursor.execute("select name from sqlite_master where type = 'table';")
        tableName = str(cursor.fetchall()[-1][0])

        print "Fill up statistics dataBase"
        for currentDataBase in dataBase:
            print("Add dataBase : {}".format(currentDataBase))
            cursor.execute("ATTACH '%s' as db2;" % (currentDataBase))
            cursor.execute("CREATE TABLE output2 AS SELECT * FROM db2.output;")
            cursor.execute("INSERT INTO " + tableName + "(" + fields +
                           ") SELECT " + fields + " FROM output2;")
            conn.commit()
            conn = cursor = None
            conn = lite.connect(finalDataBasePath)
            cursor = conn.cursor()
            cleanSqliteDatabase(finalDataBasePath, "output2")

        #plot relation
        plotsSeed = plotRelation(finalDataBasePath, dataField, seed,
                                 iota2Folder)
        #Compute statistics
        print "Compute statistics"
        statsByClass = computeStatistics(finalDataBasePath, dataField)
        statsBySeed.append(statsByClass)

    return statsBySeed
示例#7
0
    def test_tdx_client_get_local_1min_bars(self):
        df = self.tdx_client.get_local_stock_bars(
            FileUtils.convert_file_path_based_on_system(
                ".\\LC1\\SZ\\sz000001.lc1"), StockDataType.ONE_MIN)
        print(df)
        df.to_csv(
            FileUtils.convert_file_path_based_on_system(".\\CSV\\tdx001.csv"))
        print(df.columns.values)

        df['date_index'] = pd.to_datetime(df['date']).dt.strftime(
            DatetimeUtils.DATE_FORMAT)
        print(df)
def mergeSubVector(inpath, classes="", inbase="dept_", outbase="departement_"):

    listout = fut.FileSearch_AND(inpath, True, inbase, ".shp", "chk")
    listofchkofzones = fut.sortByFirstElem([
        ("_".join(x.split('_')[0:len(x.split('_')) - 1]), x) for x in listout
    ])

    for zone in listofchkofzones:
        zoneval = zone[0].split('_')[len(zone[0].split('_')) -
                                     1:len(zone[0].split('_'))]
        outfile = os.path.join(inpath, outbase + zoneval[0] + '.shp')
        mf.mergeVectors(zone[1], outfile)
        iota2Formatting(outfile, classes, outfile)
示例#9
0
def check_errors_JA(log_dir, task_name):
    """
    """
    from Common import FileUtils as fut

    if os.path.isdir(log_dir):
        all_logs = fut.FileSearch_AND(log_dir, True, ".ER")
    else:
        all_logs = fut.FileSearch_AND(os.path.split(log_dir)[0], True, task_name, ".log")
    errors = []
    for log in all_logs:
        if check_errors(log):
            errors.append(check_errors(log))
    return errors
示例#10
0
文件: GridFit.py 项目: pageoty/code
def getIntersections(outGridPath, inGridPath, tileField_first,
                     tileField_second):
    """
    OUT
    AllIntersections [list of tuple] : [(S2Tile, [L8Tile, L8Tile, L8Tile]), (...), ...]
    """
    driver = ogr.GetDriverByName("ESRI Shapefile")
    dataOut = driver.Open(outGridPath, 0)
    dataIn = driver.Open(inGridPath, 0)

    layerOut = dataOut.GetLayer()
    layerIn = dataIn.GetLayer()

    AllIntersections = []  #Ex : [[S2, [L8, L8, ..., L8]], [], ...]

    outTiles = [(outTile.GetGeometryRef().Clone(),
                 outTile.GetField(tileField_first)) for outTile in layerOut]
    inTiles = [(inTile.GetGeometryRef().Clone(),
                inTile.GetField(tileField_second)) for inTile in layerIn]

    for outTileGeom, outTile in outTiles:
        for inTileGeom, inTile in inTiles:
            intersection = outTileGeom.Intersection(inTileGeom)
            if intersection.GetArea() != 0.0 and (
                    outTile, inTile) not in AllIntersections:
                AllIntersections.append((outTile, inTile))
    return fu.sortByFirstElem(AllIntersections)
示例#11
0
def listTileEntities(raster, outpath, feature):
    """
        entities ID list of tile

        in :
            raster : bi-band raster (classification - clump)
            outpath : out directory
            feature : feature of tile from shapefile

        out :
            tile_id : list with ID

    """

    # Classification and Clump opening
    datas_classif, xsize_classif, ysize_classif, projection_classif, transform_classif = fu.readRaster(raster, True, 1)
    datas_clump, xsize_clump, ysize_clump, projection_clump, transform_clump = fu.readRaster(raster, True, 2)

    # Generate pixel coordinates of square feature corresponding to raster transform
    cols_xmin_decoup, cols_xmax_decoup, cols_ymin_decoup, cols_ymax_decoup = cellCoords(feature, transform_classif)

    # subset raster data array based on feature coordinates
    tile_classif = datas_classif[cols_ymin_decoup:cols_ymax_decoup, cols_xmin_decoup:cols_xmax_decoup]
    tile_id_all = datas_clump[cols_ymin_decoup:cols_ymax_decoup, cols_xmin_decoup:cols_xmax_decoup]

    del datas_classif, datas_clump

    # entities ID list of tile (except nodata and sea)
    tile_id = np.unique(np.where(((tile_classif > 1) & (tile_classif < 250)), tile_id_all, 0)).tolist()

    # delete 0 value
    tile_id = [int(x) for x in tile_id if x != 0]

    return tile_id
示例#12
0
def compute_fusion_options(iota2_dir_final, final_classifications, method,
                           undecidedlabel, dempstershafer_mob, pixType,
                           fusion_path):
    """ use to determine fusion parameters
    """

    if method == "majorityvoting":
        options = {
            "il": final_classifications,
            "method": method,
            "nodatalabel": "0",
            "undecidedlabel": str(undecidedlabel),
            "pixType": pixType,
            "out": fusion_path
        }
    else:
        confusionSeed = [
            fut.FileSearch_AND(os.path.join(iota2_dir_final, "TMP"), True,
                               "Classif_Seed_{}.csv".format(run))[0]
            for run in range(len(final_classifications))
        ]
        confusionSeed.sort()
        final_classifications.sort()
        options = {
            "il": final_classifications,
            "method": "dempstershafer",
            "nodatalabel": "0",
            "undecidedlabel": str(undecidedlabel),
            "method.dempstershafer.mob": dempstershafer_mob,
            "method.dempstershafer.cmfl": confusionSeed,
            "pixType": pixType,
            "out": fusion_path
        }
    return options
示例#13
0
def getNbSample(shape,
                tile,
                dataField,
                valToFind,
                resol,
                region,
                coeff,
                current_seed,
                region_field,
                region_val="-1"):

    driver = ogr.GetDriverByName("ESRI Shapefile")
    buff = []
    dataSource = driver.Open(shape, 0)
    layer = dataSource.GetLayer()
    for feature in layer:
        if str(feature.GetField(dataField)) in valToFind and str(
                feature.GetField(region_field)) == str(region_val) and str(
                    feature.GetField("seed_" + str(current_seed))) == "learn":
            geom = feature.GetGeometryRef()
            buff.append((feature.GetField(dataField), geom.GetArea()))
    rep = fu.sortByFirstElem(buff)
    repDict = {}
    for currentClass, currentAreas in rep:
        array = np.asarray(currentAreas)
        totalArea = np.sum(array)
        repDict[currentClass] = int(
            (float(coeff) * totalArea) / (int(resol) * int(resol)))

    return repDict
示例#14
0
def GetDataAugmentationSyntheticParameters(IOTA2_dir):
    """ read the */learningSample* directory

    parse the directory */learningSamples* and return a list of all sqlite files

    Parameters
    ----------

    IOTA2_dir : string
        absolute path to the IOTA2's directory

    Example
    -------

    >>> os.listdir("/learningSamples")
    ["Samples_region_2_seed0_learn.sqlite",
     "Samples_region_2_seed1_learn.sqlite",
     "Samples_region_1_seed0_learn.sqlite",
     "Samples_region_1_seed1_learn.sqlite"]

    >>> GetAugmentationSamplesParameters("/IOTA2")
        [Samples_region_1_seed0_learn.sqlite, Samples_region_2_seed0_learn.sqlite,
         Samples_region_1_seed1_learn.sqlite, Samples_region_2_seed1_learn.sqlite]

    Return
    ------
    list
        a list of sqlite files containing samples
    """
    IOTA2_dir_learningSamples = os.path.join(IOTA2_dir, "learningSamples")
    return fut.FileSearch_AND(IOTA2_dir_learningSamples, True, ".sqlite")
示例#15
0
    def test_Basic(self):
        """
        this test verify if features labels generated are similar to a reference
        produce thanks to a specific configuration file
        """
        from Sampling.DataExtraction import VectorSampler
        from Common import IOTA2Directory

        #expected output
        ref_path = os.path.join(self.iota2_directory, "data", "references",
                                "iota2tests_features_labels_test_Basic.txt")

        #test inputs
        vector_file = os.path.join(self.iota2_directory, "data", "references",
                                   "sampler",
                                   "D0005H0002_polygons_To_Sample.shp")
        L8_rasters = os.path.join(self.iota2_directory, "data", "L8_50x50")

        #generate IOTA output directory
        IOTA2Directory.GenerateDirectories(self.test_working_directory)

        #fill up configuration file
        self.config.setParam('chain', 'outputPath',
                             self.test_working_directory)
        self.config.setParam('chain', 'listTile', "D0005H0002")
        self.config.setParam('chain', 'featuresPath',
                             self.test_working_directory_tmp)
        self.config.setParam('chain', 'L8Path', L8_rasters)
        self.config.setParam('chain', 'userFeatPath', 'None')
        self.config.setParam('argTrain', 'samplesOptions',
                             '-sampler random -strategy all')
        self.config.setParam('argTrain', 'cropMix', False)
        self.config.setParam('argTrain', 'samplesClassifMix', False)
        self.config.setParam('GlobChain', 'useAdditionalFeatures', False)

        #Launch sampling
        VectorSampler.generateSamples(vector_file, None, self.config)

        test_vector = fut.fileSearchRegEx(self.test_working_directory +
                                          "/learningSamples/*sqlite")[0]
        test_field_list = fut.getAllFieldsInShape(test_vector, driver='SQLite')

        with open(ref_path, 'r') as f:
            ref_field_list = [line.rstrip() for line in f]

        #check outputs
        self.assertTrue(ref_field_list == test_field_list)
示例#16
0
def getAll_regions(tileName, folder):
    allRegion = []
    allShape = fu.FileSearch_AND(folder, True, "learn", tileName, ".shp")
    for currentShape in allShape:
        currentRegion = currentShape.split("/")[-1].split("_")[2]
        if currentRegion not in allRegion:
            allRegion.append(currentRegion)
    return allRegion
示例#17
0
 def __init__(self):
     self.__parser = configparser.ConfigParser()
     current_file = os.path.abspath(os.path.dirname(__file__))
     config_file_path = os.path.join(
         current_file,
         FileUtils.convert_file_path_based_on_system('../../config.json'))
     with open(config_file_path, 'r') as config_file:
         self.__config = json.load(config_file)
示例#18
0
 def step_inputs(self):
     """
     Return
     ------
         the return could be and iterable or a callable
     """
     from Common import FileUtils as fut
     return fut.getCmd(os.path.join(self.output_path, "cmd", "confusion", "confusion.txt"))
示例#19
0
def genRasterEnvelope(raster, outputShape):
    """
    raster [string]
    workingDir [string] workingDirectory
    """
    rasterName = os.path.splitext(os.path.split(raster)[-1])[0]

    minX, maxX, minY, maxY = fut.getRasterExtent(raster)
    epsg = fut.getRasterProjectionEPSG(raster)

    driver = ogr.GetDriverByName("ESRI Shapefile")
    data_source = driver.CreateDataSource(outputShape)
    srs = osr.SpatialReference()
    srs.ImportFromEPSG(int(epsg))

    out_lyr = data_source.CreateLayer(rasterName,
                                      srs,
                                      geom_type=ogr.wkbPolygon)

    field_ext = ogr.FieldDefn("ext", ogr.OFTString)
    field_ext.SetWidth(24)
    out_lyr.CreateField(field_ext)

    #geom
    ul = (minX, maxY)
    ur = (maxX, maxY)
    lr = (maxX, minY)
    ll = (minX, minY)
    ring = ogr.Geometry(ogr.wkbLinearRing)
    ring.AddPoint(ul[0], ul[1])
    ring.AddPoint(ur[0], ur[1])
    ring.AddPoint(lr[0], lr[1])
    ring.AddPoint(ll[0], ll[1])
    ring.AddPoint(ul[0], ul[1])

    # Create polygon
    poly = ogr.Geometry(ogr.wkbPolygon)
    poly.AddGeometry(ring)

    feature = ogr.Feature(out_lyr.GetLayerDefn())
    feature.SetField("ext", "extent")
    feature.SetGeometry(poly)
    out_lyr.CreateFeature(feature)
    feature = data_source = None

    return outputShape
示例#20
0
def createRegionsByTiles(shapeRegion,
                         field_Region,
                         pathToEnv,
                         pathOut,
                         pathWd,
                         logger_=logger):
    """
    create a shapeFile into tile's envelope for each regions in shapeRegion and for each tiles
    IN :
        - shapeRegion : the shape which contains all regions
        - field_Region : the field into the region's shape which describes each tile belong to which model
        - pathToEnv : path to the tile's envelope with priority
        - pathOut : path to store all resulting shapeFile
        - pathWd : path to working directory (not mandatory, due to cluster's architecture default = None)
    """
    pathName = pathWd
    if pathWd == None:
        #sequential case
        pathName = pathOut

    #getAllTiles
    AllTiles = fu.FileSearch_AND(pathToEnv, True, ".shp")
    regionList = fu.getFieldElement(shapeRegion, "ESRI Shapefile",
                                    field_Region, "unique")
    shpRegionList = splitVectorLayer(shapeRegion, field_Region, "int",
                                     regionList, pathName)
    AllClip = []
    for shp in shpRegionList:
        for tile in AllTiles:
            logger_.info("Extract %s in %s", shp, tile)
            pathToClip = fu.ClipVectorData(shp, tile, pathName)
            AllClip.append(pathToClip)

    if pathWd:
        for clip in AllClip:
            cmd = "cp " + clip.replace(".shp", "*") + " " + pathOut
            run(cmd)
    else:
        for shp in shpRegionList:
            path = shp.replace(".shp", "")
            os.remove(path + ".shp")
            os.remove(path + ".shx")
            os.remove(path + ".dbf")
            os.remove(path + ".prj")

    return AllClip
示例#21
0
def getTileSameDate(folder):
    buf = []
    content = os.listdir(folder)
    for currentContent in content:
        date = currentContent.split("_")[2].split("-")[0]
        buf.append((date, folder+"/"+currentContent))
    buf = fu.sortByFirstElem(buf)
    out = [currentList for date, currentList in buf if len(currentList) > 1]
    return out
示例#22
0
    def test_config_provider(self):
        current_file = os.path.abspath(os.path.dirname(__file__))
        parent_of_parent_dir = os.path.join(
            current_file, FileUtils.convert_file_path_based_on_system('../'))
        print(parent_of_parent_dir)

        print(
            self.cfg_provider.get_tdx_stock_directory_path(
                StockConfig.StockDataType.DAILY, 'sz'))
示例#23
0
def generateTif(vectorFile, pixSize):

    minX, minY, maxX, maxY = fu.getShapeExtent(vectorFile)
    cmd = "gdal_rasterize -te " + str(minX) + " " + str(minY) + " " + str(
        maxX) + " " + str(maxY) + " -a Tile -tr " + str(pixSize) + " " + str(
            pixSize) + " " + vectorFile + " " + vectorFile.replace(
                ".shp", ".tif")
    print(cmd)
    os.system(cmd)
def extractPixelValue(rasters,
                      bands,
                      paramstats,
                      xpt,
                      ypt,
                      dataframe,
                      idval=0):
    """Extract pixel value and store it on a Pandas dataframe

    Parameters
    ----------
    rasters : list
        list of rasters to analyse

    bands : ndarray
        raster bands or raster files store in numpy array

    paramstats : dict
        list of statistics to compute (e.g. {1:'stats', 2:'rate'})

    xpt : float
        Point x coordinates 

    ypt : float
        Point y coordinates 

    dataframe : Pandas Dataframe
        Pandas Dataframe

    idval : integer
        index value to store in dataframe

    Return
    ----------
    GeoPandas or Pandas DataFrame
        
    """

    for param in paramstats:

        band = bands[:, :, int(param) - 1]
        nbband = int(param)

        ### Pixel value extraction ###
        if band.size != 0:
            methodstat = paramstats[param]
            if "val" in methodstat:
                colpt, rowpt = fut.geoToPix(rasters[0], xpt, ypt)
                cols = "valb%s" % (param)
                dataframe.update(pad.DataFrame(data=[rasterStats(band, nbband, None, (colpt, rowpt))], \
                                           index=[idval], \
                                           columns=[cols]))

            band = None

    return dataframe
示例#25
0
文件: GridFit.py 项目: pageoty/code
def getPaths(TileFolder, pattern):
    Tiles = os.listdir(TileFolder)
    paths = []
    for currentS2Tile in Tiles:
        if os.path.isdir(TileFolder + "/" + currentS2Tile):
            stack = fu.FileSearch_AND(TileFolder + "/" + currentS2Tile, True,
                                      pattern)
            if stack:
                paths.append(stack[0])
    return paths
示例#26
0
    def step_clean(self):
        """
        """
        from Common import FileUtils as fut

        for filetoremove in fut.FileSearch_AND(self.tmpdir, True, "mask", ".tif"):
            os.remove(filetoremove)

        if os.path.exists(os.path.join(self.outputPath, 'final', 'simplification', 'classif_regul.tif')):
            os.remove(os.path.join(self.tmpdir, 'regul1.tif'))            
示例#27
0
文件: GridFit.py 项目: pageoty/code
def createOutGrid(TileFolder, pattern, outputProjection, tileNameField,
                  outGridPath):
    paths = getPaths(TileFolder, pattern)
    #paths = ['/work/theia/oso/sensorsDatas/S2/20152016//T30TVT/SENTINEL2A_20160729-112407-023_L2A_T30TVT_D_V1-0/SENTINEL2A_20160729-112407-023_L2A_T30TVT_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30TWP/SENTINEL2A_20160726-111748-462_L2A_T30TWP_D_V1-0/SENTINEL2A_20160726-111748-462_L2A_T30TWP_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30TWS/SENTINEL2A_20160815-110803-010_L2A_T30TWS_D_V1-0/SENTINEL2A_20160815-110803-010_L2A_T30TWS_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30TWT/SENTINEL2A_20151229-111920-437_L2A_T30TWT_D_V1-0/SENTINEL2A_20151229-111920-437_L2A_T30TWT_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30TXN/SENTINEL2A_20160723-110712-857_L2A_T30TXN_D_V1-0/SENTINEL2A_20160723-110712-857_L2A_T30TXN_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30TXP/SENTINEL2A_20160623-105858-730_L2A_T30TXP_D_V1-0/SENTINEL2A_20160623-105858-730_L2A_T30TXP_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30TXQ/SENTINEL2A_20160815-110803-010_L2A_T30TXQ_D_V1-0/SENTINEL2A_20160815-110803-010_L2A_T30TXQ_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30TXR/SENTINEL2A_20160815-110803-010_L2A_T30TXR_D_V1-0/SENTINEL2A_20160815-110803-010_L2A_T30TXR_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30TXS/SENTINEL2A_20160716-110923-852_L2A_T30TXS_D_V1-0/SENTINEL2A_20160716-110923-852_L2A_T30TXS_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30TXT/SENTINEL2A_20151229-111920-437_L2A_T30TXT_D_V1-0/SENTINEL2A_20151229-111920-437_L2A_T30TXT_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30TYN/SENTINEL2A_20160125-111611-703_L2A_T30TYN_D_V1-0/SENTINEL2A_20160125-111611-703_L2A_T30TYN_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30TYP/SENTINEL2A_20160204-110240-456_L2A_T30TYP_D_V1-0/SENTINEL2A_20160204-110240-456_L2A_T30TYP_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30TYQ/SENTINEL2A_20160723-110712-857_L2A_T30TYQ_D_V1-0/SENTINEL2A_20160723-110712-857_L2A_T30TYQ_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30TYR/SENTINEL2A_20151226-111142-750_L2A_T30TYR_D_V1-0/SENTINEL2A_20151226-111142-750_L2A_T30TYR_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30TYS/SENTINEL2A_20160312-105037-460_L2A_T30TYS_D_V1-0/SENTINEL2A_20160312-105037-460_L2A_T30TYS_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30TYT/SENTINEL2A_20151206-110834-178_L2A_T30TYT_D_V1-0/SENTINEL2A_20151206-110834-178_L2A_T30TYT_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30UUU/SENTINEL2A_20160410-112358-413_L2A_T30UUU_D_V1-0/SENTINEL2A_20160410-112358-413_L2A_T30UUU_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30UVU/SENTINEL2A_20160719-112117-457_L2A_T30UVU_D_V1-0/SENTINEL2A_20160719-112117-457_L2A_T30UVU_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30UVV/SENTINEL2A_20160507-110656-458_L2A_T30UVV_D_V1-0/SENTINEL2A_20160507-110656-458_L2A_T30UVV_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30UWA/SENTINEL2A_20160121-113008-064_L2A_T30UWA_D_V1-0/SENTINEL2A_20160121-113008-064_L2A_T30UWA_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30UWU/SENTINEL2A_20151222-113332-762_L2A_T30UWU_D_V1-0/SENTINEL2A_20151222-113332-762_L2A_T30UWU_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30UWV/SENTINEL2A_20160709-112403-413_L2A_T30UWV_D_V1-0/SENTINEL2A_20160709-112403-413_L2A_T30UWV_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30UXA/SENTINEL2A_20160507-110656-458_L2A_T30UXA_D_V1-0/SENTINEL2A_20160507-110656-458_L2A_T30UXA_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30UXU/SENTINEL2A_20160417-111159-116_L2A_T30UXU_D_V1-0/SENTINEL2A_20160417-111159-116_L2A_T30UXU_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30UXV/SENTINEL2A_20160507-110656-458_L2A_T30UXV_D_V1-0/SENTINEL2A_20160507-110656-458_L2A_T30UXV_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30UYA/SENTINEL2A_20151129-112140-218_L2A_T30UYA_D_V1-0/SENTINEL2A_20151129-112140-218_L2A_T30UYA_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30UYU/SENTINEL2A_20151226-111142-750_L2A_T30UYU_D_V1-0/SENTINEL2A_20151226-111142-750_L2A_T30UYU_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T30UYV/SENTINEL2A_20160112-110648-877_L2A_T30UYV_D_V1-0/SENTINEL2A_20160112-110648-877_L2A_T30UYV_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TCH/SENTINEL2A_20160401-105759-039_L2A_T31TCH_D_V1-0/SENTINEL2A_20160401-105759-039_L2A_T31TCH_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TCJ/SENTINEL2A_20160727-104250-774_L2A_T31TCJ_D_V1-0/SENTINEL2A_20160727-104250-774_L2A_T31TCJ_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TCK/SENTINEL2A_20160312-105037-460_L2A_T31TCK_D_V1-0/SENTINEL2A_20160312-105037-460_L2A_T31TCK_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TCL/SENTINEL2A_20151203-110846-328_L2A_T31TCL_D_V1-0/SENTINEL2A_20151203-110846-328_L2A_T31TCL_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TCM/SENTINEL2A_20160102-110129-139_L2A_T31TCM_D_V1-0/SENTINEL2A_20160102-110129-139_L2A_T31TCM_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TCN/SENTINEL2A_20160501-105310-197_L2A_T31TCN_D_V1-0/SENTINEL2A_20160501-105310-197_L2A_T31TCN_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TDH/SENTINEL2A_20160816-104025-461_L2A_T31TDH_D_V1-0/SENTINEL2A_20160816-104025-461_L2A_T31TDH_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TDJ/SENTINEL2A_20160727-104250-774_L2A_T31TDJ_D_V1-0/SENTINEL2A_20160727-104250-774_L2A_T31TDJ_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TDK/SENTINEL2A_20160607-104026-455_L2A_T31TDK_D_V1-0/SENTINEL2A_20160607-104026-455_L2A_T31TDK_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TDL/SENTINEL2A_20151230-105153-392_L2A_T31TDL_D_V1-0/SENTINEL2A_20151230-105153-392_L2A_T31TDL_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TDM/SENTINEL2A_20160322-105248-343_L2A_T31TDM_D_V1-0/SENTINEL2A_20160322-105248-343_L2A_T31TDM_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TDN/SENTINEL2A_20160717-104026-462_L2A_T31TDN_D_V1-0/SENTINEL2A_20160717-104026-462_L2A_T31TDN_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TEH/SENTINEL2A_20160425-103025-458_L2A_T31TEH_D_V1-0/SENTINEL2A_20160425-103025-458_L2A_T31TEH_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TEJ/SENTINEL2A_20160806-104026-455_L2A_T31TEJ_D_V1-0/SENTINEL2A_20160806-104026-455_L2A_T31TEJ_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TEK/SENTINEL2A_20160816-104025-461_L2A_T31TEK_D_V1-0/SENTINEL2A_20160816-104025-461_L2A_T31TEK_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TEL/SENTINEL2A_20160806-104026-455_L2A_T31TEL_D_V1-0/SENTINEL2A_20160806-104026-455_L2A_T31TEL_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TEM/SENTINEL2A_20151230-105153-392_L2A_T31TEM_D_V1-0/SENTINEL2A_20151230-105153-392_L2A_T31TEM_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TEN/SENTINEL2A_20151203-105818-575_L2A_T31TEN_D_V1-0/SENTINEL2A_20151203-105818-575_L2A_T31TEN_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TFH/SENTINEL2A_20151217-103953-944_L2A_T31TFH_D_V1-0/SENTINEL2A_20151217-103953-944_L2A_T31TFH_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TFJ/SENTINEL2A_20160727-104250-774_L2A_T31TFJ_D_V1-0/SENTINEL2A_20160727-104250-774_L2A_T31TFJ_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TFK/SENTINEL2A_20160717-104833-511_L2A_T31TFK_D_V1-0/SENTINEL2A_20160717-104833-511_L2A_T31TFK_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TFL/SENTINEL2A_20160816-104025-461_L2A_T31TFL_D_V1-0/SENTINEL2A_20160816-104025-461_L2A_T31TFL_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TFM/SENTINEL2A_20160707-104025-456_L2A_T31TFM_D_V1-0/SENTINEL2A_20160707-104025-456_L2A_T31TFM_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TFN/SENTINEL2A_20151223-105843-962_L2A_T31TFN_D_V1-0/SENTINEL2A_20151223-105843-962_L2A_T31TFN_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TGH/SENTINEL2A_20160724-103229-121_L2A_T31TGH_D_V1-0/SENTINEL2A_20160724-103229-121_L2A_T31TGH_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TGJ/SENTINEL2A_20160415-103022-461_L2A_T31TGJ_D_V1-0/SENTINEL2A_20160415-103022-461_L2A_T31TGJ_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TGK/SENTINEL2A_20160408-104020-456_L2A_T31TGK_D_V1-0/SENTINEL2A_20160408-104020-456_L2A_T31TGK_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TGL/SENTINEL2A_20160205-103556-319_L2A_T31TGL_D_V1-0/SENTINEL2A_20160205-103556-319_L2A_T31TGL_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TGM/SENTINEL2A_20160528-104248-160_L2A_T31TGM_D_V1-0/SENTINEL2A_20160528-104248-160_L2A_T31TGM_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31TGN/SENTINEL2A_20160205-103556-319_L2A_T31TGN_D_V1-0/SENTINEL2A_20160205-103556-319_L2A_T31TGN_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31UCP/SENTINEL2A_20151203-105818-575_L2A_T31UCP_D_V1-0/SENTINEL2A_20151203-105818-575_L2A_T31UCP_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31UCQ/SENTINEL2A_20151206-110834-178_L2A_T31UCQ_D_V1-0/SENTINEL2A_20151206-110834-178_L2A_T31UCQ_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31UCR/SENTINEL2A_20151229-111920-437_L2A_T31UCR_D_V1-0/SENTINEL2A_20151229-111920-437_L2A_T31UCR_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31UCS/SENTINEL2A_20160125-111611-703_L2A_T31UCS_D_V1-0/SENTINEL2A_20160125-111611-703_L2A_T31UCS_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31UDP/SENTINEL2A_20160102-110129-139_L2A_T31UDP_D_V1-0/SENTINEL2A_20160102-110129-139_L2A_T31UDP_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31UDQ/SENTINEL2A_20160125-111611-703_L2A_T31UDQ_D_V1-0/SENTINEL2A_20160125-111611-703_L2A_T31UDQ_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31UDR/SENTINEL2A_20151226-111142-750_L2A_T31UDR_D_V1-0/SENTINEL2A_20151226-111142-750_L2A_T31UDR_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31UDS/SENTINEL2A_20160125-111611-703_L2A_T31UDS_D_V1-0/SENTINEL2A_20160125-111611-703_L2A_T31UDS_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31UEP/SENTINEL2A_20160717-104026-462_L2A_T31UEP_D_V1-0/SENTINEL2A_20160717-104026-462_L2A_T31UEP_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31UEQ/SENTINEL2A_20160720-105547-946_L2A_T31UEQ_D_V1-0/SENTINEL2A_20160720-105547-946_L2A_T31UEQ_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31UER/SENTINEL2A_20151206-110834-178_L2A_T31UER_D_V1-0/SENTINEL2A_20151206-110834-178_L2A_T31UER_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31UES/SENTINEL2A_20160305-110109-717_L2A_T31UES_D_V1-0/SENTINEL2A_20160305-110109-717_L2A_T31UES_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31UFP/SENTINEL2A_20160720-105547-946_L2A_T31UFP_D_V1-0/SENTINEL2A_20160720-105547-946_L2A_T31UFP_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31UFQ/SENTINEL2A_20160511-105343-672_L2A_T31UFQ_D_V1-0/SENTINEL2A_20160511-105343-672_L2A_T31UFQ_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31UFR/SENTINEL2A_20160607-104026-455_L2A_T31UFR_D_V1-0/SENTINEL2A_20160607-104026-455_L2A_T31UFR_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31UFS/SENTINEL2A_20160508-104027-456_L2A_T31UFS_D_V1-0/SENTINEL2A_20160508-104027-456_L2A_T31UFS_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31UGP/SENTINEL2A_20160408-104020-456_L2A_T31UGP_D_V1-0/SENTINEL2A_20160408-104020-456_L2A_T31UGP_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31UGQ/SENTINEL2A_20160816-104025-461_L2A_T31UGQ_D_V1-0/SENTINEL2A_20160816-104025-461_L2A_T31UGQ_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T31UGR/SENTINEL2A_20160119-105107-606_L2A_T31UGR_D_V1-0/SENTINEL2A_20160119-105107-606_L2A_T31UGR_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T32TLP/SENTINEL2A_20160405-103019-462_L2A_T32TLP_D_V1-0/SENTINEL2A_20160405-103019-462_L2A_T32TLP_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T32TLQ/SENTINEL2A_20160803-103724-960_L2A_T32TLQ_D_V1-0/SENTINEL2A_20160803-103724-960_L2A_T32TLQ_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T32TLR/SENTINEL2A_20160326-103406-538_L2A_T32TLR_D_V1-0/SENTINEL2A_20160326-103406-538_L2A_T32TLR_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T32TLS/SENTINEL2A_20160126-104630-775_L2A_T32TLS_D_V1-0/SENTINEL2A_20160126-104630-775_L2A_T32TLS_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T32TLT/SENTINEL2A_20160126-104630-775_L2A_T32TLT_D_V1-0/SENTINEL2A_20160126-104630-775_L2A_T32TLT_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T32TMM/SENTINEL2A_20160711-102030-066_L2A_T32TMM_D_V1-0/SENTINEL2A_20160711-102030-066_L2A_T32TMM_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T32TMN/SENTINEL2A_20160728-101603-978_L2A_T32TMN_D_V1-0/SENTINEL2A_20160728-101603-978_L2A_T32TMN_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T32TNL/SENTINEL2A_20160728-101603-978_L2A_T32TNL_D_V1-0/SENTINEL2A_20160728-101603-978_L2A_T32TNL_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T32TNM/SENTINEL2A_20160718-101028-464_L2A_T32TNM_D_V1-0/SENTINEL2A_20160718-101028-464_L2A_T32TNM_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T32TNN/SENTINEL2A_20160708-101602-980_L2A_T32TNN_D_V1-0/SENTINEL2A_20160708-101602-980_L2A_T32TNN_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T32ULU/SENTINEL2A_20160126-104630-775_L2A_T32ULU_D_V1-0/SENTINEL2A_20160126-104630-775_L2A_T32ULU_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T32ULV/SENTINEL2A_20151207-103733-673_L2A_T32ULV_D_V1-0/SENTINEL2A_20151207-103733-673_L2A_T32ULV_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T32UMU/SENTINEL2A_20151207-103733-673_L2A_T32UMU_D_V1-0/SENTINEL2A_20151207-103733-673_L2A_T32UMU_D_V1-0_FRE_B2.tif', '/work/theia/oso/sensorsDatas/S2/20152016//T32UMV/SENTINEL2A_20160714-103025-460_L2A_T32UMV_D_V1-0/SENTINEL2A_20160714-103025-460_L2A_T32UMV_D_V1-0_FRE_B2.tif']
    driver = ogr.GetDriverByName("ESRI Shapefile")
    try:
        if os.path.exists(outGridPath):
            driver.DeleteDataSource(outGridPath)
        output = driver.CreateDataSource(outGridPath)
    except ValueError:
        raise Exception("Could not create output datasource " + outGridPath)

    srs = osr.SpatialReference()
    srs.ImportFromEPSG(int(outputProjection))
    layer = output.CreateLayer(outGridPath.split("/")[-1].replace(".shp", ""),
                               geom_type=ogr.wkbPolygon,
                               srs=srs)
    layer.CreateField(ogr.FieldDefn(tileNameField, ogr.OFTString))
    layerDef = layer.GetLayerDefn()
    if layer is None:
        raise Exception("Could not create output layer")

    for currentTile in paths:
        currentProjection = fu.getRasterProjectionEPSG(currentTile)
        minX, maxX, minY, maxY = fu.getRasterExtent(currentTile)
        upperL = (minX, maxY)
        upperR = (maxX, maxY)
        lowerL = (minX, minY)
        lowerR = (maxX, minY)
        upperL_out = converCoord(upperL, int(currentProjection),
                                 int(outputProjection))
        upperR_out = converCoord(upperR, int(currentProjection),
                                 int(outputProjection))
        lowerL_out = converCoord(lowerL, int(currentProjection),
                                 int(outputProjection))
        lowerR_out = converCoord(lowerR, int(currentProjection),
                                 int(outputProjection))
        TileName = getTileNameFromRaster(currentTile)
        addTileToGrid(upperL_out, upperR_out, lowerR_out, lowerL_out, layer,
                      layerDef, tileNameField, TileName)

    output.Destroy()
def storeRasterInArray(rasters):
    """Store list of raster or multi-band raster in a ndarray

    Parameters
    ----------

    rasters : list
        list of rasters to analyse

    Return
    ----------
    ndarray

    """

    # get raster size with first raster file
    data = fut.readRaster(rasters[0], False)

    # get rasters or bands number
    if len(rasters) == 1:
        nbbands = fut.getRasterNbands(rasters[0])

    elif len(rasters) > 1:
        nbbands = len(rasters)

    # Set a empty ndarrays with same dimension as input rasters
    outdata = np.zeros([data[1], data[0], nbbands])

    # Populate output ndarrays
    if len(rasters) == 1:
        for nbband in range(nbbands):
            outdata[:, :, nbband] = fut.readRaster(rasters[0], True,
                                                   nbband + 1)[0]

    elif len(rasters) > 1:
        for idx, raster in enumerate(rasters):
            outdata[:, :, idx] = fut.readRaster(raster, True)[0]
    else:
        raise Exception("No input raster provided to store in Numpy array")

    return outdata
示例#29
0
    def step_inputs(self):
        """
        Return
        ------
            the return could be and iterable or a callable
        """

        from Common import FileUtils as fut

        listout = fut.FileSearch_AND(self.tmpdir, True, "mask", ".tif")

        return [listout]
示例#30
0
def GetDataAugmentationByCopyParameters(iota2_dir_samples):
    """ read the */learningSample* directory

    parse the IOTA2's directory */learningSamples* and return a list by seed
    in order to feed DataAugmentationByCopy function

    Parameters
    ----------

    iota2_dir_samples : string
        absolute path to the /learningSamples IOTA2's directory

    Example
    -------

    >>> os.listdir("/learningSamples")
    ["Samples_region_2_seed0_learn.sqlite",
     "Samples_region_2_seed1_learn.sqlite",
     "Samples_region_1_seed0_learn.sqlite",
     "Samples_region_1_seed1_learn.sqlite"]

    >>> GetSamplesSet("/learningSamples")
        [[Samples_region_1_seed0_learn.sqlite, Samples_region_2_seed0_learn.sqlite],
         [Samples_region_1_seed1_learn.sqlite, Samples_region_2_seed1_learn.sqlite]]

    Return
    ------
    list
        a list of list where each inner list contains all samples for a given run
    """
    seed_pos = 3
    samples_set = [(os.path.basename(samples).split("_")[seed_pos], samples)
                   for samples in fut.FileSearch_AND(
                       iota2_dir_samples, True, "Samples_region", "sqlite")]
    samples_set = [
        samplesSeed for seed, samplesSeed in fut.sortByFirstElem(samples_set)
    ]
    return samples_set