Closed znicholls closed 5 years ago
Indeed, this use case already popped up in the SR15, in parictular notebook sr15_2.0_categories_indicators.ipynb
at https://github.com/iiasa/ipcc_sr15_scenario_analysis.
Below, a few lines of code copy-pasted from that notebook - a bit more elaborate than your suggestion because it did a lot more things, like also adding a meta-column in which year peak temperature was reached, and doing that for multiple climate models.
median_warming = 'AR5 climate diagnostics|Temperature|Global Mean|MAGICC6|MED'
def peak_warming(x, return_year=False):
peak = x[x == x.max()]
if return_year:
return peak.index[0]
else:
return float(max(peak))
median_temperature = sr1p5.filter(variable=median_warming).timeseries()
name = 'median warming at peak (MAGICC6)'
sr1p5.set_meta(median_temperature.apply(peak_warming, raw=False, axis=1), name)
I'm a bit hesitant about the very concise df.add_peak_temperature_meta()
, because the exact variable string from which to derive that info will be application-specific - or which climate model to use.
But a more generic df.set_meta_from_data()
might be useful, e.g.,
df.set_meta_from_data(name, method, column='value', **kwargs)
where
kwargs
can be additional filters (for example apply only where variable='Temperature'
or region='World'
)method
can be min, max, mean, median, and maybe even other pyam
functions like pyam.timeseries.cross_threshold()
or cumulative()
column
would be what to set as meta - the actual value
(default) or the year
/region
/... column where the value is reached (e.g., year of peak temperature)name
is the column name in meta
(similar to the use in df.set_meta()
)So your use case could then be implemented with:
df.set_meta_from_data(variable='Temperature', name='Peak temperature', method='max')
Nice that looks very elegant!
Hi folks - just catching up on this now. It seems like @danielhuppmann has a proposal for a more generic metadata addition. Should we make that a separate issue with the proposal and close this one?
Should we make that a separate issue with the proposal and close this one?
Works for me
Ok, great. I'll leave that to you guys then =)
On Tue, May 28, 2019 at 9:55 AM Zeb Nicholls notifications@github.com wrote:
Should we make that a separate issue with the proposal and close this one?
Works for me
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/IAMconsortium/pyam/issues/237?email_source=notifications&email_token=AAKUAEKQH22JEKLKC6IHIGDPXTQOZA5CNFSM4HPLBAZKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWLJBFY#issuecomment-496406679, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKUAEMMNFARYGNDKKHYBFLPXTQOZANCNFSM4HPLBAZA .
closing in favour of #238
@gidden and @danielhuppmann is there a function that allows the user to easily add peak temperature for each scenario as a metadata column of an
IamDataFrame
? I'm thinking something like,df.add_peak_temperature_meta()
.Maybe it's currently a two-line solution, something like the below?
Sorry if this is already in there and should be obvious, I couldn't work it out. If it's not in there, I'm happy for you to assign this one to me (I won't get to it straight away but will eventually).