import iris import numpy as np from copy import deepcopy import cf_units def main(): inFile = "/gws/nopw/j04/nexcs/pmcguire/ILAMB/OBS_DATA_20240722/DATA/mrro/CLASS/mrro.nc" outFile = "/gws/nopw/j04/nexcs/pmcguire/ILAMB/OBS_DATA_20240722/DATA/mrro/CLASS/mrro_new.nc" cubes = iris.load(inFile) #for some reason, this only returns cubes number 0, not cubes number 1 (cubes number 1 has the mrro_sd) print(cubes) print(cubes[0].coord('time')) #Fix time dimension #Previously, the points array was int64, and the bounds array was float64, which doesn't work with either ILAMB or ncview timeMiddle = deepcopy(cubes[0].coord("time").points).astype(np.float64) timeBounds = deepcopy(cubes[0].coord("time").bounds) cubes[0].remove_coord('time') new_time = iris.coords.DimCoord(timeMiddle, standard_name='time') cubes[0].add_dim_coord(new_time,0) #Previously, there was no H:M:S time stamp cubes[0].coord('time').units = cf_units.Unit("days since 2003-01-01 00:00:00", calendar='365_day') cubes[0].coord('time').bounds = None cubes[0].coord('time').bounds = timeBounds print(cubes[0].coord('time')) iris.save(cubes,outFile, fill_value=99999) if __name__ == '__main__': main()