L1

Table of contents

class l1.l1_event.L1C_event(tiles_collection=None, bands_names=None, event_class=None, event_name=None, device=device(type='cpu'))[source]

Creates an L1C image from a tiles collection and band_names. It is possible to associate an image class to the image.

Parameters:
  • tiles_collection (list, optional) – list of L1C_tile. Defaults to None.

  • bands_names (list, optional) – list of band names. Defaults to None.

  • event_class (string, optional) – class name. Defaults to None.

  • event_name (str, optional) – event name. Defaults to None.

  • device (torch.device, optional) – device for each L0 tile in the image. Defaults to torch.device(“cpu”).

crop_tile(l0_granule_coordinates, out_dir_path=None, out_name_ending=None, lat_lon_format=True, verbose=True, cfg_file_dict=None, id_l0_l1_dict=None, database='THRAWS', overwrite=False)[source]

Create a mosaic of l1 tiles and crop the mosaic by using the l0_granule_coordinates. The output file is saved as TIF file into the directory specified through “”out_dir_path””.

Parameters:
  • l0_granule_coordinates (list) – list of coordinates of a referene l0_granule.

  • out_dir_path (src, optional) – path to the output directory containing the cropped TIF file. If None, default path is used. Defaults to None.

  • out_name_ending (src, optional) – optional ending for the output name. Defaults to None.

  • lat_lon_format (bool, optional) – if True, coordinates points are in (LAT, LON) format. Defaults to True.

  • verbose (bool, optional) – if True, verbose mode is used. Defaults to True.

  • cfg_file_dict (dict, optional) – dictionary containing paths to the different end2end directories. If None, internal CSV database will be parsed.

  • id_l0_l1_dict (dict, optional) – id-l0-l1 dictionary. If None, internal CSV database will be parsed.

  • database (string, optional) – database name. Defaults to “THRAWS”.

  • overwrite (bool, optional) – if True, the file is overwritten if exists, otherwise tile generation is skipped. Defaults to False.

Returns:

output file name

Return type:

src

from_database(id_event, bands_list=None, cfg_file_dict=None, id_l0_l1_dict=None, reproject_bounds=True, verbose=True, database='THRAWS')[source]

Read specific bands of the L1 Sentine2 image “”id_event””, specified in “bands_list”, from database.

Parameters:
  • id_event (str) – event ID.

  • bands_list (list, optional) – bands list. If None, all bands are used and sorted according to the datasheet order. Defaults to None.

  • cfg_file_dict (dict, optional) – dictionary containing paths to the different end2end directories. If None, internal CSV database will be parsed.

  • id_l0_l1_dict (dict, optional) – id-l0-l1 dictionary. If None, internal CSV database will be parsed.

  • reproject_bounds (bool, optional) – if True, bounds are reprojected to EPGS:4326.

  • verbose (bool, optional) – if True, if True, verbose mode is used. Defaults to True.

  • database (string, optional) – database name. Defaults to “THRAWS”.

from_path(l1c_dir_path, bands_list, reproject_bounds=True, verbose=True)[source]

Read specific bands of the Sentinel-2 L0 event located at “”l0_dir_path””.

Parameters:
  • l1c_dir_path (str) – path to the l0 event dir.

  • None (bands list. If) –

  • None. (all bands are used and sorted according to the datasheet order. Defaults to) –

  • reproject_bounds (bool, optional) – if True, bounds are reprojected to EPGS:4326.

  • verbose (bool, optional) – if True, if True, verbose mode is used. Defaults to True.

get_bands_list()[source]

Returns the list of bands of every L1C_tile object in the collection.

Returns:

band names.

Return type:

list

get_event_class()[source]

Get event class.

Returns:

Returns {useful granules : bounding box dictionary}

Return type:

dict

get_tile(tile_idx)[source]

It returns the tile addressed by tile_idx.

Parameters:

tile_idx (int) – tile index.

get_tiles_info(tiles_idx=None)[source]

Return info of the tiles requested through tiles_idx from tiles names.

Parameters:
  • tiles_idx (list, optional) – list of tiles for which getting the names.

  • None (If) –

  • None. (all the names of the tiles in the collection are returned. Defaults to) –

Raises:

ValueError – Empty tiles lists

Returns:

tiles name : tiles info

Return type:

dictionary

get_tiles_names(tiles_idx=None)[source]

Return names of the tiles requested through tiles_idx from tiles names.

Parameters:

tiles_idx (list, optional) – list of tiles for which getting the names. If None, all the names of the tiles in the collection are returned. Defaults to None.

Raises:

ValueError – Empty tiles lists

Returns:

tiles’ names.

Return type:

list

is_void()[source]

Returns true if the image is void.

