alan-turing-institute / deepsensor

A Python package for tackling diverse environmental prediction tasks with NPs.
https://alan-turing-institute.github.io/deepsensor/
MIT License
69 stars 12 forks source link

Create empty space Spatiotemporal Xarray coordinate difference tolerance #78

Closed nilsleh closed 8 months ago

nilsleh commented 8 months ago

I am looking to change the predict step according to #75 and I am working with CMIP6 data. I am currently getting the ValueError that Coordinates must be uniformly spaced here, given small numerical differences that cause the ValueError:

print(np.diff(x2_predict))
array([1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 0.9999924 ,
       1.0000076 , 1.        , 1.        , 0.9999924 , 1.0000076 ,
       1.        , 1.        , 0.9999924 , 1.0000076 , 1.        ,
       1.        , 0.9999924 , 1.0000076 , 1.        , 1.        ,
       0.9999924 , 1.0000076 , 1.        , 1.        , 0.9999924 ,
       1.0000076 , 1.        , 1.        , 1.0000076 , 0.9999924 ,
       1.        , 1.        , 1.0000076 , 0.9999924 , 1.        ,
       1.        , 1.0000076 , 0.9999924 , 1.        , 1.        ,
       1.0000076 , 0.9999924 , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 0.99998474, 1.0000153 , 1.        , 1.0000153 ,
       0.99998474, 1.        , 1.        , 1.        , 0.99998474,
       1.0000153 , 1.        , 1.0000153 , 0.99998474, 1.        ,
       1.        , 1.        , 0.99998474, 1.0000153 , 1.        ,
       1.0000153 , 0.99998474, 0.99998474, 1.0000153 , 1.        ,
       1.0000153 , 0.99998474, 1.        , 1.        , 1.        ,
       0.99998474, 1.0000153 , 1.        , 1.0000153 , 0.99998474,
       1.        , 1.        , 1.        , 0.99998474, 1.0000153 ,
       1.        , 1.0000153 , 0.99998474, 1.        , 1.        ,
       1.        , 0.99998474, 1.0000153 , 1.        , 1.0000153 ,
       0.99998474, 1.        , 1.        , 1.        , 0.99998474,
       1.0000153 , 1.        , 1.0000153 , 0.99998474, 1.        ,
       1.        , 1.        , 0.99998474, 1.0000153 , 1.        ,
       1.0000153 , 0.99998474, 0.99998474, 1.0000153 , 1.        ,
       1.0000153 , 0.99998474, 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        , 1.        ,
       1.        , 1.        , 1.        , 1.        ], dtype=float32)

the np.allclose() functions default absolute tolerance is 1e-8, with a tolerance of 1e-5 this assert statement would be true. But currently, there seems no other way around than changing the source code?

tom-andersson commented 8 months ago

Thanks for raising this @nilsleh. TBH I can't remember why I added this check for coordinate uniformity. This may have crept in as part of efforts to address https://github.com/tom-andersson/deepsensor/issues/19. However, I don't think it is necessary.

I think I'll remove the uniformity check and let you know when that's on main.

However, for the time being, please could you manually override your CMIP6 data coordinates with .assign_coords? I've moved this method locally and need to push some changes as part of that refactor before I can push this fix.

tom-andersson commented 8 months ago

This is now fixed in main. Let me know if that fixes things.