{ "cells": [ { "cell_type": "markdown", "id": "44a202c1-ec83-4d8b-b232-6f69d7d55ace", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "## Precomputed: regridding numpy arrays" ] }, { "cell_type": "raw", "id": "ff059052-b505-4ff3-896a-f0ed48800f8d", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "This example shows how to interpolate numpy arrays using the :ref:`precomputed ` 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": [ "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), {'grid': [1, 1]})" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "res, res_grid = regrid(values, in_grid={\"grid\": \"O32\"}, out_grid={\"grid\": [1,1]}, backend=\"precomputed\") \n", "res.shape, res_grid" ] }, { "cell_type": "raw", "id": "2199e309-305e-46e6-b6db-747fcc3a1930", "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." ] }, { "cell_type": "code", "execution_count": null, "id": "3b00a3f6-5ce3-4175-8776-8c0331f82130", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "dev", "language": "python", "name": "dev" }, "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.12" } }, "nbformat": 4, "nbformat_minor": 5 }