Skip to content

Latest commit

 

History

History
600 lines (314 loc) · 26.3 KB

README.md

File metadata and controls

600 lines (314 loc) · 26.3 KB

AB ELECTRICITY GRID MODELLING

Code and functions to visually analyze large groups of forecasting energy data. Data is taken from SQL server databases, excel files, and .R files. Formatting is based on Aurora software output, but code could be modified to work for other model outputs.

Also includes functions and code segments to visualize historical data from Alberta's electricity sector.

CONTENTS

CODE FILES

Files to be run following each simulation. Database Loading is the main code, the rest are useful in specific situations only.

Database_Loading

Contains the main code which is used to load data from Microsoft SQL server into the R environment. The script the imports chosen tables, filters required information, and formats dates. The code also contains format information for figures such as legend colors, text sizes, and names.

The sections referencing AESO data and filtering this data can be skipped if no comparison is needed.

Database_Loading Special Notes:
  • Make sure the R project file (ab-net-zero-grid-model) is open first or "here" commands will not function.

  • Before running, create a folder called "Data Files" in the project directory. Create two folders inside names "Result Files" and "Alberta Data", populate "Alberta Data" with nrgstream data. This just prevents said data from being uploaded to GitHub

    • This folder is referenced in the .gitignore file
  • A folder called "Figures (Local)" should also be created in the project directory of R, this allows figures to be saved locally as opposed to on GitHub. - This folder is referenced in the .gitignore file

    image

  • Once this file is run through completion, can call any functions as long as the right tables have been loaded in!

Scenario_Compare

Contains packages and code to compare R files between scenarios. Requires same file set up as Database_Loading to save results. Includes options to combine files into single excel and .r format and compare files using plots.

Scenario_Compare Special Notes:
  • Make sure the R project file (ab-net-zero-grid-model) is open first or "here" commands will not function.
  • The function "AnnualDataR" must be run before combining files. This function creates .r data that will be combined and referenced.
  • Before running, create a folder called "Data Files" in the project directory and add two sub-folders called "Result Files" and "Scenario Compare".
    • This folder is referenced in the .gitignore file

AESO_TradeAnalysis

Script imports data and analyses intertie behavior. Also looks at link capabilities over selected time periods. One-off code.

AESO_TradeAnalysis Special Notes:
  • Make sure the project file is open first or "here" commands wont work right.
  • Before running, create folder called "Data Files" within project directory and populate it with AESO data.
  • Once this file is run through completion, can call any functions with environment that is loaded.

AESO-Analysis

Script for general analysis and plots related to historical generation using NRGstream data.

  • Make sure the project file is open first or "here" commands wont work right.
  • Before running, create folder called "Data Files" within project directory and populate it with AESO data.
  • Once this file is run through completion, can call any functions with environment that is loaded.

Misc_Data_Visuals

Plots not directly related to simulation and modelling work. Inlcudes AESO planning area plots data and more.

Misc_Data_Visuals Special Notes:
  • Make sure the project file is open first or "here" commands wont work right.
  • Before running, create folder called "Data Files/AESO Planning Locations" within project directory and populate it geographical data and project information.

Referenced_Code

Codes adapted from Dr. Andrew Leach and Taylor Pawlenchuk.Functions are used inside some other functions.

wind_maps

Codes to plot map of AB wind potential and solar potential. Includes options to include existing or proposed project locations based on excel file.

FUNCTION FILES

Functions are found in the "Functions" folder and are organized into categories and stored in respective code files. For each function, there is a short description bellow, for more details (including inputs and required tables) see .R file.

Build_Retire_Functions

Functions to evaluate additions and retirements of electricity grid based on long-term capacity expansion. May be some hard coded values!

