import netCDF4
def get_nc_var3d(nc_hndl, var, year):
"""
Get value from netcdf for variable var for year
:param nc_hndl: handle to netcdf file
:param var: which variable to extract
:param year:
:return:
"""
val = nc_hndl.variables[var][int(year), :, :]
return val
I have this function which gets a slice from a netcdf file (array with dimension of 720 x 1440). I call this function from different functions multiple times. I would like to cache the output from this function and use that next time it is called with the same parameters. How can I do that?
Note: functools lrucache does not work as it returns this error:
TypeError: unhashable type: 'MaskedArray'