diff --git a/.gitignore b/.gitignore index f0e2666..d6049a3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ -*.Rhistory -*/.Rhistory +.Rhistory RTS_Data/rts_PLEXOS_data_check RTS_Data/rts_PLEXOS.xlsx Create_PLEXOS_database/1-parse-matpower/outputs/*.csv diff --git a/Create_PLEXOS_database/2-create-excel/.Rhistory b/Create_PLEXOS_database/2-create-excel/.Rhistory index 90865c7..b4f2c5a 100644 --- a/Create_PLEXOS_database/2-create-excel/.Rhistory +++ b/Create_PLEXOS_database/2-create-excel/.Rhistory @@ -1,242 +1,70 @@ -install.packages('openxlsx') -library(rplexos) -plexos_open('//plexossql/data/moconnel/CA Flexibility Paper/Mark_runs') -s -files = plexos_open('//plexossql/data/moconnel/CA Flexibility Paper/Mark_runs') -View(files) -View(files) -db = files[1] -View(db) -db = files[,1] -View(db) -db = files[1,] -View(db) -database = db -gsub('.*Model ', '', database[1,3]) -plexos_open(c('//plexossql/data/moconnel/CA Flexibility Paper/Mark_runs/1','//plexossql/data/moconnel/CA Flexibility Paper/Mark_runs/2')) -files = plexos_open(c('//plexossql/data/moconnel/CA Flexibility Paper/Mark_runs/1','//plexossql/data/moconnel/CA Flexibility Paper/Mark_runs/2')) -View(files) -query_year(files, 'Generator', 'Generation') -sum_year(files, 'Generator', 'Generation') -results = query_year(files, 'Region', 'Load') -View(results) -library(dplyr) -library(data.table) -library(reshape2) -library(plyr) -# Load all files -mapping = fread('//plexossql/data/moconnel/Gen_CSV_Mapping_Files/GenNamesTEPPC_2024_RPV_dispatch.CSV') -max.cap.monthly.plexos = fread('//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/all_maxCap_monthly_fromWECCdb.csv') -max.cap.static.plexos = fread('//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/all_maxCap_static_fromWECCdb.csv') -min.stable.plexos = fread('//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/all_minStable_fromWECCdb.csv') -max.energy.monthly.plexos = fread('//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/hydro_MaxEnergyMonth_fromWECCdb.csv') -gen_jennie = fread('//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/all_maxCap_minStable_WECC_jennie.csv') -View(gen_jennie) -View(max.cap.monthly.plexos) -max.cap.monthly.plexos = merge(max.cap.monthly.plexos, mapping, by='name') -max.cap.static.plexos = merge(max.cap.static.plexos, mapping, by='name') -min.stable.plexos = merge(min.stable.plexos, mapping, by='name') -max.energy.monthly.plexos = merge(max.energy.monthly.plexos, mapping, by='name') -View(max.cap.monthly.plexos) -unique(max.cap.monthly.plexos$Type) -unique(max.cap.static.plexos$Type) -unique(max.energy.monthly.plexos$Type) -str(max.cap.monthly.plexos) -max.cap.monthly.plexos <- max.cap.monthly.plexos[Type=='Hydro',] -View(max.cap.monthly.plexos) -unique(max.cap.monthly.plexos$Type) -max.cap.monthly.plexos = fread('//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/all_maxCap_monthly_fromWECCdb.csv') -max.cap.monthly.plexos = merge(max.cap.monthly.plexos, mapping, by='name') -max.cap.monthly.plexos -unique(max.cap.monthly.plexos$Type) -View(max.cap.monthly.plexos) -max.cap.monthly.plexos <- max.cap.monthly.plexos[Type=='Hydro',] -max.cap.static.plexos <- max.cap.monthly.plexos[Type=='Hydro',] -min.stable.plexos <- min.stable.plexos[Type=='Hydro',] -max.energy.monthly.plexos <- max.energy.monthly.plexos[Type=='Hydro',] -gen_jennie <- gen_jennie[Type=='Hydro',] -View(max.cap.static.plexos) -View(max.cap.monthly.plexos) -View(max.cap.static.plexos) -max.cap.static.plexos = fread('//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/all_maxCap_static_fromWECCdb.csv') -max.cap.static.plexos = merge(max.cap.static.plexos, mapping, by='name') -max.cap.static.plexos <- max.cap.monthly.plexos[Type=='Hydro',] -View(max.cap.static.plexos) -max.cap.static.plexos = fread('//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/all_maxCap_static_fromWECCdb.csv') -View(max.cap.static.plexos) -max.cap.static.plexos = merge(max.cap.static.plexos, mapping, by='name') -View(max.cap.static.plexos) -max.cap.static.plexos <- max.cap.static.plexos[Type=='Hydro',] -View(max.cap.static.plexos) -length(unique(max.cap.static.plexos$name)) -length(unique(max.cap.monthly.plexos$name)) -test[1] = (unique(max.cap.static.plexos$name) -) -test = data.table(monthly = unique(max.cap.monthly.plexos$name), static = unique(max.cap.static.plexos)) -View(test) -rm(test) -test = data.table(monthly = unique(max.cap.monthly.plexos$name), static = unique(max.cap.static.plexos)) -View(test) -test <- data.table(monthly = unique(max.cap.monthly.plexos$name), static = unique(max.cap.static.plexos)) -test1 = unique(max.cap.monthly.plexos$name) -test2 = unique(max.cap.static.plexos$name) -test3 = data.table(test1, test2) -View(test3) -test3[,diff := test1==test2] -View(test3) -sum(test3$diff) -nrow(test43) -nrow(test3) -rm(test, test3, test1, test2) -View(max.cap.monthly.plexos) -View(max.cap.static.plexos) -unique(max.cap.static.plexos$Scenario) -View(max.cap.monthly.plexos) -max.cap.monthly.plexos = dcast(max.cap.monthly.plexos, name+TypeSpecific~Month, value.var='Max Capacity') -View(max.cap.monthly.plexos) -View(min.stable.plexos) -unique(min.stable.plexos$scenario) -min.stable.plexos <- min.stable.plexos[scenario=='Monthly Min Stable Level'] -min.stable.plexos = dcast(min.stable.plexos, name~timeslice, value.var='value') -View(max.energy.monthly.plexos) -unique(max.energy.monthly.plexos$scenario) -max.energy.monthly.plexos <- max.energy.monthly.plexos[scenario=='update from V1.1 to V1.2' | scenario==''] -View(max.energy.monthly.plexos) -max.energy.dates = max.energy.monthly.plexos[date.from!=""] -max.energy.dates = max.energy.dates[grepl(2024, max.energy.dates[,date.from])] -max.energy.base = max.energy.monthly.plexos[date.from==""] -max.energy <- rbind(max.energy.base, max.energy.dates) -max.energy <- data.table(dcast(max.energy, name+timeslice~scenario, value.var='value')) -View(max.energy) -max.energy[, value := `update from V1.1 to V1.2`] -max.energy[is.na(value), value := Var.3] -View(max.energy) -max.energy = dcast(max.energy, name~timeslice, value.var='value') -View(max.energy) -library(dplyr) -library(data.table) -library(reshape2) -library(plyr) -# Load all files -mapping = fread('//plexossql/data/moconnel/Gen_CSV_Mapping_Files/GenNamesTEPPC_2024_RPV_dispatch.CSV') -max.cap.monthly.plexos = fread('//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/all_maxCap_monthly_fromWECCdb.csv') -# max.cap.static.plexos = fread('//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/all_maxCap_static_fromWECCdb.csv') -min.stable.plexos = fread('//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/all_minStable_fromWECCdb.csv') -max.energy.monthly.plexos = fread('//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/hydro_MaxEnergyMonth_fromWECCdb.csv') -gen_jennie = fread('//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/all_maxCap_minStable_WECC_jennie.csv') -# Add gen type to files -max.cap.monthly.plexos = merge(max.cap.monthly.plexos, mapping, by='name') -# max.cap.static.plexos = merge(max.cap.static.plexos, mapping, by='name') -min.stable.plexos = merge(min.stable.plexos, mapping, by='name') -max.energy.monthly.plexos = merge(max.energy.monthly.plexos, mapping, by='name') -# Remove all non-hydro generators -max.cap.monthly.plexos <- max.cap.monthly.plexos[Type=='Hydro',] -# max.cap.static.plexos <- max.cap.static.plexos[Type=='Hydro',] -min.stable.plexos <- min.stable.plexos[Type=='Hydro',] -max.energy.monthly.plexos <- max.energy.monthly.plexos[Type=='Hydro',] -gen_jennie <- gen_jennie[Type=='Hydro',] -max.energy.monthly.plexos <- max.energy.monthly.plexos[scenario=='update from V1.1 to V1.2' | scenario==''] -max.energy.dates = max.energy.monthly.plexos[date.from!=""] -max.energy.dates = max.energy.dates[grepl(2024, max.energy.dates[,date.from])] -max.energy.base = max.energy.monthly.plexos[date.from==""] -max.energy <- rbind(max.energy.base, max.energy.dates) -max.energy <- data.table(dcast(max.energy, name+timeslice~scenario, value.var='value')) -max.energy[, value := `update from V1.1 to V1.2`] -max.energy[is.na(value), value := Var.3] -max.energy.monthly.plexos = fread('//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/hydro_MaxEnergyMonth_fromWECCdb.csv') -min.stable.plexos <- min.stable.plexos[scenario=='Monthly Min Stable Level'] -min.stable.plexos = dcast(min.stable.plexos, name~timeslice, value.var='value') -# write.csv(min.stable, '//nrelqnap01d/plexos/projects/im3/Thermal_Hydro_Gen_Params/monthlyMinStable_hydro.csv', row.names=FALSE) -# Extract monthly maximum energy for hydro units from database, and then write csv file -max.energy.monthly.plexos <- max.energy.monthly.plexos[scenario=='update from V1.1 to V1.2' | scenario==''] -max.energy.dates = max.energy.monthly.plexos[date.from!=""] -max.energy.dates = max.energy.dates[grepl(2024, max.energy.dates[,date.from])] -max.energy.base = max.energy.monthly.plexos[date.from==""] -max.energy <- rbind(max.energy.base, max.energy.dates) -max.energy <- data.table(dcast(max.energy, name+timeslice~scenario, value.var='value')) -max.energy[, value := `update from V1.1 to V1.2`] -max.energy[is.na(value), value := Var.3] -# max.energy[is.na(value), value := `MonthlyEnergy with K equal to zero`] -max.energy = dcast(max.energy, name~timeslice, value.var='value') -View(max.energy) -View(gen_jennie) -gen_maxCap = fread('//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/all_maxCap_static_WECC_plexos_output.csv') -View(gen_maxCap) -gen_maxCap = merge(gen_maxCap, mapping, by='name') -gen_maxCap = fread('//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/all_maxCap_static_WECC_plexos_output.csv') -gen_maxCap = merge(gen_maxCap, mapping, by='name') -View(gen_maxCap) -gen_maxCap[Type %in% c('CHP-QF', 'Gas CT', 'Biomass', 'Gas CC', 'Coal', 'Steam', 'Nuclear')] -gen_maxCap <- gen_maxCap[Type %in% c('CHP-QF', 'Gas CT', 'Biomass', 'Gas CC', 'Coal', 'Steam', 'Nuclear')] -gen_maxCap_db = fread('//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/all_maxCap_static_fromWECCdb.csv') -gen_maxCap_db = merge(gen_maxCap_db, mapping, by='name') -max.cap.thermal = gen_maxCap_db[Type %in% c('CHP-QF', 'Gas CT', 'Biomass', 'Gas CC', 'Coal', 'Steam', 'Nuclear')] -max.cap.thermal.noscen = max.cap.thermal[Scenario == ''] -max.cap.thermal.lcgs = max.cap.thermal[Scenario == 'CA_GasFleet_LCGS'] -for ( i in max.cap.thermal.lcgs[,name] ) { -max.cap.thermal.noscen[name==i, `Max Capacity` := max.cap.thermal.lcgs[name==i, `Max Capacity`]] -} -therm.db = max.cap.thermal.noscen -View(max.cap.thermal.noscen) -View(gen_maxCap) -mapping = fread('//plexossql/data/moconnel/Gen_CSV_Mapping_Files/GenNamesTEPPC_2024_RPV_dispatch.CSV') -gen_maxCap_db = fread('//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/all_maxCap_static_fromWECCdb.csv') -gen_maxCap_db = merge(gen_maxCap_db, mapping, by='name') -max.cap.thermal = gen_maxCap_db[Type %in% c('CHP-QF', 'Gas CT', 'Biomass', 'Gas CC', 'Coal', 'Steam', 'Nuclear')] -max.cap.thermal.noscen = max.cap.thermal[Scenario == ''] -max.cap.thermal.lcgs = max.cap.thermal[Scenario == 'CA_GasFleet_LCGS'] -for ( i in max.cap.thermal.lcgs[,name] ) { -max.cap.thermal.noscen[name==i, `Max Capacity` := max.cap.thermal.lcgs[name==i, `Max Capacity`]] -} -therm.db = max.cap.thermal.noscen -gen_maxCap = fread('//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/all_maxCap_static_WECC_plexos_output.csv') -gen_maxCap = merge(gen_maxCap, mapping, by='name') -gen_maxCap <- gen_maxCap[Type %in% c('CHP-QF', 'Gas CT', 'Biomass', 'Gas CC', 'Coal', 'Steam', 'Nuclear')] -write.csv(gen_maxCap, '//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/plexos_mapCap.csv', row.names=FALSE) -write.csv(therm.db, '//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/prevoius_mapCap.csv', row.names=FALSE) -gen_maxCap_db = fread('//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/all_maxCap_static_fromWECCdb.csv') -gen_maxCap_db = merge(gen_maxCap_db, mapping, by='name') -max.cap.thermal = gen_maxCap_db[Type %in% c('CHP-QF', 'Gas CT', 'Biomass', 'Gas CC', 'Coal', 'Steam', 'Nuclear')] -max.cap.thermal.noscen = max.cap.thermal[Scenario == ''] -max.cap.thermal.lcgs = max.cap.thermal[Scenario == 'CA_GasFleet_LCGS'] -for ( i in max.cap.thermal.lcgs[,name] ) { -max.cap.thermal.noscen[name==i, `Max Capacity` := max.cap.thermal.lcgs[name==i, `Max Capacity`]] -} -View(max.cap.thermal.noscen) -gen_maxCap = fread('//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/all_maxCap_static_WECC_plexos_output.csv') -gen_maxCap = merge(gen_maxCap, mapping, by='name') -gen_maxCap <- gen_maxCap[Type %in% c('CHP-QF', 'Gas CT', 'Biomass', 'Gas CC', 'Coal', 'Steam', 'Nuclear')] -write.csv(gen_maxCap, '//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/plexos_maxCap.csv', row.names=FALSE) -write.csv(therm.db, '//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/prevoius_maxCap.csv', row.names=FALSE) -gen_maxCap = fread('//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/all_maxCap_static_WECC_plexos_output.csv') -gen_maxCap = merge(gen_maxCap, mapping, by='name') -gen_maxCap <- gen_maxCap[Type == 'Hydro'] -View(gen_maxCap) -write.csv(gen_maxCap, '//nrelqnap01d/plexos/projects/im3/WECC_db_gen_data/plexos_maxCap_hydro.csv', row.names=FALSE) -library(rplexos) -process_folder('//nrelqnap01d/plexos/projects/im3/PLEXOS database/Model DA_Nodal_Baseline_IM3_1day_regionLoad Solution/') -process_folder('//nrelqnap01d/plexos/projects/im3/PLEXOS database/Model DA_Nodal_Baseline_IM3_1day_regionLoad Solution') -db = plexos_open('//nrelqnap01d/plexos/projects/im3/PLEXOS database/Model DA_Nodal_Baseline_IM3_1day_regionLoad Solution') -prop = query_property(db) -View(prop) -?query_log_steps -library(rplexos) -?query_log_steps -source('C:/Users/moconnel/Documents/RTS-GMLC/Create_PLEXOS_database/1-parse-matpower/parse_matpower.R', echo=TRUE) -source('C:/Users/moconnel/Documents/RTS-GMLC/Create_PLEXOS_database/2-create-excel/run_PSSE2PLEXOS.R', echo=TRUE) -source('C:/Users/moconnel/Documents/RTS-GMLC/Create_PLEXOS_database/1-parse-matpower/parse_matpower.R', echo=TRUE) -source('C:/Users/moconnel/Documents/RTS-GMLC/Create_PLEXOS_database/2-create-excel/run_PSSE2PLEXOS.R', echo=TRUE) -source('X:/MAGMA/run_html_output_rts.R', echo=TRUE) -source('X:/MAGMA/run_html_output_rts.R', echo=TRUE) -source('X:/MAGMA/run_html_output_rts.R', echo=TRUE) -source('X:/MAGMA/run_html_output_rts.R', echo=TRUE) -source('X:/MAGMA/run_html_output_rts.R', echo=TRUE) -source('C:/Users/moconnel/Documents/RTS-GMLC/Create_PLEXOS_database/1-parse-matpower/parse_matpower.R', echo=TRUE) -source('C:/Users/moconnel/Documents/RTS-GMLC/Create_PLEXOS_database/1-parse-matpower/parse_matpower.R', echo=TRUE) -traceback() -storage.csp.da <- fread("../../RTS_Data/storage.csp.da.csv") -storage.csp.rt <- fread("../../RTS_Data/storage.csp.rt.csv") -source('C:/Users/moconnel/Documents/RTS-GMLC/Create_PLEXOS_database/1-parse-matpower/parse_matpower.R', echo=TRUE) -source('C:/Users/moconnel/Documents/RTS-GMLC/Create_PLEXOS_database/2-create-excel/run_PSSE2PLEXOS.R', echo=TRUE) -source('C:/Users/moconnel/Documents/RTS-GMLC/Create_PLEXOS_database/1-parse-matpower/parse_matpower.R', echo=TRUE) -source('C:/Users/moconnel/Documents/RTS-GMLC/Create_PLEXOS_database/2-create-excel/run_PSSE2PLEXOS.R', echo=TRUE) +sessionInfo() +as.posixct("2024-01-01 00:01:00") +as.POSIXct("2024-01-01 00:01:00") +seq(as.POSIXct("2024-01-01 00:01:00"),as.POSIXct("2025-01-01 00:00:00"),by = '5 minute') +seq(as.POSIXct("2024-01-01 00:01:00"),as.POSIXct("2025-01-01 00:00:00"),by = 'hour') +seq(as.POSIXct("2024-01-01 01:00:00"),as.POSIXct("2025-01-01 00:00:00"),by = 'hour') +seq(as.POSIXct("2024-01-01 01:00:00"),as.POSIXct("2025-01-01 00:00:00"),by = 5) +seq(as.POSIXct("2024-01-01 01:00:00"),as.POSIXct("2025-01-01 00:00:00"),by = 5*60) +x - seq(as.POSIXct("2024-01-01 01:00:00"),as.POSIXct("2025-01-01 00:00:00"),by = 5*60) +x = seq(as.POSIXct("2024-01-01 01:00:00"),as.POSIXct("2025-01-01 00:00:00"),by = 5*60) +x +hour(x) +as.hour(x) +pacman::p_load(lubridate) +hour(x) +ts = data.table(Year = year(x),Hour = hour(x),Minute=minute(x),value=0) +pacman::p_load(lubridate,data.table) +ts = data.table(Year = year(x),Hour = hour(x),Minute=minute(x),value=0) +ts +x = seq(as.POSIXct("2024-01-01 01:00:00"),as.POSIXct("2024-12-31 23:55:00"),by = 5*60) +ts = data.table(Year = year(x),Hour = hour(x),Minute=minute(x),value=0) +ts +write.csv(ts,file='Documents/repos/RTS-GMLC/RTS_Data/timeseries_data_files/hydro/region1_Hydro_RT.csv') +write.csv(ts,file='Documents/repos/RTS-GMLC/RTS_Data/timeseries_data_files/hydro/region2_Hydro_RT.csv') +write.csv(ts,file='Documents/repos/RTS-GMLC/RTS_Data/timeseries_data_files/hydro/region3_Hydro_RT.csv') +write.csv(ts,file='Documents/repos/RTS-GMLC/RTS_Data/timeseries_data_files/hydro/region3_Hydro_RT.csv',row.names = F) +write.csv(ts,file='Documents/repos/RTS-GMLC/RTS_Data/timeseries_data_files/hydro/region3_Hydro_RT.csv',row.names = F,quote = F) +ts = data.table(Year = year(x),Hour = hour(x),Minute=minute(x),value=0) +ts = data.table(Year = year(x),Month = month(x),Day=day(x),Period = (hour(x)-1)*12 + minute(x),value=0) +ts +ts = data.table(Year = year(x),Month = month(x),Day=day(x),Period = (hour(x)-1)*12 + minute(x)/5,value=0) +ts +5*12*12 +5*12*24 +max(ts$Period) +ts = data.table(Year = year(x),Month = month(x),Day=day(x),Period = (hour(x))*12 + minute(x)/5,value=0) +ts +ts = data.table(Year = year(x),Month = month(x),Day=day(x),Period = ((hour(x)-1)*12 + minute(x))/5,value=0) +ts +mintue(x)-1 +minute(x)-1 +minute(x) +minute(x)/5 +minute(x)/5+1 +(minute(x)/5+1)*(hour(x)) +(minute(x)/5+1) +(minute(x)/5+1)+(12*hour(x)) +12*24 +ts = data.table(Year = year(x),Month = month(x),Day=day(x),Period = (minute(x)/5+1)+(12*hour(x)),value=0) +ts +ts = data.table(Year = year(x),Month = month(x),Day=day(x),Period = (minute(x)/5+1)+(12*(hour(x)-1)),value=0) +ts +24*12 +View(ts) +x = seq(as.POSIXct("2024-01-01 00:00:00"),as.POSIXct("2024-12-31 23:55:00"),by = 5*60) +ts = data.table(Year = year(x),Month = month(x),Day=day(x),Period = (minute(x)/5+1)+(12*(hour(x))),value=0) +View(ts) +write.csv(ts,file='Documents/repos/RTS-GMLC/RTS_Data/timeseries_data_files/hydro/region3_Hydro_RT.csv',row.names = F,quote = F) +write.csv(ts,file='Documents/repos/RTS-GMLC/RTS_Data/timeseries_data_files/hydro/region2_Hydro_RT.csv',row.names = F,quote = F) +write.csv(ts,file='Documents/repos/RTS-GMLC/RTS_Data/timeseries_data_files/hydro/region1_Hydro_RT.csv',row.names = F,quote = F) +setwd('Documents/repos/RTS-GMLC/') +setwd('Create_PLEXOS_database/') +source('create_RTS_spreadsheet.R') +source('1-parse-matpower/parse_matpower.R') +setwd('../2-create-excel') +source('run_PSSE2PLEXOS.R') +prop.table() +Properties.sheet +Properties.sheet[property=='Heat Rate'] +Properties.sheet[property=='Heat Rate']