Hi
The immediate cause of the issue that you are facing is that when you want to join cubes into one along an existing dimension, you need to use cubes.concatenate_cube() instead of cubes.merge_cube(). See: https://scitools.org.uk/iris/docs/v2.4.0/userguide/merge_and_concat.html.
But if you do that (having removed inconsistent attributes) for the FIO-ESM-2-0 files you have below, this may well fail because the “latitude” and “longitude” auxiliary coordinates are not consistent (at least, this is the case for the versions of these files at BADC). If I do this (on JASMIN):
import iris
from iris.experimental.equalise_cubes import equalise_attributes
cubes = iris.load(['/badc/cmip6/data/CMIP6/CMIP/FIO-QLNM/FIO-ESM-2-0/historical/r1i1p1f1/Omon/tos/gn/v20191122/tos_Omon_FIO-ESM-2-0_historical_r1i1p1f1_gn_185001-201412.nc',
'/badc/cmip6/data/CMIP6/ScenarioMIP/FIO-QLNM/FIO-ESM-2-0/ssp245/r1i1p1f1/Omon/tos/gn/v20191227/tos_Omon_FIO-ESM-2-0_ssp245_r1i1p1f1_gn_201501-210012.nc'])
equalise_attributes(cubes)
cubes.concatenate_cube()
This reports the following:
ConcatenateError: failed to concatenate into a single cube.
An unexpected problem prevented concatenation.
Expected only a single cube, found 2.
Investigating the consistency of coordinates tells me that the longitude and latitude coordinates differ:
for coord in cubes[0].coords():
print('Coord {} is equal: {}'.format(coord.name(), coord == cubes[1].coord(coord.name())))
Coord time is equal: False
Coord cell index along second dimension is equal: True
Coord cell index along first dimension is equal: True
Coord latitude is equal: False
Coord longitude is equal: False
And further comparisons of the points and bounds of the longitude and latitude coordinates tell me that it is the points for both coordinates that are close, but different:
import numpy as np
for coord in ['longitude', 'latitude']:
for attr in ['points', 'bounds']:
print('Quantity {}.{} are all the same?: {}'.format(coord, attr,
np.all(getattr(cubes[0].coord(coord), attr) == getattr(cubes[1].coord(coord), attr))))
print('Quantity {}.{} are all close?: {}'.format(coord, attr,
np.all(np.isclose(getattr(cubes[0].coord(coord), attr), getattr(cubes[1].coord(coord), attr)))))
Quantity longitude.points are all the same?: False
Quantity longitude.points are all close?: True
Quantity longitude.bounds are all the same?: True
Quantity longitude.bounds are all close?: True
Quantity latitude.points are all the same?: False
Quantity latitude.points are all close?: True
Quantity latitude.bounds are all the same?: True
Quantity latitude.bounds are all close?: True
Because the points are all close but not quite the same, one answer is to just copy them from one cube to the other:
for coord in ['longitude', 'latitude']:
cubes[1].coord(coord).points = cubes[0].coord(coord).points
cubes.concatenate_cube()
Out[58]: <iris 'Cube' of sea_surface_temperature / (degC) (time: 3012; cell index along second dimension: 384; cell index along first dimension: 320)>
And all is well. Be aware that you may also need to use iris.util.unify_time_coordinates() on the cubes for some CMIP6 models before they will concatenate.
Best wishes
Tony
--
You received this message because you are subscribed to the Google Groups "SciTools (iris, cartopy, cf_units, etc.) -
https://github.com/scitools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
scitools-iri...@googlegroups.com.
To view this discussion on the web, visit
https://groups.google.com/d/msgid/scitools-iris/3e87d5da-66d5-4205-b414-74c34c2bc47bn%40googlegroups.com.