-
Notifications
You must be signed in to change notification settings - Fork 142
Integrates risk trajectories within climada #1037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Co-authored-by: Lukas Riedel <[email protected]>
Co-authored-by: Lukas Riedel <[email protected]>
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
I created a discussion here #1039 |
- Replaced RiskPeriod class by CalcRiskPeriod class to centralize shared computations and dynamic metric instantiation. - Improved efficiency by reusing shared computations across metrics. - Added InterpolationStrategy and ImpactCalcStrategy classes to abstract that part of the computation
Small comments to the tutorial. They are really just from a user’s perspective at the moment.
Really exciting, overall the use looks very straightforward! (edited) |
res = [] | ||
for point in range(interpolation_range): | ||
ratio = point / (interpolation_range - 1) | ||
mat_interpolated = mat_start * (1 - ratio) + ratio * mat_end | ||
mat_interpolated.data = np.exp(mat_interpolated.data * np.log(rate)) | ||
res.append(mat_interpolated) | ||
return res |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also be a list comprehension.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And curiosity, what does res
stand for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result / return
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this is a terrible name, but also not fundamental.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you handle the change of .data
within a list comprehension ?
A snapshot of exposure, hazard, and impact function at a specific date. | ||
|
||
Attributes | ||
---------- | ||
date : datetime | ||
Date of the snapshot. | ||
measure: Measure | None | ||
The possible measure applied to the snapshot. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably incomplete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Properties have their own docstring if you are talking about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmmm ok, I see. This is quite confusing, since the properties are just wrapper for attributes which are not described here. Reading this, one does not know what is in the snapshot, it looks like there are only dates and measures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but this is the PEP standard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Started with an overview of the easier parts. Will need much more time for the more complex core classes.
from climada.trajectories.riskperiod import ( | ||
AllLinearStrategy, | ||
CalcRiskPeriod, | ||
ImpactCalcComputation, | ||
ImpactComputationStrategy, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to not import these modules directly (instead of importing them from riskperiod
) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the question?
Do you mean from riskperiod import
instead of from climada.trajectories.riskperiod
?
This is virtually the same (slightly more robust). These lines are generated automatically by my LSP when a new import is required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for being unclear. I meant that for instance ImpactCalcComputation
should be imported from its module, i.e. from climada.trajectories.impact_calc_strat
right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right! Yes indeed this is not elegant.
In any case, I think I am going to make proxies within trajectory/__init__.py
to simplify imports.
LOGGER = logging.getLogger(__name__) | ||
|
||
POSSIBLE_METRICS = ["eai", "aai", "return_periods", "risk_components", "aai_per_group"] | ||
DEFAULT_RP = [50, 100, 500] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As raised in the discussion, I think there is a conundrum with this default. It should imho be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it a forced input? What if people are not interested in RP? Is it empty by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not undersand this response exactly.
Having arbitrary defined default RPs, which sometimes are applied, and sometimes user input RPs are applied, is confusing, as explained in the discussion to this PR. So, I would remove the default here. You can always set the default in the method that computes the values for the RPs. Then it is clear to the user. I would also choose a bit more conservative values, e.g., [20, 50, 100]. The RP500 is only rarely available in hazard datasets.
Does this clarify the response?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So how it works now is that the methods do not have RPs has argument any more (simplifies a lot) and always use the .return_periods attribute which has a default value (changed to 20, 50, 100) and can be set at init (to be coded still) or via the property afterwards (and takes care of updating the metrics).
Does that work for you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good! Important is that you can set it in the init and via properties too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in 3a026cd
- Fixes aai per group in static - components -> contributions - privatisation of some funs
- reworked return periods (only changed via the property, not the metrics methods) - removed npv boolean, risk is now always computed with risk discount if present - reworked caching (results are now correctly cached) - reworked computation related properties (now more tightly connected to computings objects - removed `time_points` from computing object as not usable - clearer names
Changes proposed in this PR:
Implements
RiskTrajectory
objects to ease the evaluation of risk / impact in between two points in time.See the associated discussion here: #1039
A notebook showcasing this new module is available in
doc/tutorial/climada_trajectory.ipynb
. (It is not a real tutorial yet, but will serve as its basis).Also note that the future option appraisal module will be based on this.
Remaining TODO s
Snapshot
by their date when instantiatingExposures
have the same shape within a risk trajectory.group_id
are identical forExposures
or handle that case (Handled, different group_id are possible, metric is computed at each date and interpolated in between)PR Author Checklist
develop
)PR Reviewer Checklist