Sen2cor 2.8 Error : esacciSnow Condition


i am processing data capture on 28th Dec 2020 using sen2cor 2.8 ( standalone module) ( windows as well as Linux) .

The issue is specific to data capture on this date ( fails for all scenes) , for other dates it works fine ( before 28 Dec or after 28 Dec)

It gives below error

Progress[%]: 5.34 : PID-35200, L2A_Tables: band ASP imported, elapsed time[s]: 12.480, total: 0:03:00.673000
0…10…20…30…40…50…60…70…80…90…100 - done.

Progress[%]: 5.46 : PID-35200, L2A_Tables: band WBI imported, elapsed time[s]: 3.887, total: 0:03:04.560000
0…10…20…30…40…50…60…70…80…90…100 - done.

Progress[%]: 5.69 : PID-35200, L2A_Tables: band LCM imported, elapsed time[s]: 7.267, total: 0:03:11.827000

local variable ‘esacciSnowCondition’ referenced before assignment
Traceback (most recent call last):
File “C:\project\Sen2Cor-02.08.00-win64\Sen2Cor-02.08.00-win64\Lib\site-packages\sen2cor\”, line 495, in main
if tile.process() == True:
File “C:\projectr\Sen2Cor-02.08.00-win64\Sen2Cor-02.08.00-win64\Lib\site-packages\sen2cor\”, line 118, in process
if not self.process_resolution(20):
File “C:\projectr\Sen2Cor-02.08.00-win64\Sen2Cor-02.08.00-win64\Lib\site-packages\sen2cor\”, line 148, in process_resolution
return self._process()
File “C:\projectr\Sen2Cor-02.08.00-win64\Sen2Cor-02.08.00-win64\Lib\site-packages\sen2cor\”, line 162, in _process
if self.preprocess() == False:
File “C:\projectr\Sen2Cor-02.08.00-win64\Sen2Cor-02.08.00-win64\Lib\site-packages\sen2cor\”, line 251, in preprocess
if(self.tables.importBandList() == False):
File “C:\projectr\Sen2Cor-02.08.00-win64\Sen2Cor-02.08.00-win64\Lib\site-packages\sen2cor\”, line 1044, in importBandList
if(self.gdalCCI_snowc() == False):
File “C:\projectr\Sen2Cor-02.08.00-win64\Sen2Cor-02.08.00-win64\Lib\site-packages\sen2cor\”, line 1622, in gdalCCI_snowc
callstr = command + arguments + t_srs + t_warp + esacciSnowCondition + ’ ’ + cci_snowc_dst + self._DEV0
UnboundLocalError: local variable ‘esacciSnowCondition’ referenced before assignment
Progress[%]: 100.00 : Application terminated with at least one error.

I figured out the issue, it is due to leap year. in the the condition to select the aux file based on the name does not satisfy so it fails.
December 28 2020 day of Year is 363, based on that it need to select the aux data file, but fails as the difference is more 4 days. ( the code says it should be less than 4)

below is snippet where it fails

        if (doy_acq > 363) | ((doy_acq > 362) & (not isLeap)):
            esacciSnowCondition = listSnowConditionFiles[-1]
            # special handling for Day Of Year 61
            if doy_acq == 61:
                esacciSnowCondition = listSnowConditionFiles[8]  # corresponds to 9th weekly product of the year

            datePattern = os.path.join(esacciSnowConditionDir,'ESACCI-LC-L4-Snow-Cond-AggOcc-500m-P13Y7D-2000-2012-%Y%m%d-v2.0.tif')
            for SnowConditionFile in listSnowConditionFiles:
                doy_file = datetime.strptime(SnowConditionFile, datePattern).timetuple().tm_yday
                if abs(doy_acq - doy_file) < 4:   # this condition does not satisfy so it does not assign a value to the variable esacciSnowCondition so it throws an error ahead 
                    esacciSnowCondition = SnowConditionFile

There are two ways to fix it,

  • Change the condition for day_acq>363 to 362

  • In the aux data copy the file “ESACCI-LC-L4-Snow-Cond-AggOcc-500m-P13Y7D-2000-2012-20001224-v2.0.tif” in the same directory and rename it to ESACCI-LC-L4-Snow-Cond-AggOcc-500m-P13Y7D-2000-2012-20001227-v2.0.tif