Skip to content

Preserve dtype for wrap_lons #4119

@stephenworsley

Description

@stephenworsley

📰 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.

# It is important to use 64bit floating precision when changing a floats
# numbers range.
lons = lons.astype(np.float64)
return ((lons - base + period * 2) % period) + base

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Good First IssueA good issue to take on if you're just getting started with Iris development

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions