hypso.utils

Submodules

Package Contents

Classes

MyProgressBar

Class used to display a progress bar on the screen for bulk downloading.

Functions

find_file(path, str_in_file[, suffix, type])

Find recursively a single file (or first occurance) in a specified directory.

is_integer_num(n)

Check if a number is an integer

find_dir(path, str_in_dir[, type])

Find recursively a directory (or first occurance) in a specified directory.

HSI2RGB(wY, HSI[, d, threshold])

Calculate a colore accurate RGB image with HSI values. Original function used for the paper

print_nc(nc_file_path)

Print the contents of a .nc file

find_all_files(path, str_in_file[, suffix, type])

Find recursively all files in a specified directory.

compare_netcdf_files(file1, file2)

Compare two .nc files and returns a pandas DataFrame where each attribute, variable and values are compared side

find_closest_water_lat_lon_match(sat_obj, target_lat, ...)

Find the closest Image lat and lon to the targat specificed that is also a water pixel.

hypso.utils.find_file(path, str_in_file, suffix=None, type='partial')

Find recursively a single file (or first occurance) in a specified directory.

Parameters:
  • path (pathlib.Path) – Directory path on which to look for files.

  • str_in_file (str) – Check if this string is in the file name

  • suffix (Union[str, None]) – Check if file extension matches the suffix provided

  • type (Literal[partial, exact]) – Type of comparisson of “str_in_file”. If “partial”, then “str_in_file” will be checked to be in the filename, otherwise “exact” will check if the filename matches exactly the string provided.

Returns:

Path of the file or None if no file found

Return type:

Union[pathlib.Path, None]

hypso.utils.is_integer_num(n)

Check if a number is an integer

Parameters:

n – Number to check

Returns:

Boolean value indicating whether or not the number is an integer

Return type:

bool

hypso.utils.find_dir(path, str_in_dir, type='partial')

Find recursively a directory (or first occurance) in a specified directory.

Parameters:
  • path (pathlib.Path) – Directory path on which to look for files.

  • str_in_dir (str) – Check if this string is in the directory name

  • type (Literal[partial, exact]) – Type of comparisson of “str_in_file”. If “partial”, then “str_in_file” will be checked to be in the filename, otherwise “exact” will check if the filename matches exactly the string provided.

Returns:

Path of the file or None if no file found

Return type:

Union[pathlib.Path, None]

hypso.utils.HSI2RGB(wY, HSI, d=65, threshold=0.002)

Calculate a colore accurate RGB image with HSI values. Original function used for the paper “Creating RGB Images from Hyperspectral Images Using a Color Matching Function” by M. Magnusson, J. Sigurdsson, S. E. Armansson, M. O. Ulfarsson, H. Deborah and J. R. Sveinsson,

If you use this method, please cite the following paper: @INPROCEEDINGS{hsi2rgb, author={M. {Magnusson} and J. {Sigurdsson} and S. E. {Armansson} and M. O. {Ulfarsson} and H. {Deborah} and J. R. {Sveinsson}}, booktitle={IEEE International Geoscience and Remote Sensing Symposium}, title={Creating {RGB} Images from Hyperspectral Images using a Color Matching Function}, year={2020}, volume={}, number={}, pages={}}

Paper is available at https://www.researchgate.net/profile/Jakob_Sigurdsson

Parameters:
  • wY – Wavelengths in nm

  • HSI – Hyperspectral Image as a (#pixels x #bands) matrix,

  • d (Literal[50, 55, 65, 75]) – Determines the illuminant used, if in doubt use d65. Values of 50, 55, 65, 75

  • threshold – True if RGB thesholding should be done to increase contrast

Returns:

RGB Image array

Return type:

numpy.ndarray

hypso.utils.print_nc(nc_file_path)

Print the contents of a .nc file :param nc_file_path: Absolute path to a .nc file

Returns:

No return

Parameters:

nc_file_path (str) –

Return type:

None

hypso.utils.find_all_files(path, str_in_file, suffix=None, type='partial')

Find recursively all files in a specified directory.

Parameters:
  • path (pathlib.Path) – Directory path on which to look for files.

  • str_in_file (str) – Check if this string is in the file name

  • suffix (Union[str, None]) – Check if file extension matches the suffix provided

  • type (Literal[partial, exact]) – Type of comparisson of “str_in_file”. If “partial”, then “str_in_file” will be checked to be in the filename, otherwise “exact” will check if the filename matches exactly the string provided.

Returns:

List of file paths

Return type:

list

class hypso.utils.MyProgressBar(text_prefix)

Class used to display a progress bar on the screen for bulk downloading.

__call__(block_num, block_size, total_size)
hypso.utils.compare_netcdf_files(file1, file2)

Compare two .nc files and returns a pandas DataFrame where each attribute, variable and values are compared side by side.

Parameters:
  • file1 (str) – Absolute path to file 1

  • file2 (str) – Absolute path to file 2

Returns:

Dataframe with the compared characteristics

Return type:

pandas.DataFrame

hypso.utils.find_closest_water_lat_lon_match(sat_obj, target_lat, target_lon, water_pixel_filter=False)

Find the closest Image lat and lon to the targat specificed that is also a water pixel.

Parameters:
  • water_pixel_filter (bool) – If true, the closest pixel should also be classified as water pixel.

  • sat_obj – Hypso satellite object

  • target_lat (float) – Target latitude

  • target_lon (float) – Target longitude

Returns:

Row, col and dist_to_target in km from the closes water pixel

Return type:

Tuple[int, int, float]