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

refactor calcFEdemand #458

Merged
merged 26 commits into from
Feb 6, 2024
Merged

refactor calcFEdemand #458

merged 26 commits into from
Feb 6, 2024

Conversation

fbenke-pik
Copy link
Contributor

@fbenke-pik fbenke-pik commented Jan 4, 2024

Purpose:

Split up code in calcFEdemand by sectors, so that sector experts can adjust input data generation for their sector without messing with other sectors by accident.

Implementation Details

  • code of calcFEdemand is moved to calcFeDemandBuildings, calcFeDemandIndustry and calcFeDemandBuildings.
  • no longer needed subtypes were removed: ES, EsUeFe_in, EsUeFe_out, UE_for_Eff, FE_for_Eff
  • calcFEdemand no longer has any subtypes, calling it corresponds to formerly calling it with subtype FE
  • the subtypes FE_buildings, UE_buildings were migrated to calcFeDemandBuildings, as they only produce EDGE buildings data
  • the refactoring of code within the calc functions was kept to an absolute minimum necessary to spread code across functions per sector

Removed subtypes from calcFEdemand

  • ES, in consequence removed f29_esdemand.cs4r
  • EsUeFe_in, EsUeFe_out, in consequence removed p36_serviceInputs.cs4r, p36_serviceOutputs.cs4r
  • UE_for_Eff, FE_for_Eff, in consequence removed calcEnergyEffPaths, which creates output file f29_efficiency_growth.cs4

Refactoring of EDGE Buildings functions

  • renamed readEDGE, convertEDGE to readEdgeBuildings and convertEdgeBuildings
  • split reading in stationary data from readEDGE (subtype FE_stationary), as this is read in from a different source than EDGE Buildings
  • remove no longer needed subtypes from readEDGE: Capital, CapitalUnit, ES_buildings
  • rename subtypes in readEDGE: FE_buildings -> FE
  • removed subytpe CapitalUnit from calcCapital, as it is no longer needed in it's only calling function readEDGE -> therefore calcCapital no longer needs subtypes and former subtype Capital corresponds to current code; file f29_capitalUnitProjections.cs45 is no longer generated
  • remove EDGE buildings data from calcCapital, as it is no longer used. in consequence, f29_capitalQuantity.cs4r now has less variables, but one additional year (see below for details)

Depends on

remindmodel/remind#1509

Tests and Validation

  • expected file missing: f29_capitalUnitProjections.cs4r, f29_efficiency_growth.cs4r, f29_esdemand.cs4r, p36_serviceInputs.cs4r, p36_serviceOutputs.cs4r
  • expected file diffs: f29_capitalQuantity.cs4r, f_fedemand.cs4r (see below)
  • other than that, there should be not file differences in the data
inputdata-comparedata "rev6.60feDemandBaseline_2b1450bc_remind.tgz" "rev6.60feDemandCompare_2b1450bc_remind.tgz"
inputdata-comparedata "rev6.60feDemandBaseline_62eff8f7_remind.tgz" "rev6.60feDemandCompare_62eff8f7_remind.tgz"

differences in f_fedemand.cs4r

  • adds values for ueHDVt and ueLDVt for Low Energy, Campaigners and Navigate Scenarios due to a bugfix in this line

differences in f29_capitalQuantity.cs4r

  • removes
 [1] "gdp_SSP1.kapal"   "gdp_SSP2.kapal"   "gdp_SSP3.kapal"   "gdp_SSP4.kapal"   "gdp_SSP5.kapal"   "gdp_SSP1.kapsc"   "gdp_SSP2.kapsc"  
 [8] "gdp_SSP3.kapsc"   "gdp_SSP4.kapsc"   "gdp_SSP5.kapsc"   "gdp_SSP1.kaphc"   "gdp_SSP2.kaphc"   "gdp_SSP3.kaphc"   "gdp_SSP4.kaphc"  
[15] "gdp_SSP5.kaphc"   "gdp_SSP2EU.kapal" "gdp_SSP2EU.kapsc" "gdp_SSP2EU.kaphc" "gdp_SDP.kapal"    "gdp_SDP.kapsc"    "gdp_SDP.kaphc"   
[22] "gdp_SDP_EI.kapal" "gdp_SDP_EI.kapsc" "gdp_SDP_EI.kaphc" "gdp_SDP_RC.kapal" "gdp_SDP_RC.kapsc" "gdp_SDP_RC.kaphc" "gdp_SDP_MC.kapal"
[29] "gdp_SDP_MC.kapsc" "gdp_SDP_MC.kaphc"
  • adds year 1995

@fbenke-pik fbenke-pik force-pushed the feDemand branch 3 times, most recently from 63907ff to 17643ef Compare January 9, 2024 17:32
@fbenke-pik fbenke-pik force-pushed the feDemand branch 8 times, most recently from afe593d to 6e767cb Compare January 12, 2024 13:46
@0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q
Copy link
Member

other than that, there should be not file differences in the data

And, is there?

@fbenke-pik
Copy link
Contributor Author

No, there are no unexpected differences in input data, other than the ones I listed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One immediate problem: there are now eight instances where we interact with the "fake" SSP2EU scenarios ([↑], [↑], [↑], [↑], [↑], [↑], [↑], [↑]).
I think this should be abstracted away (somehow), because I am currently struggling with extending it to yet more "fake" scenarios, and it is not pretty.

@mellamoSimon
Copy link
Contributor

moin!
I just wanted to ask if you will consider streamlining these "fake SSP2EU" scenarios within this PR or if it's going to be postponed. And in both cases what is the timeline, if there's any? I need to finish some project work in the next week(s) that requires several "fake SSP2EU" scenarios. Thank you very much!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bs538, are you OK with killing ODYM_RECC? It was not used in the end, right?

