Python client for interfacing with the Sofar Wavefleet API to access Spotter Data
Project description
Sofar Ocean API Python Client
Python Client for the Sofar Ocean Spotter API
Requirements
- Python3 (Preferably 3.7) and pip
- python-dotenv
- requests
- Pytest (If developing/Contributing)
- Setuptools (If developing/Contributing)
Installation
- Make sure that you have the requirements listed above
pip install pysofar
to your desired python environment- Create a file in your home directory (on unix
~/
) calledsofar_api.env
. Put your API token and key inside in the formatWF_API_TOKEN=<token>
We have included an example file named ex.sofar_api.env in the repository which you can copy (Just make sure to change the name and update the token to match yours). If you do not currently have an API token, log into your sofar account here. Open the sidebar and clickapi
. You should see a section calledAuthentication
which will have a button to generate a token. You can also use this to update your token to a new one, should you desire. - Test with
python3 -c 'import pysofar'
. If this runs successfully, chances are everything worked. - If you wish to develop/contribute to this project see contributing.
Basic Classes
Included here are basic descriptions of some of the classes. Further documentation is provided within each function itself.
Sofar.py
- SofarApi: Initialize to get access most of the api endpoints
- Properties:
- Devices (Spotters that belong to this account). List of Dictionaries of Id and Name
- Device Ids. List of the id's of the devices
- Methods
- get_device_location_data: Most recent location data of the devices
- get_latest_data: Use to grab the latest data from a specific spotter
- get_sensor_data: Gets smart mooring sensor data for a specific spotter in a date range
- update_spotter_name: Update the name of a specific spotter
- get_wave_data: Gets all of the wave data for all of the spotters in a date range
- get_wind_data: Same as above but for wind
- get_frequency_data: Same as above but for frequency
- get_track_data: Same as above but for tracking data
- get_all_data: Returns all of wave, wind, frequency, track for all spotters in a date range
- get_spotters: Returns Spotter objects updated with data values
- WaveDataQuery: Use for more fine tuned querying for a specific spotter
- Methods:
- execute: Runs the query with the set parameters
- limit: Limit of how many results to return
- waves: Input True to include wave data in results
- wind: ^ but for winds
- track: ^ but for track
- frequency: ^ but for frequency
- directional_moments: Input true to include directional moments if frequency data is also included
- set_start_date: Set the start date of the data to be queried
- clear_start_date: No lower bound on the dates for the spotter data requested
- set_end_date: Sets the end date of data to be queried
- clear_end_date: No upper bound on the dates for the spotter data requested
- Miscellaneous Functions
- get_and_update_spotters: Same as SofarApi.get_spotters but can be used standalone
Spotter.py
- Spotter: Class representing a spotter and its properties
-
Properties:
- id
- name
- mode
- lat
- lon
- battery_power
- battery_voltage
- solar_voltage
- humidity
- timestamp
-
Methods:
- change_name: Updates the spotters name
- update: Updates the spotters attributes with the latest data values
- latest_data: Gets latest_data from this spotter
- grab_data: More fine tuned data querying for this spotter
A small example
from pysofar.sofar import SofarApi
from pysofar.spotter import Spotter
# init the api
api = SofarApi()
# get the devices belonging to you
devices = api.devices
print(devices)
# grab spotter objects for the devices
spotter_grid = api.get_spotters()
# each array value is a spotter object
spt_0 = spotter_grid[0]
print(spt_0.mode)
print(spt_0.lat)
print(spt_0.lon)
print(spt_0.timestamp)
# Get most recent data from the above spotter with waves
spt_0_dat = spt_0.latest_data()
print(spt_0_dat)
# what if we want frequency data with directional moments as well
spt_0_dat_freq = spt_0.latest_data(include_directional_moments=True)
print(spt_0_dat_freq)
# What about a specific range of time with waves and track data
spt_0_query = spt_0.grab_data(
limit=100,
start_date='2019-01-01',
end_date='2019-06-30',
include_track=True
)
print(spt_0_query)
# What if we want all data from all spotters over all time
# this will take a few seconds
all_dat = api.get_all_data()
print(all_dat.keys())
print(all_dat)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pysofar-0.1.16.tar.gz
(18.5 kB
view details)
Built Distribution
pysofar-0.1.16-py3-none-any.whl
(18.6 kB
view details)
File details
Details for the file pysofar-0.1.16.tar.gz
.
File metadata
- Download URL: pysofar-0.1.16.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8da1d2ee83bb0fe101daa0ba7ff5358c9dc646e31c4bda4054a82900ab9ac423 |
|
MD5 | e89ad4389f444ee4f54462f560c95c88 |
|
BLAKE2b-256 | 30cf0476a3ec417720e6e30a8bc0092a0b94a64f358c940d5ff3b10dcca7b579 |
File details
Details for the file pysofar-0.1.16-py3-none-any.whl
.
File metadata
- Download URL: pysofar-0.1.16-py3-none-any.whl
- Upload date:
- Size: 18.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3efaa88803e40cab95c2ac5bbc2c1951919f7863e15e6a169f76a699d0e62427 |
|
MD5 | e72905653917952517ef591efdbfa19b |
|
BLAKE2b-256 | 1644f6776b893a042064028f6b1493a366f14fba916c5c6a8112194875213810 |