aisdb.weather.data_store module
- class aisdb.weather.data_store.WeatherDataStore(short_names: list, start: datetime, end: datetime, weather_data_path: str)[source]
Bases:
object
- extract_weather(latitude, longitude, time) dict [source]
Extract weather data for a specific latitude, longitude, and timestamp.
- Parameters:
latitude (float) – Latitude of the point.
longitude (float) – Longitude of the point.
time (int) – Timestamp.
- Returns:
A dictionary containing the extracted weather data (e.g., {‘10u’: 5.2, ‘10v’: 3.1}).
- Return type:
dict
Example
>>> store.extract_weather(40.7128, -74.0060, 1674963000) {'10u': 5.2, '10v': 3.1} >>> store.extract_weather(40.7128, -74.0060, 2023-05-01T12:00:00) {'10u': 5.2, '10v': 3.1}
- yield_tracks_with_weather(tracks) dict [source]
Yields tracks with weather. Takes a generator of track dictionaries, retrieves corresponding weather data from an xarray Dataset, and adds the weather data to each track.
- Parameters:
tracks – A generator of dictionaries, where each dictionary represents a track and contains ‘lon’, ‘lat’, and ‘time’ keys with lists or numpy arrays of longitudes, latitudes, and timestamps, respectively.
- Yields:
tracks – A generator of dictionaries, where each dictionary is a track with an added ‘weather_data’ key. The ‘weather_data’ value is a dictionary containing weather variable names.
- aisdb.weather.data_store.dt_to_iso8601(timestamp)[source]
Convert a any timestamp to an ISO 8601 formatted string.
- Parameters:
timestamp (float) – Any timestamp (seconds since epoch).
- Returns:
The timestamp in ISO 8601 format (e.g., ‘2025-01-29T12:34:56.000000000’).
- Return type:
str
Example
>>> dt_to_iso8601(1674963000) '2023-01-29T12:30:00.000000000'
- aisdb.weather.data_store.get_monthly_range(start, end) list [source]
Generate a list of month-year strings between two given timestamps.
- Parameters:
start – The start timestamp.
end – The end timestamp.
- Returns:
A list of strings representing the month-year range (e.g., [‘2023-01’, ‘2023-02’]).
- Return type:
list
Example
>>> get_monthly_range(1672531200, 1675123200) ['2023-01', '2023-02']