Skip to content
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

Integrate the BOARIO model into CLIMADA SupplyChain Module #81

Merged
merged 57 commits into from
Aug 19, 2024

Conversation

aleeciu
Copy link
Collaborator

@aleeciu aleeciu commented Jun 8, 2023

This PR integrates the BOARIO model (https://github.com/spjuhel/BoARIO) developed by @spjuhel into the CLIMADA's SupplyChain module.

Missing:

PR Author Checklist

TODOs:

  • Make sure to set BoARIO dependency to >=v0.5.9 for compatibility.
  • Make sure v0.5.9 is made available on conda-forge.

PR Reviewer Checklist


23/04/24 Remarks from @spjuhel while working on the PR:

  • Doing multiple run with different event type can lead the boario_params["event"] dict to hold unwanted keyword arguments for specific events (ie boario_params["event"]["recovery_time"] is set to a default value if we instantiate an EventKapitalRecovery, which currently causes an error when instantiating an EventKapitalRebuild afterward. I've corrected this on the boario side, which will be part of its v0.5.9 release.
  • Also, on this point, I'm actually a bit unsure if setting default values and logging it in debug is the proper way. I would at least change it to a warning, and I'm more in favour of raising an explicit error that tells the user to set a value.
  • pymrio v0.5.4, just out, introduces Ghosh calculation (which we currently do by ourselves). I think we can just bump the dependency to this version and use their functions.
  • The objective of the PR is to finish the coupling with boario, but I plan to do a rework of the module soon, to improve its overal structure, test coverage, etc...

spjuhel and others added 16 commits February 21, 2023 14:25
Additions
- added boario imports
- added extended parsing of final demand in parse_mriot_from_df (required by boario)
- added negative total final demand fix
- added two approaches cases in calc_indirect_production_impacts (only aggregated implemented atm)

Matters to attend
- specify boario_output_dir (I will set registering files optional at some point, but probably not very soon)
- Implement the results returned
- Changed names in model instantiation ('kapital' → 'productive_capital')
- Added `psi_param` and `inventory_restoration_tau` in model instantiation (the values are the default values, this is only for transparency if you want to set these values programmatically at some point)
- Removed multiplication by model.monetary_factor in Event instantiation (this is done more properly inside BoARIO now)
- Swapped `add_event` to `add_events` for lisibility (since the method now exists)
- The `production_evolution` dataframe is now directly accessible as a simulation property, hence I simplified the `self.indir_prod_impt_mat` affectation
- Commented the mriot.unit part as it is not required anymore (see below)
The stock of capital should be in the same unit as the MRIOT, so we just divide it by the conversion factor.
@aleeciu
Copy link
Collaborator Author

aleeciu commented Jun 9, 2023

Hi @spjuhel, I got a question after reading the BoARIO's docs again:

currently ARIOPsiModel instance receives exposure as productive_capital_vector = self.secs_exp / self.conversion_factor(). This makes sense as CLIMADA's exposure should be stock exposure. However, I can envision some peculiar use-cases where CLIMADA's exposure is already about production. Thus impact is also about production.

From https://spjuhel.github.io/BoARIO/boario-math.html, I see that BOARIO actually can handle these use-cases as it can shock 1) productive capital (what we do now), 2) households (not relevant here) but also 3) production capacity.

How should ARIOPsiModel be instantiated in case 3) ?

Thanks.

@spjuhel
Copy link
Collaborator

spjuhel commented Jun 12, 2023

Hi @aleeciu,

This is handled by the type of Event you instantiate. Currently there's 3:

  • EventKapitalRecover (Currently in Climada, it was the simplest + most tested one at the time)
  • EventKapitalRebuild (Where the direct damages also create a rebuilding demand)
  • EventArbitraryProd (Which I implemented recently and corresponds to case 3)

Note that:

  • Case 3 has been far less extensively tested and used than case 1 and 2.
  • impact has to be given as a fraction of production capacity directly in this case.

I think in the long run, Climada's default should probably be EventKapitalRebuild, as it is hard to justify the absence of a rebuilding demand (especially after a Cyclone, for instance). But that requires to define the set of rebuilding sectors and their "market share" of the rebuilding demand, which is hard to generalize over different MRIOT.

@aleeciu
Copy link
Collaborator Author

aleeciu commented Jun 16, 2023

Thanks @spjuhel . I integrated the three BOARIO models now. Got to figure out how to best handle the kwargs in self.calc_impacts since they should end up in different boario classes.

Using complex events set (for example TCs from multiple bassins) can lead to
event_id / occurences to not be ordered. Using .max() and .min() insure we use
the correct 'first' event and 'last' event.
@spjuhel
Copy link
Collaborator

spjuhel commented Apr 24, 2024

@emanuel-schmid or @peanutfun this is almost done, I have some quick technical questions:
I have to:

  • enforce the v0.5.9 dependency for boario
  • solve these conflicts in the requirements
  • update the changelog: any do and don't for this?.

Also can I safely black-format the whole file?

@spjuhel
Copy link
Collaborator

spjuhel commented May 24, 2024

I think I have adressed all remaining problems and remarks and the last remaining thing would be to add boario==0.5.9 dependency on jenkins (@emanuel-schmid can you do it?), and check that the tests are running.

@emanuel-schmid emanuel-schmid merged commit d587dbd into develop Aug 19, 2024
11 checks passed
@emanuel-schmid emanuel-schmid deleted the feature/climada_boario branch August 19, 2024 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants