-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- preparation of calcScaling inclusion (not yet ready)
- Loading branch information
1 parent
8d5f8ad
commit c399001
Showing
8 changed files
with
124 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
Type: Package | ||
Package: gdx2 | ||
Title: Interface package for GDX files in R | ||
Version: 0.1.6 | ||
Date: 2024-07-25 | ||
Version: 0.1.7 | ||
Date: 2024-07-26 | ||
Authors@R: c( | ||
person("Jan Philipp", "Dietrich", email = "[email protected]", | ||
comment = c(affiliation = "Potsdam Institute for Climate Impact Research", ORCID = "0000-0002-4309-6431"), role = c("aut","cre"))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#' calcScaling | ||
#' | ||
#' This function creates a GAMS file with scaling of variables. The scaling is | ||
#' calculated based on a gdx file containing all variables of a run. | ||
#' | ||
#' @param gdx path to a gdx file | ||
#' @param file A file name the scaling GAMS code should be written to. If NULL | ||
#' the code is returned by the function | ||
#' @param magnitude The order of magnitude for which variables should be | ||
#' scaled. All variables with average absolute values which are either below | ||
#' 10e(-magnitude) or above 10e(magnitude) will be scaled. | ||
#' @return A vector with the scaling GAMS code if file=NULL, otherwise nothing | ||
#' is returned. | ||
#' @author Jan Philipp Dietrich | ||
#' @seealso \code{\link{readGDX}} | ||
#' @examples | ||
#' \dontrun{ | ||
#' calcScaling("fulldata.gdx") | ||
#' } | ||
calcScaling <- function(gdx, file = NULL, magnitude = 2) { | ||
v <- readGDX(gdx, types = "variables", field = "l") | ||
out <- NULL | ||
for (x in names(v)) { | ||
# calculate order of magnitude (oof) | ||
oof <- round(log10(mean(abs(v[[x]])))) | ||
if (is.nan(oof)) oof <- 0 | ||
cat("\n oof =", oof, " ", x) | ||
if (length(attr(v[[x]], "gdxdata")$domains) == 0) { | ||
sets <- "" | ||
} else { | ||
sets <- paste("(", paste(attr(v[[x]], "gdxdata")$domains, collapse = ","), ")", sep = "") | ||
} | ||
if (oof != -Inf && (oof < -1 * magnitude || oof > 1 * magnitude)) { | ||
out <- c(out, paste(x, ".scale", sets, " = 10e", oof, ";", sep = "")) | ||
} | ||
} | ||
cat("\n\n") | ||
|
||
if (!is.null(file)) { | ||
writeLines(out, file) | ||
} else { | ||
return(out) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.