{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Aggregate model-level fields to a 3D-field, save it to netCDF" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:32:07.711491Z", "iopub.status.busy": "2025-01-13T11:32:07.711171Z", "iopub.status.idle": "2025-01-13T11:32:08.235406Z", "shell.execute_reply": "2025-01-13T11:32:08.234928Z" } }, "outputs": [], "source": [ "# for figures in notebook\n", "%matplotlib inline\n", "# import & initialize epygram\n", "import epygram\n", "epygram.init_env()\n", "# path to file\n", "import os\n", "INPUTS_DIR = os.path.join('..', 'inputs')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:32:08.237598Z", "iopub.status.busy": "2025-01-13T11:32:08.237370Z", "iopub.status.idle": "2025-01-13T11:32:08.378807Z", "shell.execute_reply": "2025-01-13T11:32:08.378300Z" } }, "outputs": [], "source": [ "# open resource as a meta-CL-resource, CL = Combine Levels\n", "r = epygram.resources.meta_resource(os.path.join(INPUTS_DIR, 'ICMSHAROM+0022'), 'r', 'CL')\n", "# in this case, field need to be defined with GRIB2 nomenclature" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:32:08.380946Z", "iopub.status.busy": "2025-01-13T11:32:08.380728Z", "iopub.status.idle": "2025-01-13T11:32:10.833468Z", "shell.execute_reply": "2025-01-13T11:32:10.832957Z" } }, "outputs": [], "source": [ "f = r.readfield({'discipline':0, 'parameterCategory':0, 'parameterNumber':0, 'typeOfFirstFixedSurface':119})" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:32:10.835620Z", "iopub.status.busy": "2025-01-13T11:32:10.835405Z", "iopub.status.idle": "2025-01-13T11:32:10.953519Z", "shell.execute_reply": "2025-01-13T11:32:10.953044Z" } }, "outputs": [], "source": [ "print(f.spectral)\n", "f.sp2gp()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:32:10.955444Z", "iopub.status.busy": "2025-01-13T11:32:10.955239Z", "iopub.status.idle": "2025-01-13T11:32:10.957882Z", "shell.execute_reply": "2025-01-13T11:32:10.957493Z" } }, "outputs": [], "source": [ "print(f.getdata(d4=True).shape)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:32:10.959519Z", "iopub.status.busy": "2025-01-13T11:32:10.959327Z", "iopub.status.idle": "2025-01-13T11:32:11.982326Z", "shell.execute_reply": "2025-01-13T11:32:11.981804Z" } }, "outputs": [], "source": [ "f.dump_to_nc('/tmp/temp.nc', variablename='temperature')" ] }, { "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": 2 }