Skip to content

Module fordead.validation_module

Functions

attribute_id_to_obs

def attribute_id_to_obs(
    obs,
    name_column
)
Adds an ID column if it doesn't already exists. If column named after name_column parameter does not exist in the geodataframe, adds one with integers from 1 to the number of observations.

Parameters
----------
obs : geopandas GeoDataFrame
    Observation points or polygons
name_column : str
    Name of the ID column.

Returns
-------
obs : geopandas GeoDataFrame
    Observation points or polygons with added column named using parameter name_column if it doesn't already exist.

buffer_obs

def buffer_obs(
    obs,
    buffer,
    name_column
)
Applies a buffer to dilate or erode observations. Names of discarded observations too small compared to a eroding buffer are printed.

Parameters
----------
obs : geopandas GeoDataFrame
    Observation points or polygons with a column named name_column used to identify observations.
buffer : int
    Length in meters of the buffer used to dilate (positive integer) or erode (negative integer) the observations. Some observations may disappear completely if a negative buffer is applied.
name_column : str
    Name of the column used to identify observations.

Returns
-------
obs : geopandas GeoDataFrame
    Observation polygons with the buffer applied.

extract_raster_values

def extract_raster_values(
    points,
    sentinel_dir,
    extracted_reflectance,
    name_column,
    bands_to_extract
)
Must have the same crs

get_bounds

def get_bounds(
    obs
)
Get bounds of around of a polygons so it matches the limits of Sentinel-2 pixels

Parameters
----------
obs : geopandas GeoDataFrame
    A polygon

Returns
-------
bounds : 1D array
    Bounds around the polygon

get_grid_points

def get_grid_points(
    obs_polygons,
    sentinel_dir,
    name_column,
    list_tiles
)
Generates points in a grid corresponding to the centroids of Sentinel-2 pixels inside the polygons.

Parameters
----------
obs_polygons : geopandas GeoDataFrame
    Observation polygons with a column named name_column used to identify observations.
sentinel_dir : str
    Path of directory containing Sentinel-2 data.
name_column : str
    Name of the column used to identify observations.
list_tiles : list
    A list of names of Sentinel-2 directories. If this parameter is used, extraction is  limited to those directories.

Returns
-------
grid_points : geopandas GeoDataFrame
    Points corresponding to the centroids of the Sentinel-2 pixels of each Sentinel-2 tile intersecting with the polygons.

get_polygons_from_sentinel_dirs

def get_polygons_from_sentinel_dirs(
    sentinel_dir,
    list_tiles
)
Creates a Sentinel-2 tiles extent vector from existing Sentinel-2 data

Parameters
----------
sentinel_dir : str
    Path of directory containing Sentinel-2 data.
list_tiles : list
    A list of names of Sentinel-2 directories. If this parameter is used, extraction is  limited to those directories.

Returns
-------
concat_areas : geopandas GeoDataFrame
    Vector containing the extent of Sentinel-2 tiles contained in sentinel_dir directory, with 'epsg' and 'area_name' columns corresponding to the projection system and the name of the tile derived from the name of the directory containing its data.

get_sen_intersection

def get_sen_intersection(
    obs_polygons,
    sen_polygons,
    name_column
)
Observations polygons are intesected with Sentinel-2 tiles extent vector. Intersections where the observation polygon did not entirely fit in the sentinel-2 tile are removed.
Observation polygons which intersect no Sentinel-2 tiles are removed and their IDs are printed.

Parameters
----------
obs_polygons : geopandas GeoDataFrame
    Polygons of observations.
sen_polygons : geopandas GeoDataFrame
    Polygons of Sentinel-2 tiles extent with 'area_name' and 'epsg' columns corresponding to the name of the tile, and the projection system respectively.
name_column : str
    Name of the ID column.

Returns
-------
geopandas GeoDataFrame
    Intersection of obs_polygons and sen_polygons, with incomplete intersections removed.

get_sen_intersection_points

def get_sen_intersection_points(
    points,
    sen_polygons,
    name_column
)
Intersects observation points with Sentinel-2 tiles extent vector.
Adds an 'id_pixel' column filled with 0 so the resulting vector can be used in export_reflectance function.
Points outside of available Sentinel-2 tiles are detected and their IDs are printed.

Parameters
----------
points : geopandas GeoDataFrame
    Observation points used for intersection
sen_polygons : geopandas GeoDataFrame
    Polygons of Sentinel-2 tiles extent with 'area_name' and 'epsg' columns corresponding to the name of the tile, and the projection system respectively.
name_column : str
    Name of the ID column in points

Returns
-------
obs_intersection : geopandas GeoDataFrame
    Intersection of points and sen_polygons, with added 'id_pixel' columns

get_sen_obs_intersection

def get_sen_obs_intersection(
    obs_polygons,
    sentinel_dir,
    name_column,
    list_tiles
)
Creates a Sentinel-2 tiles extent vector from existing Sentinel-2 data, then intersects it with observations polygons, adding their epsg and name.
Polygons which do not fit enterely in at least one existing Sentinel-2 tile are removed.

Parameters
----------
obs_polygons : geopandas GeoDataFrame
    Observation polygons with ID column named after name_column parameter.
sentinel_dir : str
    Path of directory containing Sentinel-2 data.
name_column : str
    Name of the column used to identify observations.
list_tiles : list
    A list of names of Sentinel-2 directories. If this parameter is used, extraction is  limited to those directories.

Returns
-------
sen_intersection : geopandas GeoDataFrame
    Intersection of obs_polygons and Sentinel-2 tiles, adding 'area_name' and 'epsg' columns corresponding to the name of the tile, and the projection system respectively. 

polygons_to_grid_points

def polygons_to_grid_points(
    polygons,
    name_column
)
Converts polygons to points corresponding to the centroids of the Sentinel-2 pixels of each Sentinel-2 tile intersecting with the polygons.
Prints polygons with no pixels centroids inside of them.  

Parameters
----------
polygons : geopandas GeoDataFrame
    Observation polygons with 'area_name' and 'epsg' columns, corresponding to the name of a Sentinel-2 tile and its CRS respectively.
name_column : str
    Name of the ID column.

Returns
-------
grid_points : geopandas GeoDataFrame
    Points corresponding to the centroids of the Sentinel-2 pixels of each Sentinel-2 tile intersecting with the polygons.

process_points

def process_points(
    points,
    sentinel_dir,
    name_column,
    list_tiles
)
Creates a Sentinel-2 tiles extent vector from existing Sentinel-2 data, then intersects it with observations points, adding their epsg and name.

Parameters
----------
points : geopandas GeoDataFrame
    Points used to intersect with Sentinel-2 tiles.
sentinel_dir : str
    Path of directory containing Sentinel-2 data.
name_column : str
    Name of the ID column in points.
list_tiles : list
    A list of names of Sentinel-2 directories. If this parameter is used, extraction is limited to those directories.

Returns
-------
geopandas GeoDataFrame
    Points with added 'epsg', 'area_name' and 'id_pixel' columns.