glider_ingest.utils
Module containing utility functions for the package.
Module Contents
- glider_ingest.utils.find_nth(haystack: str, needle: str, n: int) int[source]
Find the nth occurrence of a substring in a string.
- Parameters:
haystack (str) – The string to search in.
needle (str) – The substring to find.
n (int) – The occurrence number of the substring to find.
- Returns:
The index of the nth occurrence of the substring, or -1 if not found.
- Return type:
int
- glider_ingest.utils.get_polygon_bounds(longitude: numpy.ndarray, latitude: numpy.ndarray) list[source]
Generate polygon coordinates for the dataset’s global attributes.
- glider_ingest.utils.get_polygon_coords(longitude: numpy.ndarray, latitude: numpy.ndarray, lat_max: float, lat_min: float, lon_max: float, lon_min: float) str[source]
Generate polygon coordinates for the dataset’s global attributes.
- Parameters:
ds_mission (xarray.Dataset) – The mission dataset containing latitude and longitude values.
- Returns:
A string representation of the polygon in Well-Known Text (WKT) format.
- Return type:
str
Notes
The polygon is constructed based on the northmost, eastmost, southmost, and westmost points where latitude is below 29.5.
- glider_ingest.utils.get_wmo_id(glider_id: str | int) str[source]
Extract the WMO ID from a glider ID.
- glider_ingest.utils.invert_dict(dict: invert_dict.dict) invert_dict.dict[source]
Invert the keys and values of a dictionary.
- Parameters:
dict (dict) – The dictionary to invert.
- Returns:
A new dictionary with keys and values swapped.
- Return type:
dict
- glider_ingest.utils.print_time(message: str) None[source]
Print a message with the current time appended.
- Parameters:
message (str) – The message to print.
Notes
The current time is formatted as ‘HH:MM:SS’.