Functions:

  • Retirecol : Plotting the resources retired as a bar chart.

  • RetireMW : Plotting the resource capacity retired as a bar chart.

  • Builtcol : Plotting the resources built as a bar chart. This is not the best visual when partial builds are allowed! Partial builds limits the capacity but not the actual number of units.

  • Build_A_MW : Plotting the capacity of resources built by Aurora (does not include AESO que projects).

  • BuildMW : Plotting the built capacity for ALL new resources (resource table and new resource table).

  • Eval_CapChange : Shows net capacity changes each year. The first year of data does not have a prior capacity to compare to, so it is not used.

  • TotalCapChange : Shows capacity changes each year, includes additions and retirements.

  • Units : Unit specific bar chart showing builds by unit for certain resource type (ex: "WND").

  • Slack : Unit specific bar chart showing units not built (or available) for certain resource type.

  • BuildUnits : Show units built compared to available ones for a resource type.

  • Build_CCSRet : Show CCS retrofit options and what took place.

  • Build_CCSRet2 : Show base units for CCS retrofit options and year retired to allow retrofit.

  • CC_Fate_study : Show if combined cycle gas plants continue to opperate, retire, or retrofit over entire study.

  • CC_Fate_year : Shows total combined cycle gas capacity in each year of study. Includes retirement and retrofit option.

Daily_Output_Functions

Hourly outut for single days under alternative conditions.

  • CompDay_Season : Compare two typical days in winter and summer.

  • CompDay_Wind : Plot max and min wind days for a given year.

  • CompDay_Solar : Plot max and min solar days for a given year.

  • CompDay_Years : Compare the saem day in two different years.

  • CompDay_AESO : Compare a specified day from the simulation with actual data.

Data_Filt_To_File

Filters and organizes annual and hourly data, sends to an excel file or .R file which can be easily interpreted and exported to other programs. Also includes functions to filter and reformat key data for comparison between scenarios.

Functions:

  • AnnaulDataExcel : Writes all relevant annual data to an excel file on different sheets.

  • HourlyDataExcel : Writes all relevant hourly data to an excel file on different sheets.

  • HourlyDataR : Writes all relevant hourly data to an R file on different sheets.

  • AnnualDataR : Filters and organizes annual data, sends to R files for easy accessibility.

  • CombineFilesR : Reads filtered R data and combines two files into a single excel sheet and output R data files.

  • CombineFilesR_multiple : Reads filtered R data and combines mutliple files into a single excel sheet and output R data files.

Data_Filt_To_Table Special Notes:
  • Excel sheets will be written to the "Data Files" folder stored locally within the R project. If the name is not changes it will be over-written when running again.

Developing_Functions

Functions that are not completed yet and are not yet categorized. Space to test functions out. When functions are de-bugged and working they will be moved to a different file.

Emission_Functions

Functions to evaluate and show emissions.

Functions:

  • AnnualEmStackCol : Plot annual emissions by resource group as as stacked chart.

  • AnnualEmLine : Plot annual emissions by resource group as as line chart.

  • Emissions_CER_Res : Plot annual emissions for CER resources.

  • Emissions_CER_group : Plot annual emissions grouped by year CER is in effect.

Group_PlotSave

Quickly save groups of plots to folders without creating each figure individually.

Functions:

  • GGSave_Loc : Saves all plots to a new folder named after case using ggplot.

  • GGSave_Loc_custom : Saves all plots to a new folder names after case, custom image size.

  • GGSave_Loc_Ex : Saves all plots to a new folder called "Additional Analysis" inside image folder named after case using ggplot.

  • GGSave_Loc_narrow : Saves all plots to a new folder named after case using ggplot, narrow image.

  • GGSave_Loc_wide : Saves all plots to a new folder named after case using ggplot, wide image.

  • GGSave_Loc_hourly : Saves all plots to a new folder names after case, bigger and wider image.

  • Value_saveall : Save all value plots including NPV, annual value, annual value per MWh generated.

  • Slack_saveall : Save plots to compare available units and built units in capacity expansion.

  • Analysis_saveall : Save general analysis plots including capacity, generation, emissions, and cost information.

  • Detail_Gen_save : Save detailed generation plots, shows hourly generation in different months and years.

  • Ren_Curtail_Gen_save : Save detailed year of weeks and daily generation plots with curtailment..

  • CER_saveall : Save plot related to CER constraint implimentation.

