Skip to content

Commit

Permalink
add fuel_eval argentina, still needs fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
ibarraespinosa committed Aug 26, 2024
1 parent c6a3a16 commit 225f17a
Show file tree
Hide file tree
Showing 8 changed files with 762 additions and 359 deletions.
Binary file modified projects/argentina/estimation/2019.tar.gz
Binary file not shown.
168 changes: 95 additions & 73 deletions projects/argentina/estimation/2019/config/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ setDT(mileage)
setDT(tfs)
setDT(veh)

# vehicle ####
reg <- unique(fuel_month$region)
if(!any(grepl("region", names(veh)))) {
if(add_reg_veh) {
switch (language,
"portuguese" = cat( "Adicionando `region` em `veh`\n"),
"english" = cat( "Adding `region` column in `veh`\n"),
"spanish" = cat( "Agregando columna `region` en `veh`\n"))

veh <- rbindlist(lapply(seq_along(reg), function(i){
veh$region <- reg[i]
veh
}))

}}


# fuel ####
setDT(fuel_month)

# necesita columnas Year, Month, FUEL_M3 *density_tm3
Expand All @@ -32,15 +50,19 @@ fuel_month[, type := "data"]

pmonth <- fuel_month

fuel_month[, sum(consumption_t),
by = .(region,
Year,
fuel,
type)
fuel_month[, sum(consumption_t),
by = .(region,
Year,
fuel,
type,
density_tm3)
] -> fuel

names(fuel)[ncol(fuel)] <- "consumption_t"

fuel$consumption_t <- units::set_units(fuel$consumption_t, "t")
fuel$density_tm3 <- units::set_units(fuel$density_tm3, "t/m3")

setDT(fuel_spec)
setDT(met)
setDT(euro)
Expand Down Expand Up @@ -121,7 +143,7 @@ switch (language,
# pastas
if(delete_directories){
choice <- 1

if(language == "portuguese") {
# choice <- utils::menu(c("Sim", "Não"), title="Apagar pastas csv, emi, images, notes, post e veh??")
if(choice == 1){
Expand All @@ -131,7 +153,7 @@ if(delete_directories){
unlink("notes", recursive = T)
unlink("post", recursive = T)
unlink("veh", recursive = T)
}
}
} else if(language == "english"){
# choice <- utils::menu(c("Yes", "No"), title="Delete folders `csv`, `emi`, `images`, `notes`, `post` e `veh`??")
if(choice == 1){
Expand All @@ -141,8 +163,8 @@ if(delete_directories){
unlink("notes", recursive = T)
unlink("post", recursive = T)
unlink("veh", recursive = T)
}
}

} else if(language == "spanish"){
# choice <- utils::menu(c("Si", "No"), title="Borrar carpetas `csv`, `emi`, `images`, `notes`, `post` y `veh`??")
if(choice == 1){
Expand All @@ -152,7 +174,7 @@ if(delete_directories){
unlink("images", recursive = T)
unlink("post", recursive = T)
unlink("veh", recursive = T)
}
}
}
}

Expand All @@ -178,10 +200,10 @@ n_LCV <- metadata$vehicles[grep(pattern = "LCV", x = metadata$vehicles)]
n_TRUCKS <- metadata$vehicles[grep(pattern = "TRUCKS", x = metadata$vehicles)]
n_BUS <- metadata$vehicles[grep(pattern = "BUS", x = metadata$vehicles)]
n_MC <- metadata$vehicles[grep(pattern = "MC", x = metadata$vehicles)]
n_veh <- list(PC = n_PC,
LCV = n_LCV,
TRUCKS = n_TRUCKS,
BUS = n_BUS,
n_veh <- list(PC = n_PC,
LCV = n_LCV,
TRUCKS = n_TRUCKS,
BUS = n_BUS,
MC = n_MC)
# Plot Fuel ####
switch (language,
Expand All @@ -200,9 +222,9 @@ p <- ggplot(pmonth,
theme(panel.spacing = unit(0,'lines'))
p

png("images/FUEL.png",
width = 3000,
height = 2000,
png("images/FUEL.png",
width = 3000,
height = 2000,
units = "px",
res = 300)
print(p)
Expand All @@ -215,15 +237,15 @@ switch (language,
"spanish" = cat("Plotando flota \n"))
setDT(veh)
setDT(metadata)
vv <- melt.data.table(data = veh[, c(metadata$vehicles,
"Year"),
with = F],
id.vars = c("Year"),
vv <- melt.data.table(data = veh[, c(metadata$vehicles,
"Year"),
with = F],
id.vars = c("Year"),
variable.name = "vehicles",
value.name = "veh")
vv <- merge(vv,
metadata[,
c("vehicles",
vv <- merge(vv,
metadata[,
c("vehicles",
"family",
"fuel",
"size"),
Expand All @@ -235,24 +257,24 @@ vv$sf <- paste(vv$size, vv$fuel)
fam <- unique(metadata$family)

for(i in seq_along(fam)) {

ggplot(vv[family == fam[i] &
veh> 0],
veh> 0],
aes(x = Year,
y = veh,
colour = vehicles)) +
geom_point() +
geom_line() +
theme_bw()-> p
png(paste0("images/FLEET_", fam[i], ".png"),
width = 3000,
height = 2500,


png(paste0("images/FLEET_", fam[i], ".png"),
width = 3000,
height = 2500,
"px",
res = 300)
print(p)
dev.off()
print(p)
dev.off()
}


Expand All @@ -266,9 +288,9 @@ switch (language,
for(i in seq_along(n_veh)) {
df_x <- tfs[, n_veh[[i]], with = F]
png(
paste0("images/TFS_",
paste0("images/TFS_",
names(n_veh)[i],
".png"),
".png"),
2000, 1500, "px",res = 300)
colplot(df = df_x,
cols = n_veh[[i]],
Expand Down Expand Up @@ -318,7 +340,7 @@ switch(language,

for (i in seq_along(n_veh)) {
df_x <- as.data.frame(s)[, n_veh[[i]]]

png(
paste0(
"images/S_",
Expand Down Expand Up @@ -354,69 +376,69 @@ peuro <- euro[, metadata$vehicles, with = F]

for(i in 1:ncol(peuro)){
peuro[[i]] <- gsub("Euro ", "", peuro[[i]])
peuro[[i]] <- as.roman(peuro[[i]])
peuro[[i]] <- suppressWarnings(as.roman(peuro[[i]]))
peuro[[i]] <- as.numeric(peuro[[i]])
}
}

peuro[is.na(peuro)] <- 0
peuro$Year<- euro$Year
melt.data.table(peuro, measure.vars = metadata$vehicles, id.vars = "Year") -> dfeuro

ggplot(dfeuro,
ggplot(dfeuro,
aes(x = Year,
y = variable,
fill = as.factor(value))) +
geom_tile() +
theme_bw(base_size = 14) -> p

png(paste0("images/standard.png"),
width = 3000,
height = 2500,
png(paste0("images/standard.png"),
width = 3000,
height = 2500,
"px",
res = 300)
print(p)
dev.off()
print(p)
dev.off()


# Plot Temperature ####
units(celsius(1))$numerator

ggplot(met,

ggplot(met,
aes(x = date,
y = Temperature)) +
geom_line() +
labs(title = year_select) +
facet_wrap(~ region) +
labs(title = year_select) +
facet_wrap(~ region) +
theme_bw(base_size = 16) -> p


png("images/Temperature.png",
width = 2000,
height = 1500,

png("images/Temperature.png",
width = 2000,
height = 1500,
"px",
res = 300)
print(p)
print(p)
dev.off()


# Plot Rain ####
ggplot(rain,

ggplot(rain,
aes(x = date,
y = PN)) +
geom_line() +
labs(title = year_select) +
facet_wrap(~ region) +
labs(title = year_select) +
facet_wrap(~ region) +
theme_bw(base_size = 16) -> p


png("images/Rain.png",
width = 2000,
height = 1500,

png("images/Rain.png",
width = 2000,
height = 1500,
"px",
res = 300)
print(p)
print(p)
dev.off()


Expand All @@ -440,7 +462,7 @@ units(celsius(1))$numerator
# theme = theme)
# dev.off()
# }
#
#


# Notes ####
Expand All @@ -449,16 +471,16 @@ switch (language,
"english" = cat("\nTaking some notes\n"),
"spanish" = cat("\nEscribiendo notas\n"))

vein_notes(notes = c("Default notes for vein::get_project"),
file = "notes/README",
title = paste0("Argentina by state ", year_select),
approach = 'Top-Down',
traffic = "DNRBA",
composition = "DNRBA",
ef = "COPERT",
cold_start = "COPERT",
evaporative = "Running Losses, Diurnal and Hot Soak",
standards = "EURO",
vein_notes(notes = c("Default notes for vein::get_project"),
file = "notes/README",
title = paste0("Argentina by state ", year_select),
approach = 'Top-Down',
traffic = "DNRBA",
composition = "DNRBA",
ef = "COPERT",
cold_start = "COPERT",
evaporative = "Running Losses, Diurnal and Hot Soak",
standards = "EURO",
mileage = "Bruni and Bales 2013")
# saveRDS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ Argentina by state 2019

Directory: /media/sergio/ext4/models/vein/projects/argentina/estimation/2019

Local Time: 2024-08-19 22:12:00.049551
Local Time: 2024-08-25 16:30:38.66824
Inventory compiler: sergio
========================================

sysname = Linux
release = 6.8.0-40-generic
version = #40-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 5 10:34:03 UTC 2024
release = 6.8.0-41-generic
version = #41-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 2 20:41:06 UTC 2024
nodename = sergio-gl639sd
machine = x86_64
user = sergio
Expand All @@ -19,7 +19,7 @@ nickname = Race for Your Life
Memory used = 1520Mb
========================================

VEIN version = 1.1.3
VEIN version = 1.1.4
========================================

Traffic:
Expand Down Expand Up @@ -60,8 +60,10 @@ BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.12.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8
[8] LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

time zone: America/Denver
tzcode source: system (glibc)
Expand All @@ -70,14 +72,19 @@ attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] stars_0.6-6 abind_1.4-5 eixport_0.6.0 units_0.8-5 data.table_1.15.4 ggplot2_3.5.1 cptcity_1.0.6 sf_1.0-16 vein_1.1.3
[1] stars_0.6-6 abind_1.4-5 eixport_0.6.0 units_0.8-5 data.table_1.15.4
[6] ggplot2_3.5.1 cptcity_1.0.6 sf_1.0-16 vein_1.1.4

loaded via a namespace (and not attached):
[1] utf8_1.2.4 class_7.3-22 KernSmooth_2.23-24 lattice_0.22-5 magrittr_2.0.3 grid_4.4.1 cellranger_1.1.0 processx_3.8.4 pkgbuild_1.4.4 e1071_1.7-14
[11] DBI_1.2.3 ps_1.7.7 fansi_1.0.6 scales_1.3.0 codetools_0.2-20 cli_3.6.3 rlang_1.1.4 munsell_0.5.1 remotes_2.5.0 withr_3.0.0
[21] tools_4.4.1 raster_3.6-26 parallel_4.4.1 colorspace_2.1-1 ncdf4_1.23 curl_5.2.1 vctrs_0.6.5 R6_2.5.1 proxy_0.4-27 lifecycle_1.0.4
[31] classInt_0.4-10 pkgconfig_2.0.3 desc_1.4.3 callr_3.7.6 terra_1.7-78 pillar_1.9.0 gtable_0.3.5 glue_1.7.0 Rcpp_1.0.13 tibble_3.2.1
[41] farver_2.1.2 labeling_0.4.3 dotCall64_1.1-1 compiler_4.4.1 readxl_1.4.3 sp_2.1-4
[1] utf8_1.2.4 generics_0.1.3 class_7.3-22 KernSmooth_2.23-24 lattice_0.22-5
[6] magrittr_2.0.3 grid_4.4.1 cellranger_1.1.0 e1071_1.7-14 DBI_1.2.3
[11] fansi_1.0.6 scales_1.3.0 codetools_0.2-20 cli_3.6.3 rlang_1.1.4
[16] munsell_0.5.1 withr_3.0.1 tools_4.4.1 raster_3.6-26 parallel_4.4.1
[21] dplyr_1.1.4 colorspace_2.1-1 ncdf4_1.23 vctrs_0.6.5 R6_2.5.1
[26] proxy_0.4-27 lifecycle_1.0.4 classInt_0.4-10 pkgconfig_2.0.3 terra_1.7-78
[31] pillar_1.9.0 gtable_0.3.5 glue_1.7.0 Rcpp_1.0.13 tibble_3.2.1
[36] tidyselect_1.2.1 rstudioapi_0.16.0 farver_2.1.2 labeling_0.4.3 dotCall64_1.1-1
[41] compiler_4.4.1 readxl_1.4.3 sp_2.1-4

========================================

Expand Down
Loading

0 comments on commit 225f17a

Please sign in to comment.