{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Load a Time Series of Data From the NEMO Model\n\nThis example demonstrates how to load multiple files containing data output by\nthe NEMO model and combine them into a time series in a single cube. The\ndifferent time dimensions in these files can prevent Iris from concatenating\nthem without the intervention shown here.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\n\nimport iris\nimport iris.plot as iplt\nimport iris.quickplot as qplt\nfrom iris.util import equalise_attributes, promote_aux_coord_to_dim_coord\n\n\ndef main():\n    # Load the three files of sample NEMO data.\n    fname = iris.sample_data_path(\"NEMO/nemo_1m_*.nc\")\n    cubes = iris.load(fname)\n\n    # Some attributes are unique to each file and must be removed to allow\n    # concatenation.\n    equalise_attributes(cubes)\n\n    # The cubes still cannot be concatenated because their dimension coordinate\n    # is \"time_counter\", which has the same value for each cube.  concatenate\n    # needs distinct values in order to create a new DimCoord for the output\n    # cube.  Here, each cube has a \"time\" auxiliary coordinate, and these do\n    # have distinct values, so we can promote them to allow concatenation.\n    for cube in cubes:\n        promote_aux_coord_to_dim_coord(cube, \"time\")\n\n    # The cubes can now be concatenated into a single time series.\n    cube = cubes.concatenate_cube()\n\n    # Generate a time series plot of a single point\n    plt.figure()\n    y_point_index = 100\n    x_point_index = 100\n    qplt.plot(cube[:, y_point_index, x_point_index], \"o-\")\n\n    # Include the point's position in the plot's title\n    lat_point = cube.coord(\"latitude\").points[y_point_index, x_point_index]\n    lat_string = \"{:.3f}\\u00B0 {}\".format(\n        abs(lat_point), \"N\" if lat_point > 0.0 else \"S\"\n    )\n    lon_point = cube.coord(\"longitude\").points[y_point_index, x_point_index]\n    lon_string = \"{:.3f}\\u00B0 {}\".format(\n        abs(lon_point), \"E\" if lon_point > 0.0 else \"W\"\n    )\n    plt.title(\n        \"{} at {} {}\".format(\n            cube.long_name.capitalize(), lat_string, lon_string\n        )\n    )\n\n    iplt.show()\n\n\nif __name__ == \"__main__\":\n    main()"
      ]
    }
  ],
  "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.8"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}