Returns:

True if the image is void.

Return type:

bool

merge_tiles_band(band_name, merge_path)[source]

Merge tiles by performing a mosaic. The merged file is saved at path “”merge_path””

Parameters:
  • band_name (src) – band name

  • merge_path (src) – output path to save the merged file.

set_useful_tiles(useful_tiles_list)[source]

useful_tiles_list (list): Set useful tiles from list.

show_tiles()[source]

Show tiles.

show_tiles_info()[source]

Print tiles info.

class l1.l1_tile.L1C_tile(tile_bands=None, bands_names=None, tile_name=None, tile_coordinates=None, tile_footprint_coordinates=None, bands_file_name_dict=None, crs=None, device=device(type='cpu'))[source]

Initialize an L0 tile.

Parameters:
  • tile_bands (list, optional) – list of torch tensors representing each band in the format [H,W]. Defaults to None.

  • bands_names (list, optional) – list of band names. Defaults to None.

  • tile_name (string, optionl) – tile name. Defaults to None.

  • tile_coordinates (list, optional) – list containing [lan, lon] for every corner point. Defaults to None.

  • tile_footprint_coordinates (list, optional) – list containing [lan, lon] for every point of the tile. Defaults to None.

  • bands_file_name_dict (dict, optional) – dictionary associating the orginal jp2 file to each band. Defaults to None.

  • csr (string, optional) – crs. Defaults to None.

  • device (torch.device, optional) – torch.device. Defaults to torch.device(“cpu”).

as_tensor(requested_bands=None, downsampling=True)[source]

Returns a tensor containing all the bands if all the requested bands have the same resolution.

Parameters:
  • requested_bands (list, optional) – list of requested bands. If None, all the bands are used. Defaults to None.

  • downsampling (boolean, optional) – if True, bands are downsampled to the lowest resolution. Otherwise, they are upsampled to the highest one. Defaults to True.

Raises:

ValueError – The tile is empty

Returns:

tensor containing the requested bands.

Return type:

torch.tensor

create_tile(bands_list, tile_bands, tile_name, tile_coordinates, footprint_coordinates, bands_file_name_dict, crs)[source]

Creates a tile from the list of bands and from a torch tensor.

Parameters:
  • bands_list (list) – list of band names.

  • tile_bands (list) – list of torch.tensors (bands) in format [H,W]

  • tile_name (str) – tile name.

  • tile_coordinates (list) – list of tile’s corners coordinates.

  • footprint_coordinates (list) – list of tile’s footprint’s coordinates.

  • bands_file_name_dict (dict) – bands_file_name_dict.

  • crs (string) – crs

export_to_tif(save_path)[source]

Export to TIF file.

Parameters:
  • save_path (str) – save path.

  • downsampling (bool, optional) – If True, bands are downsampled. Defaults to True.

get_band(band_name)[source]

Returns a specific band as a tensor.

Parameters:

band_name (string) – band name

Returns:

requested band.

Return type:

torch.tensor

get_bands_file_name_dict()[source]

Returns the tile’s band_name jp2 dictionary.

Returns:

tiles bands_file_name_dict.

Return type:

dict

get_bands_names()[source]

Returns band names

Returns:

list of band names.

Return type:

list

get_tile_coordinates(latlon_format=True)[source]

Returns the tile’s coordinates. :param latlon_format: if True, LAT, LON format is used. Defaults to True. :type latlon_format: bool, optional

Returns:

polygon coordinates.

Return type:

list

get_tile_footprint_coordinates()[source]

Returns the tile’s footprint coordinates.

Returns:

polygon coordinates.

Return type:

list

get_tile_info()[source]

Returns name, sensing time, acquisition time, and coners coordinates.

Returns:

name datetime: sensing time. datetime: acquisition time. list: tile’s corners’ coordinates. list: tile’s footprint’s coordinates.

Return type:

string

show_bands(requested_bands=None, downsampling=False, oversampling=False)[source]

It shows the requested bands.

Parameters:
  • requested_bands (list, optional) – list of requested bands to show. If None, all the bands are shown. Defaults to None.

  • downsampling (bool, optional) – if True, bands are downsampled to have the same resolution. Default to False.

  • oversampling (bool, optional) – if True, bands are oversampled to have the same resolution. Downsampling has priority over upampling. Default to False.

show_bands_superimposition(requested_bands=None, downsampling=True)[source]

It shows the superimposition of bands in requested_bands

Parameters:
  • requested_bands (list, optional) – requested bands list. If None, all the bands are used. Defaults to None.

  • downsampling (boolean, optional) – if True, bands are downsampled to have the same resolution. Default to False.

Raises:

ValueError – Impossible to superimpose more than 3 bands