{ "cells": [ { "cell_type": "markdown", "id": "cd110cd9-f40e-4ccf-b702-b40d611f60bf", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "## MIR: regridding numpy arrays" ] }, { "cell_type": "raw", "id": "e6004fb6-603c-4671-977c-3ce72e16a42d", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "This example shows how to interpolate numpy arrays using the :ref:`mir ` backend." ] }, { "cell_type": "code", "execution_count": 1, "id": "5854d65c-ef1e-4c99-8c09-fa8e7612f399", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [], "source": [ "from earthkit.regrid.array import regrid\n", "import numpy as np" ] }, { "cell_type": "markdown", "id": "de55e418-ffa0-4609-b6dc-a9b23ebe77b8", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "First, we generate random data matching the size of an O32 octahedral reduced Gaussian grid." ] }, { "cell_type": "code", "execution_count": 2, "id": "a71db0be-2233-4133-b03f-9219dc84e3f3", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [], "source": [ "values = np.random.random(5248)" ] }, { "cell_type": "raw", "id": "c1a951b8-f550-45f1-aef4-3bed884a7bdf", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "Next, interpolate the array onto a 1x1 degree global regular latitude-longitude grid using :ref:`regrid() `. The input and output grids are defined by a :ref:`gridspec `. Both the input and the output values are numpy arrays." ] }, { "cell_type": "code", "execution_count": 3, "id": "24ccc6b5-90c2-4e4d-8175-677c5d0f12ed", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [ { "data": { "text/plain": [ "((181, 360),\n", " {'east': 359, 'grid': [1, 1], 'north': 90, 'south': -90, 'west': 0})" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "res, res_grid = regrid(values, in_grid={\"grid\": \"O32\"}, out_grid={\"grid\": [1,1]}) \n", "res.shape, res_grid" ] }, { "cell_type": "raw", "id": "537e772f-d965-42dc-b395-62a3be7eb7f5", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ ":ref:`regrid() ` returns a tuple with the regridded array and the resulting gridspec. This latter might be different than the one specified in ``out_grid`` because MIR can perform normalisation and other adjustments on it. " ] }, { "cell_type": "code", "execution_count": null, "id": "13cac978-b11a-463d-a877-9b3bdfb9b7b0", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "mir", "language": "python", "name": "mir" }, "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.13.1" } }, "nbformat": 4, "nbformat_minor": 5 }