Welcome to the SOFAR API Client. It is a simple and easy to use way to access the following API endpoints:
- Marine Weather
- Wave Spectra
- Spotter Sensor
Check out our weather dashboard at https://weather.sofarocean.com/.
npm install --save @sofarocean/sofar-api-client
The Sofar API uses token-based authentication. To get started using the Sofar API, you'll need to retrieve or generate an authentication token.
Get your API token in the Weather Dashboard by signing up for a user, then navigating to Account > API Access.
Typescript:
import { SDK } from 'sofar-sdk';
async function main(): Promise<number> {
const apiKey = 'YOUR API KEY';
const sdk = new SDK(apiKey);
console.log(await sdk.spotters.getSpotters());
return 0;
}
main();
JavaScript:
var SDK = require('@sofarocean/sofar-sdk').SDK;
var apiKey = 'YOUR API KEY';
var sdk = new SDK(apiKey);
sdk.spotters.getSpotters().then((spotters) => {
console.log(spotters);
});
For the full API documentation, see here.
sdk.marineWeather
.getPointForecast('SofarOperationalWaveModel', -152.0001, 37.0001, [
'SofarOperationalWaveModel-significantWaveHeight',
'SofarOperationalWaveModel-meanDirection',
])
.then((data) => {
console.log(data);
});
sdk.marineWeather
.getPointHindcast(
'SofarOperationalWaveModel',
-152,
37,
new Date('2020-07-12T22:00:00Z'),
new Date('2020-07-12T24:00:00Z'),
['SofarOperationalWaveModel-significantWaveHeight', 'SofarOperationalWaveModel-meanDirection'],
)
.then((data) => {
console.log(data);
});
sdk.marineWeather
.getModels()
.then((models) => {
console.log('Weather models:');
console.dir(models, { depth: null });
})
.catch((err) => {
console.error(JSON.stringify(err));
});
sdk.marineWeather
.getModelMetadata('NOAACoralReefWatch')
.then((metadata) => {
console.log('Model category metadata:');
console.dir(metadata, { depth: null });
})
.catch((err) => {
console.error(JSON.stringify(err));
});
sdk.marineWeather
.getDataCategories()
.then((categories) => {
console.log('Data categories:');
console.dir(categories, { depth: null });
})
.catch((err) => {
console.error(JSON.stringify(err));
});
sdk.marineWeather
.getDataCategoryMetadata('coralEcosystem')
.then((metadata) => {
console.log('Data category metadata:');
console.dir(metadata, { depth: null });
})
.catch((err) => {
console.error(JSON.stringify(err));
});
sdk.spotters.getSpotters().then((spotters) => {
console.log(spotters);
});
sdk.spotters
.getSpotter('SPOT-0222')
.getWaveData({ includeWindData: true, includeFrequencyData: true })
.then((data) => {
console.log(data);
});
sdk.waveSpectra
.getWaveSpectraForecast({ latitude: 34.5, longitude: 200 })
.then((spectra) => {
spectra
.download(`${spectra.latitude}_${spectra.longitude}.netcdf`)
.then(() => {
// successfully written data to stream.
})
.catch((err) => {
console.error(err);
});
})
.catch((err) => {
console.error(err);
});
sdk.waveSpectra.getWaveSpectraForecast({ latitude: 34.5, longitude: 200 }).then((spectra) => {
spectra.download('test.netcdf').then(() => {
console.log('done');
});
});
The build step runs the typescript compilers and also recreates the documentation.
yarn build
yarn test
When commiting to master, the docs directory is updated automatically through a GitHub Workflow and commited. The /docs directory is used for github pages.
Releases to NPM are handled through a github action workflow. To release a new version, update the version in the package.json file, then create a new tag in /releases/VERSION_NUMBER (eg: /releases/1.0.2).