@bs538
Copy link
Contributor

bs538 commented Jan 17, 2024

@bs538, are you OK with killing ODYM_RECC? It was not used in the end, right?

No, it wasn't used in the version for the final scenario runs. But the SHAPE papers are only about to be submitted, so if possible without major trouble I'd be in favour of keeping it in case we need to make modifications during the review.

@0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q
Copy link
Member

One immediate problem: there are now eight instances where we interact with the "fake" SSP2EU scenarios ([↑], [↑], [↑], [↑], [↑], [↑], [↑], [↑]). I think this should be abstracted away (somehow), because I am currently struggling with extending it to yet more "fake" scenarios, and it is not pretty.

What's the general feeling about passing that information along via madrat::setConfig(), @fbenke-pik?

@fbenke-pik
Copy link
Contributor Author

@0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q @mellamoSimon

Concerning "fake scenarios": thanks for pointing this out, Michaja. Indeed, there is potential for simplifying the code and I will do so.

Simón, for this PR my goal is to not change input data if possible. So in the end the scenarios will still be in the files generated as part of this PR. Will check together with the rest of RSE if we can get rid of some of it (maybe as part of a larger refactoring in REMIND) as a next step.

I will add further changes to this PR that postpone the generation of fake scenarios to the latest possible point, so that industry and transport no longer have to deal with it in the respective calcFEdemand functions, as it will only be done in calcFEDemand in the very end.

@fbenke-pik
Copy link
Contributor Author

What's the general feeling about passing that information along via madrat::setConfig()

Haven't thought about it yet. What kind of info would you like to pass via setConfig?

@0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q
Copy link
Member

What's the general feeling about passing that information along via madrat::setConfig()

Haven't thought about it yet. What kind of info would you like to pass via setConfig?

setConfig(meaningful_option_name = list(
  gdp_SSP2EU = paste0("gdp_SSP2EU_", 
                      c(paste0("NAV_",   c("act", "tec", "ele", "lce", "all")),
                        paste0("CAMP_",  c("weak", "strong")),
                        paste0("ECEMF_", c("modEffInd", "IndLMD")),
                        paste0("GCS_",   c("IndLMD")))),
  gdp_SSP2 = "gdp_SSP2_lowEn"))

@robinhasse
Copy link
Contributor

What's the general feeling about passing that information along via madrat::setConfig()

Isn't that information we can share with a mapping? Seems a bit cleaner to me than introducing a new key in the madrat configuration.

@0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q
Copy link
Member

Kinda weird to read a file over and over again for the same bit of information. But than again, what's not weird with mrremind

@fbenke-pik
Copy link
Contributor Author

fbenke-pik commented Jan 22, 2024

One immediate problem: there are now eight instances where we interact with the "fake" SSP2EU scenarios ([↑], [↑], [↑], [↑], [↑], [↑], [↑], [↑]). I think this should be abstracted away (somehow), because I am currently struggling with extending it to yet more "fake" scenarios, and it is not pretty.

Had a closer look, and unfortunately there is not much potential to simplify the code here (although I would have loved to get rid of some of it)

The assumption for this PR is that all these duplicate scenarios must still be present in the generated inputdata files for REMIND, using the same file structure. (If this was not the case, we could further simplify the code, but this should be done in a separate PR)

Why can't we get rid of it?

  • Cannot be removed from readEdgeBuildings, convertEdgeBuildings and calcFeDemandBuildings, because the input data from EDGE Buildings actually has "real" data for these scenarios as of now.
  • In theory, I could remove the duplication from readStationary, convertStationary and calcFeDemandIndustry; but then I would have to reintroduce it in calcFeDemandBuildings for stationary data and in calcFEdemand for the Industry and Transport data before merging it with the data from calcFeDemandBuildings, and it would not be much prettier than what we have right now.
  • readEDGETransport is a different routine existing alongside calcFEdemand and is currently refactored by Johanna, so out of scope for this PR

Also, I would like to highlight that this duplication has always been there, it was not introduced by this PR.

If we agreed on generating separate feDemand files for industry, transport and buildings that are read in individually by the respective modules in REMIND, we could definitely simplify the code and get rid of the fake scenarios. But this sth we would have to agree on collectively and implement separately (and it includes a potentially complex (?) refactoring on REMIND side).

@fbenke-pik
Copy link
Contributor Author

What's the general feeling about passing that information along via madrat::setConfig()

Haven't thought about it yet. What kind of info would you like to pass via setConfig?

setConfig(meaningful_option_name = list(
  gdp_SSP2EU = paste0("gdp_SSP2EU_", 
                      c(paste0("NAV_",   c("act", "tec", "ele", "lce", "all")),
                        paste0("CAMP_",  c("weak", "strong")),
                        paste0("ECEMF_", c("modEffInd", "IndLMD")),
                        paste0("GCS_",   c("IndLMD")))),
  gdp_SSP2 = "gdp_SSP2_lowEn"))

Why would I want to change the config? From my understanding, inputdata generation always generates all the possible scenario data any REMIND run would want to use, no?

@fbenke-pik fbenke-pik merged commit 6d65824 into pik-piam:master Feb 6, 2024
2 checks passed
@fbenke-pik fbenke-pik deleted the feDemand branch February 6, 2024 15:19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robertpietzcker I think this is only needed for complex - I will double check, but I think it can be deleted completely. Do you remember anything regarding this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI there is a separate follow-up draft PR where we remove code related to transport
#468

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.

6 participants