Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: regrid2 converts time coordinates to int instead of preserving original datetime objects after annual cycle climatology #709

Open
lee1043 opened this issue Oct 10, 2024 · 4 comments · May be fixed by #716
Assignees
Labels
type: bug Inconsistencies or issues which will cause an issue or problem for users or implementors.

Comments

@lee1043
Copy link
Collaborator

lee1043 commented Oct 10, 2024

What happened?

When proceeding regrid2 after getting an annual cycle, somehow it loses the time coordinate data array (see below log print 4).

What did you expect to happen? Are there are possible answers you came across?

It does not happen when using xesmf regridder. time coordinate has to be preserved (see below log print 5).

Minimal Complete Verifiable Example (MVCE)

import xcdat as xc

# Prepare data
target_grid = xc.create_uniform_grid(-90, 90, 5, 0, 180, 5)
f = "/p/user_pub/PCMDIobs/obs4MIPs/ECMWF/ERA-INT/mon/pr/gn/v20210727/pr_mon_ERA-INT_PCMDI_gn_197901-201903.nc"

# Open data and test
ds = xc.open_dataset(f) # 1

# Immediate interpolation
ds_interp = ds.regridder.horizontal('pr', target_grid, tool='regrid2') # 2

# Interpolation after getting climatology
ds_ac = ds.temporal.climatology('pr', freq="month", weighted=True) # 3, annual cycle
ds_ac_interp_regrid2 = ds_ac.regridder.horizontal('pr', target_grid, tool='regrid2') # 4 interp (regrid2)
ds_ac_interp_xesmf = ds_ac.regridder.horizontal('pr', target_grid, tool='xesmf', method='bilinear')  # 5 interp (xesmf)

print(1, list(ds.coords))
print(2, list(ds_interp.coords))
print(3, list(ds_ac.coords))
print(4, list(ds_ac_interp_regrid2.coords))
print(5, list(ds_ac_interp_xesmf.coords))

Relevant log output

1 ['lat', 'lon', 'time']
2 ['lon', 'lat', 'time']
3 ['lat', 'lon', 'time']
4 ['lon', 'lat']
5 ['time', 'lon', 'lat']

Anything else we need to know?

I guess difference between regrid2 and xesmf output is in time array. From regrid 2, it is a data array with index numbers 0 to 11, but from xesmf, it is cftime object.

  • time before interpolation
ds_ac.time
xarray.DataArray'time'time: 12
array([cftime.DatetimeGregorian(1, 1, 1, 0, 0, 0, 0, has_year_zero=False),
       cftime.DatetimeGregorian(1, 2, 1, 0, 0, 0, 0, has_year_zero=False),
       cftime.DatetimeGregorian(1, 3, 1, 0, 0, 0, 0, has_year_zero=False),
       cftime.DatetimeGregorian(1, 4, 1, 0, 0, 0, 0, has_year_zero=False),
       cftime.DatetimeGregorian(1, 5, 1, 0, 0, 0, 0, has_year_zero=False),
       cftime.DatetimeGregorian(1, 6, 1, 0, 0, 0, 0, has_year_zero=False),
       cftime.DatetimeGregorian(1, 7, 1, 0, 0, 0, 0, has_year_zero=False),
       cftime.DatetimeGregorian(1, 8, 1, 0, 0, 0, 0, has_year_zero=False),
       cftime.DatetimeGregorian(1, 9, 1, 0, 0, 0, 0, has_year_zero=False),
       cftime.DatetimeGregorian(1, 10, 1, 0, 0, 0, 0, has_year_zero=False),
       cftime.DatetimeGregorian(1, 11, 1, 0, 0, 0, 0, has_year_zero=False),
       cftime.DatetimeGregorian(1, 12, 1, 0, 0, 0, 0, has_year_zero=False)],
      dtype=object)
Coordinates:
time (time) object 0001-01-01 00:00:00 ... 0001-12-...
Indexes: (1)
Attributes: 
bounds : time_bnds
axis : T
long_name : time
standard_name : time
  • time after interpolation using regrid2
ds_ac_interp_regrid2.time
xarray.DataArray'time'time: 12
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11])
  • time after interpolation using xesmf
ds_ac_interp_xesmf.time
xarray.DataArray'time'time: 12
array([cftime.DatetimeGregorian(1, 1, 1, 0, 0, 0, 0, has_year_zero=False),
       cftime.DatetimeGregorian(1, 2, 1, 0, 0, 0, 0, has_year_zero=False),
       cftime.DatetimeGregorian(1, 3, 1, 0, 0, 0, 0, has_year_zero=False),
       cftime.DatetimeGregorian(1, 4, 1, 0, 0, 0, 0, has_year_zero=False),
       cftime.DatetimeGregorian(1, 5, 1, 0, 0, 0, 0, has_year_zero=False),
       cftime.DatetimeGregorian(1, 6, 1, 0, 0, 0, 0, has_year_zero=False),
       cftime.DatetimeGregorian(1, 7, 1, 0, 0, 0, 0, has_year_zero=False),
       cftime.DatetimeGregorian(1, 8, 1, 0, 0, 0, 0, has_year_zero=False),
       cftime.DatetimeGregorian(1, 9, 1, 0, 0, 0, 0, has_year_zero=False),
       cftime.DatetimeGregorian(1, 10, 1, 0, 0, 0, 0, has_year_zero=False),
       cftime.DatetimeGregorian(1, 11, 1, 0, 0, 0, 0, has_year_zero=False),
       cftime.DatetimeGregorian(1, 12, 1, 0, 0, 0, 0, has_year_zero=False)],
      dtype=object)

Environment

Error occurred with xcdat 0.7.1 and 0.7.2

@lee1043 lee1043 added the type: bug Inconsistencies or issues which will cause an issue or problem for users or implementors. label Oct 10, 2024
@tomvothecoder
Copy link
Collaborator

Hey @lee1043, is this a major disruptive bug that we should prioritize?

@lee1043
Copy link
Collaborator Author

lee1043 commented Oct 16, 2024

Hey @lee1043, is this a major disruptive bug that we should prioritize?

Hi @tomvothecoder, thank you for checking it with me. I believe so because I think there is a very good chance this will start impacting PMP and obs4MIPs workflow.

@tomvothecoder
Copy link
Collaborator

@jasonb5 do you have time to work on this within the next few weeks? If not, I can take a look at it.

@jasonb5
Copy link
Collaborator

jasonb5 commented Oct 17, 2024

@tomvothecoder Yea I can look at this in the next few weeks.

@tomvothecoder tomvothecoder changed the title [Bug]: proceeding regrid2 after annual cycle lose time coordinate [Bug]: regrid2 converts time coordinates to int instead of preserving original datetime objects Oct 23, 2024
@tomvothecoder tomvothecoder changed the title [Bug]: regrid2 converts time coordinates to int instead of preserving original datetime objects [Bug]: regrid2 converts time coordinates to int instead of preserving original datetime objects after climatology Oct 23, 2024
@tomvothecoder tomvothecoder changed the title [Bug]: regrid2 converts time coordinates to int instead of preserving original datetime objects after climatology [Bug]: regrid2 converts time coordinates to int instead of preserving original datetime objects after annual cycle climatology Oct 23, 2024
@jasonb5 jasonb5 linked a pull request Nov 21, 2024 that will close this issue
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Inconsistencies or issues which will cause an issue or problem for users or implementors.
Projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

3 participants