Package: pysofar
Sofar Ocean API Python ClientPython Client for the Sofar Ocean Spotter APIRequirementsPython3 (Preferably 3.7) and pippython-dotenvrequestsPytest (If developing/Contributing)Setuptools (If developing/Contributing)InstallationMake sure that you have the requirements listed abovepip install pysofarto your desired python environmentCreate 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 namedex.sofar_api.envin 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 accounthere. Open the sidebar and clickapi. You should
see a section calledAuthenticationwhich 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 withpython3 -c 'import pysofar'. If this runs successfully, chances are everything worked.If you wish to develop/contribute to this project seecontributing.Basic ClassesIncluded here are basic descriptions of some of the classes. Further documentation is provided
within each function itself.Sofar.pySofarApi: Initialize to get access most of the api endpointsProperties:Devices (Spotters that belong to this account). List of Dictionaries of Id and NameDevice Ids. List of the id's of the devicesMethodsget_device_location_data: Most recent location data of the devicesget_latest_data: Use to grab the latest data from a specific spotterget_sensor_data: Gets smart mooring sensor data for a specific spotter in a date rangeupdate_spotter_name: Update the name of a specific spotterget_wave_data: Gets all of the wave data for all of the spotters in a date rangeget_wind_data: Same as above but for windget_frequency_data: Same as above but for frequencyget_track_data: Same as above but for tracking dataget_all_data: Returns all of wave, wind, frequency, track for all spotters in a date rangeget_spotters: Returns Spotter objects updated with data valuesWaveDataQuery: Use for more fine tuned querying for a specific spotterMethods:execute: Runs the query with the set parameterslimit: Limit of how many results to returnwaves: Input True to include wave data in resultswind: ^ but for windstrack: ^ but for trackfrequency: ^ but for frequencydirectional_moments: Input true to include directional moments if frequency data is also includedset_start_date: Set the start date of the data to be queriedclear_start_date: No lower bound on the dates for the spotter data requestedset_end_date: Sets the end date of data to be queriedclear_end_date: No upper bound on the dates for the spotter data requestedMiscellaneous Functionsget_and_update_spotters: Same as SofarApi.get_spotters but can be used standaloneSpotter.pySpotter: Class representing a spotter and its propertiesProperties:idnamemodelatlonbattery_powerbattery_voltagesolar_voltagehumiditytimestampMethods:change_name: Updates the spotters nameupdate: Updates the spotters attributes with the latest data valueslatest_data: Gets latest_data from this spottergrab_data: More fine tuned data querying for this spotterA small examplefrompysofar.sofarimportSofarApifrompysofar.spotterimportSpotter# init the apiapi=SofarApi()# get the devices belonging to youdevices=api.devicesprint(devices)# grab spotter objects for the devicesspotter_grid=api.get_spotters()# each array value is a spotter objectspt_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 wavesspt_0_dat=spt_0.latest_data()print(spt_0_dat)# what if we want frequency data with directional moments as wellspt_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 dataspt_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 secondsall_dat=api.get_all_data()print(all_dat.keys())print(all_dat)