AI4S2S / s2spy

A high-level python package integrating expert knowledge and artificial intelligence to boost (sub) seasonal forecasting
https://ai4s2s.readthedocs.io/
Apache License 2.0
20 stars 7 forks source link

Util to convert intervals to bounds, issue #79 #104

Closed BSchilperoort closed 2 years ago

BSchilperoort commented 2 years ago

As Sem noticed (#79), having data of the type pd.Interval will prevent users from saving their xr.Dataset to netCDF. Therefore we decided on converting the intervals to bounds, following CF conventions.

This PR adds a utility function that will convert the intervals of the resampled data to bounds, and this function is called at the end of the resample_xarray routine.

To ensure that the calendar-resampled data can always be written to a netcdf file, a test was added for this functionality.


The resampled data will now look like the following. Changes are in bold.


Dimensions:      (anchor_year: 39, i_interval: 12, latitude: 5, longitude: 13,
                  bounds: 2)
Coordinates:
  * anchor_year  (anchor_year) int32 1980 1981 1982 1983 ... 2015 2016 2017 2018
  * i_interval   (i_interval) int64 0 1 2 3 4 5 6 7 8 9 10 11
  * latitude     (latitude) float64 47.5 42.5 37.5 32.5 27.5
  * longitude    (longitude) float64 177.5 182.5 187.5 ... 227.5 232.5 237.5
    index        (anchor_year, i_interval) int64 0 1 2 3 4 ... 464 465 466 467
    interval     (bounds, anchor_year, i_interval) datetime64[ns] 1980-08-01 ...
    target       (i_interval) bool True False False False ... False False False
Data variables:
    sst          (latitude, longitude, anchor_year, i_interval) float64 284.2...
review-notebook-app[bot] commented 2 years ago

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

sonarcloud[bot] commented 2 years ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication