hypso.classification.WaterDetection.waterdetect.InputOutput module

class hypso.classification.WaterDetection.waterdetect.InputOutput.DWLandsatMaskProcessor(base_folder, x_size, y_size, shape_file=None, temp_dir=None)

Bases: object

LandsatMaskDict = {'cirrus_conf1': 256, 'cirrus_conf2': 512, 'clear': 2, 'cloud': 32, 'cloud_conf1': 64, 'cloud_conf2': 128, 'cloud_shadow': 8, 'fill': 1, 'snow': 16, 'terrain_occlusion': 1024, 'water': 4}
get_combined_masks(masks_list)
open_gdal_masks(shape_file, temp_dir)
open_mask(shape_file, temp_dir)
class hypso.classification.WaterDetection.waterdetect.InputOutput.DWLoader(input_folder, shape_file=None, product='S2_THEIA', ref_band='Red', single_mode=False)

Bases: object

property area_name

Extracts the name of the area based on the shapefile name :return: name of the area

band_ids = {'Blue': 1, 'Green': 2, 'Mir': 11, 'Mir2': 12, 'Nir': 7, 'Nir2': 8, 'Red': 3, 'RedEdg1': 4, 'RedEdg2': 5, 'RedEdg3': 6}
property bands_path

Return the directory of the bands depending on the product :return: PosixPath of the directory containing the bands

clip_bands(bands_to_clip, ref_band, temp_dir)
property current_image_folder

Returns the full path folder of current (selected) image :return: Posixpath of current image

property current_image_name

Returns the name of the current (selected) image :return: String name of the current (selected) image

property geo_transform
get_bands_files()

Retrieve the full path of bands saved for the current image, according to the product :return: Posix_path of bands files

get_offset(band)

Get the offset value to be applied to the band. This offset exists in the Sen2Cor images after 25 January 2022. https://sentinels.copernicus.eu/documents/247904/4830984/OMPC.CS.DQR.002.07-2022%20-%20i52r0%20-%20MSI%20L2A%20DQR%20August%202022.pdf/36edbb04-0c6c-fba3-5c34-0ba3be82e91c @param band: Reflectance band @return: Value to be added to the loaded band

property glint_name

” Name of the glint image for the report

property granule_metadata

Returns the full path folder of the image’s granule metadata :return: Posixpath of current image’s granule metadata

load_masks(product_masks_list, external_mask, mask_name, mask_valid_value=None, mask_invalid_value=None)
load_raster_bands(bands_list)
Parameters:

bands_list (list) –

property metadata

Returns the full path folder of the image’s metadata :return: Posixpath of current image’s metadata

open_current_image(ref_band_name='Red')

Load a bands list, given a image_list and a dictionary of Keys(BandName) and identifiers to parse the filename ex. {‘Green’:’B3’, ‘Red’:’B4’…} The result, will be a dictionary with Keys(BandName) and GdalDatasets as values

static open_gdal_image(bands_list, desired_band)

Get the image in the list corresponding to the informed Band. Return the image opened with GDAL as a RasterImage object If cant find the band return None If is more than 1 image, raise exception

