Skip to content
This repository has been archived by the owner on Apr 30, 2021. It is now read-only.

wrong time values in results from compute_mon_anomaly and compute_mon_climatology #96

Closed
klindsay28 opened this issue Mar 13, 2019 · 6 comments

Comments

@klindsay28
Copy link

The time values returned by compute_mon_anomaly and compute_mon_climatology are wrong.

The python code in the following file, which has a .txt suffix to enable me to attach it, exhibits the problem:
esmlab_compute_mon.py.txt

It uses the function dset from tests/conftest.py to create an example dataset, and then prints time from dset, and the datasets returned by compute_mon_anomaly and compute_mon_climatology.

print(ds.time) returns:

<xarray.DataArray 'time' (time: 24)>
array([ 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365, 396, 424,
455, 485, 516, 546, 577, 608, 638, 669, 699, 730])
Coordinates:

  • time (time) int64 31 59 90 120 151 181 212 ... 577 608 638 669 699 730
    Attributes:
    units: days since 0001-01-01 00:00:00
    calendar: noleap
    bounds: time_bound

print(compute_mon_anomaly(ds).time) returns:

<xarray.DataArray 'time' (time: 24)>
array([-182.5, -182.5, -182.5, -182.5, -182.5, -182.5, -182.5, -182.5, -182.5,
-182.5, -182.5, -182.5, 182.5, 182.5, 182.5, 182.5, 182.5, 182.5,
182.5, 182.5, 182.5, 182.5, 182.5, 182.5])
Coordinates:

  • time (time) float64 -182.5 -182.5 -182.5 -182.5 ... 182.5 182.5 182.5
    Attributes:
    units: days since 0001-01-01 00:00:00
    calendar: noleap
    bounds: time_bound

I expect this to report the same values as print(ds.time), and it does not.

print(compute_mon_climatology(ds).time) returns:

<xarray.DataArray 'time' (time: 12)>
array([213.5, 241.5, 272.5, 302.5, 333.5, 363.5, 394.5, 425.5, 455.5, 486.5,
516.5, 547.5])
Coordinates:

  • time (time) float64 213.5 241.5 272.5 302.5 ... 455.5 486.5 516.5 547.5
    Attributes:
    long_name: time
    units: days since 0001-01-01 00:00:00
    bounds: time_bound

I expect this to report values corresponding to mid-Jan, mid-Feb, ..., and it does not.
I expect this to have the same calendar attribute that ds has, and it does not.

I am using the trunk of esmlab. conda list returns the following for xarray, numpy, and esmlab:

esmlab 2019.2.0+30.ged53a19 dev_0
numpy 1.15.4 py36h7e9f1db_0
numpy-base 1.15.4 py36hde5b4d6_0
xarray 0.11.3 pypi_0 pypi

@klindsay28
Copy link
Author

FYI, the incorrect time values seem to have been introduced with #75. When I run the above code with 6e89f2a, right before #75, the reported time values are somewhat reasonable.
That said, even with that hash, the results have the following issues:

  1. compute_mon_anomaly(ds).time is encoded, even though ds.time is not (this is what time_manager: returns ds with original time #75 was fixing)
  2. compute_mon_climatology(ds).time doesn't have a calendar attribute, even though ds.time does
    @matt-long, could you take a look at this? It feels related to compute_ann_mean does not work if time is encoded #93, which was also introduced with time_manager: returns ds with original time #75.

@matt-long
Copy link
Contributor

@klindsay28, I am looking at this now. I understand what's going on: we are retaining the original time coordinate in "undecoded form" (i.e. float) and doing computations on it. I think this is appropriate for operations like compute_ann_mean, but not appropriate for compute_mon_clim or compute_mon_anomaly.

I am thinking about how best to address the issue.

@klindsay28
Copy link
Author

Are you saying that xarray operations on datasets are being applied to coordinate variables? If so, that sounds undesirable. Actually, it sounds so undesirable that I think I must be misunderstanding what you are saying. However, if I am right, is there a way to tell xarray not to do that.

@matt-long
Copy link
Contributor

@klindsay28 I have a partial fix for this issue on my fork: https://github.com/matt-long/esmlab

Further work is required to clean things up and address #93. I addressed the first failure point there, but there's another error related to time_bound being decoded.

@klindsay28
Copy link
Author

Thanks. I'm able to use your fork with just a couple of workarounds in my scripts.

@andersy005
Copy link
Contributor

@klindsay28, feel free to close this in case #98 fixes this issue

@andersy005 andersy005 added this to the sprint-mar04-mar17 milestone Mar 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants