<jupyter_start><jupyter_text>Flood mapping example Using sample data<jupyter_code>import matplotlib.pyplot as plt, numpy as np, xarray
import algorithm
ds = xarray.open_dataset('example_data.nc').isel(time=0)

plt.imshow(ds.vv.data, vmax=0.5)
plt.title('Radar backscatter')
plt.colorbar().set_label('intensity (linear)')
result = algorithm.classify(ds.vv.data, ds.wofs.data, ds.hand.data, ds.landcover.data, True)

plt.imshow(result)
plt.title('Flood extent')
plt.colorbar().set_label('fuzzy boolean')<jupyter_output>/g/data1a/u46/users/brl654/MonashRadarWater/repo/notebooks/algorithm.py:496: RuntimeWarning: invalid value encountered in log10
  backscatter = np.log10(despeckle(backscatter)) * 10
/g/data1a/u46/users/brl654/MonashRadarWater/repo/notebooks/algorithm.py:506: RuntimeWarning: invalid value encountered in greater
  persistent = wofs > 0.8
/g/data1a/u46/users/brl654/MonashRadarWater/repo/notebooks/algorithm.py:507: RuntimeWarning: invalid value encountered in greater
  historic = wofs > 0.001
/g/data1a/u46/users/brl654/MonashRadarWater/repo/notebooks/algorithm.py:508: RuntimeWarning: invalid value encountered in less
  lowlying = hand < 20
/g/data1a/u46/users/brl654/MonashRadarWater/repo/notebooks/algorithm.py:428: RuntimeWarning: divide by zero encountered in double_scalars
  enhance = 4 * (C / HO)**2
/g/data1a/u46/users/brl654/MonashRadarWater/repo/notebooks/algorithm.py:429: RuntimeWarning: divide by zero encountered in double_scalars
  attenuate = 4 * (C / HNO)**2<jupyter_text>Using data through Digital Earth AustraliaWOfS is sourced through the production DEA index. SAR is sourced through a beta DEA index. HAND and Landcover (DLCD) are sourced through the local NCI filesystem. The Open Data Cube API is utilised in each request, to extract the region of interest and to stack all layers consistently.<jupyter_code>import datacube.testutils.io

prodcube = datacube.Datacube()
sarcube = datacube.Datacube(config={'db_hostname': 'agdcdev-db.nci.org.au',
                                    'db_port': 6432,
                                    'db_database': 'radar_test'})<jupyter_output><empty_output><jupyter_text>Confirm that SAR data is available for the period and region of interest:<jupyter_code>#lat, lon = -27.1544, 149.0677 # surat
#lat, lon = -28.034167, 148.581667 # st george
lat, lon = -18.1975, 125.56766 # Fitzroy Crossing

radius = 0.2
query = dict(product='s1_gamma0_scene',
             time=('2017-02-11', '2017-02-12'),
             lat=(lat-radius,lat+radius),
             lon=(lon-radius,lon+radius))
len(sarcube.find_datasets(**query)) # Count potential scenes
radar = sarcube.load(**query, group_by='solar_day').isel(time=0) # retrieve raster data
radar['db'] = (radar.vv.dims, 10 * np.log10(algorithm.despeckle(radar.vv.data))) # apply prefiltering

# visualise
fig, axes = plt.subplots(ncols=2, figsize=(10,3))
radar.vv.plot(vmin=0, vmax=0.18, ax=axes[0])
radar.db.plot(vmax=0, ax=axes[1])<jupyter_output>/g/data/v10/public/modules/dea-env/20200713/lib/python3.6/site-packages/ipykernel_launcher.py:2: RuntimeWarning: invalid value encountered in log10<jupyter_text>Load other ancilliary products (Water Observations from Space, Height Above Nearest Drainage, and Dynamic Land Cover Dataset):<jupyter_code>wofs = prodcube.load(product='wofs_summary', lat=query['lat'], lon=query['lon']).isel(time=0)
hand = datacube.testutils.io.rio_slurp_xarray("HANDpysheds1000_Albers25m.tif", gbox=radar.geobox)
lc = datacube.testutils.io.rio_slurp_xarray("LC_2011_FitzroyCatch_Albers25m.tif", gbox=radar.geobox)

# visualise
fig, axes = plt.subplots(ncols=3, figsize=(12,2.5)) # display in the same row
wofs.frequency.plot(ax=axes[0])
hand.plot(ax=axes[1])
lc.plot(ax=axes[2])<jupyter_output><empty_output><jupyter_text>Apply the flood detection algorithm:<jupyter_code>result = algorithm.classify(radar.db.data, wofs.frequency.data, hand.data, lc.data)

plt.imshow(result)
plt.colorbar().set_label('fuzzy boolean')<jupyter_output>/g/data1a/u46/users/brl654/MonashRadarWater/repo/notebooks/algorithm.py:428: RuntimeWarning: divide by zero encountered in double_scalars
  enhance = 4 * (C / HO)**2
/g/data1a/u46/users/brl654/MonashRadarWater/repo/notebooks/algorithm.py:429: RuntimeWarning: divide by zero encountered in double_scalars
  attenuate = 4 * (C / HNO)**2
{'fraction_non_alphanumeric': 0.1284191006026889, 'fraction_numerical': 0.050301344459898006, 'mean_word_length': 5.364306784660767, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '370587', 'license': 'Apache-2.0', 'n_tokens_mistral': 1705, 'n_tokens_neox': 1547, 'n_words': 300, 'path': 'Demo.ipynb', 'repo_name': 'GeoscienceAustralia/dea-sar-flood-veg', 'size': '4314'}