Add 'ww3_variables.py'
parent
15de751a03
commit
852e95a264
@ -0,0 +1,40 @@
|
||||
"""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)
|
Loading…
Reference in New Issue