Query Sensor Data Out of Senaps

Senaps has a myriad of data Queries that enable data to be extracted out of Senaps in a consistent and clearly defined manner. This extracted data can be manipulated and modeled at the will of the developer and then pushed back to Senaps to be accessed and visualized in downstream solutions.

get_platform Function

Get a collection of platforms you have access to.

platforms = senaps_client.get_platform(
  id,
  
  )

where,

  • id: Only return platforms with this id or partial match using wildcards (*, ?).
    • * matches zero or more characters
    • ? matches exactly one character.

get_observations Function

Talk about the function in a general way

  observations = senaps_client.get_observations(
    
  streamid,
  groupid,
  platformid,
  start,
  end,
  time,
  si = True,
  ei = True,
  bounds,
  media,
  limit=1000,
  sort,
  skipstreams,
  limitstreams,
  csvheader,
  jsonstreamlink
    
)
  res = sensor_client$get_observations(
  streamid,
  groupid,
  platformid,
  start,
  end,
  time,
  si = True,
  ei = True,
  bounds,
  media,
  limit,
  sort,
  skipstreams,
  limitstreams,
  csvheader,
  jsonstreamlink
)

where,

  • streamid`: Stream identifier, or a comma-separated list of stream identifiers. Wildcards (* and ?) are permitted. This parameter, the 'groupid' parameter, or the 'platformid' parameter must be set.
  • groupid: Group identifier, or a comma-separated list of group identifiers. Wildcards (* and ?) are permitted. This parameter, the 'streamid' parameter, or the 'platformid' parameter must be set.
  • platformid: Platform identifier, or a comma-separated list of platform identifiers. Wildcards (* and ?) are permitted. This parameter, the 'streamid' parameter, or the 'groupid' parameter must be set.
  • start: Start date ISO 8601 Date-Time eg "2015-11-12T00:00:00.000Z"
  • end: End date ISO 8601 Date-Time eg "2015-11-12T00:00:00.000Z"
  • time: Timestamp of a specific result. ISO 8601 Date-Time eg "2015-11-12T00:00:00.000Z"
  • si: Is the start parameter treated as an inclusive boundary
  • ei: Is the end parameter treated as an inclusive boundary
  • bounds: Boundary filter for a geolocation stream, or any stream located by a geolocation stream. The boundary is provided as a POLYGON in WTK format.
  • media: Format of response. Valid formats are CSV, JSON, and GeoJSON (for geolocation value streams)
  • limit: Limit the number of results. The limit is 1000 by default.
  • sort: Sort the results. By default, results are returned in ascending order.
  • skipstreams: When making a multi-stream request, skip this many streams.
  • limitstreams: When making a multi-stream request, return results for up to this many
  • csvheader: If false, additional headers will be removed from the CSV response. This will allow the response to be directly loaded by CSV software such as Excel.
  • jsonstreamheader: If false the stream links in the response at JSON path _embedded.stream will be suppressed from JSON responses.

Use Case: Query Data Out of ICT Data Weather Station (MNLA1K01)

We would like to thank ICT International for allowing us to use their weather station data to create this use case.

Step 1: Find the your Sensor (Platform) in Senaps

  • Step 1a: Login to Senaps
  • Step 1b: Navigate and Click Data and then Platforms
  • Step 1c:
  1. Click on the Name filter and search for your given platform, in this example mnla.
  2. Copy the Platform ID Ready to add it to your Python Code

Step 2: Access and Extract Data Streams inside the platform in Python

The below code:

  • i. Initialize your Senaps Credentials in the Python environment, ensuring you can only see and access data you have permission to see.
📘

Senaps API Credentials

You will need your Senpas API credentials for the following script. These are different to your Eratos API credentials. Tutorial to get your Senaps API credentials can be found here.

  • ii. Check the platform ID you have copied from the platform is valid.
  • iii. Extract all data inside the platform into a Pandas Dataframe
from senaps_sensor.parsers import PandasObservationParser
from senaps_sensor.api import API
from senaps_sensor.auth import HTTPKeyAuth
from tabulate import tabulate

#i
creds_path = r"PATH_TO_YOUR_SENAPS_CREDS"

# Opening JSON file
f = open(creds_path)
  
# returns JSON object as 
# a dictionary
creds = json.load(f)

#ii
senaps_client = API(HTTPKeyAuth(creds['senaps_key']), host="senaps.eratos.com"))

platform_id = 'datafarmer.uh7PXm5fX4h0hyTm3nwX'

platform = senaps_client.get_platform(id = platform_id)

#iii

df_ICT_weather_station = senaps_client.get_observations(streamid=f'{platform_id}.*',  limit=50, 
                                                    limitstreams=5,
                                                    media="csv", 
                                                    sort="descending", 
                                                    parser=PandasObservationParser(), platformid = platform_id )

print(df_ICT_weather_station.columns)

# Extract air-temp and humdity values
df_ICT_subset = df_ICT_weather_station[['datafarmer.uh7PXm5fX4h0hyTm3nwX.air_temp',
                                        'datafarmer.uh7PXm5fX4h0hyTm3nwX.humidity',
                                        ]]

# Rename Columns
df_ICT_subset = df_ICT_subset.rename(columns={'datafarmer.uh7PXm5fX4h0hyTm3nwX.air_temp': 'air_temp',
                               'datafarmer.uh7PXm5fX4h0hyTm3nwX.humidity': 'relative_humidity'})


#Print Table 
print(tabulate(df_ICT_subset, headers='keys', tablefmt='fancy_grid'))