OpasnetUtils/Drafts: Difference between revisions

From Opasnet
Jump to navigation Jump to search
(→‎Timelineplot: some bugs fixed)
 
(8 intermediate revisions by the same user not shown)
Line 22: Line 22:


=== Calculations ===
=== Calculations ===
====Expand_index====
<rcode name="expand_index" label="Initiate expand_index" embed=1>
# This is code Op_en6007/expand_index in page [[OpasnetUtils/Drafts]]
library(OpasnetUtils)
#' Copies results from one location to other locations while keeping everything else constant
#' @param ova ovariable to be used
#' @param locations list of relevant indices. Each item is a list that has a name of an existing locations, and the content is a vector of new location names.
#' @return the input ovariable with new rows containing the new locations
expand_index <- function(ova, locations) {
  if("ovariable" %in% class(ova)) out <- ova@output else out <- ova
  for(i in names(locations)) {
    for(j in names(locations[[i]])) {
      addpiece <- out[out[[i]]==j,]
      for(k in locations[[i]][[j]]) {
        addpiece[[i]] <- k
        out <- rbind(out,addpiece)
      }
    }
  }
  if("ovariable" %in% class(ova)) ova@output <- out else ova <- out
  return(ova)
}
objects.store(expand_index)
cat("Function expand_index stored.\n")
</rcode>


====Functions for ovariable diagnostics====
====Functions for ovariable diagnostics====
Line 265: Line 296:
objects.store(webropol.convert, merge.questions)
objects.store(webropol.convert, merge.questions)
cat("Functions webropol.convert, merge.questions stored.\n")
cat("Functions webropol.convert, merge.questions stored.\n")
</rcode>
==== HNH2035 functions ====
These are functions that were needed and developed for the [[:op_fi:Hiilineutraali Helsinki 2035]] work.
<rcode name="hnh2035" label="Initiate functions for HNH2035" embed=1>
#This is code Op_en6007/hnh2035 on page [OpasnetUtils/Drafts]]
library(OpasnetUtils)
# pushIndicatorGraph was moved to package https://github.com/jtuomist/CNH-energy
# Colors from the Helsinki theme
colhki <- rep(c("#0072c6","#00d7a7","#c2a251","#9fc9eb","#ffc61e","#009246"),5)
#' Remove overlap with happened and scenarios, and then combine lines
#' @param ova ovariable where lines are combined
#' @param measured name for the scenario that contain actual data about measured things
combineLines <- function(ova, measured="toteutunut") {
  tst <- unique(ova[ova$Scenario==measured,]$Year) # Years with data
  out <- ova[ova$Scenario==measured | !ova$Year %in% tst,] # Remove scenarios if data
  tmp <- out[out$Scenario==measured & out$Year == max(tst),colnames(out@output)!="Scenario"]
  tmp <- tmp * Ovariable(
    output=data.frame(
      Scenario=setdiff(unique(out$Scenario),measured),
      Result=1
    ),
    marginal=c(TRUE,FALSE)
  )
  out <- combine(tmp,out, name=ova@name)
  return(out)
}
objects.store(combineLines, colhki)
cat("Function combineLines and colour vector colhki stored.\n")
</rcode>
</rcode>


Line 270: Line 337:


<rcode name="miscellaneous" embed=1>
<rcode name="miscellaneous" embed=1>
#This is code Op_en6007/webropol on page [OpasnetUtils/Drafts]]
#This is code Op_en6007/miscellaneous on page [OpasnetUtils/Drafts]]


library(OpasnetUtils)
library(OpasnetUtils)

Latest revision as of 10:37, 6 March 2021



Question

Which functions are so useful that they should be taken into OpasnetUtils package? This page contains draft function which will be included when they are good enough and found important.

Answer

Call the objects stored by this code from another rode with this command:

objects.latest("Op_en6007", code_name = "answer") # Old version that fetches all objects, depreciated and not updated.
objects.latest("Op_en6007", code_name = "diagnostics") # Functions for ovariable and model diagnostics: ovashapetest, showLoctable, binoptest
objects.latest("Op_en6007", code_name = "webropol") # Functions for operating with Webropol data
objects.latest("Op_en6007", code_name = "miscellaneous") # Functions for various tasks
objects.latest("Op_en6007", code_name = "gis") # Functions for ovariable, KML and Googl maps interactions

Rationale

Calculations

Expand_index

+ Show code

Functions for ovariable diagnostics

showind has problems with get() but this version of code was acceptable [1].

+ Show code

Functions for Webropol data

+ Show code

HNH2035 functions

These are functions that were needed and developed for the op_fi:Hiilineutraali Helsinki 2035 work.

+ Show code

Miscellaneous functions

+ Show code

Functions for GIS data

+ Show code

Timelineplot

+ Show code

See also

References


Related files

<mfanonymousfilelist></mfanonymousfilelist>