From ffca4070728c75ca2c178fcd34717d7ae5a5cf16 Mon Sep 17 00:00:00 2001 From: Panos Mavrogiorgos Date: Fri, 5 May 2023 15:22:01 +0300 Subject: [PATCH] notebooks: Update notebooks/API.ipynb --- notebooks/API.ipynb | 100 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 78 insertions(+), 22 deletions(-) diff --git a/notebooks/API.ipynb b/notebooks/API.ipynb index a129cd3..05475b7 100644 --- a/notebooks/API.ipynb +++ b/notebooks/API.ipynb @@ -1,9 +1,19 @@ { "cells": [ + { + "cell_type": "markdown", + "id": "2b140634-be0f-40c4-8928-6ae5b04e35e3", + "metadata": { + "tags": [] + }, + "source": [ + "## Imports" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "f3e4d71b-357e-45e2-aa3e-9e89b1b662ab", + "id": "5c7e57bd-c71d-4dc0-83aa-3bbb397fc4d4", "metadata": { "tags": [] }, @@ -18,29 +28,29 @@ { "cell_type": "code", "execution_count": null, - "id": "768d9e0a-0ff5-4720-98a0-7d1b5d116042", + "id": "21da8e29-2fa0-4250-abaf-f952cdd71349", "metadata": { "tags": [] }, "outputs": [], "source": [ - "%load_ext autoreload\n", - "%autoreload 2" + "# debug\n", + "import sys\n", + "\n", + "print(sys.executable)\n", + "print(sys.version_info)" ] }, { "cell_type": "code", "execution_count": null, - "id": "d3538025-3dab-4ce1-b080-e9c70d32914b", + "id": "4e8dad1d-f5e5-498b-bc2c-063670fc2e83", "metadata": { "tags": [] }, "outputs": [], "source": [ - "import os\n", - "\n", - "os.environ['USE_PYGEOS'] = '0' # remove geopandas warnings\n", - "\n", + "# main imports\n", "import holoviews as hv\n", "import numpy as np\n", "import pandas as pd\n", @@ -49,26 +59,46 @@ "hv.extension(\"bokeh\")" ] }, + { + "cell_type": "markdown", + "id": "9f6cbedd-e4f7-43bc-bf06-a531826c14a5", + "metadata": { + "tags": [] + }, + "source": [ + "## Open a dataset\n", + "\n", + "Thalassa supports the output of several solvers (e.g. Schism, ADCIRC). \n", + "In order to do so, it converts the output of these files to a common \"schema\".\n", + "This process is called \"normalization\".\n", + "\n", + "> \"normalization\" == Renaming of dimensions and variables\n", + "\n", + "The most convenient way to apply this normalization process is to use the `api.open_dataset()` function which is a wrapper around `xr.open_dataset()`." + ] + }, { "cell_type": "code", "execution_count": null, - "id": "1779d199-055f-47f6-a296-f823cec4329c", + "id": "c34a0afe-9394-4f49-8edc-90418609a280", "metadata": { "tags": [] }, "outputs": [], "source": [ "%%bash\n", - "pushd /tmp\n", - "wget --quiet https://github.com/ec-jrc/Thalassa/files/10867068/fort.63.zip \n", - "unzip -o fort.63.zip\n", - "popd" + "if [[ ! -f /tmp/fort.63.nc ]]; then\n", + " pushd /tmp\n", + " wget --quiet https://github.com/ec-jrc/Thalassa/files/10867068/fort.63.zip \n", + " unzip -o fort.63.zip\n", + " popd\n", + "fi" ] }, { "cell_type": "code", "execution_count": null, - "id": "73965237-0675-49d1-ae01-e45a67bd77d4", + "id": "d1da964f-7982-47d2-862c-bdc4edd165b1", "metadata": { "tags": [] }, @@ -76,6 +106,18 @@ "source": [ "from thalassa import api\n", "\n", + "api.open_dataset?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8c0e749f-2b45-4244-944c-f8419133d43a", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ "filename = \"/tmp/fort.63.nc\"\n", "ds = api.open_dataset(filename)\n", "ds" @@ -92,7 +134,7 @@ "\n", "`thalassa` supports several types of graphs, including:\n", " \n", - "- A visualization of the variables at various timestamps and or layers.\n", + "- A visualization of the variables at various timestamps and/or layers.\n", "- A visualization of the mesh\n", "- Extraction of timeseries from specific points\n", "\n", @@ -145,23 +187,37 @@ { "cell_type": "code", "execution_count": null, - "id": "f42fc4d5-37ff-4195-8cb2-03986c2bcfaa", + "id": "43e0da2f-27ea-4bee-b3d1-6d6a9d800a2f", "metadata": { "tags": [] }, "outputs": [], "source": [ - "layout = tiles * raster.opts(width=600, cmap=\"viridis\") \n", - "layout\n", + "raster_layout = tiles * raster.opts(width=600, cmap=\"viridis\") \n", + "raster_layout\n", + "\n", "(pointer_dmap + tap_dmap).opts(shared_axes=False)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bac88601-c15e-4b74-841d-4e8f0d184566", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "mesh_layout = tiles * wireframe.opts(width=600)\n", + "mesh_layout" + ] } ], "metadata": { "kernelspec": { - "display_name": "thalassa", + "display_name": "python3", "language": "python", - "name": "thalassa" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -173,7 +229,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.16" + "version": "3.11.3" } }, "nbformat": 4,