Ejemplo n.º 1
0
    def fmask(self):
        '''-----\n
            This method applies Fmask algorithm or its equivalent with the BQA band (default for Ecopotential)'''

        os.chdir(self.ruta_escena)

        print('Starting Cloud Mask')

        try:

            print('Starting Fmask')
            t = time.time()
            #Last value is the cloud confidence value
            a = os.system(
                'removethisisFmaskinstalled/usr/GERS/Fmask_4_0/application/run_Fmask_4_0.sh /usr/local/MATLAB/MATLAB_Runtime/v93 3 3 1 {}'
                .format(self.umbral))
            a
            if a == 0:
                self.cloud_mask = 'Fmask'
                print('Cloud Mask (Fmask) generated in ' +
                      str(t - time.time()) + ' seconds')

            else:

                print('Starting Cloud Mask with BQA band')
                outfile = os.path.join(
                    os.path.join(self.ruta_escena, self.escena + '_Fmask.tif'))

                for i in os.listdir(self.ruta_escena):
                    if i.endswith('BQA.TIF'):
                        bqa = os.path.join(self.ruta_escena, i)
                        masker = LandsatMasker(bqa, collection=1)
                        conf = LandsatConfidence.high

                        cloud = masker.get_cloud_mask(conf)
                        cirrus = masker.get_cirrus_mask(conf)
                        shadow = masker.get_cloud_shadow_mask(conf)

                        MASCARA = cloud + cirrus + shadow
                        masker.save_tif(MASCARA, outfile)

                self.cloud_mask = 'BQA'
                print('Cloud Mask (BQA) generated in ' + str(t - time.time()) +
                      ' seconds')
                print('Calling get_water')
                self.get_water()

        except Exception as e:

            print("Unexpected error:", type(e), e)
Ejemplo n.º 2
0
output_shadow_mask_path = "{0}/{1}/{1}_bqa_shadow_mask.TIF".format(
    landsat_scenes_path, sceneID)
output_cloudshadow_mask_path = "{0}/{1}/{1}_bqa_cloudshadow_mask.TIF".format(
    landsat_scenes_path, sceneID)

# load the QA band directly
#
# The "collection" parameter is required for landsat to specify the collection
# number. Acceptable number: 0 (pre-collection), 1 (collection-1)

masker = LandsatMasker(bqa_band_path, collection=1)

# algorithm has high confidence that this condition exists
# (67-100 percent confidence)
conf = LandsatConfidence.medium

# Get mask indicating cloud pixels with high confidence
cloud_mask = masker.get_cloud_mask(conf, cumulative=True)

# save the result
masker.save_tif(cloud_mask, output_cloud_mask_path)
if shadow:
    # Get mask indicating cloud pixels with high confidence
    cloud_shadow_mask = masker.get_cloud_shadow_mask(conf, cumulative=True)
    masker.save_tif(cloud_shadow_mask, output_shadow_mask_path)
    # Merge the Cloud and Cloud-Shadow mask
    gdal_calc_string = "gdal_calc.py -A {} -B {} --outfile={} --calc='logical_or(A==1,B==1)'".format(
        output_cloud_mask_path, output_shadow_mask_path,
        output_cloudshadow_mask_path)
    os.system(gdal_calc_string)
# Done