{ "cells": [ { "attachments": {}, "cell_type": "markdown", "id": "fe5f8c50-64ec-4f30-929d-fd457b8a2ec1", "metadata": {}, "source": [ "# Cubes Visualization with Lexcube" ] }, { "attachments": {}, "cell_type": "markdown", "id": "fee89449-12da-494c-bb02-684bf14cad01", "metadata": {}, "source": [ "This tutorial shows how to visualize different cubes using Lexcube:" ] }, { "cell_type": "code", "execution_count": 1, "id": "d6b60e78-9e6c-40d8-bbea-dccc66376347", "metadata": {}, "outputs": [], "source": [ "import cubo\n", "import lexcube" ] }, { "cell_type": "markdown", "id": "b75eaf5f-db3c-4c0b-a57e-4c0e930e3201", "metadata": {}, "source": [ "If you are in Google Colab you have to run the following cell:" ] }, { "cell_type": "code", "execution_count": null, "id": "9a250d0c-b500-4cb3-9cf1-b63327789e26", "metadata": {}, "outputs": [], "source": [ "# from google.colab import output\n", "# output.enable_custom_widget_manager()" ] }, { "cell_type": "markdown", "id": "0c782f3e-9afa-4463-9d08-39acab77da92", "metadata": {}, "source": [ "## Sentinel-2\n", "\n", "An example over crop fields in Colombia." ] }, { "cell_type": "code", "execution_count": 2, "id": "8ead0866-3b85-4b04-97c0-b38742df9b80", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/net/home/dmontero/.conda/envs/cube/lib/python3.11/site-packages/stackstac/prepare.py:408: UserWarning: The argument 'infer_datetime_format' is deprecated and will be removed in a future version. A strict version of it is now the default, see https://pandas.pydata.org/pdeps/0004-consistent-to-datetime-parsing.html. You can safely remove this argument.\n", " times = pd.to_datetime(\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d0fb535457894a53a80e3f64cf865024", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Cube3DWidget(api_metadata={'/api': {'status': 'ok', 'api_version': 5}, '/api/datasets': [{'id': 'default', 'sh…" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s2 = cubo.create(\n", " lat=4.31,\n", " lon=-76.2,\n", " collection=\"sentinel-2-l2a\",\n", " bands=[\"B02\",\"B03\",\"B04\"],\n", " start_date=\"2019-01-01\",\n", " end_date=\"2021-12-31\",\n", " edge_size=64,\n", " resolution=10,\n", " query={\"eo:cloud_cover\": {\"lt\": 40}}\n", ")\n", "\n", "ws2 = lexcube.Cube3DWidget(s2.sel(band=\"B04\"), cmap=\"viridis\", vmin=0, vmax=2000)\n", "ws2" ] }, { "cell_type": "markdown", "id": "3c4a1f25-7002-4dbf-bf6e-d9bbe3874b43", "metadata": {}, "source": [ "## Sentinel-1\n", "\n", "A C-band cube over the Panama Canal." ] }, { "cell_type": "code", "execution_count": 5, "id": "6ac0c7bf-7a46-4fd6-911b-c629625222f8", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/net/home/dmontero/.conda/envs/cube/lib/python3.11/site-packages/stackstac/prepare.py:408: UserWarning: The argument 'infer_datetime_format' is deprecated and will be removed in a future version. A strict version of it is now the default, see https://pandas.pydata.org/pdeps/0004-consistent-to-datetime-parsing.html. You can safely remove this argument.\n", " times = pd.to_datetime(\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "70cc3db0f13c4c3cbd90e6d9767379e4", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Cube3DWidget(api_metadata={'/api': {'status': 'ok', 'api_version': 5}, '/api/datasets': [{'id': 'default', 'sh…" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s1 = cubo.create(\n", " lat=8.93548,\n", " lon=-79.56005,\n", " collection=\"sentinel-1-rtc\",\n", " bands=[\"vv\",\"vh\"],\n", " start_date=\"2021-01-01\",\n", " end_date=\"2021-12-31\",\n", " edge_size=256,\n", " resolution=10,\n", ")\n", "\n", "ws1 = lexcube.Cube3DWidget(s1.sel(band=\"vv\"), cmap=\"Greys_r\", vmin=0, vmax=0.6)\n", "ws1" ] }, { "cell_type": "markdown", "id": "489fe636-b6a2-4882-8165-e4457d86aa7c", "metadata": {}, "source": [ "## MODIS Gross Primary Productivity (GPP)\n", "\n", "GPP over the Hainich National Park in Germany." ] }, { "cell_type": "code", "execution_count": 6, "id": "cfc12730-c388-42d4-9db1-b182027ba15a", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/net/home/dmontero/.conda/envs/cube/lib/python3.11/site-packages/stackstac/prepare.py:408: UserWarning: The argument 'infer_datetime_format' is deprecated and will be removed in a future version. A strict version of it is now the default, see https://pandas.pydata.org/pdeps/0004-consistent-to-datetime-parsing.html. You can safely remove this argument.\n", " times = pd.to_datetime(\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "f2d762d0d98440d8b9cf8dce35b01e8b", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Cube3DWidget(api_metadata={'/api': {'status': 'ok', 'api_version': 5}, '/api/datasets': [{'id': 'default', 'sh…" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gpp = cubo.create(\n", " lat=51.0825008,\n", " lon=10.437455,\n", " collection=\"modis-17A2H-061\",\n", " bands=[\"Gpp_500m\"], \n", " start_date=\"2022-01-01\", \n", " end_date=\"2022-12-31\",\n", " edge_size=64, \n", " resolution=500,\n", ").where(lambda x: x[\"platform\"] == \"terra\",drop=True)\n", "\n", "wgpp = lexcube.Cube3DWidget(gpp.sel(band=\"Gpp_500m\"), cmap=\"YlGn\", vmin=0, vmax=0.1)\n", "wgpp" ] }, { "cell_type": "markdown", "id": "09c87326-d55c-45c1-ac18-5ca576b6a2c3", "metadata": {}, "source": [ "## MODIS Land Surface Temperature (LST)\n", "\n", "LST over Budapest." ] }, { "cell_type": "code", "execution_count": 12, "id": "bac80211-b8de-426e-b9f7-87d9d040c633", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/net/home/dmontero/.conda/envs/cube/lib/python3.11/site-packages/stackstac/prepare.py:408: UserWarning: The argument 'infer_datetime_format' is deprecated and will be removed in a future version. A strict version of it is now the default, see https://pandas.pydata.org/pdeps/0004-consistent-to-datetime-parsing.html. You can safely remove this argument.\n", " times = pd.to_datetime(\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "9edd9a7db6b346d48cd2bff345fc3872", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Cube3DWidget(api_metadata={'/api': {'status': 'ok', 'api_version': 5}, '/api/datasets': [{'id': 'default', 'sh…" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lst = cubo.create(\n", " lat=47.49744,\n", " lon=19.048363,\n", " collection=\"modis-11A2-061\",\n", " bands=[\"LST_Day_1km\"], \n", " start_date=\"2022-01-01\", \n", " end_date=\"2022-12-31\",\n", " edge_size=128, \n", " resolution=500,\n", ").where(lambda x: x[\"platform\"] == \"terra\",drop=True)\n", "\n", "wlst = lexcube.Cube3DWidget(lst.sel(band=\"LST_Day_1km\"), cmap=\"inferno\", vmin=270, vmax=310)\n", "wlst" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.6" } }, "nbformat": 4, "nbformat_minor": 5 }