From 852e95a26454cc51f96b7261f8f5f5ff065a1200 Mon Sep 17 00:00:00 2001 From: Dan Howe Date: Wed, 28 Aug 2019 09:02:41 +1000 Subject: [PATCH] Add 'ww3_variables.py' --- ww3/ww3_variables.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 ww3/ww3_variables.py diff --git a/ww3/ww3_variables.py b/ww3/ww3_variables.py new file mode 100644 index 0000000..f57d834 --- /dev/null +++ b/ww3/ww3_variables.py @@ -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)