This example shows how to query the Total Evapotranspiration from OpenDAP http://dap.nci.org.au/thredds/remoteCatalogService?catalog=http://dapds00.nci.org.au/thredds/catalog/ub8/au/OzWALD/daily/catalog.xml
The notebook provides widget interfaces for users to interact with. It then shows users how to perform various operations with xarray and then plot it using matplotlib - including locating the nearest grid to the selected city, and slicing the data by time.
In [46]:
!pip install xarray netCDF4 geopy
In [47]:
#setup widgets
import ipywidgets as widgets
w = widgets.Dropdown(
options=['Melbourne', 'Sydney', 'Canberra', 'Brisbane', 'Adelaide', 'Hobart', 'Perth', 'Darwin'],
description='Capital city:',
disabled=False,
)
arrYears = [str(i) for i in range(2000,2017)]
wYear = widgets.SelectionSlider(
options=arrYears,
value=arrYears[-1],
description='Select year:',
disabled=False,
continuous_update=False,
orientation='horizontal',
readout=True
)
In [48]:
w
In [49]:
wYear
In [50]:
year = wYear.value
In [51]:
import xarray as xr
max_day_etot = "http://dapds00.nci.org.au/thredds/dodsC/ub8/au/OzWALD/daily/OzWALD.daily.ETtot.{}.nc".format(year)
max_day_etot
Out[51]:
In [52]:
dataset = xr.open_dataset(max_day_etot)
dataset
Out[52]:
In [53]:
dataset.ETtot
Out[53]:
In [54]:
from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="CSIRO widget")
location = geolocator.geocode("{},australia".format(w.value))
print((location.latitude, location.longitude))
print(location.raw)
In [55]:
lon_st = location.longitude
lat_st = location.latitude
etot = dataset.ETtot.sel(longitude=lon_st, latitude=lat_st, method='nearest')
etot
Out[55]:
In [56]:
p = etot.plot()
In [57]:
import pandas as pd
startdate = year + '-01-01'
enddate = year + '-06-30'
timerange = pd.date_range(startdate, enddate, freq='D')
timerange
Out[57]:
In [58]:
six_month_ds = etot.sel({'time': timerange})
In [59]:
six_month_ds.plot()
Out[59]:
In [63]:
# get Melbourne coordinates
geolocator = Nominatim(user_agent="CSIRO widget")
mel_location = geolocator.geocode("Melbourne,australia".format(w.value))
etot_mel = dataset.ETtot.sel(longitude=mel_location.longitude, latitude=mel_location.latitude, method='nearest')
# get sydney coordinates and data
syd_location = geolocator.geocode("Sydney,australia".format(w.value))
etot_syd = dataset.ETtot.sel(longitude=syd_location.longitude, latitude=syd_location.latitude, method='nearest')
In [64]:
etot_mel.plot()
Out[64]:
In [65]:
etot_syd.plot()
Out[65]:
In [ ]: