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

New HDD/CDD calculation added #23

Merged
merged 10 commits into from
Apr 8, 2024
Merged

New HDD/CDD calculation added #23

merged 10 commits into from
Apr 8, 2024

Conversation

hagento
Copy link
Collaborator

@hagento hagento commented Feb 28, 2024

A new approach for calculating HDD/CDD's has been added - calcHDDCDD, calcBAITpars - that bases upon the bias-adjusted internal temperature (BAIT). The calculation relies on processing raster data from the ISIMIP repository which are defined in the inst/extdata/sectoral/filemappings directory. These are read in using the functions readISIMIPbuildings and convertISIMIPbuildings which are tailored for pre-processing the raster data optimally for the above named purposes.
The code is working but partially throws memory conflicts that still need to be resolved with further development.

@hagento hagento requested a review from robinhasse February 28, 2024 10:42
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated


# prepare input for calcBAIT()
calcBaitInput <- function(frsds=NULL, fsfc=NULL, fhuss=NULL, baitInput=NULL, mean=FALSE) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe avoid this kind of function name to avoid confusion with madrat calc functions?

R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated
# swap ambient temperature values with corresponding DD values
hddcdd <- classify(temp, factors)

terra::time(hddcdd) <- as.Date(dates)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure you that have another function called time? If not, drop the package name.

Suggested change
terra::time(hddcdd) <- as.Date(dates)
time(hddcdd) <- as.Date(dates)

R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
R/calcHDDCDD.R Outdated Show resolved Hide resolved
@robinhasse
Copy link
Contributor

Very impressive work so far, @hagento ! I mainly looked at calcHDDCDD so far. Here, just a couple of general remarks:

  • You did a good job already in breaking down calcHDDCDD into smaller subfunctions. I feel readability would improve a lot, if you go a bit further: Move all subfunctions that only work with arguments directly passed to them (should be most) outside of calcHDDCDD but still in the same file. The I would give all of them individual rogygen header where you specify all parameters and the output. That would help a lot in understanding the code.
  • Try to avoid function calls with explicit package prefix like package::function() whenever possible. If you have no name conflict, move them to the roxygen header.
  • I would recommend running linter on your files from time to time (in RStudio: Dropdown on Addins -> Lint current file). You have some coding style issues, but that is not as important now. But you are no allowed to use certain apply functions which I believe you currently do. Rewriting this with allowed function can be annoying so it is good to save the time.
  • There seem to be some committed mappings that should rather go to the EDGE-B input integration PR

@robinhasse
Copy link
Contributor

robinhasse commented Apr 2, 2024

Great update, @hagento ! Documentation is so much better now. Please rename all functions starting with calc to something else (eg get) to avoid confusion with madrat functions - apart from calcHDDCDD obviously. This is not just about users reading the code but also madrat's logic. madrat::getCalculations would falsely list the functions for instance.

@hagento hagento merged commit b08f2dd into pik-piam:main Apr 8, 2024
2 checks passed
@hagento hagento deleted the dev branch April 8, 2024 15:14
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.

2 participants