Stations¶
- 
class 
historical_obs_sqlalchemy.Station(_id=None, description=None, location=None, elevation=None, starts_at=None, ends_at=None)¶ - 
classmethod 
by_id(station_id)¶ Retrieves the Station with the given id.
Example usage:
from historical_obs_sqlalchemy import Station station = Station.by_id('my-station-id')
Parameters: station_id – the id of the station. 
- 
delete()¶ Deletes the station and all associated observation and measurements from the database.
Example usage:
from historical_obs_api import Station station = Station.by_id('XYZ') station.delete()
- 
description¶ string representing the station’s description.
- 
elevation¶ float representing the station’s elevation in meters.
- 
ends_at¶ arrow to the latest recorded observation time.
- 
id¶ string representing a station’s unique identifier.
- 
latest_observation()¶ Returns the latest observation for a station.
Usage:
from historical_obs_sqlalchemy import Station station = Station.by_id('my-station-of-interest') latest_ob = station.latest_observation()
- 
location¶ geojson.Point representing the station’s location.
- 
classmethod 
nearest(location, radius=50.0, limit=None, span=None)¶ Retrieves a list of stations along with their distance from the point of interest within a specified radius in kilometers. Results in a list of tuples sorted from nearest to farthest as [(Station, distance),...].
To find all stations within 25 kilometers of Oklahoma City:
from historical_obs_sqlalchemy import Station okc_stations = Station.nearest(35.467, -97.516, radius=25) nearest_station = okc_stations[0]
Parameters: - location – geojson.Point representing your location.
 - radius – the radius in kilometers surrounding your point of interest.
 - limit – the maximum number of stations to return.
 - span – filters stations with observations within the given span. Should match result of Arrow.span method.
 
- 
observations(start=None, end=None, limit=25)¶ Retrieves the latest observations for a Station. Results in a list of observations sorted from latest to most recent.
To get the latest obs for for a Station:
from historical_obs_sqlalchemy import Station station = Station.by_id('my-station-of-interest') observations = station.observations()
If you’re interested in all obs for a period of time:
from historical_obs_sqlalchemy import Station station = Station.by_id('my-station-of-interest') observations = station.observations(start='2015-05-01', end='2015-05-07', limit=None)
Parameters: - start – the earliest time for your observations. Can be anything parseable by the arrow library.
 - end – the latest time for your observations. Can be anything parseable by the arrow library.
 - limit – the number of observations to return.
 
- 
record_observation(observation)¶ Records an observation for a station.
Here’s an example of recording an observation with precipitation and temperature measurements:
import arrow from historical_obs_sqlalchemy import Station, Observation station = Station.by_id('my-station-of-interest') observation = Observation('2015-05-01T00:00:00Z') observation.measure('precipitation', 12.5) observation.measure('temperature', 37.5) station.add_observation(observation)
- 
save()¶ Immediately saves or updates a station in the database.
Example usage:
from historical_obs_api import Station station = Station(id='XYZ', description='Station XYZ', latitude=35.0, longitude=-97.0, elevation=366) stations.save() station.description = 'new description' station.save()
- 
classmethod 
save_batch(stations)¶ Saves multiple stations.
Example usage:
from historical_obs_api import Station station_foo = Station(id='Foo', description='Station Foo', latitude=36.0, longitude=-91.0) station_bar = Station(id='Bar', description='Station Bar', latitude=37.0, longitude=-92.0) Station.save_batch([station_foo, station_bar])
Parameters: stations – a list of Station objects. 
- 
starts_at¶ arrow to the earliest recorded observation time.
- 
classmethod