Intertie_Functions

Functions To use for plotting and evaluating intertie activities. Also shows information on trade and what is happening in BC/MT/SK.

Functions:

  • Imp_Exp1 : AB imports and exports plotted as yearly totals.

  • Imp_Exp2 : AB imports and exports plotted as annual chart, shows hourly patterns.

  • Imp_ExpWk: AB imports and exports for a single week.

  • BC_SK_IE : BC and SK imports and exports.

  • MN_Trade_Price : Get trade and price each month to compare.

  • MN_TradeOnly : AB imports and exports and pool price for specific month.

  • T_month_all_Sim : All trade for each month over one year.

Historical Fit Functions. Included for looking at historical trade patterns only.

  • Capab_year : Capability of intertie over entire year.

  • Capab_mn : Capability of intertie over selected month. Choose between min, max, or average.

  • Capab_Allmn : Capability of intertie over all months of year. Choose between min, max, or average.

  • Capab_stats : Gives mean, max, min, and standard deviation for capabilities over intertie lines.

  • ZeroTrade : Percentage of time where intertie capability is zero.

Intertie_Functions Special Notes:
  • HR FIT Functions are also included in this file. These were used to build and analyze historical trade patterns.

other_functions

Additional functions to use, not related the data itself. Used within main functions.

Functions:

  • packs_check : Checks if packages are installed, installs them if not, and loads required functions.

  • yhour : Get the hour of year associated with a date in the form "%Y-%m-%d %H:%M:%S" (EX: Jan 1 at 1:00 = 0001, Dec 31 at 23:00 = 8760).

  • round_any : Use to round value to a certain accuracy.

  • HrTime : Convert the date and select a subset for one day from the data pulled in.

  • WkTime : Convert the date and select a subset for one week from the data pulled in.

  • YrDay_Time : Convert the date and select a subset for specific year and day.

  • YrTime : Convert the date and select a subset for one week from the data pulled in.

  • Legend_PlotAll : Plot legend for all things referenced in other plots.

  • Legend_PlotMain : Plot legend for main things referenced in other plots.

  • Legend_PlotGray : Plot legend for main things referenced in other plots in grayscale.

  • NRG_student_generate_R : Format input data and save as R files.

  • Load_NRG_hourly : Load nrgstream hourly data, can only be used once R file is generated.

Output_Gen_Functions

Functions to use for plotting and evaluating simulation data on resource outputs and generation. Also plots other miscalaneous things not covered elsewhere

