{ "cells": [ { "cell_type": "markdown", "id": "58c35970-3e91-47f9-9cf9-663a81039589", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "## Using UK Met Office PP files" ] }, { "cell_type": "raw", "id": "a320d6a7-0f8f-489e-9cd2-b8f0332607fe", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "This example uses a small PP file containing global temperature data. \n", "\n", "We can read this data as a :ref:`file source ` using the `Iris `_ library under the hood. \n", "\n", "Please note, PP file support requires the ``scitools-iris`` and ``ncdata`` packages to be installed." ] }, { "cell_type": "code", "execution_count": 1, "id": "6625ad75-a1cd-4f5b-a04b-2e1a63aafb89", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/cgr/venv/dev/lib/python3.13/site-packages/array_api_compat/torch/_info.py:361: UserWarning: 'mkldnn' is no longer used as device type. So torch.device('mkldnn') will be deprecated and removed in the future. Please use other valid device types instead. (Triggered internally at /Users/runner/work/pytorch/pytorch/pytorch/c10/core/Device.cpp:42.)\n", " a = torch.empty((0,), device=torch.device(device_name, index=i))\n", "/Users/cgr/venv/dev/lib/python3.13/site-packages/iris/fileformats/netcdf/saver.py:2857: IrisDeprecation: Saving to netcdf with legacy-style attribute handling for backwards compatibility.\n", "This mode is deprecated since Iris 3.8, and will eventually be removed.\n", "Please consider enabling the new split-attributes handling mode, by setting 'iris.FUTURE.save_split_attrs = True'.\n", " warn_deprecated(message)\n", "/Users/cgr/venv/dev/lib/python3.13/site-packages/ncdata/xarray.py:165: FutureWarning: In a future version, xarray will not decode the variable 'forecast_period' into a timedelta64 dtype based on the presence of a timedelta-like 'units' attribute by default. Instead it will rely on the presence of a timedelta64 'dtype' attribute, which is now xarray's default way of encoding timedelta64 values.\n", "To continue decoding into a timedelta64 dtype, either set `decode_timedelta=True` when opening this dataset, or add the attribute `dtype='timedelta64[ns]'` to this variable on disk.\n", "To opt-in to future behavior, set `decode_timedelta=False`.\n", " ds = store_entrypoint.open_dataset(self, **xr_load_kwargs)\n" ] } ], "source": [ "import earthkit.data as ekd\n", "\n", "# we ensure the example file is available. \n", "ekd.download_example_file(\"air_temp.pp\")\n", "\n", "ds = ekd.from_source(\"file\", \"air_temp.pp\")" ] }, { "cell_type": "markdown", "id": "044b5b88-848a-49ee-8d91-5996a1327a48", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "The resulting object is an Xarray fieldList." ] }, { "cell_type": "code", "execution_count": 2, "id": "f21a9370-1ded-4334-af4d-d244b325561b", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
variablelevelvalid_datetimeunits
0air_temperatureNone1998-12-01T00:00:00K
\n", "
" ], "text/plain": [ " variable level valid_datetime units\n", "0 air_temperature None 1998-12-01T00:00:00 K" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds.ls()" ] }, { "cell_type": "code", "execution_count": 3, "id": "5a70b28d-3244-46ee-afdc-27ad31b0d226", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(73, 96)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds[0].shape" ] }, { "cell_type": "code", "execution_count": 4, "id": "0f76468d-3bc0-4b86-9b21-9cb3e9a6d4a7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([254.644, 254.644, 254.644, 254.644, 254.644], dtype=float32)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds[0].values[:5]" ] }, { "cell_type": "code", "execution_count": 5, "id": "1b189c2e-0981-4ff0-b99b-62e2a60c7c69", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'lat': array([[ 89.999985, 89.999985, 89.999985, ..., 89.999985, 89.999985,\n", " 89.999985],\n", " [ 87.499985, 87.499985, 87.499985, ..., 87.499985, 87.499985,\n", " 87.499985],\n", " [ 84.999985, 84.999985, 84.999985, ..., 84.999985, 84.999985,\n", " 84.999985],\n", " ...,\n", " [-84.999954, -84.999954, -84.999954, ..., -84.999954, -84.999954,\n", " -84.999954],\n", " [-87.499954, -87.499954, -87.499954, ..., -87.499954, -87.499954,\n", " -87.499954],\n", " [-89.999954, -89.999954, -89.999954, ..., -89.999954, -89.999954,\n", " -89.999954]], shape=(73, 96), dtype=float32),\n", " 'lon': array([[ 0. , 3.749999, 7.499998, ..., 348.7499 , 352.4999 ,\n", " 356.2499 ],\n", " [ 0. , 3.749999, 7.499998, ..., 348.7499 , 352.4999 ,\n", " 356.2499 ],\n", " [ 0. , 3.749999, 7.499998, ..., 348.7499 , 352.4999 ,\n", " 356.2499 ],\n", " ...,\n", " [ 0. , 3.749999, 7.499998, ..., 348.7499 , 352.4999 ,\n", " 356.2499 ],\n", " [ 0. , 3.749999, 7.499998, ..., 348.7499 , 352.4999 ,\n", " 356.2499 ],\n", " [ 0. , 3.749999, 7.499998, ..., 348.7499 , 352.4999 ,\n", " 356.2499 ]], shape=(73, 96), dtype=float32)}" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds[0].to_latlon()" ] }, { "cell_type": "code", "execution_count": null, "id": "6d5789d4-10e9-4283-9773-dc94b0f30f5f", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "dev", "language": "python", "name": "dev" }, "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.13.1" } }, "nbformat": 4, "nbformat_minor": 5 }