Helios-SDK-Python¶
Use the Helios APIs in Python.
Helios® weather analytics from Harris Corporation provide fast and accurate local ground weather intelligence to assist organizations with real-time decision making. Helios analyzes content from thousands of existing public and private video cameras, providing immediate confirmation of ground weather condition changes at a detailed local level. For more details, refer to helios.earth.
The Helios SDK brings the core API functionality along with extensions to Python. Many of the capabilities are thread-enabled allowing for batch jobs. The overall goal is to provide the tools necessary to quickly begin using the Helios product.
For further developer information, refer to the Helios developer documentation.
Installation¶
Install from PyPI (recommended)¶
pip install helios-sdk
Install from source (bleeding edge)¶
Clone the GitHub repository:
git clone https://github.com/harris-helios/helios-sdk-python.git
Then cd
to the helios-sdk-python directory and run the
install command:
cd helios-sdk-python
pip install .
Authentication¶
All Helios API methods require valid authentication and are protected using the OAuth 2.0 “client credentials” flow. The general process for authenticating requests involves first requesting an access token using the developer API key pair, and then requesting protected data using the access token. Request access if you would like to obtain an API key.
Using Environment Variables¶
Add “helios_client_id”: “your ID key”
Add “helios_client_secret”: “your secret key”
Add “helios_api_url”: “API URL associated with your account credentials”
- “helios_api_url” is optional.
Using an Authentication File¶
Create a “.helios” directory in your home directory.
Create a “credentials.json” file in your “.helios” directory.
Copy and paste the following into the “credentials.json” file and fill in your authentication values.
- “helios_api_url” is optional. If you do not need a custom API URL,
then leave this out of your json file or set to null.
{
"helios_client_id" : "your ID key" ,
"helios_client_secret" : "your secret key",
"helios_api_url" : null
}
For more information refer to the authentication documentation
Using the Core APIs¶
Creating Instances¶
Instances of the core APIs are easy to create.
import helios
alerts = helios.Alerts()
cameras = helios.Cameras()
observations = helios.Observations()
collections = helios.Collections()
Each instance will internally initialize a Helios
Session
and call
start_session
.
Examples¶
Find alerts¶
import helios
alerts = helios.Alerts()
# Retrieve ressults for New York.
ny_alert_results = alerts.index(state='New York')
# Gather the camera IDs from the results.
ny_alert_ids = ny_alert_results.id
ny_alert_results
is an instance ofIndexResults
.
Find camera times and download images¶
import helios
import numpy as np
cameras = helios.Cameras()
# Find cameras in Maryland.
md_cam_results = cameras.index(state='Maryland')
cam_id = md_cam_results.id[0]
# Find image times for the given camera id.
image_times = cameras.images(cam_id, '2018-01-01')
# Download the images.
show_image_results = cameras.show_image(cam_id,
image_times,
out_dir='/temp/data',
return_image_data=True)
# Get a list of image data. (return_image_dat was True)
img_data = show_image_results.image_data
md_cam_results
is an instance ofIndexResults
.show_image_results
is an instance ofShowImageResults
.
Find observations and work with collections¶
import helios
import requests
from helios.utilities import parsing_utils
observations = helios.Observations()
collections = helios.Collections()
# Find Observations
index_results = observations.index(state='georgia',
sensors='sensors[visibility]=0',
time_min='2018-02-10T18:00Z',
time_max='2018-02-10T18:15Z')
# Get id for each observation feature.
ids = [x.id for x in index_results]
# Convenience properties also exist for combining attributes from all features.
ids_1 = index_results.id
# Create new collection.
new_id = collections.create('Temp Collection', 'example collection', ['test', 'temp'])
# Add Observations to collection.
payload = [{'observation_id': x} for x in ids]
add_result = collections.add_image(new_id, payload)
# Check for http failures.
if len(add_result.failed) > 0:
print('Failures occurred!')
# Simple data analysis - find all unique cameras for the added observation images.
ims = collections.images(new_id)
cams = set([parsing_utils.parse_camera(x) for x in ims])
index_results
is an instance ofIndexResults
.add_result
is an instance ofAddImageResults
.
Session Instances¶
A Helios Session
depends
on properly established authentication procedures. See
Authentication for more information. It also stores your
authentication information and will fetch an API token. This
token is required for any API queries.
Once a session has been created, the token will be written to a .helios_token file in your home directory. This token will be reused until it becomes invalid.
Creating a Session¶
If authentication is stored on your machine starting a session is
simple. Create a Session
instance without any inputs. The authentication information
stored on your machine will automatically be applied.
import helios
sess = helios.Session()
This will automatically make a call to the
start_session
method to fetch the token.
If successful, the sess
instance will now have all the
authentication information needed to being using the core APIs.
Token Expiration¶
Restarting Python if your token expires while the SDK is in use is not
necessary. Call start_session
to perform the token verification process. This will acquire a new token if it
has expired.
After the a token has been re-acquired you will need to create new core API instances using the session.
Reusing a Session¶
Creating a Session
instance allows
you to use a single instance across all Core APIs. This avoids multiple token
verifications with the initialization of every Core API instance. Refer to
helios_session_instances for more information.
import helios sess = helios.Session() sess.start_session() alerts = helios.Alerts(session=sess) cameras = helios.Cameras(session=sess)
In the above code sess
is started once and used across
Alerts
and
Cameras
.
Using a Custom env
¶
When creating a Session
instance
an optional input variable, env
, can be used for dynamic
credential usage.
This optional input must consist of a dictionary containing all necessary information for authentication.
custom_env = {'HELIOS_KEY_ID': 'mykeyid', 'HELIOS_KEY_SECRET': 'mykeysecret'}
sess = helios.Session(env=custom_env)
sess.start_session()
License¶
The HeliosSDK is released under terms of MIT license.
Core APIs¶
Alerts¶
Helios Alerts API.
Methods are meant to represent the core functionality in the developer documentation. Some may have additional functionality for convenience.
-
class
helios.alerts_api.
Alerts
(session=None)[source]¶ Helios alerts provide real-time severe weather alerts.
National Weather Service:
- Severe weather alerts for the United States are provided by the National Weather Service. These alerts cover events such as Flood Warnings, Severe Thunderstorm Warnings, and Special Weather Statements.
Helios:
- Alerts generated by Helios are based on the sensor measurements from the Observations API. These alerts represent regional areas with a high detection confidence and currently include: Road Wetness Watch, Poor Visibility Watch, and Heavy Precip Watch.
-
index
(**kwargs)[source]¶ Get alerts matching the provided spatial, text, or metadata filters.
The maximum skip value is 4000. If this is reached, truncated results will be returned. You will need to refine your query to avoid this.
Parameters: **kwargs – Any keyword arguments found in the alerts_index_documentation. Returns: IndexResults
-
show
(alert_ids)[source]¶ Get attributes for alerts.
Parameters: alert_ids (str or sequence of strs) – Helios alert ID(s). Returns: ShowResults
-
class
helios.alerts_api.
AlertsFeature
(feature)[source]¶ Individual Alert GeoJSON feature.
-
area_description
¶ str – ‘areaDesc’ value for the feature.
-
bbox
¶ sequence of floats – ‘bbox’ value for the feature.
-
category
¶ str – ‘category’ value for the feature.
-
certainty
¶ str – ‘certainty’ value for the feature.
-
country
¶ str – ‘country’ value for the feature.
-
description
¶ str – ‘description’ value for the feature.
-
effective
¶ str – ‘effective’ value for the feature.
-
event
¶ str – ‘event’ value for the feature.
-
expires
¶ str – ‘expires’ value for the feature.
-
headline
¶ str – ‘headline’ value for the feature.
-
id
¶ str – ‘id’ value for the feature.
-
json
¶ dict – Raw ‘json’ for the feature.
-
origin
¶ str – ‘origin’ value for the feature.
-
severity
¶ str – ‘severity’ value for the feature.
-
states
¶ sequence of strs – ‘states’ value for the feature.
-
status
¶ str – ‘status’ value for the feature.
-
urgency
¶ str – ‘urgency’ value for the feature.
-
-
class
helios.alerts_api.
IndexResults
(content, records)[source]¶ Index results for the Alerts API.
IndexResults is an iterable for GeoJSON features. This allows the user to iterate and select based on Feature attributes in each element.
All features within IndexResults are instances of
AlertsFeature
-
area_description
¶ ‘areaDesc’ values for every feature.
-
bbox
¶ ‘bbox’ values for every feature.
-
category
¶ ‘category’ values for every feature.
-
certainty
¶ ‘certainty’ values for every feature.
-
country
¶ ‘country’ values for every feature.
-
description
¶ ‘description’ values for every feature.
-
effective
¶ ‘effective’ values for every feature.
-
event
¶ ‘event’ values for every feature.
-
expires
¶ ‘expires’ values for every feature.
-
failed
¶ Records for queries that failed.
-
headline
¶ ‘headline’ values for every feature.
-
id
¶ ‘id’ values for every feature.
-
json
¶ Raw ‘json’ for every feature.
-
origin
¶ ‘origin’ values for every feature.
-
severity
¶ ‘severity’ values for every feature.
-
states
¶ ‘states’ values for every feature.
-
status
¶ ‘status’ values for every feature.
-
succeeded
¶ Records for queries that succeeded.
-
urgency
¶ ‘urgency’ values for every feature.
-
-
class
helios.alerts_api.
ShowResults
(content, records)[source]¶ Show results for the Alerts API.
ShowResults is an iterable for GeoJSON features. This allows the user to iterate and select based on Feature attributes in each element.
All features within ShowResults are instances of
AlertsFeature
-
area_description
¶ ‘areaDesc’ values for every feature.
-
bbox
¶ ‘bbox’ values for every feature.
-
category
¶ ‘category’ values for every feature.
-
certainty
¶ ‘certainty’ values for every feature.
-
country
¶ ‘country’ values for every feature.
-
description
¶ ‘description’ values for every feature.
-
effective
¶ ‘effective’ values for every feature.
-
event
¶ ‘event’ values for every feature.
-
expires
¶ ‘expires’ values for every feature.
-
failed
¶ Records for queries that failed.
-
headline
¶ ‘headline’ values for every feature.
-
id
¶ ‘id’ values for every feature.
-
json
¶ Raw ‘json’ for every feature.
-
origin
¶ ‘origin’ values for every feature.
-
severity
¶ ‘severity’ values for every feature.
-
states
¶ ‘states’ values for every feature.
-
status
¶ ‘status’ values for every feature.
-
succeeded
¶ Records for queries that succeeded.
-
urgency
¶ ‘urgency’ values for every feature.
-
Cameras¶
Helios Cameras API.
Methods are meant to represent the core functionality in the developer documentation. Some may have additional functionality for convenience.
-
class
helios.cameras_api.
Cameras
(session=None)[source]¶ The Cameras API provides access to all cameras in the Helios Network.
-
images
(camera_id, start_time, end_time=None, limit=500)[source]¶ Get the image times available for a given camera in the media cache.
The media cache contains all recent images archived by Helios, either for internal analytics or for end user recording purposes.
Parameters: - camera_id (str) – Camera ID.
- start_time (str) – Starting image timestamp, specified in UTC as an ISO 8601 string (e.g. 2014-08-01 or 2014-08-01T12:34:56.000Z).
- end_time (str, optional) – Ending image timestamp, specified in UTC as an ISO 8601 string (e.g. 2014-08-01 or 2014-08-01T12:34:56.000Z).
- limit (int, optional) – Number of images to be returned, up to a max of 500. Defaults to 500.
Returns: Image times.
Return type: sequence of strs
-
index
(**kwargs)[source]¶ Get cameras matching the provided spatial, text, or metadata filters.
The maximum skip value is 4000. If this is reached, truncated results will be returned. You will need to refine your query to avoid this.
Parameters: **kwargs – Any keyword arguments found in the cameras_index_documentation. Returns: IndexResults
-
show
(camera_ids)[source]¶ Get attributes for cameras.
Parameters: camera_ids (str or sequence of strs) – Helios camera ID(s). Returns: ShowResults
-
show_image
(camera_id, times, out_dir=None, return_image_data=False)[source]¶ Get images from the media cache.
The media cache contains all recent images archived by Helios, either for internal analytics or for end user recording purposes.
Parameters: - camera_id (str) – Camera ID.
- times (str or sequence of strs) – Image times, specified in UTC as an ISO 8601 string (e.g. 2017-08-01 or 2017-08-01T12:34:56.000Z). The image with the closest matching timestamp will be returned.
- out_dir (optional, str) – Directory to write images to. Defaults to None.
- return_image_data (optional, bool) – If True images will be returned as numpy.ndarrays. Defaults to False.
Returns:
-
-
class
helios.cameras_api.
CamerasFeature
(feature)[source]¶ Individual Camera GeoJSON feature.
-
city
¶ str – ‘city’ value for the feature.
-
country
¶ str – ‘country’ value for the feature.
-
description
¶ str – ‘description’ value for the feature.
-
direction
¶ str – ‘direction’ value for the feature.
-
id
¶ str – ‘id’ value for the feature.
-
json
¶ dict – Raw ‘json’ for the feature.
-
region
¶ str – ‘region’ value for the feature.
-
state
¶ str – ‘state’ value for the feature.
-
video
¶ bool – ‘video’ value for the feature.
-
-
class
helios.cameras_api.
IndexResults
(content, records)[source]¶ Index results for the Cameras API.
IndexResults is an iterable for GeoJSON features. This allows the user to iterate and select based on Feature attributes for each element.
All features within IndexResults are instances of
CamerasFeature
-
city
¶ ‘city’ values for every feature.
-
country
¶ ‘country’ values for every feature.
-
description
¶ ‘description’ values for every feature.
-
direction
¶ ‘direction’ values for every feature.
-
failed
¶ Records for queries that failed.
-
id
¶ ‘id’ values for every feature.
-
json
¶ Raw ‘json’ for every feature.
-
region
¶ ‘region’ values for every feature.
-
state
¶ ‘state’ values for every feature.
-
succeeded
¶ Records for queries that succeeded.
-
video
¶ ‘video’ values for every feature.
-
-
class
helios.cameras_api.
ShowImageResults
(content, records)[source]¶ Show_image results for the Cameras API.
ShowImageResults is an iterable for the fetched image content. Each element of the iterable will be an ndarray if return_image_data was True.
-
failed
¶ Records for queries that failed.
-
image_data
¶ Image data if return_image_data was True.
-
name
¶ Names of all images.
-
output_file
¶ Full paths to all written images.
-
succeeded
¶ Records for queries that succeeded.
-
-
class
helios.cameras_api.
ShowResults
(content, records)[source]¶ Show results for the Cameras API.
ShowResults is an iterable for GeoJSON features. This allows the user to iterate and select based on Feature attributes for each element.
All features within ShowResults are instances of
CamerasFeature
-
city
¶ ‘city’ values for every feature.
-
country
¶ ‘country’ values for every feature.
-
description
¶ ‘description’ values for every feature.
-
direction
¶ ‘direction’ values for every feature.
-
failed
¶ Records for queries that failed.
-
id
¶ ‘id’ values for every feature.
-
json
¶ Raw ‘json’ for every feature.
-
region
¶ ‘region’ values for every feature.
-
state
¶ ‘state’ values for every feature.
-
succeeded
¶ Records for queries that succeeded.
-
video
¶ ‘video’ values for every feature.
-
Collections¶
Helios Collections API.
Methods are meant to represent the core functionality in the developer documentation. Some may have additional functionality for convenience.
-
class
helios.collections_api.
AddImageResults
(content, records)[source]¶ Add_image results for Collections API.
-
failed
¶ Records for queries that failed.
-
succeeded
¶ Records for queries that succeeded.
-
-
class
helios.collections_api.
Collections
(session=None)[source]¶ The Collections API allows users to group and organize individual image frames.
Collections are intended to be short-lived resources and will be accessible for 90 days from the time the collection was created. After that time period has expired, the collection and all associated imagery will be removed from the system.
-
add_image
(collection_id, assets)[source]¶ Add images to a collection from Helios assets.
assets dictionary templates:
# Asset examples that can be included in the `assets` input list. {'camera_id': ''} {'camera_id': '', 'time': ''} {'observation_id': ''} {'collection_is': '', 'image': ''}
Usage example:
import helios collections = helios.Collections() camera_id = '...' times = [...] # List of image times. destination_id = '...' data = [{'camera_id': camera_id, 'time': x} for x in times] collections.add_image(destination_id, data)
Parameters: - collection_id (str) – Collection ID.
- assets (dict or sequence of dicts) – Data containing any of these payloads (camera_id), (camera_id, time), (observation_id), (collection_id, image). E.g. data = [{‘camera_id’: ‘cam_01’, time: ‘2017-01-01T00:00:000Z’}]
Returns:
-
copy
(collection_id, new_name)[source]¶ Copy a collection and its contents to a new collection.
Parameters: - collection_id (str) – Collection ID.
- new_name (str) – New collection name.
Returns: New collection ID.
Return type: str
-
create
(name, description, tags=None)[source]¶ Create a new collection.
Parameters: - name (str) – Display name for the collection.
- description (str) – Description for the collection.
- tags (str or sequence of strs, optional) – Optional comma-delimited keyword tags to be added to the collection.
Returns: New collection ID.
Return type: str
-
delete
(collection_id)[source]¶ Delete an empty collection.
If the collection is not empty, delete will fail. Use the
empty
method to remove all imagery before calling this method.Parameters: collection_id (str) – Collection to delete. Returns: JSON response Return type: dict
-
empty
(collection_id)[source]¶ Bulk remove (up to 1000) images from a collection.
Parameters: collection_id (str) – Collection to empty. Returns: JSON response. Return type: dict
-
images
(collection_id, camera=None, old_flag=False)[source]¶ Get all image names in a given collection.
When using the optional camera input parameter only images from that camera will be returned.
Parameters: - collection_id (str) – Collection ID.
- camera (str, optional) – Camera ID to be found.
- old_flag (bool, optional) – Flag for finding old format image names. When True images that do not contain md5 hashes at the start of their name will be found.
Returns: Image names.
Return type: sequence of strs
-
index
(**kwargs)[source]¶ Get collections matching the provided spatial, text, or metadata filters.
The maximum skip value is 4000. If this is reached, truncated results will be returned. You will need to refine your query to avoid this.
Parameters: **kwargs – Any keyword arguments found in the collections_index_documentation. Returns: IndexResults
-
remove_image
(collection_id, names)[source]¶ Remove images from a collection.
Parameters: - collection_id (str) – Collection ID to remove images from.
- names (str or sequence of strs) – List of image names to be removed.
Returns:
-
show
(collection_id, limit=200, marker=None)[source]¶ Get the attributes and image list for collections.
The results will also contain image names available in the collection. These are limited to a maximum of 200 per query.
Parameters: - collection_id (str) – Collection ID.
- limit (int, optional) – Number of image names to be returned with each response. Defaults to 200. Max value of 200 is allowed.
- marker (str, optional) – Pagination marker. If the marker is an exact match to an existing image, the next image after the marker will be the first image returned. Therefore, for normal linked list pagination, specify the last image name from the current response as the marker value in the next request. Partial file names may be specified, in which case the first matching result will be the first image returned.
Returns:
-
show_image
(collection_id, image_names, out_dir=None, return_image_data=False)[source]¶ Get images from a collection.
Parameters: - collection_id (str) – Collection ID to add images into.
- image_names (str or sequence of strs) – Image names.
- out_dir (optional, str) – Directory to write images to. Defaults to None.
- return_image_data (optional, bool) – If True images will be returned as numpy.ndarrays. Defaults to False.
Returns:
-
update
(collections_id, name=None, description=None, tags=None)[source]¶ Update a collection.
Parameters: - collections_id (str) – Collection ID.
- name (str, optional) – Name to be changed to.
- description (str, optional) – Description to be changed to.
- tags (str or sequence of strs, optional) – Optional comma-delimited keyword tags to be changed to.
-
-
class
helios.collections_api.
CollectionsFeature
(feature)[source]¶ Individual Collection JSON result.
-
bucket
¶ str – ‘bucket’ value for the result.
-
created_at
¶ str – ‘city’ value for the result.
-
description
¶ str – ‘created_at’ value for the result.
-
id
¶ str – ‘_id’ value for the result.
-
images
¶ sequence of strs – ‘images’ value for the result.
-
json
¶ dict – Raw JSON result.
-
name
¶ str – ‘name’ value for the result.
sequence of strs – ‘tags’ value for the result.
-
updated_at
¶ str – ‘updated_at’ value for the result.
-
user_id
¶ str – ‘user_id’ value for the result.
-
-
class
helios.collections_api.
IndexResults
(content, records)[source]¶ Index results for the Collections API.
IndexResults is an iterable for the results JSON response. This allows the user to iterate and select based on result attributes.
All features within IndexResults are instances of
CollectionsFeature
-
bucket
¶ ‘bucket’ values for every result.
-
created_at
¶ ‘city’ values for every result.
-
description
¶ ‘created_at’ values for every result.
-
failed
¶ Records for queries that failed.
-
id
¶ ‘_id’ values for every result.
-
json
¶ Raw ‘json’ for every feature.
-
name
¶ ‘name’ values for every result.
-
succeeded
¶ Records for queries that succeeded.
‘tags’ values for every result.
-
updated_at
¶ ‘updated_at’ values for every result.
-
user_id
¶ ‘user_id’ values for every result.
-
-
class
helios.collections_api.
RemoveImageResults
(content, records)[source]¶ Remove_image results for the Collections API.
-
failed
¶ Records for queries that failed.
-
succeeded
¶ Records for queries that succeeded.
-
-
class
helios.collections_api.
ShowImageResults
(content, records)[source]¶ Show_image results for the Collections API.
ShowImageResults is an iterable for the fetched image content. Each element of the iterable will be an ndarray if return_image_data was True.
-
failed
¶ Records for queries that failed.
-
image_data
¶ Image data if return_image_data was True.
-
name
¶ Names of all images.
-
output_file
¶ Full paths to all written images.
-
succeeded
¶ Records for queries that succeeded.
-
-
class
helios.collections_api.
ShowResults
(feature)[source]¶ Show results for the Collections API.
The features within ShowResults is an instances of
CollectionsFeature
Observations¶
Helios Observations API.
Methods are meant to represent the core functionality in the developer documentation. Some may have additional functionality for convenience.
-
class
helios.observations_api.
IndexResults
(content, records)[source]¶ Index results for the Observations API.
IndexResults is an iterable for GeoJSON features. This allows the user to iterate and select based on Feature attributes.
All features within IndexResults are instances of
ObservationsFeature
-
city
¶ ‘city’ values for every feature.
-
country
¶ ‘country’ values for every feature.
-
description
¶ ‘description’ values for every feature.
-
failed
¶ Records for queries that failed.
-
id
¶ ‘id’ values for every feature.
-
json
¶ Raw ‘json’ for every feature.
-
prev_id
¶ ‘prev_id’ values for every feature.
-
region
¶ ‘region’ values for every feature.
-
sensors
¶ ‘sensors’ values for every feature.
-
sensors_to_dataframes
(output_dir=None, prefix=None)¶ Combine sensor blocks and other useful feature information for observations into Pandas DataFrame objects.
DataFrames will contain the time, value, previous value, observation ID, and previous observation ID from each feature.
Optionally, DataFrames can be written to CSV files. These will follow the format of {prefix}_{sensor_name}.csv.
Parameters: - output_dir (str, optional) – Output directory to write files to. If None, then no files will be written. Defaults to None.
- prefix (str, optional) – Prefix to append to filenames. If None, no prefix will be prepended. Defaults to None.
Returns: Pandas DataFrame objects for each sensor.
Return type: dict
-
state
¶ ‘state’ values for every feature.
-
succeeded
¶ Records for queries that succeeded.
-
time
¶ ‘time’ values for every feature.
-
-
class
helios.observations_api.
Observations
(session=None)[source]¶ The Observations API provides ground-truth data generated by the Helios analytics.
-
index
(**kwargs)[source]¶ Get observations matching the provided spatial, text, or metadata filters.
The maximum skip value is 4000. If this is reached, truncated results will be returned. You will need to refine your query to avoid this.
Usage example:
import helios obs = helios.Observations() state = 'Maryland' bbox = [-169.352,1.137,-1.690,64.008] sensors = 'sensors[visibility][min]=0&sensors[visibility][max]=1' results = obs.index(state=state, bbox=bbox, sensors=sensors)
Usage example for transitions:
import helios obs = helios.Observations() # transition from dry/wet to partial/fully-covered snow roads sensors = 'sensors[road_weather][data][min]=6&sensors[road_weather][prev][max]=3' results = obs.index(sensors=sensors_query)
Parameters: **kwargs – Any keyword arguments found in the observations_index_documentation. Returns: IndexResults
-
preview
(observation_ids, out_dir=None, return_image_data=False)[source]¶ Get preview images from observations.
Parameters: - observation_ids (str or sequence of strs) – list of observation IDs.
- out_dir (optional, str) – Directory to write images to. Defaults to None.
- return_image_data (optional, bool) – If True images will be returned as numpy.ndarrays. Defaults to False.
Returns:
-
show
(observation_ids)[source]¶ Get attributes for observations.
Parameters: observation_ids (str or sequence of strs) – Helios observation ID(s). Returns: ShowResults
-
-
class
helios.observations_api.
ObservationsFeature
(feature)[source]¶ Individual Observation GeoJSON feature.
-
city
¶ str – ‘city’ value for the feature.
-
country
¶ str – ‘country’ value for the feature.
-
description
¶ str – ‘description’ value for the feature.
-
id
¶ str – ‘id’ value for the feature.
-
json
¶ dict – Raw JSON feature.
-
prev_id
¶ str – ‘prev_id’ value for the feature.
-
region
¶ str – ‘region’ value for the feature.
-
sensors
¶ dict – ‘sensors’ value for the feature.
-
state
¶ str – ‘state’ value for the feature.
-
time
¶ str – ‘time’ value for the feature.
-
-
class
helios.observations_api.
PreviewResults
(content, records)[source]¶ Preview results from the Observations API.
PreviewResults is an iterable for the fetched image content. Each element of the iterable will be an ndarray if return_image_data was True.
-
failed
¶ Records for queries that failed.
-
image_data
¶ Image data if return_image_data was True.
-
name
¶ Names of all images.
-
output_file
¶ Full paths to all written images.
-
succeeded
¶ Records for queries that succeeded.
-
-
class
helios.observations_api.
ShowResults
(content, records)[source]¶ Show results from the Observations API.
ShowResults is an iterable for GeoJSON features. This allows the user to iterate and select based on Feature attributes.
All features within ShowResults are instances of
ObservationsFeature
-
city
¶ ‘city’ values for every feature.
-
country
¶ ‘country’ values for every feature.
-
description
¶ ‘description’ values for every feature.
-
failed
¶ Records for queries that failed.
-
id
¶ ‘id’ values for every feature.
-
json
¶ Raw ‘json’ for every feature.
-
prev_id
¶ ‘prev_id’ values for every feature.
-
region
¶ ‘region’ values for every feature.
-
sensors
¶ ‘sensors’ values for every feature.
-
sensors_to_dataframes
(output_dir=None, prefix=None)¶ Combine sensor blocks and other useful feature information for observations into Pandas DataFrame objects.
DataFrames will contain the time, value, previous value, observation ID, and previous observation ID from each feature.
Optionally, DataFrames can be written to CSV files. These will follow the format of {prefix}_{sensor_name}.csv.
Parameters: - output_dir (str, optional) – Output directory to write files to. If None, then no files will be written. Defaults to None.
- prefix (str, optional) – Prefix to append to filenames. If None, no prefix will be prepended. Defaults to None.
Returns: Pandas DataFrame objects for each sensor.
Return type: dict
-
state
¶ ‘state’ values for every feature.
-
succeeded
¶ Records for queries that succeeded.
-
time
¶ ‘time’ values for every feature.
-
Session¶
Manager for the authorization token required to access the Helios API.
-
class
helios.core.session.
Session
(env=None)[source]¶ Manages API tokens for authentication.
Authentication credentials can be specified using the env input parameter, environment variables, or a credentials.json file in your ~/.helios directory. See the official documentation for more authentication information.
- Required keys:
- helios_client_id: Client ID from API key pair.
- helios_client_secret: Client Secret ID from API key pair.
- Optional keys:
- helios_api_url: Optional, URL for API endpoint.
A session can be established and reused for multiple core API instances.
import helios sess = helios.Session() alerts = helios.Alerts(session=sess) cameras = helios.Cameras(session=sess)
If a session is not specified before hand, one will be initialized automatically. This is less efficient because each core API instance will try to initialize a session.
import helios alerts = helios.Alerts() cameras = helios.Cameras()
Utilities¶
json_utils¶
Helper functions for JSON objects.
-
helios.utilities.json_utils.
merge_json
(data, keys)[source]¶ Merge JSON fields into a single list.
Keys can either be a single string or a list of strings signifying a chain of “keys” into the dictionary.
Parameters: - data (list) – Dictionary to merge data from.
- keys (str or sequence of strs) – A chain of keys into the dictionary to get to the field that will be merged.
Returns: Merged values.
Return type: list
-
helios.utilities.json_utils.
read_json_file
(json_file, **kwargs)[source]¶ Read a json file.
Parameters: - json_file (str) – Full path to JSON file.
- **kwargs – Any keyword argument from the json.load method.
Returns: JSON formatted dictionary.
Return type: dict
parsing_utils¶
Helper functions for paths and URLs.
-
helios.utilities.parsing_utils.
parse_camera
(data)[source]¶ Parse camera name from a URL or image name.
Parameters: data (str) – Image URL or name. Returns: Camera name. Return type: str
-
helios.utilities.parsing_utils.
parse_image_name
(url)[source]¶ Parse image name from a URL.
Parameters: url (str) – Image URL. Returns: Image name. Return type: str