{ "cells": [ { "cell_type": "markdown", "id": "355e0c61", "metadata": {}, "source": [ "# New Zealand DEM remake\n", "\n", "See the original notebook [here](https://nbviewer.org/github/royalosyin/Work-with-DEM-data-using-Python-from-Simple-to-Complicated/blob/master/Sup03-Ridgelines%20Map%20of%20DEM.ipynb)." ] }, { "cell_type": "code", "execution_count": 1, "id": "9d10728d", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "4d778c93", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "7faa0eb9", "metadata": {}, "outputs": [], "source": [ "def dataset_array_to_dataframe(dataset_array):\n", " df = pd.DataFrame.from_records([\n", " (j, i, a)\n", " for i, r in enumerate(dataset_array)\n", " for j, a in enumerate(r)\n", " ], columns=[\"x\", \"y\", \"h\"])\n", " return df\n", "\n", "def process_rows(df, step=1):\n", " def add_tails_to_row(subdf, y):\n", " xmin, xmax = subdf['x'].min(), subdf['x'].max()\n", " return pd.concat([\n", " subdf,\n", " pd.DataFrame({'x': [xmin - 1, xmax + 1], 'y': [y, y], 'h': [0, 0]})\n", " ], ignore_index=True).assign(h_max=lambda d: d['h'].max())\n", " return pd.concat([\n", " add_tails_to_row(df[df['y'] == y], y) for y in range(df['y'].min(), df['y'].max() + 1, step)\n", " ]).sort_values(by=['y', 'x']).reset_index(drop=True)" ] }, { "cell_type": "code", "execution_count": 4, "id": "439267fa", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(4243, 4)\n" ] }, { "data": { "text/html": [ "\n", " | x | \n", "y | \n", "h | \n", "h_max | \n", "
---|---|---|---|---|
0 | \n", "432 | \n", "6 | \n", "0.000000 | \n", "180.143860 | \n", "
1 | \n", "433 | \n", "6 | \n", "114.518776 | \n", "180.143860 | \n", "
2 | \n", "435 | \n", "6 | \n", "180.143860 | \n", "180.143860 | \n", "
3 | \n", "436 | \n", "6 | \n", "0.000000 | \n", "180.143860 | \n", "
4 | \n", "420 | \n", "8 | \n", "0.000000 | \n", "124.377769 | \n", "