{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Modify field data, by adding a white noise to it\n", "\n", "and visualization of differences as (DCT) variance spectrum plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:34:05.596532Z", "iopub.status.busy": "2025-01-13T11:34:05.596031Z", "iopub.status.idle": "2025-01-13T11:34:06.133825Z", "shell.execute_reply": "2025-01-13T11:34:06.133343Z" } }, "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:06.136088Z", "iopub.status.busy": "2025-01-13T11:34:06.135838Z", "iopub.status.idle": "2025-01-13T11:34:08.335561Z", "shell.execute_reply": "2025-01-13T11:34:08.335060Z" } }, "outputs": [], "source": [ "r = epygram.open(os.path.join(INPUTS_DIR, 'ICMSHAROM+0022'), 'r')\n", "t59 = r.readfield('S059TEMPERATURE')\n", "t59.sp2gp()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:34:08.337537Z", "iopub.status.busy": "2025-01-13T11:34:08.337354Z", "iopub.status.idle": "2025-01-13T11:34:08.524006Z", "shell.execute_reply": "2025-01-13T11:34:08.523527Z" } }, "outputs": [], "source": [ "# initial field\n", "sp59 = t59.dctspectrum()\n", "sp59.name = t59.fid['FA']" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:34:08.526156Z", "iopub.status.busy": "2025-01-13T11:34:08.525909Z", "iopub.status.idle": "2025-01-13T11:34:08.627364Z", "shell.execute_reply": "2025-01-13T11:34:08.626814Z" } }, "outputs": [], "source": [ "# add a white noise\n", "import numpy\n", "field_data = t59.getdata()\n", "noise = numpy.random.normal(0, size=field_data.shape)\n", "t59.setdata(field_data + noise)\n", "# and compute DCT spectrum\n", "sp59n = t59.dctspectrum()\n", "sp59n.name = sp59.name + '(noised)'" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:34:08.629073Z", "iopub.status.busy": "2025-01-13T11:34:08.628914Z", "iopub.status.idle": "2025-01-13T11:34:09.288090Z", "shell.execute_reply": "2025-01-13T11:34:09.287390Z" } }, "outputs": [], "source": [ "# and plot\n", "fig, ax = epygram.spectra.plotspectra([sp59, sp59n])" ] }, { "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 }