Library Modules

intertidal_locator.crop_cell(cell: Image, cell_lon_min: int, cell_lat_max: int, lon_min: float, lon_max: float, lat_min: float, lat_max: float) ndarray[source]

Crops the cell image to the specified area.

Parameters:
  • cell ((PIL.Image.Image)) – The cell image to be cropped.

  • cell_lon_min ((int)) – Minimum longitude of the cell.

  • cell_lat_max ((int)) – Maximum latitude of the cell.

  • lon_min ((float)) – Minimum longitude of the area.

  • lat_min ((float)) – Minimum latitude of the area.

  • lon_max ((float)) – Maximum longitude of the area.

  • lat_max ((float)) – Maximum latitude of the area.

Returns:

The data read from the specified area of the Image, as a numpy array.

Return type:

(numpy.ndarray) cropped_cell_array

intertidal_locator.download_data(datadir: str, periods: list[str] = None, makedirs=True) None[source]

Downloads and extracts the intertidal data from Global Intertidal Change website (www.intertidal.app).

Downloading all periods is about 0.9 Go, however, after extraction it goes up, about 44.3 Go (very sparse data). You need 5 Go of free space per period.

This function iterates through a predefined list of time periods, constructs the corresponding download URLs, downloads the zip files for each period, extracts the contents into the specified destination folder, and deletes the zip files after extraction.

Parameters:
  • datadir ((str)) – The directory where downloaded files will be extracted.

  • periods=None ((list[str])) – List of periods to download. If None, download all available periods.

  • makedirs=True ((bool)) – If True and folderpath’s directory does not exist, create it.

Return type:

None

Raises:
  • MemoryError: – Free space on your disk is too small for the periods you want to download.

  • ConnectionError: – Fail to download a period zip file.

intertidal_locator.find_area_cells(lon_min: float, lon_max: float, lat_min: float, lat_max: float) list[tuple[int, int]][source]

Finds all cells that intersect with a given rectangle area defined by its longitude and latitude boundaries.

The longitude must be between [-180,180] while the latitude must be between [-60,60] (the whole earth latitude is not covered, for more information refer to http://dx.doi.org/10.1038/s41586-018-0805-8)

Parameters:
  • lon_min ((float)) – Minimum longitude of the area.

  • lat_min ((float)) – Minimum latitude of the area.

  • lon_max ((float)) – Maximum longitude of the area.

  • lat_max ((float)) – Maximum latitude of the area.

Returns:

A list of tuples, where each tuple represents the (cell_lon_min, cell_lat_max) of a cell that intersects the area.

Return type:

(list[tuple[int,int]]) cells

intertidal_locator.find_point_cell(lon: float, lat: float) tuple[int, int][source]

Finds which cell contains a single point (lon, lat).

The longitude must be between [-180,180] while the latitude must be between [-60,60] (the whole earth latitude is not covered, for more information refer to http://dx.doi.org/10.1038/s41586-018-0805-8)

Parameters:
  • lon ((float)) – Longitude of the point.

  • lat ((float)) – Latitude of the point.

Returns:

Tuple that represents the (cell_lon_min, cell_lat_max) coordinate.

Return type:

(tuple[int,int]) cell_coord

Raises:

ValueError: – If the area is outside the valid latitude range or if the longitude is not in valid format.

intertidal_locator.get_intertidal_area(lon_min: float, lon_max: float, lat_min: float, lat_max: float, datadir: str, period: str = '2014-2016') ndarray[source]

Retrieves the intertidal area data for the specified area.

The longitude must be between [-180,180] while the latitude must be between [-60,60] (the whole earth latitude is not covered, for more information refer to http://dx.doi.org/10.1038/s41586-018-0805-8)

Parameters:
  • lon_min ((float)) – Minimum longitude of the area.

  • lat_min ((float)) – Minimum latitude of the area.

  • lon_max ((float)) – Maximum longitude of the area.

  • lat_max ((float)) – Maximum latitude of the area.

  • datadir ((str)) – The directory path where the data files are stored.

  • period='2014-2016' ((str)) – The data period to retrieve.

Returns:

The array representing the intertidal area for the specified area.

Return type:

(numpy.ndarray) intertidal_area

intertidal_locator.merge_crops(cropped_cell_arrays: list[ndarray], cell_coords: list[tuple[int, int]]) ndarray[source]

Merges multiple cropped cell arrays into a single array based on their spatial coordinates.

Parameters:
  • cropped_cell_arrays ((list[numpy.ndarray])) – A list of cropped cell arrays to be merged.

  • (list[tuple[int – A list of tuples containing the cell coordinate (cell_lon_min, cell_lat_max) corresponding to each cropped cell array.

  • cell_coords (int]])) – A list of tuples containing the cell coordinate (cell_lon_min, cell_lat_max) corresponding to each cropped cell array.

Returns:

The merged array combining the cropped cell arrays.

Return type:

(numpy.ndarray) merged_cropped_cell_array

Raises:
  • ValueError: – If the number of cell coordinates does not match the number of cropped cell arrays or if the list is empty.

  • NotImplementedError: – If the number of cropped cell arrays is not 1, 2, or 4. Not 3 because the area is a rectangle. Not more because it would require too much RAM for most use cases.

intertidal_locator.read_cell(cell_lon_min: int, cell_lat_max: int, datadir: str, period: str = '2014-2016') Image[source]

Reads and returns a cell image file based on cell coordinate.

Parameters:
  • cell_lon_min ((int)) – Minimum longitude of the cell.

  • cell_lat_max ((int)) – Maximum latitude of the cell.

  • datadir ((str)) – Path to directory containing data.

  • period='2014-2016' ((str)) – The data period to read.

Returns:

The image object read from the specified file.

Return type:

(PIL.Image.Image) cell