You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
877 B
Python
41 lines
877 B
Python
"""get_ww3.py
|
|
Show available variables inside WW3 dataset
|
|
D. Howe
|
|
2019-08-28
|
|
"""
|
|
import netCDF4
|
|
import pandas as pd
|
|
import xarray as xr
|
|
from tqdm import tqdm
|
|
|
|
# Set product code
|
|
product_code = 'ww3.aus_4m'
|
|
|
|
# Set month
|
|
date = '2013-01'
|
|
|
|
url = ('http://data-cbr.csiro.au/thredds/dodsC/catch_all/'
|
|
'CMAR_CAWCR-Wave_archive/CAWCR_Wave_Hindcast_aggregate/gridded/')
|
|
|
|
# Get date string for current month
|
|
date_str = pd.to_datetime(date).strftime('%Y%m')
|
|
|
|
# Open dataset
|
|
ds = xr.open_dataset(url + f'{product_code}.{date_str}.nc')
|
|
|
|
# Extract variables metadata
|
|
rows = []
|
|
for key, val in ds.variables.items():
|
|
row = {}
|
|
row['name'] = key
|
|
row['description'] = val.attrs['long_name']
|
|
try:
|
|
row['units'] = val.attrs['units']
|
|
except KeyError:
|
|
row['units'] = '-'
|
|
rows.append(row)
|
|
|
|
# Show data
|
|
df = pd.DataFrame(rows).set_index('name')
|
|
print(df)
|