SciTools / iris-esmf-regrid

A collection of structured and unstructured ESMF regridding schemes for Iris.
https://iris-esmf-regrid.readthedocs.io/en/latest
BSD 3-Clause "New" or "Revised" License
19 stars 17 forks source link

`dtype` of regridded cube changes after realizing the data #238

Closed schlunma closed 4 months ago

schlunma commented 1 year ago

🐛 Bug Report

After regridding a cube with dtype=float32 using regrid_unstructured_to_rectilinear and realizing the data the output cube's dtype is float64. If the data is saved and re-loaded before realizing the data, the dtype does not change.

How To Reproduce

import numpy as np

import iris
from iris.coords import DimCoord
from iris.cube import Cube
from iris.experimental.ugrid import PARSE_UGRID_ON_LOAD

import esmf_regrid
from esmf_regrid.experimental.unstructured_scheme import regrid_unstructured_to_rectilinear

print("iris version:", iris.__version__)
print("iris-esmf-regrid version:", esmf_regrid.__version__)

path = iris.sample_data_path('mesh_C4_synthetic_float.nc')
with PARSE_UGRID_ON_LOAD.context():
    cube = iris.load_cube(path)
    print("dtype input cube:", cube.dtype)

lat = DimCoord([10, 20, 30], standard_name='latitude', units='degrees_north')
lon = DimCoord([10, 20, 30], standard_name='longitude', units='degrees_east')
lat.guess_bounds()
lon.guess_bounds()
target = Cube(np.ones((3, 3)), dim_coords_and_dims=[(lat, 0), (lon, 1)])

regridded_cube = regrid_unstructured_to_rectilinear(cube, target)
print("dtype regridded cube before cube.data:", regridded_cube.dtype)

# If the following lines are added, the dtype is still float32 after realizing
# the data
# from pathlib import Path
# x = Path.home() / 'test.nc'
# iris.save(regridded_cube, x)
# regridded_cube = iris.load_cube(x)

regridded_cube.data
print("dtype regridded cube after cube.data:", regridded_cube.dtype)

prints

iris version: 3.4.0
iris-esmf-regrid version: 0.5.0
dtype input cube: float32
dtype regridded cube before cube.data: float32
dtype regridded cube after cube.data: float64

Expected behaviour

The dtype should be float32 for the regridding cube even after realizing the data.

Environment

bjlittle commented 1 year ago

Thanks @schlunma for raising this.

@stephenworsley is on the case and will dip into this asap, cheers :+1:

github-actions[bot] commented 1 year ago

@SciTools-incubator/esmf-regrid-devs This issue is stale due to a lack of activity in the last 90 days. Remove stale label or comment, otherwise this issue will close automatically in 7 days time.

schlunma commented 1 year ago

still relevant

github-actions[bot] commented 1 year ago

@SciTools-incubator/esmf-regrid-devs This issue is stale due to a lack of activity in the last 90 days. Remove stale label or comment, otherwise this issue will close automatically in 7 days time.

github-actions[bot] commented 7 months ago

@SciTools-incubator/esmf-regrid-devs This issue is stale due to a lack of activity in the last 180 days. Remove stale label or comment, otherwise this issue will close automatically in 14 days time.

schlunma commented 7 months ago

still relevant