{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# ipygany\n", "\n", "[ipygany](https://ipygany.readthedocs.io/en/latest/) is a library that allows client side GPU rendering. This is useful because the data is sotred on the server and manipulations of the visualisation are near realtime.\n", "\n", "This example:\n", "1. Imports a netcdf file using xarray\n", "1. Converts the netcdf file to a pyvista structured mesh\n", "1. Converts the pyvista mesh to ipygany mesh\n", "1. Colors and warps the mesh\n", "1. Shows the interaction\n", "\n", "## Imports" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pyvista as pv\n", "import numpy as np\n", "import xarray as xr\n", "\n", "from ipygany import PolyMesh, Scene, IsoColor, WarpByScalar, ColorBar, colormaps\n", "from ipywidgets import VBox, FloatSlider, FileUpload, Dropdown, jslink" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Data upload" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "94b526e389de48bf850bf4994f266bcc", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FileUpload(value={}, description='Upload')" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Create file upload\n", "# To load several files press shift with selecting - \n", "#all the files have to be selected at the same time.\n", "\n", "file_upload = FileUpload(multiple=False)\n", "file_upload" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n", "Dimensions: (lat: 180, lon: 360)\n", "Coordinates:\n", " * lon (lon) float64 -179.5 -178.5 -177.5 -176.5 ... 177.5 178.5 179.5\n", " * lat (lat) float64 -89.5 -88.5 -87.5 -86.5 -85.5 ... 86.5 87.5 88.5 89.5\n", "Data variables:\n", " TOPO (lat, lon) float32 187.9 179.5 420.2 ... -3.48e+03 -3.48e+03\n", "Attributes:\n", " history: Created with add_noise.ncl -- 08.06.21 JBL
array([-179.5, -178.5, -177.5, ..., 177.5, 178.5, 179.5])
array([-89.5, -88.5, -87.5, -86.5, -85.5, -84.5, -83.5, -82.5, -81.5, -80.5,\n", " -79.5, -78.5, -77.5, -76.5, -75.5, -74.5, -73.5, -72.5, -71.5, -70.5,\n", " -69.5, -68.5, -67.5, -66.5, -65.5, -64.5, -63.5, -62.5, -61.5, -60.5,\n", " -59.5, -58.5, -57.5, -56.5, -55.5, -54.5, -53.5, -52.5, -51.5, -50.5,\n", " -49.5, -48.5, -47.5, -46.5, -45.5, -44.5, -43.5, -42.5, -41.5, -40.5,\n", " -39.5, -38.5, -37.5, -36.5, -35.5, -34.5, -33.5, -32.5, -31.5, -30.5,\n", " -29.5, -28.5, -27.5, -26.5, -25.5, -24.5, -23.5, -22.5, -21.5, -20.5,\n", " -19.5, -18.5, -17.5, -16.5, -15.5, -14.5, -13.5, -12.5, -11.5, -10.5,\n", " -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,\n", " 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5,\n", " 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, 16.5, 17.5, 18.5, 19.5,\n", " 20.5, 21.5, 22.5, 23.5, 24.5, 25.5, 26.5, 27.5, 28.5, 29.5,\n", " 30.5, 31.5, 32.5, 33.5, 34.5, 35.5, 36.5, 37.5, 38.5, 39.5,\n", " 40.5, 41.5, 42.5, 43.5, 44.5, 45.5, 46.5, 47.5, 48.5, 49.5,\n", " 50.5, 51.5, 52.5, 53.5, 54.5, 55.5, 56.5, 57.5, 58.5, 59.5,\n", " 60.5, 61.5, 62.5, 63.5, 64.5, 65.5, 66.5, 67.5, 68.5, 69.5,\n", " 70.5, 71.5, 72.5, 73.5, 74.5, 75.5, 76.5, 77.5, 78.5, 79.5,\n", " 80.5, 81.5, 82.5, 83.5, 84.5, 85.5, 86.5, 87.5, 88.5, 89.5])
array([[ 187.87802, 179.5152 , 420.18768, ..., 347.60684, 239.41174,\n", " 328.91446],\n", " [ 235.72939, 183.35826, 130.25673, ..., 371.88663, 166.54791,\n", " 501.75983],\n", " [ 306.57602, 315.51505, 293.3875 , ..., 346.78452, 228.24268,\n", " 200.96342],\n", " ...,\n", " [-3480. , -3480. , -3480. , ..., -3480. , -3480. ,\n", " -3480. ],\n", " [-3480. , -3480. , -3480. , ..., -3480. , -3480. ,\n", " -3480. ],\n", " [-3480. , -3480. , -3480. , ..., -3480. , -3480. ,\n", " -3480. ]], dtype=float32)