Air pollution emissions in Helsinki: Difference between revisions
Jump to navigation
Jump to search
(→Calculations: now seems to work) |
|||
(10 intermediate revisions by the same user not shown) | |||
Line 12: | Line 12: | ||
== Answer == | == Answer == | ||
* Model run 12.12.2018 [http://en.opasnet.org/en-opwiki/index.php?title=Special:RTools&id=tYDyrFr6SqKZlwoK] | |||
<rcode name="answer" graphics=1 embed=0> | |||
# This is code Op_en7923/answer on page [[Air pollution emissions in Helsinki]] | |||
library(OpasnetUtils) | |||
library(ggplot2) | |||
library(plotly) | |||
library(httr) | |||
library(jsonlite) | |||
objects.latest("Op_en6007", code_name="hnh3035") # [[OpasnetUtils/Drafts]] combineLines, pushIndicatorGraph | |||
objects.latest("Op_en7923", code_name="emission") # [[Air pollution emissions in Helsinki]] emission | |||
emission <- EvalOutput(emission) | |||
gp <- ggplot(emission@output, aes(x=Year, weight=emissionResult, fill=Sector))+geom_bar()+ | |||
facet_wrap(~City, scales="free_y")+ | |||
theme_gray(base_size=20)+ | |||
labs(y="CO2eq emissions (kton/a)") | |||
gp | |||
objects.latest("Op_en7923", code_name="caremission") # [[Air pollution emissions in Helsinki]] | |||
caremission <- EvalOutput(caremission) | |||
gpcar <- ggplot(caremission@output, aes(x=Year, weight=caremissionResult, fill=Vehicle))+geom_bar()+ | |||
facet_grid(Pollutant~Municipality, scales="free_y")+ | |||
theme_gray(base_size=20)+ | |||
labs(y="CO2eq emissions (kton/a)") | |||
gpcar | |||
if(FALSE) { | |||
# https://plot.ly/ggplot2/user-guide/#interactively-view-the-json-object | |||
pushIndicatorGraph(gpcar, "https://hnhteamy.fi/v1/indicator/8/") | |||
cat("Plotly graphs on vehile fleet and km POSTed to HNH server.\n") | |||
} | |||
</rcode> | |||
== Rationale == | == Rationale == | ||
Line 18: | Line 60: | ||
* [[Emission factors for burning processes]] | * [[Emission factors for burning processes]] | ||
* [[Emission factors for road transport]] | |||
* [[Road traffic in Helsinki]] | |||
=== Calculations === | === Calculations === | ||
Line 26: | Line 70: | ||
The actual data: (key is unique to every download instance and is generated when the above link is opened) - http://cl1.opasnet.org/opasnet_base_2/index.php?key=8dYqLbtppz4HM7sYaAyj4t6S49jQNRWJ | The actual data: (key is unique to every download instance and is generated when the above link is opened) - http://cl1.opasnet.org/opasnet_base_2/index.php?key=8dYqLbtppz4HM7sYaAyj4t6S49jQNRWJ | ||
<rcode name="fuelUse" label="Initiate ovariable fuelUse" embed=1> | <rcode name="fuelUse" label="Initiate ovariable fuelUse (for developers only)" embed=1> | ||
# This is code Op_en7923/fuelUse on page [[Air pollution emissions in Helsinki]] | # This is code Op_en7923/fuelUse on page [[Air pollution emissions in Helsinki]] | ||
library(OpasnetUtils) | library(OpasnetUtils) | ||
Line 37: | Line 81: | ||
), | ), | ||
formula = function(...) { | formula = function(...) { | ||
HSYdata$CO2 <- NULL | |||
levels(HSYdata$Sector) <- tolower(levels(HSYdata$Sector)) | levels(HSYdata$Sector) <- tolower(levels(HSYdata$Sector)) | ||
levels(HSYdata$Consumer) <- tolower(levels(HSYdata$Consumer)) | levels(HSYdata$Consumer) <- tolower(levels(HSYdata$Consumer)) | ||
Line 51: | Line 93: | ||
</rcode> | </rcode> | ||
<rcode name="emission" label="Initiate ovariable emission" embed=1> | <rcode name="emission" label="Initiate ovariable emission (for developers only)" embed=1> | ||
# This is code Op_en7923/emission on page [[Air pollution emissions in Helsinki]] | # This is code Op_en7923/emission on page [[Air pollution emissions in Helsinki]] | ||
library(OpasnetUtils) | library(OpasnetUtils) | ||
Line 84: | Line 126: | ||
ggplot(emission@output, aes(x=Year, weight=emissionResult, fill=Sector))+geom_bar()+ | ggplot(emission@output, aes(x=Year, weight=emissionResult, fill=Sector))+geom_bar()+ | ||
facet_wrap(~City, scales="free_y") | facet_wrap(~City, scales="free_y")+ | ||
theme_gray(base_size=20)+ | |||
labs(y="CO2eq emissions (kton/a)") | |||
opbase.upload( | opbase.upload( | ||
Line 98: | Line 142: | ||
) | ) | ||
cat("Ovariable emission uploaded as the answer of this knowledge crystal page.\n") | cat("Ovariable emission uploaded as the answer of this knowledge crystal page.\n") | ||
</rcode> | |||
<rcode name="caremission" label="Initiate ovariable caremission (for developers only)" embed=1 graphics=1> | |||
# This is code Op_en7923/caremission on page [[Air pollution emissions in Helsinki]] | |||
library(OpasnetUtils) | |||
library(ggplot2) | |||
caremission <- Ovariable( | |||
"caremission", | |||
dependencies = data.frame( | |||
Name=c("carkm","caremf"), | |||
Ident=c( | |||
"Op_en7926/carkm", # [[Road traffic in Helsinki]] | |||
"Op_en2989/caremf" # [[Emission factors for road transport]] | |||
) | |||
), | |||
formula = function(...) { | |||
out <- carkm * caremf / 1000 # Mkm * g/km --> kton | |||
return(out) | |||
} | |||
) | |||
caremission@meta$unit <- "kton/a" | |||
ggplot(EvalOutput(caremission)@output, aes(x=Year, weight=caremissionResult, fill=Vehicle))+ | |||
geom_bar()+facet_wrap(~Pollutant, scales="free_y") | |||
objects.store(caremission) | |||
cat("Ovariable caremission stored.\n") | |||
</rcode> | |||
==== Push indicator to HNH2035 ==== | |||
<rcode label="Push emission indicators (new version)" embed=1> | |||
library(OpasnetUtils) | |||
library(quiltr) | |||
library(plotly) | |||
library(ggplot2) | |||
objects.latest("Op_en6007", code_name="hnh2035") # [[OpasnetUtils/Drafts]] combineLines, pushIndicatorGraph | |||
dat <- qload("jyrjola/hsy", "pks_khk_paastot") | |||
dat <- dat[dat$Kaupunki=="Helsinki" , ] | |||
dat <- as.data.frame(dat) | |||
teeplotly <- function(dat,sector,title) { | |||
emis <- as.data.frame(dat) | |||
emis$Sector <- emis[[sector]] | |||
emis <- aggregate(emis["Päästöt"], emis[c("Vuosi","Sector")], sum) | |||
tmp <- aggregate(emis["Päästöt"],emis["Vuosi"],sum) | |||
pred <- rbind( | |||
data.frame( | |||
Vuosi=c(2000,2035), | |||
Tyyppi="toteuma", | |||
Paastot = predict( | |||
lm(Päästöt ~ Vuosi, data=tmp[tmp$Vuosi!=1990,]), | |||
newdata=data.frame(Vuosi=c(2000,2035)) | |||
) | |||
), | |||
data.frame( | |||
Vuosi=c(2017,2035), | |||
Tyyppi="tavoite", | |||
Paastot= c( | |||
tmp$Päästöt[tmp$Vuosi==2017], | |||
tmp$Päästöt[tmp$Vuosi==1990]*0.2) | |||
) | |||
) | |||
emis <- emis[emis$Vuosi!=1990,] | |||
p_emis <- plot_ly() %>% | |||
add_trace( | |||
x = ~emis$Vuosi, y = ~emis$Päästöt, type = 'bar', | |||
color = ~emis$Sector, legendgroup="mitattu") %>% | |||
# add_trace( # This is commented out because it causes an error in push process | |||
# x = ~pred$Vuosi, y = ~pred$Paastot, | |||
# linetype = ~pred$Tyyppi, mode='lines', | |||
# type = 'scatter', legendgroup = "ennuste") %>% | |||
layout( | |||
barmode="stack", | |||
title=title, | |||
xaxis=list(title="Vuosi"), | |||
yaxis=list(title="Päästö CO2e kton/a") | |||
) | |||
return(p_emis) | |||
} | |||
# p <- teeplotly(dat,"Sektori1","Kasvihuonekaasupäästöt Helsingissä sektoreittain") | |||
# pushIndicatorGraph(p, paste0(urli,6,"/")) | |||
p <- teeplotly(dat[dat$Sektori1=="Liikenne",],"Sektori2","Liikenteen kasvihuonekaasupäästöt Helsingissä") | |||
pushIndicatorGraph(p, 24) | |||
p <- teeplotly(dat[dat$Sektori2=="Tieliikenne",],"Sektori3","Tieliikenteen kasvihuonekaasupäästöt Helsingissä") | |||
pushIndicatorGraph(p, 23) | |||
p <- teeplotly(dat[dat$Sektori2 %in% c("Raideliikenne","Laivaliikenne"),],"Sektori3","Raide- ja laivaliikenteen kasvihuonekaasupäästöt Helsingissä") | |||
pushIndicatorGraph(p, 67) | |||
p <- teeplotly(dat[dat$Sektori3=="Henkilöautot",],"Sektori4","Henkilöautojen kasvihuonekaasupäästöt Helsingissä") | |||
pushIndicatorGraph(p, 11) | |||
p <- teeplotly(dat[dat$Sektori1=="Sähkö",],"Sektori2","Sähköntuotannon kasvihuonekaasupäästöt Helsingissä") | |||
pushIndicatorGraph(p, 30) | |||
p <- teeplotly(dat[dat$Sektori1=="Lämmitys",],"Sektori2","Lämmöntuotannon kasvihuonekaasupäästöt Helsingissä") | |||
pushIndicatorGraph(p, 25) | |||
p <- teeplotly(dat[dat$Sektori2=="Öljylämmitys",],"Sektori4","Öljylämmityksen kasvihuonekaasupäästöt Helsingissä") | |||
pushIndicatorGraph(p, 35) | |||
# teeplotly(dat[dat$Sektori1=="Teollisuus ja työkoneet",],"Sektori2","Teollisuuden kasvihuonekaasupäästöt Helsingissä") | |||
# teeplotly(dat[dat$Sektori1=="Maatalous",],"Sektori2","Maatalouden kasvihuonekaasupäästöt Helsingissä") | |||
# teeplotly(dat[dat$Sektori1=="Jätteiden käsittely",],"Sektori2","Jätteenkäsittelyn kasvihuonekaasupäästöt Helsingissä") | |||
p <- teeplotly(dat[dat$Sektori1 %in% c("Teollisuus ja työkoneet","Maatalous","Jätteiden käsittely"),],"Sektori2","Teollisuuden, jätteenkäsittelyn ja maatalouden kasvihuonekaasupäästöt Helsingissä") | |||
pushIndicatorGraph(p, 66) | |||
</rcode> | |||
<rcode label="Push emission indicators to HNH2035 (for developers only)" embed=1> | |||
# This is code Op_en7923/answer on page [[Air pollution emissions in Helsinki]] | |||
library(OpasnetUtils) | |||
library(plotly) | |||
objects.latest("Op_en6007", code_name="hnh2035") # [[OpasnetUtils/Drafts]] combineLines, pushIndicatorGraph | |||
objects.latest("Op_en6007", code_name="miscellaneous") # [[OpasnetUtils/Drafts]] truncateIndex | |||
objects.latest("Op_en7923", code_name="caremission") # [[Air pollution emissions in Helsinki]] caremission | |||
caremission <- EvalOutput(caremission) | |||
tmp <- caremission[caremission$Municipality=="Helsinki" & caremission$Pollutant=="CO2eq",] | |||
tmp <- truncateIndex(oapply(tmp, cols="Location", FUN=sum), "Vehicle",6) | |||
p_caremission_co2 <- plot_ly( | |||
tmp@output, | |||
x = ~Year, y = ~caremissionResult, color = ~Vehicle, type = 'bar' | |||
) %>% | |||
layout(barmode='stack', title="Henkilöautojen kasvihuonekaasupäästöt", | |||
xaxis=list(title="Vuosi"),yaxis=list(title="CO2ekv-päästö (kton/vuosi)")) | |||
tmp <- caremission[caremission$Municipality=="Helsinki" & caremission$Pollutant=="PM2.5",] | |||
tmp <- truncateIndex(oapply(tmp, cols="Location", FUN=sum), "Vehicle",6) | |||
p_caremission_pm <- plot_ly( | |||
tmp@output, | |||
x = ~Year, y = ~caremissionResult, color = ~Vehicle, type = 'bar' | |||
) %>% | |||
layout(barmode='stack', title="Henkilöautojen pienhiukkaspäästöt", | |||
xaxis=list(title="Vuosi"),yaxis=list(title="PM2.5-päästö (kton/vuosi)")) | |||
pushIndicatorGraph(p_caremission_co2, "https://hnh.teamy.fi/v1/indicator/11/") | |||
pushIndicatorGraph(p_caremission_pm, "https://hnh.teamy.fi/v1/indicator/15/") | |||
cat("Private car CO2eq and PM2.5 emissions (indicators #11, #15) pushed to HNH2035.\n") | |||
if(FALSE) { | |||
objects.latest("Op_en7923", code_name="emission") # [[Air pollution emissions in Helsinki]] emission | |||
emission <- EvalOutput(emission) | |||
caremission <- EvalOutput(caremission) | |||
} | |||
</rcode> | </rcode> | ||
Latest revision as of 20:12, 8 February 2019
Moderator:Nobody (see all) Click here to sign up. |
This page is a stub. You may improve it into a full page. |
Upload data
|
Air pollution emissions in Helsinki estimate direct air pollution emissions (including CO2eq) from the Helsinki area.
Question
What are the amounts of air pollution (notably CO2eq and PM2.5) emitted from the Helsinki area (Helsinki specifically but also other municipalities of the Helsinki Metropolitan Area)?
Answer
- Model run 12.12.2018 [1]
Rationale
Dependencies
Calculations
The answer metadata can be obtained by using link: http://cl1.opasnet.org/opasnet_base_2/index.php?ident=op_en7923.answer&act=0
The actual data: (key is unique to every download instance and is generated when the above link is opened) - http://cl1.opasnet.org/opasnet_base_2/index.php?key=8dYqLbtppz4HM7sYaAyj4t6S49jQNRWJ