Within this example, we show the different API entry points, and how to use that data within your plotting workflow!
import requests
from IPython.display import HTML
import hvplot.pandas
import holoviews as hv
import pandas as pd
hv.extension("bokeh")
Our dataset is hosted on AWS, accessible from http://3.226.253.65
We can access our datasets using /datasets/gfs
or /datasets/ww3
for the Global Forecast System (GFS) or Wave Watch 3 (WW3) datasets respectively
response = requests.get("http://3.226.253.65/datasets/ww3/")
Since our response is html, we need the HTML
wrapper to show the xarray dataset!
HTML(response.text)
<xarray.Dataset> Dimensions: (longitude: 381, latitude: 351, time: 73, forecast_reference_time: 1) Coordinates: * longitude (longitude) float32 -93.0 -92.9 ... -55.1 -55.0 * latitude (latitude) float32 20.0 20.1 20.2 ... 54.9 55.0 * time (time) datetime64[ns] 2022-04-11T12:00:00 ... 20... * forecast_reference_time (forecast_reference_time) datetime64[ns] 2022-04... Data variables: (12/21) hs (forecast_reference_time, time, latitude, longitude) float32 ... t02 (forecast_reference_time, time, latitude, longitude) float32 ... t0m1 (forecast_reference_time, time, latitude, longitude) float32 ... t01 (forecast_reference_time, time, latitude, longitude) float32 ... fp (forecast_reference_time, time, latitude, longitude) float32 ... dir (forecast_reference_time, time, latitude, longitude) float32 ... ... ... pdir2 (forecast_reference_time, time, latitude, longitude) float32 ... pws0 (forecast_reference_time, time, latitude, longitude) float32 ... pws1 (forecast_reference_time, time, latitude, longitude) float32 ... pws2 (forecast_reference_time, time, latitude, longitude) float32 ... tws (forecast_reference_time, time, latitude, longitude) float32 ... pnr (forecast_reference_time, time, latitude, longitude) float32 ... Attributes: (12/17) WAVEWATCH_III_version_number: 5.16 WAVEWATCH_III_switches: F90 SHRD NOGRB NOPA LRB4 NC4 TRKNC PR3 ... SIN4 namelist parameter BETAMAX: 1.65 product_name: ww3.20220411.nc area: NW Atlantic 6 arc min grd2 latitude_resolution: 0.1000000 ... ... minimum_altitude: -12000 m maximum_altitude: 9000 m altitude_resolution: n/a start_date: 2022-04-11 12:00:00 stop_date: 2022-04-11 23:00:00 _xpublish_id: ww3
We can query for a single point using the /edr/position
API
point_response_ww3 = requests.get("http://3.226.253.65/datasets/ww3/edr/position?coords=POINT(-70%2043.72)¶meter-name=hs,dir")
Once we get our response, we can access the json
point_json_ww3 = point_response_ww3.json()
Our datasets are nested within this dictionary, accessible using the following syntax
# Grab our hs data field
hs_field = point_json_ww3["ranges"]["hs"]["values"]
# Grab our time field for the hs field
hs_time_field = point_json_ww3["domain"]["axes"]["t"]["values"]
We assign variable names for each of these, and pass into our pandas dataframe object
df = pd.DataFrame({"time":time_field,
"hs":hs_field})
df
time | hs | |
---|---|---|
0 | 2022-04-11T12:00:00 | 0.305014 |
1 | 2022-04-11T12:59:59 | 0.300873 |
2 | 2022-04-11T14:00:00 | 0.235915 |
3 | 2022-04-11T15:00:00 | 0.157094 |
4 | 2022-04-11T15:59:59 | 0.101346 |
... | ... | ... |
68 | 2022-04-14T08:00:00 | 0.451038 |
69 | 2022-04-14T09:00:00 | 0.493556 |
70 | 2022-04-14T09:59:59 | 0.533382 |
71 | 2022-04-14T11:00:00 | 0.569655 |
72 | 2022-04-14T12:00:00 | 0.598845 |
73 rows × 2 columns
Before we plot, let's convert our string datetime to a datetime object
df["time"] = pd.to_datetime(df.time)
Now that we have our time parsed, and the data, we can use hvplot to visualize our dataset
df.hvplot.line(x='time',
label='significant_wave_height \n at -70 deg lon, 43.72 deg lat')