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
- Make sure that you have the requirements listed above
pip install roguewaveto your desired python environment- Test with
python3 -c 'import roguewave'. If this runs successfully, chances are everything worked. - To interact with the api's you need to add the access tokens into an environmental file.
Specifically create a file called
sofar_api.envin 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()
Metadata
Release files for roguewave 0.2.32
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| roguewave-0.2.32.tar.gz | 166.1 kB | Without provenance | Details for roguewave-0.2.32.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| roguewave-0.2.32-py3-none-any.whl | Python 3 | none | any | Details for roguewave-0.2.32-py3-none-any.whl |
Total release size: 395.2 kB
Release files / roguewave-0.2.32.tar.gz
| Download URL | roguewave-0.2.32.tar.gz |
|---|---|
| Size | 166.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
87b1e90ab38c3abc719a02f593a23335e48d3f9ce8c6c64bcd0c02a6fcb1730c
|
|
BLAKE2b-256 checksum How to use checksums |
836cea6b713c98192aed24f76547d21c98d878305ba9c1a871d6082ae2128508
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.4
|
Release files / roguewave-0.2.32-py3-none-any.whl
| Download URL | roguewave-0.2.32-py3-none-any.whl |
|---|---|
| Size | 229.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2986cc703463458b0a26524c1d3b8219dc5e2be68289e6192cba9b6fa2e3e545
|
|
BLAKE2b-256 checksum How to use checksums |
3c7f5c29efb5205858ef108fc45b5aa803d370c6fa6617d56ef2566caeded30f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.4
|
Security for roguewave 0.2.32
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.