{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Make an iris cube" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "from iris.coords import DimCoord\n", "from iris.cube import Cube\n", "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Define cube coordinates" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "ysize = 20\n", "xsize = 10\n", "\n", "lats = np.linspace(-90, 90, ysize)\n", "lons = np.linspace(0, 360, xsize)\n", "\n", "latitude = DimCoord(lats, standard_name='latitude', units='degrees')\n", "longitude = DimCoord(lons, standard_name='longitude', units='degrees')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Build cube" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "long_name = 'something'\n", "units = 'kg'\n", "\n", "cube = Cube( np.zeros((ysize, xsize), np.float32), \n", " dim_coords_and_dims=[(latitude, 0),(longitude, 1)], \n", " long_name=long_name, units=units \n", " )" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "something / (kg) (latitude: 20; longitude: 10)\n", " Dimension coordinates:\n", " latitude x -\n", " longitude - x\n" ] } ], "source": [ "print(cube)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Insert data in cube\n", "make sure the shape matches!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cube.data = my_numpy_array" ] } ], "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.6.8" } }, "nbformat": 4, "nbformat_minor": 2 }