Skip to main content

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

  1. Make sure that you have the requirements listed above
  2. pip install pysofar to your desired python environment
  3. Create a file in your home directory (on unix ~/) called sofar_api.env. Put your API token and key inside in the format WF_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 click api. You should see a section called Authentication 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.
  4. Test with python3 -c 'import pysofar'. If this runs successfully, chances are everything worked.
  5. 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

  1. 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
  1. 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
  1. Miscellaneous Functions
  • get_and_update_spotters: Same as SofarApi.get_spotters but can be used standalone

Spotter.py

  1. 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)

Release files for pysofar 0.1.16

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pysofar 0.1.16
File Size Uploaded
pysofar-0.1.16.tar.gz 18.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pysofar 0.1.16
File Interpreter ABI Platform
pysofar-0.1.16-py3-none-any.whl Python 3 none any Details

Total release size: 37.1 kB

Release files / pysofar-0.1.16.tar.gz

Download URL pysofar-0.1.16.tar.gz
Size 18.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8da1d2ee83bb0fe101daa0ba7ff5358c9dc646e31c4bda4054a82900ab9ac423
BLAKE2b-256 checksum
How to use checksums
30cf0476a3ec417720e6e30a8bc0092a0b94a64f358c940d5ff3b10dcca7b579
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.6

Release files / pysofar-0.1.16-py3-none-any.whl

Download URL pysofar-0.1.16-py3-none-any.whl
Size 18.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3efaa88803e40cab95c2ac5bbc2c1951919f7863e15e6a169f76a699d0e62427
BLAKE2b-256 checksum
How to use checksums
1644f6776b893a042064028f6b1493a366f14fba916c5c6a8112194875213810
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.1.16 This release

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page