KappaMask, or km-predict, is a cloud detector developed by KappaZeta LTD for Sentinel-2 Level-1C and Level-2A input products.
The following system dependencies are needed:
- micromamba 0.18 or later (https://github.com/mamba-org/mamba)
- python 3.6 or later
- cm_vsm dependencies
Due to the long environment solve times with Miniconda, we have switched to Micromamba. If you're still using Conda, Miniconda or similar, simply substitute micromamba
with conda
in the relevant commands below.
-
Create a micromamba environment.
micromamba create -f environment.yml
-
Copy
config/config_example.json
and adapt it to your needs. -
In order to run sub-tiling procedure cm_vsm should be installed (https://github.com/kappazeta/cm-vsm).
-
Make sure that your
GDAL_DATA
environment variable has been set, according to your GDAL version instead of the placeholderYOUR_GDAL_VERSION
below:GDAL_DATA=/usr/share/gdal/YOUR_GDAL_VERSION
In the root of repository create a /data
folder and copy or symlink the .SAFE product into it.
Cloudmask inference can be run as follows:
micromamba activate km_predict
python km_predict.py -c config/your_config.json
It is possible to overwrite product_name in config file with command line argument -product
python km_predict.py -c config/your_config.json -product S2B_MSIL2A_20200401T093029_N0214_R136_T34UFA_20200401T122148
If the prediction for the same product is running multiple times and .CVAT folder is created under /data
folder, it might be convenient to disable sub_tiling procedure for the next run by -t
python km_predict.py -c config/your_config.json -product S2B_MSIL2A_20200401T093029_N0214_R136_T34UFA_20200401T122148 -t
The predictor will generate sub-tiles masks under /prediction
folder and full S2 mask under /big_image
folder
Potential solutions for typical issues encountered during setup or usage.
Sentinel-2 product splitting fails with the following messages:
INFO: KMP.P: Extracting geo-coordinates.
ERROR 4: Unable to open EPSG support file gcs.csv. Try setting the GDAL_DATA environment variable to point to the directory containing EPSG csv files.
ERROR 4: Unable to open EPSG support file gcs.csv. Try setting the GDAL_DATA environment variable to point to the directory containing EPSG csv files.
INFO: KMP.P: Projection:
terminate called after throwing an instance of 'INFO: KMP.P: Projecting AOI polygon into pixel coordinates.
GDALOGRException'
what(): GDAL OGR error : Failed to import spatial reference from EPSG, Generic failure
Magick: abort due to signal 6 (SIGABRT) "Abort"...
This indicates that the environment variable GDAL_DATA
has not been configured correctly. This could be done in a variety of ways and the preferred method depends on your linux distribution. An export call for the variable (for example, GDAL_DATA=/usr/share/gdal/2.2
) could be added to your .bashrc
, .profile
, etc. Alternatively, the variable could be set together with the python call, for example:
GDAL_DATA=/usr/share/gdal/2.2 python km_predict.py -c config/your_config.json
Sentinel-2 product splitting fails with the following messages:
terminate called after throwing an instance of 'std::filesystem::__cxx11::filesystem_error'
what(): filesystem error: directory iterator cannot open directory: No such file or directory [YOUR_DIRECTORY/km_predict/data/S2B_MSIL1C_20200401T093029_N0209_R136_T34UFA_20200401T113334.SAFE.SAFE/GRANULE/]
Magick: abort due to signal 6 (SIGABRT) "Abort"...
This means that km_predict cannot find the directory with the product_name
specified in the configuration file. The product name in the configuration file should be provided without the .SAFE
suffix.