IAMconsortium / pyam

Analysis & visualization of energy & climate scenarios
https://pyam-iamc.readthedocs.io/
Apache License 2.0
226 stars 118 forks source link

add offset method to compute offsets relative to base-year values #659

Closed gidden closed 2 years ago

gidden commented 2 years ago

Please confirm that this PR has done the following:

Description of PR

This PR introduces an offset() method which allows a user to compute offsets relative to base-time-periods in the same style as normalize().

    For example, offsetting from `year=2005` will provide data
    *relative* to `year=2005` such that the value in 2005 is 0 and 
    all other values `value[year] - value[2005]`.

    Conceptually this operation performs as:
    ```
    df - df.filter(**kwargs) + padding
    ```
codecov[bot] commented 2 years ago

Codecov Report

Merging #659 (b203f56) into main (c5e8f9c) will increase coverage by 0.0%. The diff coverage is 100.0%.

@@          Coverage Diff          @@
##            main    #659   +/-   ##
=====================================
  Coverage   94.5%   94.6%           
=====================================
  Files         59      59           
  Lines       5742    5765   +23     
=====================================
+ Hits        5431    5454   +23     
  Misses       311     311           
Impacted Files Coverage Δ
pyam/core.py 94.6% <100.0%> (+<0.1%) :arrow_up:
tests/test_core.py 100.0% <100.0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update c5e8f9c...b203f56. Read the comment docs.

danielhuppmann commented 2 years ago

Thanks @coroa for suggesting the high-performance implementation alternative!

I don't mind adding the function directly for now. If discoverability becomes an issue, we could delegate methods operating only on the timeseries data to a submodule, similar to what I did with the compute module...

gidden commented 2 years ago

Hi both - have updated based on your suggestions. Should be ready.

coroa commented 2 years ago

LGTM

gidden commented 2 years ago

Given positive response here, will go ahead with merge. See #662 for an issue on expanding documentation further.