Functions:

  • Week1_exist : Plots output for a single week given the case study, for comparison to existing data.

  • day1 : Plots output for a single day given the case study.

  • day2 : Plots output for a single day given the case study, formated for comparison.

  • Stor1 : Weekly storage output.

  • Stor2 : Weekly storage output with pool price overlaid.

  • Evalyr : Plotting year profiles of resource output.

  • Evalcap : Plotting month/year profiles of resource capacity.

  • EvalPerc : Year/month profiles as a percentage of the total.

  • Output_Comp : Plotting the capacity of resources individually for selected years as side by side bar charts.

  • AnnualDemand : Plot average demand in zone.

  • CFcompare : Compares capacity factor for two chosen years. Modified from Taylor Pawlenchuk.

  • CF_Annual : Compares capacity factor for two chosen years. Similar to plot seen on page 10 of AESOs net zero report dashboard.

  • MaxCurtail : Shows the maximum customer curtailment used in a single hour for each year.

  • CF_CER_Res : Show capacity factor for individual resources included in CER.

  • Hours_CER_Res : Show hours opperated for individual units included in CER.

  • CF_CER_groups : Show capacity factor based on year CER applies.

  • Wind_Dur : Plot wind duration curve in chosen years as % Hours vs Fleet Output (MW).

  • Wind_DurNorm : Plot wind duration curve in chosen years as % hours vs output as percent of max.

  • Week12 : Plots output for a single week given the case study. Supporting function To be used in year of weeks function.

  • year_weeks : Plots output for a single week given the case study.

  • PrOt : Plots pool price over one week of output data.

  • PrOut : Plots pool price over one week of output data with storage utilization.

  • year_stor : Plots storage output and pool price for one week of each month for selected year.

  • FourMonthSummary : Shows generation, storage, and price for one week of 4 months in a year.

  • EachResWeek : Show one week of generation and split wach resource type to its own plot.

  • Num_Startups : Show number of startups by tech and year.

  • CER_EM_hour_Res : Show hours run and total emissions for CER resources.

  • CER_EM_hour_group : Show capacity factor and emissions for CER resources based on year applied.

  • Resource_Ridge : Show capacity factor frequency for selected resources between two dates. Probability (ECDF) shown in color. Can create for weighted data or hourly dispatch data.

  • Renew_Curtail_MWa : Show average output by wind and solar with and without curtailment

  • Renew_Curtail_perc : Show average capacity factor by wind and solar with and without curtailment

Price_Functions

Functions related to technology capture prices, pool prices, and other cost related material.

Functions:

  • week_price : Electricity wholesale pool price for one week.

  • Sim_dur : Simulation duration curve ploted each year. The price duration curve represents the percentage of hours in which pool price equaled or exceeded a specified level.

  • AvgMn_price : Plots monthly average pool price with average internal load.

  • poolprice_2year : A function to plot the Monthly average pool price (Like in the AESO Market Report 2021 Figure 1).

  • AvgYr_poolprice : Plots monthly average pool price with average internal load.

  • System_Cost : Describes the average system costs incured by all resources in the system.

  • ResValue_Line : Shows the nominal annual value of resources as a line over entire study length. Based on plant type and year built. Define the Resource type based on number. 1 wind, 2- Solar, 3 - Storage, 4 - Unabated natural gas, 5- Abated natural gas, 6 - Hydrogen, 7 - Hydro, 8 - Other, 9 - Cogen.

  • ResValue_Annual : Shows the annual value of new resources based on plant type and year built. Define the Resource type based on number. 1 wind, 2- Solar, 3 - Storage, 4 - Unabated natural gas, 5- Abated natural gas, 6 - Hydrogen, 7 - Hydro, 8 - Other, 9 - Cogen.

  • ResValue_Annual_MWh : Shows the annual value per MWh for new resources based on plant type and year built. Define the Resource type based on number. 1 wind, 2- Solar, 3 - Storage, 4 - Unabated natural gas, 5- Abated natural gas, 6 - Hydrogen, 7 - Hydro, 8 - Other, 9 - Cogen.

  • ResValue_NPV_MWh : Shows the net present value per MWh generated. 1 wind, 2- Solar, 3 - Storage, 4 - Unabated natural gas, 5- Abated natural gas, 6 - Hydrogen, 7 - Hydro, 8 - Other, 9 - Cogen.

  • ResValue_NPV : Shows the net present value in 2023. 1 wind, 2- Solar, 3 - Storage, 4 - Unabated natural gas, 5- Abated natural gas, 6 - Hydrogen, 7 - Hydro, 8 - Other, 9 - Cogen.

  • capture_p : Shows capture prices by technology.

  • Relcapture_p : Shows capture prices by technology relative to pool price.

  • ach_poolprem : Shows achieved preium compared to pool price.

Res_Filter_Functions

Functions to select and sort certain resource groups for other functions to use. A collection of filters.

