iris
iris copied to clipboard
Preserve dtype for wrap_lons
📰 Custom Issue
Currently, iris.analysis.cartography.wrap_lons promotes dtype to np.float64. This is causing some users to have to manually change the dtype back to its original version.
https://github.com/SciTools/iris/blob/98baee21721826a2a3c25d9169ed7e97e16e5e12/lib/iris/analysis/cartography.py#L70-L73
I believe this is done to avoid rounding errors within the calculation. If this is the case, It may be worth converting back to the original dtype after the calculation with something like the following code:
orig_dtype = lons.dtype
lons = lons.astype(np.float64)
return (((lons – base + period * 2) % period) + base).astype(orig_dtype)