Skip to content

Instantly share code, notes, and snippets.

@ajdawson
Created June 18, 2015 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajdawson/1254056e540f5a8790dc to your computer and use it in GitHub Desktop.
Save ajdawson/1254056e540f5a8790dc to your computer and use it in GitHub Desktop.
Notes on concatenation issue
{
"metadata": {
"name": "",
"signature": "sha256:9221e598320abd5d421920f5f48638d6bb36f9a03f5f437d516a11ccd5476f17"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"import iris\n",
"import iris.coords\n",
"import iris.cube\n",
"import numpy as np"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create some dummy data consisting of two cubes, one with a length-2 time dimension and one with a length-1 time dimension. The cubes have matching metadata, as do their coordinates."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"time0 = iris.coords.DimCoord([0., 1.], units='days since 2000-01-01', standard_name='time')\n",
"time1 = iris.coords.DimCoord([2.], units='days since 2000-01-01', standard_name='time')\n",
"\n",
"lat = iris.coords.DimCoord([-10., 0., 10.], standard_name='latitude', units='degrees_north')\n",
"lon = iris.coords.DimCoord([20., 40., 60., 80.], standard_name='longitude', units='degrees_east')\n",
"\n",
"cube0 = iris.cube.Cube(np.random.random([2, 3, 4]), standard_name='air_temperature', units='K',\n",
" dim_coords_and_dims=[(time0, 0), (lat, 1), (lon, 2)])\n",
"cube1 = iris.cube.Cube(np.random.random([1, 3, 4]), standard_name='air_temperature', units='K',\n",
" dim_coords_and_dims=[(time1, 0), (lat, 1), (lon, 2)])\n",
"\n",
"cubes = iris.cube.CubeList([cube0, cube1])\n",
"print(cubes)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"0: air_temperature / (K) (time: 2; latitude: 3; longitude: 4)\n",
"1: air_temperature / (K) (time: 1; latitude: 3; longitude: 4)\n"
]
}
],
"prompt_number": 2
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Attempt to concatenate the cubes, this works..."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cubes.concatenate_cube()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 3,
"text": [
"<iris 'Cube' of air_temperature / (K) (time: 3; latitude: 3; longitude: 4)>"
]
}
],
"prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Inspect the `dim_order` attribute, it looks the same as the reported issue, but in this case the concatenation works as expected."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from iris._concatenate import _CoordSignature, _CubeSignature\n",
"cube_signatures = [_CubeSignature(cube) for cube in cubes]\n",
"coord_signatures = [_CoordSignature(cube_sig) for cube_sig in cube_signatures]\n",
"print coord_signatures[0].dim_order\n",
"print coord_signatures[1].dim_order"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[1, 1, 1]\n",
"[0, 1, 1]\n"
]
}
],
"prompt_number": 4
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment