{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Apply a mask using another field\n", "\n", "in this case, use the land-sea mask field to mask non-land values" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:34:11.207736Z", "iopub.status.busy": "2025-01-13T11:34:11.206547Z", "iopub.status.idle": "2025-01-13T11:34:11.740269Z", "shell.execute_reply": "2025-01-13T11:34:11.739792Z" } }, "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:11.742469Z", "iopub.status.busy": "2025-01-13T11:34:11.742253Z", "iopub.status.idle": "2025-01-13T11:34:11.886123Z", "shell.execute_reply": "2025-01-13T11:34:11.885619Z" } }, "outputs": [], "source": [ "r = epygram.open(os.path.join(INPUTS_DIR, 'ICMSHAROM+0022'), 'r')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:34:11.888172Z", "iopub.status.busy": "2025-01-13T11:34:11.887955Z", "iopub.status.idle": "2025-01-13T11:34:11.944257Z", "shell.execute_reply": "2025-01-13T11:34:11.943831Z" } }, "outputs": [], "source": [ "f = r.readfield('SURFTEMPERATURE')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:34:11.945793Z", "iopub.status.busy": "2025-01-13T11:34:11.945615Z", "iopub.status.idle": "2025-01-13T11:34:12.479406Z", "shell.execute_reply": "2025-01-13T11:34:12.479029Z" } }, "outputs": [], "source": [ "fig, ax = f.cartoplot(subzone='CI')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:34:12.482243Z", "iopub.status.busy": "2025-01-13T11:34:12.482074Z", "iopub.status.idle": "2025-01-13T11:34:12.485414Z", "shell.execute_reply": "2025-01-13T11:34:12.485089Z" } }, "outputs": [], "source": [ "lsm = r.readfield('SURFIND.TERREMER')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:34:12.487001Z", "iopub.status.busy": "2025-01-13T11:34:12.486846Z", "iopub.status.idle": "2025-01-13T11:34:12.791375Z", "shell.execute_reply": "2025-01-13T11:34:12.790867Z" } }, "outputs": [], "source": [ "fig, ax = lsm.cartoplot(subzone='CI')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:34:12.793231Z", "iopub.status.busy": "2025-01-13T11:34:12.793074Z", "iopub.status.idle": "2025-01-13T11:34:12.796434Z", "shell.execute_reply": "2025-01-13T11:34:12.796010Z" } }, "outputs": [], "source": [ "import numpy\n", "masked_data = numpy.ma.masked_where(lsm.getdata() < 0.5, f.getdata())\n", "f.setdata(masked_data)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:34:12.798151Z", "iopub.status.busy": "2025-01-13T11:34:12.797758Z", "iopub.status.idle": "2025-01-13T11:34:13.115384Z", "shell.execute_reply": "2025-01-13T11:34:13.114877Z" } }, "outputs": [], "source": [ "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 }