API reference¶
- class datapoint.Manager.Manager(api_key='')¶
Manager for DataHub connection.
Wraps calls to DataHub API, and provides Forecast objects. Basic Usage:
>>> import datapoint >>> m = datapoint.Manager.Manager(api_key = "blah") >>> f = m.get_forecast( latitude=50, longitude=0, frequency="hourly", convert_weather_code=True ) >>> f.now() { 'time': datetime.datetime(2024, 2, 19, 13, 0, tzinfo=datetime.timezone.utc), 'screenTemperature': { 'value': 10.09, 'description': 'Screen Air Temperature', 'unit_name': 'degrees Celsius', 'unit_symbol': 'Cel' }, 'screenDewPointTemperature': { 'value': 8.08, 'description': 'Screen Dew Point Temperature', 'unit_name': 'degrees Celsius', 'unit_symbol': 'Cel' }, 'feelsLikeTemperature': { 'value': 6.85, 'description': 'Feels Like Temperature', 'unit_name': 'degrees Celsius', 'unit_symbol': 'Cel' }, 'windSpeed10m': { 'value': 7.57, 'description': '10m Wind Speed', 'unit_name': 'metres per second', 'unit_symbol': 'm/s' }, 'windDirectionFrom10m': { 'value': 263, 'description': '10m Wind From Direction', 'unit_name': 'degrees', 'unit_symbol': 'deg' }, 'windGustSpeed10m': { 'value': 12.31, 'description': '10m Wind Gust Speed', 'unit_name': 'metres per second', 'unit_symbol': 'm/s' }, 'visibility': { 'value': 21201, 'description': 'Visibility', 'unit_name': 'metres', 'unit_symbol': 'm' }, 'screenRelativeHumidity': { 'value': 87.81, 'description': 'Screen Relative Humidity', 'unit_name': 'percentage', 'unit_symbol': '%' }, 'mslp': { 'value': 103080, 'description': 'Mean Sea Level Pressure', 'unit_name': 'pascals', 'unit_symbol': 'Pa' }, 'uvIndex': { 'value': 1, 'description': 'UV Index', 'unit_name': 'dimensionless', 'unit_symbol': '1' }, 'significantWeatherCode': { 'value': 'Cloudy', 'description': 'Significant Weather Code', 'unit_name': 'dimensionless', 'unit_symbol': '1' }, 'precipitationRate': { 'value': 0.0, 'description': 'Precipitation Rate', 'unit_name': 'millimetres per hour', 'unit_symbol': 'mm/h' }, 'probOfPrecipitation': { 'value': 21, 'description': 'Probability of Precipitation', 'unit_name': 'percentage', 'unit_symbol': '%' } }
- get_forecast(latitude, longitude, frequency='daily', convert_weather_code=True)¶
Get a forecast for the provided site
- Parameters:
latitude (float) – Latitude of forecast location
longitude (float) – Longitude of forecast location
frequency (string) – Forecast frequency. One of ‘hourly’, ‘three-hourly, ‘daily’
convert_weather_code (bool) – Convert numeric weather codes to string description
- Returns:
- class:
Forecast <Forecast> object
- Return type:
datapoint.Forecast
- class datapoint.Forecast.Forecast(frequency, api_data, convert_weather_code)¶
Forecast data returned from DataHub
Provides access to forecasts as far ahead as provided by DataHub. See the DataHub documentation for the latest limits on the forecast range. The values of data from DataHub are combined with the unit information and description and returned as a dict.
Basic Usage:
>>> import datapoint >>> m = datapoint.Manager.Manager(api_key = "blah") >>> f = m.get_forecast( latitude=50, longitude=0, frequency="hourly", convert_weather_code=True, ) >>> f.now() { 'time': datetime.datetime(2024, 2, 19, 13, 0, tzinfo=datetime.timezone.utc), 'screenTemperature': { 'value': 10.09, 'description': 'Screen Air Temperature', 'unit_name': 'degrees Celsius', 'unit_symbol': 'Cel' }, 'screenDewPointTemperature': { 'value': 8.08, 'description': 'Screen Dew Point Temperature', 'unit_name': 'degrees Celsius', 'unit_symbol': 'Cel' }, 'feelsLikeTemperature': { 'value': 6.85, 'description': 'Feels Like Temperature', 'unit_name': 'degrees Celsius', 'unit_symbol': 'Cel' }, 'windSpeed10m': { 'value': 7.57, 'description': '10m Wind Speed', 'unit_name': 'metres per second', 'unit_symbol': 'm/s' }, 'windDirectionFrom10m': { 'value': 263, 'description': '10m Wind From Direction', 'unit_name': 'degrees', 'unit_symbol': 'deg' }, 'windGustSpeed10m': { 'value': 12.31, 'description': '10m Wind Gust Speed', 'unit_name': 'metres per second', 'unit_symbol': 'm/s' }, 'visibility': { 'value': 21201, 'description': 'Visibility', 'unit_name': 'metres', 'unit_symbol': 'm' }, 'screenRelativeHumidity': { 'value': 87.81, 'description': 'Screen Relative Humidity', 'unit_name': 'percentage', 'unit_symbol': '%' }, 'mslp': { 'value': 103080, 'description': 'Mean Sea Level Pressure', 'unit_name': 'pascals', 'unit_symbol': 'Pa' }, 'uvIndex': { 'value': 1, 'description': 'UV Index', 'unit_name': 'dimensionless', 'unit_symbol': '1' }, 'significantWeatherCode': { 'value': 'Cloudy', 'description': 'Significant Weather Code', 'unit_name': 'dimensionless', 'unit_symbol': '1' }, 'precipitationRate': { 'value': 0.0, 'description': 'Precipitation Rate', 'unit_name': 'millimetres per hour', 'unit_symbol': 'mm/h' }, 'probOfPrecipitation': { 'value': 21, 'description': 'Probability of Precipitation', 'unit_name': 'percentage', 'unit_symbol': '%' } }
- at_datetime(target)¶
Return the timestep closest to the target datetime
- Parameters:
target (datetime) – Time to get the forecast for
- Returns:
Individual forecast timestep
- Return type:
dict
- data_date¶
The date the provided forecast was generated.
- distance_from_requested_location¶
The distance of the location of the provided forecast from the requested location
- elevation¶
The elevation of the location of the provided forecast
- forecast_latitude¶
The latitude of the provided forecast.
- forecast_longitude¶
The longitude of the provided forecast.
- future(days=0, hours=0, minutes=0)¶
Return the closest timestep to a date in a given amount of time
Either provide components of the time to the forecast or the total hours or minutes
Providing components:
>>> import datapoint >>> m = datapoint.Manager(api_key = "blah") >>> f = m.get_forecast(latitude=50, longitude=0, frequency="hourly") >>> f.future(days=1, hours=2)
Providing total hours:
>>> import datapoint >>> m = datapoint.Manager(api_key = "blah") >>> f = m.get_forecast(latitude=50, longitude=0, frequency="hourly") >>> f.future(hours=26)
- Parameters:
days (int) – How many days ahead
hours (int) – How many hours ahead
minutes (int) – How many minutes ahead
- Returns:
Individual forecast timestep
- Return type:
dict
- name¶
The name of the location of the provided forecast
- now()¶
Return the closest timestep to the current time
- Returns:
Individual forecast timestep
- Return type:
dict