Package: ukis-csmask
ukis-csmaskUKIS Cloud Shadow MASK (ukis-csmask) package masks clouds and cloud shadows in Sentinel-2, Landsat-9, Landsat-8, Landsat-7 and Landsat-5 images. Masking is performed with a pre-trained convolution neural network. It is fast and works directly on Level-1C data (no atmospheric correction required). Images just need to be in Top Of Atmosphere (TOA) reflectance and include at least the "blue", "green", "red" and "nir" spectral bands. Best performance (in terms of accuracy and speed) is achieved when images also include "swir16" and "swir22" spectral bands and are resampled to approximately 30 m spatial resolution.Thispublicationprovides further insight into the underlying algorithm and compares it to the widely usedFmaskalgorithm across a heterogeneous test dataset.Wieland, M.; Li, Y.; Martinis, S. Multi-sensor cloud and cloud shadow segmentation with a convolutional
neural network.Remote Sensing of Environment, 2019, 230, 1-12.https://doi.org/10.1016/j.rse.2019.05.022Thispublicationintroduces the Python package, performs additional evaluation on recent cloud and cloud shadow benchmark datasets and tests the applicability of ukis-csmask on Landsat-9 imagery.Wieland, M.; Fichtner, F.; Martinis, S. UKIS-CSMASK: A Python package for multi-sensor cloud and cloud shadow segmentation.Int. Arch. Photogramm. Remote Sens. Spatial Inf. Sci., 2022, XLIII-B3-2022, 217–222.https://doi.org/10.5194/isprs-archives-XLIII-B3-2022-217-2022If you use ukis-csmask in your work, please consider citing one of the above publications.Example (Sentinel 2)Here's an example on how to compute a cloud and cloud shadow mask from an image. Please note that here we useukis-pysatfor convencience image handling, but you can also work directly withnumpyarrays.fromukis_csmask.maskimportCSmaskfromukis_pysat.rasterimportImage,Platform# read Level-1C image from file, convert digital numbers to TOA reflectance# and make sure resolution is 30 m to get best performanceimg=Image(data="sentinel2.tif",dimorder="last")img.dn2toa(platform=Platform.Sentinel2)img.warp(resampling_method=0,resolution=30,dst_crs=img.dataset.crs)# compute cloud and cloud shadow mask# NOTE: band_order must match the order of bands in the input image. it does not have to be in this explicit order.# make sure to use these six spectral bands to get best performancecsmask=CSmask(img=img.arr,band_order=["blue","green","red","nir","swir16","swir22"],nodata_value=0,)# access cloud and cloud shadow maskcsmask_csm=csmask.csm# access valid maskcsmask_valid=csmask.valid# convert results to UKIS-pysat Imagecsmask_csm=Image(csmask.csm,transform=img.dataset.transform,crs=img.dataset.crs,dimorder="last")csmask_valid=Image(csmask.valid,transform=img.dataset.transform,crs=img.dataset.crs,dimorder="last")# write results back to filecsmask_csm.write_to_file("sentinel2_csm.tif",dtype="uint8",compress="PACKBITS")csmask_valid.write_to_file("sentinel2_valid.tif",dtype="uint8",compress="PACKBITS",kwargs={"nbits":2})Example (Landsat 8)Here's a similar example based on Landsat 8.importrasterioimportnumpyasnpfromukis_csmask.maskimportCSmaskfromukis_pysat.rasterimportImage,Platform# set Landsat 8 source path and prefix (example)data_path="/your_data_path/"L8_file_prefix="LC08_L1TP_191015_20210428_20210507_02_T1"data_path=data_path+L8_file_prefix+"/"mtl_file=data_path+L8_file_prefix+"_MTL.txt"# stack [B2:'Blue', B3:'Green', B4:'Red', B5:'NIR', B6:'SWIR1', B7:'SWIR2'] as numpy arrayL8_band_files=[data_path+L8_file_prefix+'_B'+x+'.TIF'forxin[str(x+2)forxinrange(6)]]# >> adopted from https://gis.stackexchange.com/questions/223910/using-rasterio-or-gdal-to-stack-multiple-bands-without-using-subprocess-commands# read metadata of first filewithrasterio.open(L8_band_files[0])assrc0:meta=src0.meta# update meta to reflect the number of layersmeta.update(count=len(L8_band_files))# read each layer and append it to numpy arrayL8_bands=[]forid,layerinenumerate(L8_band_files,start=1):withrasterio.open(layer)assrc1:L8_bands.append(src1.read(1))L8_bands=np.stack(L8_bands,axis=2)# <<img=Image(data=L8_bands,crs=meta['crs'],transform=meta['transform'],dimorder="last")img.dn2toa(platform=Platform.Landsat8,mtl_file=mtl_file,wavelengths=["blue","green","red","nir","swir16","swir22"])# >> proceed by analogy with Sentinel 2 exampleInstallationThe easiest way to install ukis-csmask is through pip. To install ukis-csmask withdefault CPU providerrun the following.pipinstallukis-csmask[cpu]To install ukis-csmask withOpenVino supportfor enhanced CPU inference run the following instead.pipinstallukis-csmask[openvino]To install ukis-csmask withGPU supportrun the following instead. This requires that you have a GPU with CUDA runtime libraries installed on the system.pipinstallukis-csmask[gpu]ukis-csmask depends ononnxruntime. For a list of additional dependencies check therequirements.ContributorsThe UKIS team creates and adapts libraries which simplify the usage of satellite data. Our team includes (in alphabetical order):Boehnke, ChristianFichtner, FlorianMandery, NicoMartinis, SandroRiedlinger, TorstenWieland, MarcGerman Aerospace Center (DLR)LicensesThis software is licensed under theApache 2.0 License.Copyright (c) 2020 German Aerospace Center (DLR) * German Remote Sensing Data Center * Department: Geo-Risks and Civil SecurityChangelogSeechangelog.ContributingThe UKIS team welcomes contributions from the community.
For more detailed information, see our guide oncontributingif you're interested in getting involved.What is UKIS?The DLR project Environmental and Crisis Information System (the German abbreviation is UKIS, standing forUmwelt- und Kriseninformationssystemeaims at harmonizing the development of information systems at the German Remote Sensing Data Center (DFD) and setting up a framework of modularized and generalized software components.UKIS is intended to ease and standardize the process of setting up specific information systems and thus bridging the gap from EO product generation and information fusion to the delivery of products and information to end users.Furthermore the intention is to save and broaden know-how that was and is invested and earned in the development of information systems and components in several ongoing and future DFD projects.