Functions:

  • sim_filt : This function filters for the data that will be evaluated by ID.

  • sim_filt1 : This function filters for the data that will be evaluated by ID, more detail (breaks up natural gas into combined and simple cycle).

  • sim_filt2 : This function filters for the data that will be evaluated by primary fuel type.

  • sim_filt3 : This function filters for the data that will be evaluated. Same as 2, with coal removed and storage into 3 components.

  • sim_filt4 : This function filters for the data that will be evaluated. Same as 3, however only includes Aurora build options and is based on Fuel Type.

  • sim_filt5 : This function filters for the data that will be evaluated by ID. Seperates in detail (inclusive of storage types).

  • sim_filt6 : This function filters for EVERYTHING - based on Primary Fuel Type.

  • sim_filtEm : This function filters for emission releasing resources, filtered by ID.

  • sim_filtFuel : This function filters for the data that will be evaluated. Same as 3, however only includes Aurora build options and is based on Fuel Type.

Table_Functions

Functions To use for summarizing data within R environment.

Functions:

  • Report_P : Report average zone prices in a table, organized by condition (average, peak, off-peak), year, and optionally zone).

  • Build_Totals : Report the capacity built for each fuel type in the study by year. Includes manually added additions.

  • Build_A_Totals : Report the capacity built for each fuel type in the study by year. Aurora new builds only.

aeso_gen

Functions used to used to plot and analyze other (AESO) data. Some functions based on code from Taylor Pawlenchuk (Retrieved June 3, 2022).

Functions:

  • plnt_tr : Identify specific plant traits.

  • Week_act : Plot actual AESO output for a single week.

  • Day_AESO : Plots actual AESO output for a single day.

  • wkPrice : Plot AESO pool price.

  • AESO_PrOt : Price and output side-by-side.

  • Trade_Mn_AESO : AB import and export with pool price for selected month.

  • TradeOnly_Mn_AESO : AB import and export for selected month.

  • Trade_Yr_AESO : AB import and export for a single year.

  • Duration_AESO : AB import and export along with pool price for a specific year.

  • Wind_Dur_AESO : Wind duration curve in chosen year as % Hours vs Fleet Output (MW).

  • Wind_DurNorm_AESO : Plot wind duration curve in chosen years as % Hours vs output as Percent of max

  • T_month_all : All trade for each month over one year.

  • Resource_Ridge_AESO : Show capacity factor frequency for selected resources between two dates. Probability (ECDF) shown in color.

  • AIL_Gen_Gaps : Understand differences in AIL and generation

  • Evalyr_AESO : Plotting year profiles of resource output (generation)

  • Evalcap_AESO : Plotting year profiles of resource capacity

  • Evalcap_AESO : Plot gas generation from NRG

aeso_sim_comp_1

Functions used to compare simulation data with other/actual data. Some functions have been adapted from Taylor Pawlenchuk (Retrieved June 14, 2022).

Functions:

  • AESO_SimOP : Plot comparison between actual and simulated data.

  • AESO_SimP : Plot comparison between actual and simulated data price for 1 week.

  • AESO_SimP2 : Plot comparison between actual and simulated data price for 1 week.

  • AESO_SimO : Plot comparison between actual and simulated data generation.

  • year_comp : Plots the difference in Pool Price between AESO and Sim.

  • year_dif : Bar plot showing the difference between AESO and Sim.

  • year_avg : Bar chart comparing monthly average pool prices.

  • year_pool : A function to plot the Monthly average pool price; like in the AESO Market Report 2021 Figure 1.

  • comp_dur : Plots the Pool Price duration vs percentile for AESO and Sim; like AESO Market Report 2021 Figures 2 and 3.

  • load_dur : Plots the load duration vs percentile for AESO and Sim; like AESO Market Report 2021 Figures 7 and 8

  • tech_cap : Plots the capacity factor by technology for AESO and Sim; like AESO Market Report 2021 Figure 15.

  • AESO_Sim_WindDur : Plot comparison between actual and simulated wind duration curves.

  • AESO_Sim_WindDurNorm : Plot comparison between actual and simulated wind duration curves.

  • AESO_Sim_RidgeCF : Plot comparison between actual and simulated wind ridgelines.

