<jupyter_start><jupyter_text>Querying Total Evapotranspiration from  OzWALD hosted by NCI via OpenDAPThis 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.xmlThe 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.<jupyter_code>!pip install xarray netCDF4 geopy<jupyter_output>Requirement already satisfied: xarray in /opt/conda/lib/python3.6/site-packages (0.11.3)
Requirement already satisfied: netCDF4 in /opt/conda/lib/python3.6/site-packages (1.4.2)
Requirement already satisfied: geopy in /opt/conda/lib/python3.6/site-packages (1.18.1)
Requirement already satisfied: pandas>=0.19.2 in /opt/conda/lib/python3.6/site-packages (from xarray) (0.23.4)
Requirement already satisfied: numpy>=1.12 in /opt/conda/lib/python3.6/site-packages (from xarray) (1.13.3)
Requirement already satisfied: cftime in /opt/conda/lib/python3.6/site-packages (from netCDF4) (1.0.3.4)
Requirement already satisfied: geographiclib<2,>=1.49 in /opt/conda/lib/python3.6/site-packages (from geopy) (1.49)
Requirement already satisfied: python-dateutil>=2.5.0 in /opt/conda/lib/python3.6/site-packages (from pandas>=0.19.2->xarray) (2.7.5)
Requirement already satisfied: pytz>=2011k in /opt/conda/lib/python3.6/site-packages (from pandas>=0.19.2->xarray) (2018.7)
Requirement already satisfied: six>=[...]<jupyter_text>Setup widgets to select city and year<jupyter_code>#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
)
w
wYear
year = wYear.value<jupyter_output><empty_output><jupyter_text>Setup xarray<jupyter_code>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
dataset = xr.open_dataset(max_day_etot)
dataset
dataset.ETtot<jupyter_output><empty_output><jupyter_text>Use geopy to get the lat-long coordinates for the selected city<jupyter_code>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)<jupyter_output>(-37.8142176, 144.9631608)
{'place_id': '198386686', 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', 'osm_type': 'relation', 'osm_id': '2404870', 'boundingbox': ['-37.85067', '-37.77545', '144.89709', '144.9913426'], 'lat': '-37.8142176', 'lon': '144.9631608', 'display_name': 'City of Melbourne, Victoria, Australia', 'class': 'boundary', 'type': 'administrative', 'importance': 0.923124610070791, 'icon': 'https://nominatim.openstreetmap.org/images/mapicons/poi_boundary_administrative.p.20.png'}<jupyter_text>Use city coordinates to find the nearest point in the grid for the data point<jupyter_code>lon_st = location.longitude
lat_st = location.latitude

etot = dataset.ETtot.sel(longitude=lon_st, latitude=lat_st, method='nearest')
etot<jupyter_output><empty_output><jupyter_text>Plot using matplotlib<jupyter_code>p = etot.plot()<jupyter_output><empty_output><jupyter_text>Use pandas to create a 6-month date range to filter the data for the dates selected<jupyter_code>import pandas as pd

startdate = year + '-01-01'
enddate = year + '-06-30'

timerange = pd.date_range(startdate, enddate, freq='D')
timerange
six_month_ds = etot.sel({'time': timerange})
six_month_ds.plot()<jupyter_output><empty_output><jupyter_text>Compare Melbourne and Sydney<jupyter_code># 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')
etot_mel.plot()
etot_syd.plot()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1328208413410207, 'fraction_numerical': 0.04505658765748452, 'mean_word_length': 6.482428115015974, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 41, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '664587', 'license': 'MIT', 'n_tokens_mistral': 1806, 'n_tokens_neox': 1684, 'n_words': 344, 'path': 'xarray/xarray-plot-ozwald-daily-max-temp.ipynb', 'repo_name': 'CSIRO-enviro-informatics/jupyter-examples', 'size': '4683'}