property product_dict
property projection
satellite_Dict = {'L8_L1C': {'bands_names': {'Aero': 'band1', 'Blue': 'band2', 'Green': 'band3', 'Mir': 'band6', 'Mir2': 'band7', 'Nir': 'band5', 'Red': 'band4'}, 'recursive': False, 'string': 'sr_band', 'suffix': '.tif'}, 'L8_USGS': {'bands_names': {'Green': 'B3', 'Mir': 'B6', 'Nir': 'B5', 'Red': 'B4'}}, 'S2_L1C': {'bands_names': {'Blue': 'B02', 'Green': 'B03', 'Mir': 'B11', 'Mir2': 'B12', 'Nir': 'B08', 'Nir2': 'B8A', 'Red': 'B04', 'RedEdg1': 'B05', 'RedEdg2': 'B06', 'RedEdg3': 'B07'}, 'granule_metadata': '*MTD_TL.xml', 'recursive': False, 'string': '', 'subdir': 'GRANULE/*/IMG_DATA', 'suffix': '.jp2'}, 'S2_PLANETARY': {'bands_names': {'Blue': 'B02_10m', 'Green': 'B03_10m', 'Mir': 'B11_20m', 'Mir2': 'B12_20m', 'Nir': 'B08_10m', 'Nir2': 'B8A_20m', 'Red': 'B04_10m', 'RedEdg1': 'B05_20m', 'RedEdg2': 'B06_20m', 'RedEdg3': 'B07_20m'}, 'granule_metadata': '*MTD_TL.xml', 'recursive': False, 'string': '', 'suffix': '.tif'}, 'S2_S2COR': {'bands_names': {'Blue': 'B02_10m', 'Green': 'B03_10m', 'Mir': 'B11_20m', 'Mir2': 'B12_20m', 'Nir': 'B08_10m', 'Nir2': 'B8A_20m', 'Red': 'B04_10m', 'RedEdg1': 'B05_20m', 'RedEdg2': 'B06_20m', 'RedEdg3': 'B07_20m'}, 'granule_metadata': '*MTD_TL.xml', 'metadata': 'MTD_MSIL2A.xml', 'recursive': True, 'string': '', 'subdir': 'GRANULE/*/IMG_DATA', 'suffix': '.jp2'}, 'S2_THEIA': {'bands_names': {'Blue': 'B2', 'Green': 'B3', 'Mir': 'B11', 'Mir2': 'B12', 'Nir': 'B8', 'Nir2': 'B8A', 'Red': 'B4', 'RedEdg1': 'B5', 'RedEdg2': 'B6', 'RedEdg3': 'B7'}, 'granule_metadata': '*MTD_ALL.xml', 'recursive': False, 'string': 'SRE', 'suffix': '.tif'}}
update_mask(mask)
property x_size
property y_size
class hypso.classification.WaterDetection.waterdetect.InputOutput.DWS2CORMaskProcessor(base_folder, x_size, y_size, shape_file=None, temp_dir=None)

Bases: object

Sen2CorMaskList = {'CLOUD_HIGH_PROBABILITY': 9, 'CLOUD_MEDIUM_PROBABILITY': 8, 'CLOUD_SHADOWS': 3, 'DARK_AREA_PIXELS': 2, 'NOT_VEGETATED': 5, 'NO_DATA': 0, 'SATURATED_OR_DEFECTIVE': 1, 'SNOW': 11, 'THIN_CIRRUS': 10, 'UNCLASSIFIED': 7, 'VEGETATION': 4, 'WATER': 6}
get_combined_masks(masks_list)
open_gdal_masks(shape_file, temp_dir)
open_mask(shape_file, temp_dir)
class hypso.classification.WaterDetection.waterdetect.InputOutput.DWSaver(output_folder, product_name, area_name=None)

Bases: object

property area_name
static create_base_name(product_name, image_name)
static create_output_folder(output_folder, image_name, area_name)
save_array(array, name, opt_relative_path=None, no_data_value=0, dtype=None)
save_multiband(array, name, opt_relative_path=None, no_data_value=0, dtype=None)

Save a multilayer array

Parameters:
  • array – array with all bands wanted

  • name – name of the output

Returns:

the complete filename

save_rgb_array(red, green, blue, name, opt_relative_path=None)
set_output_folder(image_name, geo_transform, projection)

For each image, the saver has to prepare the specific output directory, and saving parameters. The output directory is based on the base_output_folder, the area name and the image name :param image_name: name of the image being processed :param geo_transform: geo transformation to save rasters :param projection: projection to save rasters :return: Nothing

property temp_dir
update_geo_transform(geo_transform, projection)
class hypso.classification.WaterDetection.waterdetect.InputOutput.DWTheiaMaskProcessor(base_folder, x_size, y_size, shape_file=None, temp_dir=None)

Bases: object

TheiaCLMDict = {'clm_all_clouds': 2, 'clm_all_clouds_and_shadows': 1, 'clm_cloud_shadows': 32, 'clm_clouds_blue_band': 4, 'clm_clouds_multi_temporal': 8, 'clm_high_clouds': 128, 'clm_other_shadows': 64, 'clm_thin_clouds': 16}
TheiaMG2Dict = {'mg2_all_clouds': 2, 'mg2_cloud_shadows': 8, 'mg2_other_shadows': 16, 'mg2_snow': 4, 'mg2_sun_tangent': 128, 'mg2_sun_too_low': 64, 'mg2_terrain_mask': 32, 'mg2_water': 1}
TheiaMaskDict = {'CLM': '*_CLM_R1.tif', 'EDG': '*_EDG_R1.tif', 'MG2': '*_MG2_R1.tif', 'SAT1': '*_SAT_R1.tif', 'SAT2': '*_SAT_R2.tif'}
get_combined_masks(masks_list)
open_gdal_masks(shape_file, temp_dir)
open_masks(shape_file, temp_dir)