hypso.classification.WaterDetection.waterdetect.Common module

class hypso.classification.WaterDetection.waterdetect.Common.DWBaseConfig(config_file=None)

Bases: object

Base class for

get_option(section, key, evaluate)

Get option value :param section: :param key: :param evaluate: :return:

Parameters:

evaluate (bool) –

load_config_file(config_file)

Load config file :param config_file: :return:

return_defaults(section, key)

Return default values :param section: :param key: :return:

class hypso.classification.WaterDetection.waterdetect.Common.DWConfig(config_file=None)

Bases: DWBaseConfig

Configuration for

property average_results
property calc_glint

Returns calculated glint :return:

property classifier
property clip_band
property clip_inf_value
property clip_sup_value
property clustering_bands
property clustering_method
property create_composite

Returns the composite :return:

property detect_water_cluster
property external_mask
get_masks_list(product)
property glint_mode

Returns glint mode :return:

property graphs_bands
property linkage
property mask_invalid_value
property mask_name
property mask_valid_value
property max_clusters
property max_train_size
property maximum_invalid
property min_clusters
property min_glint_multiplier

Returns minimum glint multiplier :return:

property min_positive_pixels
property min_train_size
property pdf_reports

Returns the pdf report :return:

property pdf_resolution

Returns pdf resolution :return:

property pekel_accuracy
property pekel_water
property plot_graphs
property plot_ts
property reference_band

Returns the reference band :return:

property regularization
property save_indices
property score_index
property texture_stretching
property train_size
class hypso.classification.WaterDetection.waterdetect.Common.DWutils

Bases: object

static apply_mask(array, mask, no_data_value=- 9999, clear_nan=True)
static array2multiband(filename, array, geo_transform, projection, nodatavalue=0, dtype=None)
static array2raster(filename, array, geo_transform, projection, nodatavalue=0, dtype=None)
static array2rgb_raster(filename, red, green, blue, geo_transform, projection, nodatavalue=- 9999)
static bitwise_and(array, bit_values)
static bitwise_or(array, bit_values)
static calc_mbwi(bands, factor, mask)
static calc_normalized_difference(img1, img2, mask=None, compress_cte=0.02)

Calc the normalized difference of given arrays (img1 - img2)/(img1 + img2). Updates the mask if any invalid numbers (ex. np.inf or np.nan) are encountered :param img1: first array :param img2: second array :param mask: initial mask, that will be updated :param compress_cte: amount of index compression. The greater, the more the index will be compressed towards 0 :return: nd array filled with -9999 in the mask and the mask itself

static check_path(path_str, is_dir=False)

Check if the path/file exists and returns a Path variable with it :param path_str: path string to test :param is_dir: whether if it is a directory or a file :return: Path type variable

static create_bands_dict(bands_array, bands_order)
static create_colorbar_pdf(product_name, title, label, colormap, min_value, max_value, log_scale=False)
static create_composite(bands, folder_name, pdf=True, resolution=600, offset=0)
static create_glint_pdf(xml, name_img, output_folder, g, pdf_merger)

Function to create an image to add in the pdf report that indicates if there is glint on an image

xmlTYPE xml file

DESCRIPTION Filepath of the metadata file from L2A Sentinel 2 data: example “SENTINEL2A_20200328-104846-345_L2A_T31TFJ_C_V2-2_MTD_ALL.xml”

name_img : getting current image name

output_folder: filepath of the output folder

g: TYPE list

DESCRIPTION list with glint values for each band of the Sentinel 2 product

pdf_merger: function to add an element to a pdf

static extract_angles_from_xml(xml)
xmlTYPE xml file

DESCRIPTION Filepath of the metadata file from L2A Sentinel 2 data: example “SENTINEL2A_20200328-104846-345_L2A_T31TFJ_C_V2-2_MTD_ALL.xml”

Return g:

list of glint values

SZATYPE float

DESCRIPTION. Sun zenith angle

SazATYPE float

DESCRIPTION. Sun azimuth angle

zenith_angleTYPE list of strings

DESCRIPTION. Mean_Viewing_Incidence_Angle_List for all the bands

azimuth_angleTYPE list of strings

DESCRIPTION. Mean_Viewing_Incidence_Angle_List for all the bands

static find_file_glob(file_string, folder)
static flatten(x)
static get_directories(input_folder)

