Not Logged In

MetOffer 1.3

metoffer is a simple wrapper for the API provided by the British
Met Office known as DataPoint. It
can be used to retrieve weather observations and forecasts. At its
heart is the MetOffer class which has methods to retrieve data
available through the API and make them available as Python objects.
Also included are a couple of functions and classes useful for
interpretting the data.

Example

Get forecast for Met Office site closest to supplied latitude and
longitude, the forecast to be given in three-hourly intervals:

It’s worth noting here that, if you expect many requests for forecast data
to be made, it is probably better to use the functions called by this
convenience function so that data that does not change often (e.g. data
about Met Office sites) may be cached.

The Site Class

Describes object to hold site metadata. Also describes method
(distance_to_coords) to return a Site instance’s ‘distance’ from any given
lat & lon coordinates. This ‘distance’ is a value which is used to guide
MetOffer.nearest_loc_forecast and MetOffer.nearest_loc_obs. It simply
calculates the difference between the two sets of coordinates and arrives at a
value through Pythagorean theorem.

The Weather Class

A hold-all for returned weather data, including associated metadata.

Useful Functions

parse_sitelist. Return list of Site instances from retrieved sitelist data.

get_nearest_site. Return a list of strings (site IDs) which can be used
as ‘request’ in calls to loc_forecast and loc_observations.

parse_val. Parse returned dict of MetOffer location-specific data into a
Weather instance. Data must be of multiple time steps. There are a couple of
points to note:

All dict keys have a tuple, even where there is no obvious need, such as
with ‘timestamp’ and ‘Weather Type’. ‘timestamp’ is a 2-tuple, all else
is a 3-tuple. This is a feature.

When the Met Office does not have a recorded observation against a category,
metoffer will return None.

For parsed DAILY forecasts, the hours and minutes of the ‘timestamp’
datetime.datetime object are superfluous. In fact, it would be misleading
to follow them. Rather, this time there is a sensible entry in the second
part of the tuple. This alternates between ‘Day’ and ‘Night’ with each
successive dict. The categories are often specific to the time of day.
This is how the API provides it. Take note as it may catch you out.