{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# netCDF specificities" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:35:23.836034Z", "iopub.status.busy": "2025-01-13T11:35:23.835400Z", "iopub.status.idle": "2025-01-13T11:35:24.364183Z", "shell.execute_reply": "2025-01-13T11:35:24.363791Z" } }, "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:35:24.366204Z", "iopub.status.busy": "2025-01-13T11:35:24.366026Z", "iopub.status.idle": "2025-01-13T11:35:24.379475Z", "shell.execute_reply": "2025-01-13T11:35:24.379036Z" } }, "outputs": [], "source": [ "r = epygram.open(os.path.join(INPUTS_DIR, 'aladin.197901.nc'), 'r')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:35:24.381043Z", "iopub.status.busy": "2025-01-13T11:35:24.380859Z", "iopub.status.idle": "2025-01-13T11:35:24.383952Z", "shell.execute_reply": "2025-01-13T11:35:24.383602Z" } }, "outputs": [], "source": [ "# Equivalent of `ncdump -h`\n", "r.what()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Specify non-trivial variables for grid" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Genuinely, this line:\n", "\n", "`r.readfield('psl')`\n", "\n", "would result in the following error:\n", "\n", "`# [2021/01/19-18:59:55][epygram.formats.netCDF][find_grid_in_variables:0459][ERROR]: unable to find X_grid in variables. Please specify with readfield() argument adhoc_behaviour={'X_grid':'name_of_the_variable'} for instance or my_resource.behave(X_grid='name_of_the_variable')`\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:35:24.385653Z", "iopub.status.busy": "2025-01-13T11:35:24.385475Z", "iopub.status.idle": "2025-01-13T11:35:24.394927Z", "shell.execute_reply": "2025-01-13T11:35:24.394551Z" } }, "outputs": [], "source": [ "# Hence we need to specify grids\n", "# just for this read\n", "f = r.readfield('psl', adhoc_behaviour={'X_grid':'nav_lon', 'Y_grid':'nav_lat'})\n", "# or for the whole runtime\n", "r.behave(X_grid='nav_lon', Y_grid='nav_lat')\n", "f = r.readfield('psl')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:35:24.396581Z", "iopub.status.busy": "2025-01-13T11:35:24.396337Z", "iopub.status.idle": "2025-01-13T11:35:24.398910Z", "shell.execute_reply": "2025-01-13T11:35:24.398558Z" } }, "outputs": [], "source": [ "print(f.validity)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Read only a single index of the data" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:35:24.400541Z", "iopub.status.busy": "2025-01-13T11:35:24.400313Z", "iopub.status.idle": "2025-01-13T11:35:24.405174Z", "shell.execute_reply": "2025-01-13T11:35:24.404880Z" } }, "outputs": [], "source": [ "f = r.readfield('psl', only={'time_counter':0})" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:35:24.406720Z", "iopub.status.busy": "2025-01-13T11:35:24.406477Z", "iopub.status.idle": "2025-01-13T11:35:24.408963Z", "shell.execute_reply": "2025-01-13T11:35:24.408600Z" } }, "outputs": [], "source": [ "print(f.validity)" ] }, { "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 }