{ "cells": [ { "cell_type": "markdown", "id": "9ca99456-817b-4669-aead-8c7d7435b0dc", "metadata": {}, "source": [ "## Polytope polygons forming a word" ] }, { "cell_type": "markdown", "id": "36b3cbce-657d-415d-a669-7f1eaeefa7d2", "metadata": {}, "source": [ "This example retrieves polygon coverages forming the word \"POLYTOPE\" from polytope and plots it onto a map." ] }, { "cell_type": "code", "execution_count": 1, "id": "bfc4e565-98cb-4e96-8deb-95e98bc6465e", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2024-12-18 09:10:11 - INFO - Key read from /Users/cgr/.polytopeapirc\n", "2024-12-18 09:10:11 - INFO - Sending request...\n", "{'request': 'class: od\\n'\n", " 'date: -1\\n'\n", " 'domain: g\\n'\n", " 'expver: 1\\n'\n", " 'feature:\\n'\n", " ' shape:\\n'\n", " ' - - - 7.258763811234218\\n'\n", " ' - 48.793723130601535\\n'\n", " ' - - 7.168488316250347\\n'\n", " ' - 49.83398497089428\\n'\n", " ' - - 8.21596726115746\\n'\n", " ' - 49.850900108140536\\n'\n", " ' - - 8.22477419294512\\n'\n", " ' - 49.63238869079714\\n'\n", " ' - - 7.425045773152021\\n'\n", " ' - 49.6375037902404\\n'\n", " ' - - 7.488604743081794\\n'\n", " ' - 48.76751542040529\\n'\n", " ' - - 7.262985428883866\\n'\n", " ' - 48.762974824632806\\n'\n", " ' type: polygon\\n'\n", " 'levtype: sfc\\n'\n", " \"number: '1'\\n\"\n", " \"param: '167'\\n\"\n", " \"step: '0'\\n\"\n", " 'stream: enfo\\n'\n", " \"time: '1200'\\n\"\n", " 'type: pf\\n',\n", " 'verb': 'retrieve'}\n", "2024-12-18 09:10:11 - INFO - Polytope user key found in session cache for user cgr\n", "2024-12-18 09:10:12 - INFO - Request accepted. Please poll ./cdcfe067-f976-47d3-8015-437dffe0d2f8 for status\n", "2024-12-18 09:10:12 - INFO - Polytope user key found in session cache for user cgr\n", "2024-12-18 09:10:12 - INFO - Checking request status (./cdcfe067-f976-47d3-8015-437dffe0d2f8)...\n", "2024-12-18 09:10:12 - INFO - The current status of the request is 'queued'\n", "2024-12-18 09:10:13 - INFO - The current status of the request is 'processing'\n", "2024-12-18 09:10:15 - INFO - The current status of the request is 'processed'\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "cdcfe067-f976-47d3-8015-437dffe0d2f8.covjson: 0%| | 0.00/5.91k [00:00" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import earthkit.data as ekd\n", "import earthkit.plots as ekp\n", "\n", "# define the polygons\n", "shape1 = [\n", " [7.258763811234218, 48.793723130601535],\n", " [7.168488316250347, 49.83398497089428],\n", " [8.21596726115746, 49.850900108140536],\n", " [8.22477419294512, 49.63238869079714],\n", " [7.425045773152021, 49.6375037902404],\n", " [7.488604743081794, 48.76751542040529],\n", " [7.262985428883866, 48.762974824632806],\n", "],\n", "\n", "shape2 = [\n", " [8.228175484385758, 49.62363905618946],\n", " [8.2383404847414, 49.30577331470633],\n", " [7.468517996271913, 49.29035950951544],\n", " [7.442698254298165, 49.394063349552624],\n", " [8.0965165757963, 49.41322522398369],\n", " [8.09028856771124, 49.63518066374158],\n", "]\n", "\n", "shape3 = [\n", " [8.778584932744309, 49.86954658650521],\n", " [8.862295524771469, 48.766918864990714],\n", " [10.061878585703141, 48.80521538773752],\n", " [10.05189374814043, 49.02912712169905],\n", " [9.126374708842917, 49.035317308040874],\n", " [9.054787898083248, 49.85647839775169],\n", " [8.79447274483195, 49.8646339236731],\n", "]\n", "\n", "shape4 = [\n", " [9.088892121315212, 49.68396293291025],\n", " [9.819571610135483, 49.684014501470756],\n", " [9.85505960658449, 49.03116952568445],\n", " [10.060153571012052, 49.027505122195635],\n", " [10.072160282281033, 49.86449197101945],\n", " [9.05948442169526, 49.85694532601448],\n", " [9.071912795654185, 49.68014004987609],\n", "]\n", "\n", "shape5 = [\n", " [10.598471035757996, 49.82012849229719],\n", " [10.623393389597027, 48.824858944891844],\n", " [12.04024144738159, 48.83198005307881],\n", " [12.006769966371252, 49.16097358155085],\n", " [10.989756517888907, 49.16815641449875],\n", " [10.948052430339942, 49.88592726422476],\n", " [10.596882802957197, 49.86398061258498],\n", "]\n", "\n", "shape6 = [\n", " [13.29197987307927, 49.97728585641272],\n", " [12.57111275146977, 49.97104094778115],\n", " [13.222322323273431, 49.37725327518439],\n", " [13.202971158951414, 48.903129615084254],\n", " [13.827804957331438, 48.88340416595227],\n", " [13.874384556433938, 49.40358865952578],\n", " [14.605299546055448, 49.93197478940584],\n", " [14.102062445091747, 49.98001098000407],\n", " [13.624487089218775, 49.55461007587729],\n", " [13.3099890365134, 49.97739580806973],\n", "]\n", "\n", "shape7 = [\n", " [15.228965549991614, 49.730373613580525],\n", " [15.230125323821682, 50.090633313563075],\n", " [17.660387372585035, 50.06822116337625],\n", " [17.577939895914568, 49.59398017760927],\n", " [16.752386182433355, 49.64920447268295],\n", " [16.58109059401943, 48.772986118860814],\n", " [16.094304206428518, 48.79160176954642],\n", " [16.185638387834643, 49.640410835320694],\n", " [15.250602552532541, 49.68736034043533],\n", "]\n", "\n", "shape8 = [\n", " [18.006103810711153, 49.874817453680265],\n", " [17.872892800864577, 48.7751276419595],\n", " [19.231045390320162, 48.68751356669205],\n", " [19.286273043798417, 48.9720484447422],\n", " [18.331513679782546, 49.02466456647059],\n", " [18.4410677556115, 49.91883884509102],\n", " [17.990407455442124, 49.9284320053506],\n", "]\n", "\n", "shape9 = [\n", " [18.523099688262818, 49.91693240270905],\n", " [19.571993355132093, 49.88820196224816],\n", " [19.269541055964595, 48.99870007380369],\n", " [18.989650825560034, 49.00717933216285],\n", " [19.1721361339051, 49.67352579852684],\n", " [18.42049036941708, 49.71965669030075],\n", " [18.436899591803154, 49.93131406908293],\n", "]\n", "\n", "shape10 = [\n", " [20.369665233263703, 48.68540724766882],\n", " [20.390795716706066, 49.82142033684306],\n", " [21.66474097162009, 49.77219361759094],\n", " [21.599781134603887, 49.45580574399338],\n", " [20.770239556798373, 49.481617120321545],\n", " [20.773898383565665, 48.68594678666463],\n", " [20.369665233263703, 48.68540724766882],\n", "]\n", "\n", "shape11 = [\n", " [20.779400086097894, 49.266396683614516],\n", " [21.291684316951347, 49.25582141560005],\n", " [21.29255644055283, 49.462413633894414],\n", " [21.60241816111113, 49.44412952745972],\n", " [21.577574878322366, 49.16620350494162],\n", " [20.792010318248543, 49.16233120403493],\n", " [20.768637193550887, 49.273598233154075],\n", "]\n", "\n", "shape12 = [\n", " [23.208137901360374, 49.651584260796994],\n", " [22.09658437133257, 49.752545184049126],\n", " [21.91802865423628, 48.67264127283525],\n", " [23.391185304246818, 48.62884428299256],\n", " [23.420678366377672, 48.95370738548149],\n", " [22.47620509293023, 48.948108124274114],\n", " [22.504379835652145, 49.154931298807696],\n", " [23.380718740911448, 49.134280180441834],\n", " [23.347965550435475, 49.36007407350195],\n", " [22.508043914644247, 49.34861103718032],\n", " [22.552065252592882, 49.49663569230876],\n", " [23.44022825068265, 49.49121931651345],\n", " [23.257411122842967, 49.664632737235905],\n", "]\n", "\n", "\n", "request_pattern = {\n", " \"class\": \"od\",\n", " \"stream\" : \"enfo\",\n", " \"type\" : \"pf\",\n", " \"date\" : -1,\n", " \"time\" : \"1200\",\n", " \"levtype\" : \"sfc\",\n", " \"expver\" : 1,\n", " \"domain\" : \"g\",\n", " \"param\" : \"167\",\n", " \"number\" : \"1\",\n", " \"step\": \"0\",\n", "}\n", "\n", "chart = ekp.Map(domain=\"Europe\")\n", "\n", "for shape in [shape1, shape2, shape3, shape4, shape5, shape6, shape7, shape8, shape9, shape10, shape11, shape12]:\n", "\n", " # retrive the given coverage from polytope and convert into Xarray\n", " request = dict(**request_pattern)\n", " request[\"feature\"] = {\"type\": \"polygon\", \"shape\": shape}\n", "\n", " ds = ekd.from_source(\"polytope\", \"ecmwf-mars\", request, stream=False, \n", " address='polytope.ecmwf.int').to_xarray()\n", "\n", " # add the Xarray dataset to the plot\n", " chart.point_cloud(ds['2t'], x=\"x\", y=\"y\",s=0.1)\n", "\n", "# generate the plot\n", "chart.coastlines()\n", "chart.borders()\n", "chart.gridlines()\n", " \n", "chart.title(\"{variable_name} (number={number})\")\n", " \n", "chart.show()" ] } ], "metadata": { "kernelspec": { "display_name": "dev_ecc", "language": "python", "name": "dev_ecc" }, "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.10.13" } }, "nbformat": 4, "nbformat_minor": 5 }