Scenario_Compare_Functions

Functions used to compare between different scenarios/simulations. To be run after files are combined in "Scenario_Compare" function

  • compare_rename : Rename scenarios for comparison, this is the name that will show up in plots.

  • AvgYr_price_COMPARE : Plot average annual pool price.

  • AvgYr_price_COMPARE2 : Plots annual average pool price, with optional historical.

  • AnnualEmLine_COMPARE : Plots annual average emissions.

  • AnnualEm_Cum_COMPARE : Plots annual average emissions in Cumulative bar chart.

  • AnnualEm_Cum_Dots : Plots annual average emissions in Cumulative bar chart.

  • Annual_Em_group : Plots annual capacity for selected resource group.

  • Total_Cap_COMPARE : Plots total capacity added.

  • Total_Cap_add_ret_COMPARE : Plots total capacity added.

  • Total_Cap_Ret_COMPARE : Plots total capacity retired.

  • Cap_Relative_COMPARE : Plots capacity additions relative to CP.

  • Cap_Year_Relative_COMPARE : Plots capacity relative to CP in chosen year.

  • Annual_Cap_Add_COMPARE : Plots annual capacity addded.

  • Annual_Cap_COMPARE : Plots annual capacity.

  • Annual_Cap_group : Plots annual capacity for selected resource group.

  • Annual_Cap_group_area : Plots annual capacity for selected resource group.

  • Total_Gen_COMPARE : Plots total study generation.

  • Annual_Gen_group : Plots annual generation for selected resource group.

  • Annual_Gen_group_area : Plots annual generation for selected resource group in area chart.

  • Annual_CF_group : Plots annual capacity factor for selected resource group.

  • Annual_Gen_group_perc : Plots annual generation percentage for selected resource group.

  • Total_Gen_Relative_COMPARE : Plots generation relative to CP.

  • Annual_Gen_COMPARE : Plots annual generation.

  • Total_Gen_Treemap_COMPARE : Plots total study generation using percentages.

  • Year_Gen_COMPARE : Plots generation for a single year.

  • Cost_Cum_COMPARE : Plots cumulative costs.

  • AnnualCost_Cum_COMPARE : Plots total cost compare.

  • AnnualCost_Cum_rel_COMPARE : Plots total cost compare, relative to CP.

  • Cost_Cum_rel_COMPARE : Plots cumulative cost compare relative to CP.

  • AnnualValue_Cum_norm : Plots total nominal resource group value.

  • Cap_Year_Relative_COMPARE : Plots total capacity relative to CP.

  • Gen_Diff_COMPARE : Plots total generation relative to CP.

  • Em_Diff_COMPARE : Plots total GHG emissions relative to CP.

  • Cost_Diff_COMPARE : Plots cost relative to CP in each year.

  • compare_metrics : Plot 4 metrics in one: capacity, generation, GHG's, and cost.

  • compare_cap_gen_em : Plot all metrics together: capacity, generation, GHG's, and cost.

  • Annual_Cap_group_dots : Plots annual capacity for selected resource group in years.

  • Cum_Gen_group_dots : Plots gen for grouped resource years.

  • CF_group_dots : Plots CF for grouped resource years.

  • value_group_dots : Value of entire study.

  • Avg_Bid_Cost_dots : Plots annual average bid by group.

  • Marginal_Resource_Compare : Plots annual average bid by group.

  • AnnualEm_vs_group : Plots annual GHG emissions compared to chosen resource group.

  • TotalCapChange_Compare : Gives capacity added and retired each year in the same plot.

  • NetCapChange_Compare : Gives net capacity added and retired each year in the same plot.