I have two netcdf files, one with precipitation, one with air temperature.
I name these "f1" and "f2"
I can load them into cubes with iris.load
I expected that the resulting cubes would be in the same order as the input files. As you can see from the code snippet below, this is not the case
precipitation is being loaded into cubes[0] regardless of the order.
Is this expected behaviour? Can I make it preserve the order?
thanks,
Morwenna
> f2 = '/dac_tasmax_19900101_e01.nc'
> f1 = 'dac_pr_19900101_e01.nc'
> aa = iris.load([f1, f2])
> print(aa)
0: precipitation / (mm) (time: 217; latitude: 61; longitude: 53)
1: air_temperature / (degC) (time: 217; latitude: 61; longitude: 53)
> a2 = iris.load([f2, f1])
> print(a2)
0: precipitation / (mm) (time: 217; latitude: 61; longitude: 53)
1: air_temperature / (degC) (time: 217; latitude: 61; longitude: 53)
def add_realization_from_filename(cube, field, filename):
# Get the integer ensemble member number from the filename
# (assuming same naming as in your example, adjust if needed)
ensemble_member = int(filename[-5:-3])
# Create a realization scalar coordinate:
realization_coord = iris.coords.AuxCoord(ensemble_member, "realization")
cube.add_aux_coord(realization_coord)
cubes = iris.load(['da_ua_19960125_e01.nc', 'da_ua_19960125_e02.nc', ...], callback=add_realization_from_filename)