Skip to main content

Python package to interact with Sofar wave data

Project description

Sofar Ocean API Python Client

Python toolbox to interact with Sofar Ocean Spotter API.

Requirements

  • Python3
  • pysofar
  • numpy
  • netCDF4
  • wheel (If developing/Contributing)
  • Pytest (If developing/Contributing)
  • Setuptools (If developing/Contributing)

Installation

  1. Make sure that you have the requirements listed above
  2. pip install roguewave to your desired python environment
  3. Test with python3 -c 'import roguewave'. If this runs successfully, chances are everything worked.
  4. To interact with the api's you need to add the access tokens into an environmental file. Specifically create a file called sofar_api.env in your user directory containing
WF_API_TOKEN=_wavefleet_token_
SPECTRAL_API_TOKEN=_spectral_api_token_

Examples

Retrieve Spectrum from observational Spotter API

from roguewave.spotterapi import get_spectrum
from datetime import datetime, timezone
import matplotlib.pyplot as plt

# The Spotter we want the data from
spotter_id = 'SPOT-0740'

# Start time to grab
start_date = datetime(2021,1,1,0,0,0,tzinfo=timezone.utc)

# End time
end_date = datetime(2021,1,6,0,0,0,tzinfo=timezone.utc)

# You will need a valid access token setup for the pysofar library for this to
# work. We refer to the pysofar documentation how to set that up.


# Get the spectra
spectra = get_spectrum(spotter_id,start_date,end_date)

# We now have spectra from the spotter we can interact with
for key in spectra:
    for spectrum in spectra[key]:
        string = f'The waveheight at {spectrum.timestamp} was {spectrum.hm0()} meter'
        print(string)

# or do a simple plot
plt.plot(spectra[spotter_id][0].frequency, spectra[spotter_id][0].variance_density,'k')
plt.xlabel('Frequency (hz)')
plt.ylabel('Variance Density (m$^2$/s)')
plt.yscale('log')
plt.title(f'spectrum for {spotter_id} at time {spectra[spotter_id][0].timestamp}')
plt.grid()
plt.show()

Retrieve Spectrum from model Spectral API

from roguewave.modeldata.sofarspectralapi import SofarSpectralAPI,load_sofar_spectral_file
import matplotlib.pyplot as plt

# Create an api Object
api = SofarSpectralAPI()

# Get all the points accessible for this particular user. This returns a list
# dictionaries containing latitudes and longitudes
points = api.points()

# Lets get the first point. This will download the netcdf containing the spectral
# forcast into the given directory.
file = api.download_spectral_file(**points[0], directory='./')

# Lets load the point. This will open the Netcdf file and return a Spectrum2D
# object. This object supports all the methods of the Spectrum1D object (hm0, 
# tm02, etc.)
data = load_sofar_spectral_file(file)

# Lets plot it
plt.pcolormesh(data[0].frequency, data[0].direction, data[0].variance_density)
plt.show()

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

roguewave-0.2.30.tar.gz (165.4 kB view details)

Uploaded Source

Built Distribution

roguewave-0.2.30-py3-none-any.whl (228.4 kB view details)

Uploaded Python 3

File details

Details for the file roguewave-0.2.30.tar.gz.

File metadata

  • Download URL: roguewave-0.2.30.tar.gz
  • Upload date:
  • Size: 165.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for roguewave-0.2.30.tar.gz
Algorithm Hash digest
SHA256 7d1ab8d3620cfa545b2e8bf7d86ac846a4b34694f9cbbcc1c309358e67df4d79
MD5 8ab451b89e4cc23baf4742447f25c231
BLAKE2b-256 a1249d284f47299f08659652b7a18ac7fe12cfc0152461b0395299b65f66b39b

See more details on using hashes here.

File details

Details for the file roguewave-0.2.30-py3-none-any.whl.

File metadata

  • Download URL: roguewave-0.2.30-py3-none-any.whl
  • Upload date:
  • Size: 228.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for roguewave-0.2.30-py3-none-any.whl
Algorithm Hash digest
SHA256 59c6c6e8edf0d5cde12c9e26d6d13e46720296abb7e921835683cea29fecf5e8
MD5 cb80604a7a575d3fb2a0125eb98d1a14
BLAKE2b-256 835adf97866a3e3b1b7e624ee5271bae74130c6bae347d4b0b843afa5660233a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page