{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Morphing: apply a local deformation of field" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:34:29.677620Z", "iopub.status.busy": "2025-01-13T11:34:29.677142Z", "iopub.status.idle": "2025-01-13T11:34:30.210049Z", "shell.execute_reply": "2025-01-13T11:34:30.209543Z" } }, "outputs": [], "source": [ "%matplotlib inline\n", "# for figures in notebook\n", "\n", "# import & initialize epygram\n", "import epygram\n", "epygram.init_env()\n", "\n", "import os\n", "INPUTS_DIR = os.path.join('..', 'inputs')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:34:30.212271Z", "iopub.status.busy": "2025-01-13T11:34:30.212061Z", "iopub.status.idle": "2025-01-13T11:34:30.411313Z", "shell.execute_reply": "2025-01-13T11:34:30.410755Z" } }, "outputs": [], "source": [ "r = epygram.open(os.path.join(INPUTS_DIR, 'ICMSHAROM+0022'), 'r')\n", "f = r.readfield('SURFTEMPERATURE')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:34:30.413465Z", "iopub.status.busy": "2025-01-13T11:34:30.413265Z", "iopub.status.idle": "2025-01-13T11:34:30.950205Z", "shell.execute_reply": "2025-01-13T11:34:30.949866Z" } }, "outputs": [], "source": [ "fig, ax = f.cartoplot(subzone='CI')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:34:30.953250Z", "iopub.status.busy": "2025-01-13T11:34:30.952937Z", "iopub.status.idle": "2025-01-13T11:34:30.957789Z", "shell.execute_reply": "2025-01-13T11:34:30.957407Z" } }, "outputs": [], "source": [ "# make 2 PointFields by extracting them from the field\n", "p1 = f.extract_point(8,45)\n", "p2 = f.extract_point(8.5, 45.5)\n", "print(p1.getdata(), p2.getdata())" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:34:30.959650Z", "iopub.status.busy": "2025-01-13T11:34:30.959341Z", "iopub.status.idle": "2025-01-13T11:34:30.961573Z", "shell.execute_reply": "2025-01-13T11:34:30.961245Z" } }, "outputs": [], "source": [ "# set arbitrary different values\n", "p1.setdata(270)\n", "p2.setdata(285)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:34:30.963281Z", "iopub.status.busy": "2025-01-13T11:34:30.963138Z", "iopub.status.idle": "2025-01-13T11:34:35.756894Z", "shell.execute_reply": "2025-01-13T11:34:35.756391Z" } }, "outputs": [], "source": [ "f.morph_with_points([p1, p2], morphing='gaussian', sigma=10000) # gaussian blending weight with 10km sigma" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:34:35.758967Z", "iopub.status.busy": "2025-01-13T11:34:35.758792Z", "iopub.status.idle": "2025-01-13T11:34:36.076695Z", "shell.execute_reply": "2025-01-13T11:34:36.076293Z" } }, "outputs": [], "source": [ "fig, ax = f.cartoplot(subzone='CI')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:34:36.079450Z", "iopub.status.busy": "2025-01-13T11:34:36.079261Z", "iopub.status.idle": "2025-01-13T11:34:38.504623Z", "shell.execute_reply": "2025-01-13T11:34:38.504171Z" } }, "outputs": [], "source": [ "# or as increment (less brutal):\n", "p = f.extract_point(7,46)\n", "p.setdata(+10) # +10K increment\n", "f.morph_with_points([p], morphing='gaussian', sigma=10000, increment=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:34:38.506475Z", "iopub.status.busy": "2025-01-13T11:34:38.506274Z", "iopub.status.idle": "2025-01-13T11:34:38.821969Z", "shell.execute_reply": "2025-01-13T11:34:38.821486Z" } }, "outputs": [], "source": [ "fig, ax = f.cartoplot(subzone='CI')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.10.12" } }, "nbformat": 4, "nbformat_minor": 1 }