There doesn't seem to be anything else that Iris should be doing automatically here. The two datasets just have different structures which can't be aligned without human intervention/interpretation.
That said, it does seem slightly restrictive that the only way to identify a coordinate in a constraint is by its name. As in this case it leads you to rename the ocean_time coordinate. I can imagine it
might be useful to have something like:
def find_time_coord(cube):
return [coord for coord in cube.coords() if coord.name().startswith('time')][0]
def time_near(time_coord, start):
try:
itime = time_coord.nearest_neighbour_index(time_coord.units.date2num(start))
except:
itime = -1
return time_coord.points[itime]
for url in urls:
cube = iris.load_cube(url, var)
time_coord = find_time_coord(cube)
iris.CoordConstraint(time_coord, time_near(time_coord, mytime))
But I wouldn't claim it's a dramatic improvement. And arguably what you're currently doing is better because by using the "rename()" method it's improving the quality of the metadata available for any subsequent operation on that cube.
NB. With your current rename('time') technique, you could still use "startswith" to identify the relevant coordinate if you so wish.
As an aside, I'd make a couple of other minor tweaks.
- If you just want a single cube then I'd use iris.load_cube(), then you don't have to use a trailing [0] and it'll complain if you get multiple matches.
- For a simple match on phenomenon name, you can replace your Constraint(name=...) with just the name. E.g. iris.load_cube(url, 'potential temperature')
- It's a good habit to always avoid "bare" except clauses. It doesn't matter very much here, but under other circumstances it can cause problems, including making your Python code ignore your attempts to kill it with Ctrl-C.