<jupyter_start><jupyter_text>Land Cover Change Detection and Description The purpose of this notebook is to provide an easy to use method for comparing and visualising differences between 2 tiles which were classified using the L3 FAO land cover classification system.<jupyter_code>%matplotlib inline
import xarray as xr
import numpy as np
import lccs_change
import matplotlib.pyplot as plt
import matplotlib as mplt<jupyter_output><empty_output><jupyter_text>Define your input files* *period1*: classified file for first time period* *period2*: classified file for second time period* *outputfile*: name of difference file to be save out<jupyter_code>period1 = xr.open_rasterio('Townsville-2010.tif')
period2 = xr.open_rasterio('Townsville-2015.tif')
outputfile =               'Townsville-diff.tif'

# period1 = xr.open_rasterio('Forescue-2010.tif')
# period2 = xr.open_rasterio('Forescue-2015.tif')
# outputfile =               'Forescue-diff.tif'

# period1 = xr.open_rasterio('Snowy-2010.tif')
# period2 = xr.open_rasterio('Snowy-2015.tif')
# outputfile =               'Snowy-diff.tif'

# period1 = xr.open_rasterio('Gwydir-2010.tif')
# period2 = xr.open_rasterio('Gwydir-2015.tif')
# outputfile =               'Gwydir-diff.tif'

# period1 = xr.open_rasterio('Leichhardt-2010.tif')
# period2 = xr.open_rasterio('Leichhardt-2015.tif')
# outputfile =               'Leichhardt-diff.tif'
# Drop "band" coord if present (thanks, rasterio)
if 'band' in period1.coords: period1 = period1.isel(band=0, drop=True)
if 'band' in period2.coords: period2 = period2.isel(band=0, drop=True)
    
# Examine unique values in the loaded data (debugging)
print("T0:",np.unique(period1.values))
print("T1:",np.unique(period2.values))<jupyter_output>T0: [111 112 123 124 215 216 227 228]
T1: [111 112 123 124 215 216 227 228]<jupyter_text>Run Change detection<jupyter_code># Process all changes
changes = lccs_change.LCCS_ChangeDetect(period1, period2)

# or, only a particular type of change
#changes = lccs_change.LCCS_ChangeDetect(period1, period2, showonly=['degradation'])

# print(changes)<jupyter_output><empty_output><jupyter_text>Visualise the changes CTV: Cultivated terrestrial veg NTV: Natural terrestrial vegCAV: Cultivated aquatic vegNAV: Natural aquatic vegAS: Artificial surfacesBS: Bare soilAW: Artificial waterNW: Natural water<jupyter_code>lccs_change.LCCS_Plot(changes)<jupyter_output><empty_output><jupyter_text>Detailed statistics about the changes<jupyter_code>changes.stats
piedata = np.array(changes.stats[['Description','Count']]).T
plt.figure(figsize=(14,3))
plt.grid(True, which='minor', axis='x')
plt.barh(piedata[0], piedata[1], log=True)
plt.gca().invert_yaxis()
plt.title('Pixel Count by Change Type')
plt.show()
# TODO: Change matrix w/ counts (or pcts)<jupyter_output><empty_output><jupyter_text>Save to disk<jupyter_code>lccs_change.write_diff(changes, outputfile, debug=False)
# # Check the output file
# %%bash -s "$outputfile"
# ls -lh $1
# gdalinfo $1<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11772530761556368, 'fraction_numerical': 0.042234785500498834, 'mean_word_length': 5.867579908675799, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '71878', 'license': 'Apache-2.0', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1043, 'n_words': 247, 'path': 'landcover_change_application/change_detection.ipynb', 'repo_name': 'opendatacube/datacube-conference-2019', 'size': '3007'}