Commit 67cc8052 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Fixed remaining tempfiles after FMASK cloud masking. Moved FMASK call to L1C_P (not yet working).

Former-commit-id: 3f0e171a
Former-commit-id: 0f0b7a66
parent 165a1b1f
......@@ -697,22 +697,7 @@ class L1A_object(GMS_object):
if algorithm == 'FMASK':
if re.search('Landsat', self.satellite, re.I):
from .fmask_runner import FMASK_Runner_Landsat
FMR = FMASK_Runner_Landsat(self.path_archive, self.satellite)
cm_gA = FMR.calc_cloudMask()
mask_clouds = cm_gA[:]
elif re.search('Sentinel-2', self.satellite, re.I):
from .fmask_runner import FMASK_Runner_Sentinel2
FMR = FMASK_Runner_Sentinel2(self.path_archive, self.satellite, scene_ID=self.scene_ID, target_res=20)
cm_gA = FMR.calc_cloudMask()
mask_clouds = cm_gA[:]
else:
self.logger.error(
'Cloud masking is not yet implemented for %s %s...' % (self.satellite, self.sensor), subset)
mask_clouds = None
pass
else:
# FIXME Landsat cloud mask pixel values are currently not compatible to definition_dicts.get_mask_classdefinition
......
......@@ -681,19 +681,52 @@ class AtmCorr(object):
return SRF(GMS_identifier_fullScene, wvl_unit='nanometers', format_bandnames=True)
def _calc_mask_clouds(self, target_res):
inObj2use = self.inObjs[0]
if re.search('Landsat', inObj2use.satellite, re.I):
from .fmask_runner import FMASK_Runner_Landsat
FMR = FMASK_Runner_Landsat(inObj2use.path_archive, inObj2use.satellite)
cm_gA = FMR.calc_cloudMask()
mask_clouds = cm_gA[:]
elif re.search('Sentinel-2', inObj2use.satellite, re.I):
from .fmask_runner import FMASK_Runner_Sentinel2
FMR = FMASK_Runner_Sentinel2(inObj2use.path_archive, inObj2use.satellite, scene_ID=inObj2use.scene_ID,
target_res=target_res)
cm_gA = FMR.calc_cloudMask()
mask_clouds = cm_gA[:]
else:
self.logger.error(
'Cloud masking is not yet implemented for %s %s...' % (inObj2use.satellite, inObj2use.sensor))
mask_clouds = None
return mask_clouds
def _get_mask_clouds(self):
"""Returns an instance of S2Mask in case cloud mask is given by input GMS objects. Otherwise None is returned.
:return:
"""
tgt_res = self.inObjs[0].ac_options['cld_mask']['target_resolution']
# check if input GMS objects provide a cloud mask
avail_cloud_masks = {inObj.GMS_identifier['Subsystem']: inObj.mask_clouds for inObj in self.inObjs}
# compute cloud mask if not already provided
if list(set(avail_cloud_masks.values())) == [None]:
inObj2use.mask_clouds = self._calc_mask_clouds(tgt_res)
cm_array = cm_gA[:]
cm_legend = cm_gA.legend
cm_geocoding = cm_gA.gt
return None
# check cloud mask target resolution
tgt_res = self.inObjs[0].ac_options['cld_mask']['target_resolution']
inObjs2use = [obj for obj in self.inObjs if obj.mask_clouds is not None and obj.mask_clouds.xgsd==tgt_res]
if not inObjs2use:
raise ValueError('Error appending cloud mask to input arguments of atmospheric correction. No input '
......
......@@ -54,6 +54,9 @@ class _FMASK_Runner(object):
os.makedirs(tempdir_rootPath)
self.tempdir = tempfile.mkdtemp(dir=tempdir_rootPath, prefix='FMASK__%s__' %os.path.basename(self.path_archive))
# create subdirectory for FMASK internal intermediate files
os.makedirs(os.path.join(self.tempdir, 'FMASK_intermediates'))
def validate_inputs(self):
if not os.path.exists(self.path_archive):
......@@ -97,9 +100,6 @@ class _FMASK_Runner(object):
if output:
return output.decode('UTF-8')
# def stack_images_within_archive(self, path_archive, matching_expression, files_in_archive=None):
# fNames = list(sorted(fnmatch.filter(self.files_in_archive, 'LC8*_B1[0,1].TIF')))
def extract_archive(self):
with tarfile.open(self.path_archive) as tarF:
......@@ -249,7 +249,7 @@ class FMASK_Runner_Landsat(_FMASK_Runner):
'-z %s' %self.angles_stack,
'-s %s' %self.saturationmask,
'-o %s' %self.cloud_mask,
#'-e %s' %os.path.join(self.tempdir, 'FMASK_intermediates')
'-e %s' %os.path.join(self.tempdir, 'FMASK_intermediates')
]) )
finally:
......@@ -352,7 +352,7 @@ class FMASK_Runner_Sentinel2(_FMASK_Runner):
% ' '.join(['-a %s' % self.TOARef,
'-z %s' % self.angles_stack,
'-o %s' % self.cloud_mask,
# '-e %s' %os.path.join(self.tempdir, 'FMASK_intermediates')
'-e %s' %os.path.join(self.tempdir, 'FMASK_intermediates')
]))
finally:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment