<jupyter_start><jupyter_text>Flow direction data The `FlwdirRaster` object is at the core of the pyflwdir package.It contains gridded flow direction data, parsed to an actionable common formatwhich describes the linear index of the next dowsntream cell.Currently we support two local flow direction (D8) data types according to the arcgis **D8** and pcraster **LDD** conventions (see figure), and one global flow direction type according to the CaMa-Flood **NEXTXY** convention. Local flow direction data types describe the next downstream cell based on a relative direction from a cell towards one of its neighboring cells, while global flow direction types describe the next downstream cell based on its row and column indices.   We read the flow direction raster data, including meta-data, using [rasterio](https://rasterio.readthedocs.io/en/latest/)<jupyter_code>import rasterio

with rasterio.open("rhine_d8.tif", "r") as src:
    flwdir = src.read(1)
    transform = src.transform
    crs = src.crs
    latlon = crs.to_epsg() == 4326<jupyter_output><empty_output><jupyter_text>Next, we parse this data to a `FlwdirRaster` object, the core object to work with flow direction data. In this step the D8 data is parsed to an actionable format. NOTE: that for most methods a first call might be a bit slow as the numba code is compiled just in time, a second call of the same methods (also with different arguments) will be much faster!<jupyter_code>import pyflwdir

flw = pyflwdir.from_array(
    flwdir, ftype="d8", transform=transform, latlon=latlon, cache=True
)
# When printing the FlwdirRaster instance we see its attributes.
print(flw)<jupyter_output><empty_output><jupyter_text>We can than make use of the many methods of the `FlwdirRaster` object, see [FlwdirRaster API](reference.rst). To visualize the flow directions we derive the stream network as vector using the [streams()](reference.rstpyflwdir.FlwdirRaster.streams) method.Each line element respresnets a stream segment with a minimal Strahler stream order of `min_sto`, as computed by [stream_order()](reference.rstpyflwdir.FlwdirRaster.stream_order).The line elements (geo features) are parsed to a [GeoDataFrame](https://geopandas.org/data_structures.htmlgeodataframe) object for visualization.<jupyter_code>import geopandas as gpd

feats = flw.streams(min_sto=4)
gdf = gpd.GeoDataFrame.from_features(feats, crs=crs)
gdf.head()
# plot
import numpy as np

# local convenience methods (see utils.py script in notebooks folder)
from utils import quickplot, colors, cm  # data specific quick plot method

# key-word arguments passed to GeoDataFrame.plot method
gdf_plot_kwds = dict(
    column="strord", cmap=colors.ListedColormap(cm.Blues(np.linspace(0.4, 1, 7)))
)
# plot streams with hillshade from elevation data (see utils.py)
ax = quickplot(gdfs=[(gdf, gdf_plot_kwds)], title="Streams")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07889273356401384, 'fraction_numerical': 0.005190311418685121, 'mean_word_length': 5.600456621004566, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 2, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '609342', 'license': 'MIT', 'n_tokens_mistral': 893, 'n_tokens_neox': 869, 'n_words': 337, 'path': 'notebooks/flwdir.ipynb', 'repo_name': 'Jiangchao3/pyflwdir', 'size': '2890'}