Preparing the land cover raster
There is currently no automatic script to generate land cover rasters. This part has to be done manually by the user.
Pixel mode
For the pixel mode, the user has to find a land cover raster and project it on the same grid as the NDVI and weather datasets. Each class should be represented as an integer (starting at one) and saved as a Geotiff file (for OTB
). Once you have a valid raster, you can reproject it and clip it using the OTB Superimpose function. Here is an example of the command you can run to do that:
(modspa_pixel) $ otbcli_Superimpose -inr reference_satellite_image.tif -inm lc_raster_input.tif -out lc_raster_output.tif -interpolator nn
Where:
-inr
is the reference image on which you want to superimpose your raster (e.g. Sentinel-2 image or extraction of Sentinel-2 image).-inm
is the raster you want to superimpose.-out
is the name of the output raster that will be created-interpolator
is the chosen interpolator (nn stands for nearest neighbor), other interpolators will not work as they will create new float values between the integer values.additional parameters like the data type can be found in the OTB documentation
You will then have a land cover raster on the same grid as the other inputs.
Parcel mode
The land cover information has to be included in the parcel definition shapefile. Each parcel should have a land cover class identification number (integers starting by one). Extraction is then done automatically using the custom_inputs_parcel.ipynb
. An xarray
dataset can then be created with the help of this function:
- modspa_pixel.preprocessing.parcel_to_pixel.convert_geodataframe_to_xarray(geodataframe_in: str | GeoDataFrame | DataFrame, save_path: str, name: str, variable: str, data_type: str, global_attributes: List[dict] = []) None [source]
Convert
geopandas GeoDataDrames
of the parcel mode intoxarray DataArray
for the model calculations. The resulting xarray dataset has dimensions:y: 1
,x: number of poygons
(to make a 2D dataset).Arguments
- geodataframe_in:
Union[str, gpd.GeoDataFrame, pd.DataFrame]
geodataframe or path to geodataframe to convert
- geodataframe_in:
- save_path:
str
save path of output xarray dataset
- save_path:
- name:
str
name of dataarray to save
- name:
- variable:
str
name of variable to extract to put in the ouput dataset
- variable:
- data_type:
str
xarray datatype corresponding the the variable name, for correct saving of the dataset
- data_type:
- global_attribute:
List[dict]
list of optionnal attributes to add to the netCDF file, give a list of single element dictionnary {key: value}
- global_attribute:
Returns
None
Land Cover preprocessing
Additional processing can be done with the custom_inputs_pixel.ipynb
or custom_inputs_parcel.ipynb
notebooks found in the preprocessing
directory.