Skip to content

Bug in Sen2Cor Processing (typo) - all_cloud_mask not generated

Hi,

I suspect I found a bug in snow_detector.py when processing in sen2cor mode (see function below). As you can see, if mode is sen2cor, the all_cloud_mask.tif will never be generated, since the code block writting to output (the bandMathAllCloud creation and execution block at snow_detector.py:370) is indented inside the "else" condition:

def extract_all_clouds(self):
        if self.mode == 'lasrc':
            # Extract shadow wich corresponds to  all cloud shadows in larsc product
            logging.info("lasrc mode -> extract all clouds from LASRC product using ComputeCloudMask application...")
            computeCMApp = compute_cloud_mask(
                self.cloud_init,
                self.all_cloud_path + GDAL_OPT,
                str(self.all_cloud_mask),
                self.ram,
                otb.ImagePixelType_uint8)
            computeCMApp.ExecuteAndWriteOutput()
            computeCMApp = None 
        else:
            if self.mode == 'sen2cor':
                logging.info("sen2cor mode -> extract all clouds from SCL layer...")
                logging.info("All clouds in sen2cor SCL layer corresponds to:")
                logging.info("- label == 3 -> Cloud shadows")
                logging.info("- label == 8 -> Cloud medium probability")
                logging.info("- label == 9 -> Cloud high probability")
                logging.info("- label == 10 -> Thin cirrus")
                condition_all_clouds = "im1b1==3 || im1b1==8 || im1b1==9 || im1b1==10"
            else:
                condition_all_clouds = "im1b1 > 0"

                bandMathAllCloud = band_math(
                    [self.cloud_init],
                    self.all_cloud_path + GDAL_OPT,
                    "("+condition_all_clouds+" > 0)?1:0",
                    self.ram,
                    otb.ImagePixelType_uint8)
                bandMathAllCloud.ExecuteAndWriteOutput()
                bandMathAllCloud = None

If running in sen2cor mode, this would generate the following error:

Traceback (most recent call last):
 File "/usr/local/app/run_snow_detector.py", line 64, in <module>
   main(sys.argv)
 File "/usr/local/app/run_snow_detector.py", line 52, in main
   snow_detector_app.detect_snow(2)
 File "/usr/local/lib/python2.7/site-packages/s2snow/snow_detector.py", line 279, in detect_snow
   self.pass1()
 File "/usr/local/lib/python2.7/site-packages/s2snow/snow_detector.py", line 553, in pass1
   bandMathPass1.ExecuteAndWriteOutput()
 File "/OTB-6.6.1-Linux64/lib/python/otbApplication.py", line 2461, in ExecuteAndWriteOutput
   return _otbApplication.Application_ExecuteAndWriteOutput(self)
RuntimeError: Cannot open image /data/output/all_cloud_mask.tif. The file does not exist.

In our team we have modified the block on snow_detector.py lines 370-377 taking it one indent to the left (taking it out of the else condition), successfully generating the required all_cloud_mask.tif file and finally being able to execute through the first pass.

I was not able to create a pull request with the fix.

Edited by Daniel Meppiel