Return a list of directories in input_folder. These folders are the repository for satellite products :param input_folder: folder that stores the images :return: list of images (i.e. directories)

static get_train_test_data(data, train_size, min_train_size, max_train_size)

Split the provided data in train-test bunches :param min_train_size: minimum data quantity for train set :param max_train_size: maximum data quantity for train set :param train_size: percentage of the data to be used as train dataset :param data: data to be split :return: train and test datasets

static gray2color_ramp(grey_array, color1=(0.0, 0.0, 0.6), color2=(0.0, 0.8, 0.0), color3=(1.0, 0.0, 0.0), min_value=0, max_value=20, colormap='viridis', limits=(0, 1))

Convert a greyscale n-dimensional matrix into a rgb matrix, adding 3 dimensions to it for R, G, and B The colors will be mixed :param max_value: Maximum value for the color ramp, if None, we consider max(grey) :param min_value: Minimum value for the color ramp, if None, we consider min(grey) :param grey_array: greyscale vector/matrix :param color1: Color for the minimum value :param color2: Color for the mid value :param color3: Color for the maximum value :param limits: Final boundary limits for the RGB values :return: Colored vector/matrix

indices = {'mbwi': ['Red', 'Green', 'Nir', 'Mir', 'Mir2'], 'mndwi': ['Green', 'Mir2'], 'ndwi': ['Green', 'Nir']}
static listify(lst, uniques=[])
static parse_maja_name(name)

Get the string with a MAJA img name (THEIA format) and extract the useful information from it. :param name: Image name :return: Dictionary with the values.

Parameters:

name (str) –

static parse_planetary_name(name)

Get the string with a MS PLANETARY name and extract the useful information from it. :param name: Image name :return: Dictionary with the values.

Parameters:

name (str) –

static parse_s2cor_name(name)

Get the string with a S2COR name (.SAFE format) and extract the useful information from it. :param name: Image name :return: Dictionary with the values.

Parameters:

name (str) –

Return type:

dict

static parse_sat_name(folder, img_type='S2_THEIA')

Function To :param folder: :param img_type:

Returns:

static plot_clustered_data(data, cluster_names, file_name, graph_options, pdf_merger)
static plot_graphs(bands, graphs_bands, labels_array, file_name, graph_title, invalid_mask=False, max_points=1000, pdf_merger=None)
static read_gdal_ds(file, shape_file, temp_dir)

Read a GDAL dataset clipping it with a given shapefile, if necessary :param file: Filepath of the GDAL file (.tif, etc.) as Pathlib :param shape_file: file path of the shapefile :param temp_dir: file path of the temporary directory :return: GDAL dataset

static remove_negatives(bands, mask=None, negative_values='mask')

Remove negatives values of given arrays b1 and b2, except masked values.

Parameters:
  • bands – list of bands to be adjusted

  • mask – initial mask

  • negative_values – mask - mask the negative values; # fixed - replace all negative values for 0.001; shift - shift each band by its minimum value, so every band has only positive values; shift_all - shift each band by the minimum value of all bands. All bands will be shifted up by the same amount

Returns:

nd arrays without negatives values

static rgb_burn_in(red, green, blue, burn_in_array, color=None, min_value=None, max_value=None, colormap='viridis', fade=1, uniform_distribution=False, no_data_value=- 9999, valid_value=1, transp=0.0)

Burn in a mask or a specific parameter into an RGB image for visualization purposes. The burn_in_array will be copied where values are different from no_data_value. :param uniform_distribution: convert the input values in a uniform histogram :param colormap: matplotlib colormap (string) to create the RGB ramp :param max_value: maximum value :param min_value: minimum value :param red: Original red band :param green: Original green band :param blue: Original blue band :param burn_in_array: Values to be burnt in :param no_data_value: Value to ne unconsidered :param color: Tuple of color (R, G, B) to be used in the burn in :param fade: Fade the RGB bands to emphasize the copied values :param transp: Transparency to use in the mask (0=opaque 1=completely transparent) :return: RGB image bands

static tif_2_pdf(tif_file, resolution=600, scale=2000)

Convert a TIF image into a PDF given a resolution :param tif_file: :param resolution: :param scale: :return:

static write_pdf(filename, text, size=(300, 50), position=(5, 5), font_color=(0, 0, 0))
hypso.classification.WaterDetection.waterdetect.Common.test_ini()