<jupyter_start><jupyter_text>Xarray-spatial User Guide: Classification tools-----[Generate terrain](Generate-Terrain-Data)[Reclassify](Reclassify)-----------  Let's use datashader to render our images...<jupyter_code>import numpy as np
import datashader as ds
from datashader.transfer_functions import shade
from datashader.transfer_functions import stack
from datashader.transfer_functions import dynspread
from datashader.transfer_functions import set_background
from datashader.colors import Elevation

import xrspatial<jupyter_output><empty_output><jupyter_text>Generate Terrain DataThe rest of the geo-related functions focus on raster data (or rasterized data, after a previous Datashader step that returns an Xarray object). To demonstrate using these raster-based functions, let's generate some fake terrain as an elevation raster:<jupyter_code>from xrspatial import generate_terrain

W = 800
H = 600

cvs = ds.Canvas(plot_width=W, plot_height=H, x_range=(-20e6, 20e6), y_range=(-20e6, 20e6))
terrain = generate_terrain(canvas=cvs)

shade(terrain, cmap=['black', 'white'], how='linear')<jupyter_output><empty_output><jupyter_text>Reclassify  Quantile Reclassify<jupyter_code>from xrspatial import hillshade
from xrspatial import quantile

qcut_agg = quantile(terrain, k=15, ignore_vals=(0,))

stack(shade(hillshade(qcut_agg), cmap=['gray', 'white'], alpha=255, how='linear'),
      shade(qcut_agg,     cmap=Elevation,         alpha=128, how='linear'))<jupyter_output><empty_output><jupyter_text>Equal Interval Reclassify<jupyter_code>from xrspatial.classify import equal_interval
from xrspatial import hillshade

equal_interval_agg = equal_interval(terrain, k=15)

stack(shade(hillshade(equal_interval_agg), cmap=['gray', 'white'], alpha=255, how='linear'),
      shade(equal_interval_agg, cmap=Elevation, alpha=128, how='linear'))<jupyter_output><empty_output><jupyter_text>Natural Breaks (Jenks) Reclassify<jupyter_code>from xrspatial.classify import natural_breaks
from xrspatial import hillshade

natural_breaks_agg = natural_breaks(terrain, num_sample=1000, k=15)

stack(shade(hillshade(natural_breaks_agg), cmap=['gray', 'white'], alpha=255, how='linear'),
      shade(natural_breaks_agg, cmap=Elevation, alpha=128, how='linear'))<jupyter_output><empty_output><jupyter_text>Regions: Groupby Pixel-Value Connectivity<jupyter_code>from xrspatial.zonal import regions
from xrspatial import hillshade
from datashader.colors import Set1, Set3

regions_agg = regions(equal_interval_agg, neighborhood=4)

stack(shade(hillshade(regions_agg), cmap=['gray', 'white'], alpha=255, how='linear'),
      shade(regions_agg, cmap=Set1, alpha=128, how='eq_hist'))
from xrspatial import pathfinding
import pandas as pd


df = pd.DataFrame({
   'x': [-13, -11, -5, 4, 9, 11, 18, 6],
   'y': [-13, -5, 0, 10, 7, 2, 5, -5],
   'id': [1, 2, 3, 4, 5, 6, 7, 8]
})

cvs = ds.Canvas(plot_width=W, plot_height=H,
                x_range=(-20, 20), y_range=(-20, 20))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12370097217566209, 'fraction_numerical': 0.03184713375796178, 'mean_word_length': 6.957333333333334, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '281054', 'license': 'MIT', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1039, 'n_words': 238, 'path': 'examples/user_guide/5_Classification.ipynb', 'repo_name': 'thuydotm/xarray-spatial', 'size': '2983'}