Skip to content

Module fordead.maja_fun

Functions

band_files

def band_files(
    indir,
    type='FRE'
)
Get band files of MAJA directory (downloaded from THEIA)
Parameters
----------
indir: str
    directory containing the raster band files
type: str
    FRE or SRE, see notes for details.
Returns
-------
list
    MAJA band files

Notes
-----

SRE is for SUrface REflectance, i.e. corrected from atmospheric and environment effects.

FRE is for Flat REflectance, adding to SRE the correction of slope effects.

See https://labo.obs-mip.fr/multitemp/sentinel-2/theias-sentinel-2-l2a-product-format for more information.

read_maja

def read_maja(
    indir,
    shapefile=None,
    res=10,
    resampling=<Resampling.cubic: 2>,
    chunks={'x': 1024, 'y': 1024, 'band': -1},
    with_vrt=False,
    vrt_ram=64
)
Read MAJA data: FRE bands and mask bbox clipped and resampled

Parameters
----------
indir: str
    MAJA file directory.
shapefile: str
    Region of interest polygon file (1 polygon expected)
res: float
    Target resolution.
resampling_method: int
    rasterio.enums.Resampling method
chunks: dict
    chunks to read/process in parallel
with_vrt: bool
    If True uses WarpedVRT and dask delayed procesing, chunking, parallelisation for reprojection task.
vrt_ram: int
    warp_mem_limit, see https://rasterio.readthedocs.io/en/latest/api/rasterio.vrt.html#rasterio.vrt.WarpedVRT

Returns
-------
(rioxarray.DataArray, rioxarray.DataArray)
    (bands, mask)
    mask has values:

    - 0 : invalid pixel,
    - 1 : valid pixel

resample_raster

def resample_raster(
    raster_path,
    resampling=<Resampling.cubic: 2>,
    res=10,
    chunks={'x': 1024, 'y': 1024, 'band': -1},
    ram=1024
)
Resample raster using WarpVRT and rioxarray

Parameters
----------
raster_path: str
resampling: int
    Method from rasterio.enums.Resampling
res: float
    Should be a divider of raster extent.
chunks: dict
    chunks of the output rioxarray
ram:
    warp_mem_limit, see https://rasterio.readthedocs.io/en/latest/api/rasterio.vrt.html#rasterio.vrt.WarpedVRT

Returns
-------
rioxarray.DataArray

Notes
-----
Inspired of:

    - https://github.com/corteva/rioxarray/issues/119
    - https://gist.github.com/rmg55/875a2b79ee695007a78ae615f1c916b2

unzip

def unzip(
    zfile,
    write_dir,
    overwrite=False
)
Unzip file

Parameters
----------
zfile: str
    Zip file path
write_dir: str
    Destination directory
overwrite: bool

Returns
-------
str
    Extracted directory path