simulations.util package¶
Submodules¶
simulations.util.DualPlots module¶
Created on Thu Jan 13 14:46:10 2022
@author: gabrielsoto
- class simulations.util.DualPlots.DualDispatchPlots(module, **kwargs)[source]¶
Bases:
simulations.util.DualPlots.DualPlots
The Plots class is a part of the PostProcessing family of classes. It can output results from Pyomo Dispatch models.
Note that the DispatchPlots class must be initialized before using.
- __init__(module, **kwargs)[source]¶
Initializes the Plots module
The instantiation of this class receives a full Dispatch object, the module being one of the Pyomo Dispatch model created in the /neup-ies/simulations/dispatch directory. It also contains various inputs relating to cosmetic parameters for matplotlib plots.
- Inputs:
module (object) : object representing Pyomo Dispatch Model with results fsl (str) : fontsize for legend loc (str) : location of legend legend_offset(bool) : are we plotting legends off-axis? lp (int) : labelpad for axis labels lps (int) : labelpad for axis labels - short version fs (int) : fontsize for labels, titles, etc. lw (int) : linewidth for plotting x_shrink (float) : (legend_offset==True) amount to shrink axis to make room for legend
- plot_pyomo_cycle_bin(ax=None, **kwargs)[source]¶
Method to plot power cycle binary data from Pyomo Dispatch on single plot
This method is used specifically to plot data from Dispatch simulation results pertaining to cycle binary values. Variables include whether power cycle is running (0 or 1), etc. Built-in options to plot legend off-axis.
- Inputs:
ax (object) : axis object to plot on plot_all_time(bool) : are we plotting all results or just a portion? title_label(str) : title name for plot start_hr (int) : (plot_all_time==False) hour used for starting index end_hr (int) : (plot_all_time==False) hour used for ending index hide_x(bool) : hiding the x-axis from this particular plot x_legend (float) : (legend_offset==True) x-offset defining left-most side of legend y_legend_L (float) : (legend_offset==True) y-offset of left y-axis plot y_legend_R (float) : (legend_offset==True) y-offset of right y-axis plot
- plot_pyomo_dual_bin(ax=None, title_label=None, plot_all_time=True, start_hr=0, end_hr=48, hide_x=False, x_legend=1.2, y_legend_L=1.0, y_legend_R=1.0)[source]¶
Method to plot solar binary data from Pyomo Dispatch on single plot
This method is used specifically to plot data from Dispatch simulation results pertaining to nuclear binary values. Variables include whether nuclear plant is running (0 or 1), etc. Built-in options to plot legend off-axis.
- Inputs:
ax (object) : axis object to plot on plot_all_time(bool) : are we plotting all results or just a portion? title_label(str) : title name for plot start_hr (int) : (plot_all_time==False) hour used for starting index end_hr (int) : (plot_all_time==False) hour used for ending index hide_x(bool) : hiding the x-axis from this particular plot x_legend (float) : (legend_offset==True) x-offset defining left-most side of legend y_legend_L (float) : (legend_offset==True) y-offset of left y-axis plot y_legend_R (float) : (legend_offset==True) y-offset of right y-axis plot
- plot_pyomo_energy(ax=None, **kwargs)[source]¶
Method to plot energy data from Pyomo Dispatch on single plot
This method is used specifically to plot energy data from Dispatch simulation results. Built-in options to plot legend off-axis.
- Inputs:
ax (object) : axis object to plot on plot_all_time(bool) : are we plotting all results or just a portion? title_label(str) : title name for plot start_hr (int) : (plot_all_time==False) hour used for starting index end_hr (int) : (plot_all_time==False) hour used for ending index hide_x(bool) : hiding the x-axis from this particular plot x_legend (float) : (legend_offset==True) x-offset defining left-most side of legend y_legend_L (float) : (legend_offset==True) y-offset of left y-axis plot y_legend_R (float) : (legend_offset==True) y-offset of right y-axis plot
- plot_pyomo_power(ax=None, title_label=None, plot_all_time=True, start_hr=0, end_hr=48, hide_x=False, x_legend=1.2, y_legend_L=1.0, y_legend_R=1.0)[source]¶
Method to plot power and pricing data from Pyomo Dispatch on single plot
This method is used specifically to plot power data from Dispatch simulation results. Built-in options to plot legend off-axis.
- Inputs:
ax (object) : axis object to plot on plot_all_time(bool) : are we plotting all results or just a portion? title_label(str) : title name for plot start_hr (int) : (plot_all_time==False) hour used for starting index end_hr (int) : (plot_all_time==False) hour used for ending index hide_x(bool) : hiding the x-axis from this particular plot x_legend (float) : (legend_offset==True) x-offset defining left-most side of legend y_legend_L (float) : (legend_offset==True) y-offset of left y-axis plot y_legend_R (float) : (legend_offset==True) y-offset of right y-axis plot
- class simulations.util.DualPlots.DualOutputExtraction(module)[source]¶
Bases:
util.SolarPlots.SolarOutputExtraction
The OutputExtraction class is a part of the PostProcessing family of classes. It extracts outputs from SSC or Dispatch models. Can be called from other plotting classes to extract outputs.
- __init__(module)[source]¶
Initializes the OutputExtraction module
The instantiation of this class receives a full module object, the module being one of the NE2 modules in the /neup-ies/simulations/modules directory. or a Dispatch module.
- Inputs:
module (object) : object representing NE2 module class after simulations
- class simulations.util.DualPlots.DualPlots(module, **kwargs)[source]¶
Bases:
util.SolarPlots.SolarPlots
The Plots class is a part of the PostProcessing family of classes. It can output results from SSCmodels. This might be a Sisyphus-ian task as some of the parameters are very unique to whatever plot you are trying to make, but will do my best to provide basic structures and templates to work off of.
Note that the Plots class must be initialized before using.
- __init__(module, **kwargs)[source]¶
Initializes the Plots module
The instantiation of this class receives a full module object, the module being one of the NE2 modules in the /neup-ies/simulations/modules directory. It also contains various inputs relating to cosmetic parameters for matplotlib plots.
- Inputs:
module (object) : object representing NE2 module class after simulations fsl (str) : fontsize for legend loc (str) : location of legend legend_offset(bool) : are we plotting legends off-axis? lp (int) : labelpad for axis labels lps (int) : labelpad for axis labels - short version fs (int) : fontsize for labels, titles, etc. lw (int) : linewidth for plotting x_shrink (float) : (legend_offset==True) amount to shrink axis to make room for legend
- plot_SSC_op_modes(ax=None, title_label=None, plot_all_time=True, start_hr=0, end_hr=48, hide_x=False, x_legend=1.2, y_legend_L=1.0, y_legend_R=1.0)[source]¶
Method to plot operating modes history on single plot
This method is used specifically to plot operating modes and relative pricing data from SSC simulation results. Built-in options to plot legend off-axis.
- Inputs:
ax (object) : axis object to plot on plot_all_time(bool) : are we plotting all results or just a portion? title_label(str) : title name for plot start_hr (int) : (plot_all_time==False) hour used for starting index end_hr (int) : (plot_all_time==False) hour used for ending index hide_x(bool) : hiding the x-axis from this particular plot x_legend (float) : (legend_offset==True) x-offset defining left-most side of legend y_legend_L (float) : (legend_offset==True) y-offset of left y-axis plot y_legend_R (float) : (legend_offset==True) y-offset of right y-axis plot
- plot_SSC_power_and_energy(ax=None, title_label=None, plot_all_time=True, start_hr=0, end_hr=48, hide_x=False, x_legend=1.2, y_legend_L=1.0, y_legend_R=1.0)[source]¶
Method to plot power and energy data on single plot
This method is used specifically to plot power and energy data from SSC simulation results. Built-in options to plot legend off-axis.
- Inputs:
ax (object) : axis object to plot on plot_all_time(bool) : are we plotting all results or just a portion? title_label(str) : title name for plot start_hr (int) : (plot_all_time==False) hour used for starting index end_hr (int) : (plot_all_time==False) hour used for ending index hide_x(bool) : hiding the x-axis from this particular plot x_legend (float) : (legend_offset==True) x-offset defining left-most side of legend y_legend_L (float) : (legend_offset==True) y-offset of left y-axis plot y_legend_R (float) : (legend_offset==True) y-offset of right y-axis plot
simulations.util.FileMethods module¶
Created on Fri Apr 2 09:23:58 2021
@author: gabrielsoto
- class simulations.util.FileMethods.FileMethods[source]¶
Bases:
object
The FileMethods class is a util class used generally to read and write data from and to files. This can be csv, text, maybe LaTeX files in the future.
- data_dir = '/home/gabrielsoto/Documents/NE2/neup-ies/simulations/data'¶
- neup_dir = '/home/gabrielsoto/Documents/NE2/neup-ies'¶
- output_dir = '/home/gabrielsoto/Documents/NE2/neup-ies/simulations/outputs'¶
- parent_dir = '/home/gabrielsoto/Documents/NE2'¶
- read_csv_through_pandas()[source]¶
Method to read csv file and return data array
- Inputs:
filepath (str) : full path to csv file
- Outputs:
data_array (list) : data in either list (SSC_ARRAY) or nested list (SSC_MATRIX) form
- read_json()[source]¶
Method to read json file and return dictionaries
- Inputs:
json_name (str) : name of json script found at ‘neup-ies/simulations/json’
- Outputs:
pysam_dict (dict) : dictionary of PySAM inputs + file names ssc_dict (dict) : dictionary of SSC inputs needed to run modules out_dict (dict) : dictionary of PySAM output keywords for extraction
- read_solar_resource_file(unit_registry)[source]¶
Method to read csv file and return data array
- Inputs:
filepath (str) : full path to file unitRegistry (pint.registry) : unique unit Pint unit registry
- Outputs:
t_dry (float Quant) : dry bulb temperature (in deg K)
- read_steam_table_file(unit_registry)[source]¶
Method to read csv file and return data array
- Inputs:
filepath (str) : full path to file unitRegistry (pint.registry) : unique unit Pint unit registry
- Outputs:
T_K (float Quant) : steam temperature (in deg K) c_p (float Quant) : steam temperature (in kJ/kg*K) H_p (float Quant) : steam temperature (in kJ/kg)
- samsim_dir = '/home/gabrielsoto/Documents/NE2/neup-ies/simulations'¶
- util_dir = '/home/gabrielsoto/Documents/NE2/neup-ies/simulations/util'¶
simulations.util.FileParser module¶
Created on Fri Apr 16 10:15:51 2021
@author: gabrielsoto
- class simulations.util.FileParser.FileParser[source]¶
Bases:
object
The FileParser class is a util class used generally to manipulate text data in files. Some main features is the ability to search existing Python class files for particular strings. Currently using regex to search for complex strings, don’t yell at me please.
- detail_latex_regex = ':\\s([\\w+\\s+\\d+\\{\\}\\[\\]\\^\\\\\\,\\$/-]+)'¶
- find_first_string_instance(search_str)[source]¶
Method to parse through file and locate string
This method parses through a given file found at the input filepath and searches for the first instance of a given string. It then returns the line number and the full line string where it was found. If not found it returns None for both outputs.
- Inputs:
fpath (str) : full path to relevant file search_str (str) : string to search
- Outputs:
line_number (str) : line number where search_str was found (None if not found) line_contents (str) : full line string where search_str was found (None if not found)
- get_dispatch_string_properties(return_case=0)[source]¶
Method to return relevant dispatch string properties
This method parses through a given file found at the input filepath and returns a dictionary with string values and line numbers for different parameter properties in the dispatcher. For now, it can sort through the Params and Variables of the Dispatch files. It returns latex+text names for all entries, latex strings containing parameter details, and section+subsection titles.
NOTE: this method is tied to the very specific aesthetic format of the Dispatch files, should they change this method will no longer work.
- Inputs:
dispatch_name (str) : name of Dispatch class to document return_case (int) : 0=return Param properties, 1=return Var properties
- Outputs:
P (dict) : dictionary with entries for line number and str contents
- get_lines_between_strings(str_start, str_end)[source]¶
Method to return all lines between two strings in a file
This method parses through a given file found at the input filepath and returns a list of lines in between two book-end strings: str_start and str_end.
- Inputs:
fpath (str) : full path to relevant file str_start (str) : first string to search str_end (str) : last string to search
- Outputs:
lines (list of str) : list of lines between book-end strings
- get_list_of_pyomo_data(params_list)[source]¶
Method to return all parameter data from a Pyomo model
This method parses through a given Pyomo model and returns a value for each parameter given in the params_list. Typically should parse through the DispatchModel first using self.get_dispatch_string_properties() to get params_list.
- Inputs:
model (PyomoModel) : Pyomo model after execution params_list (str) : list of strings representing parameter names
- Outputs:
data_list (list of int or float) : list of data values for each Pyomo parameter
- get_single_pyomo_model_data(params_list, ind)[source]¶
Method to return single parameter data from a Pyomo model
This method parses through a given Pyomo model and returns a value for a parameter from params_list specified by the index ind.
- Inputs:
model (PyomoModel) : Pyomo model after execution params_list (str) : list of strings representing parameter names ind (int) : index of params_list to return
- Outputs:
modelData (int or float) : value of requested Pyomo parameter
- param_latex_regex = '\\s#([\\w+\\d+\\{\\}\\^\\\\\\,-]+):\\s'¶
- param_txt_regex = 'self.model.(\\w+)\\s?='¶
- section_regex = '###\\s([\\w+\\s+]+)\\s###'¶
- subsection_regex = '#-------\\s([\\w+\\s+]+)\\s---------'¶
- write_pyomo_params_to_excel(dispatch_name, xls_file_name)[source]¶
Method to write all Pyomo parameters to an Excel sheet
This method parses through a given Pyomo model and returns a value for each parameter given in the params_list. Then it saves the data to an Excel sheet called “Raw Data” in an xlsx file specified by the user input. Output file will be written in the simulations/outputs folder. Excel sheet will have three columns: Parameter name, its value, and a txt description.
TODO: perhaps this method belongs in FileMethods?
- Inputs:
model (PyomoModel) : Pyomo model after execution dispatch_name (str) : name of Dispatch model in the simulations/dispatch folder xls_file_name (str) : name of desired output file (just filename, no directories)
- write_pyomo_params_to_table(dispatch_name, txt_file_name, param_or_var=0)[source]¶
Method to write all Pyomo parameters to an text file with LaTeX
This method parses through a given Pyomo model and returns parameter names and information. In a text file specified by the user, it writes LaTeX formatted sections and subsections of the parameter listings.
- Inputs:
model (PyomoModel) : Pyomo model after execution dispatch_name (str) : name of Dispatch model in the simulations/dispatch folder txt_file_name (str) : name of desired output file (just filename, no directories) param_or_var (int) : select either Parameters or Variables to write
- write_pyomo_params_to_text(dispatch_name, txt_file_name, param_or_var=0)[source]¶
Method to write all Pyomo parameters to an text file with LaTeX
This method parses through a given Pyomo model and returns parameter names and information. In a text file specified by the user, it writes LaTeX formatted sections and subsections of the parameter listings.
- Inputs:
model (PyomoModel) : Pyomo model after execution dispatch_name (str) : name of Dispatch model in the simulations/dispatch folder txt_file_name (str) : name of desired output file (just filename, no directories) param_or_var (int) : select either Parameters or Variables to write
simulations.util.NuclearTESLoadProfiles module¶
Created on Tue Mar 8 11:46:53 2022
@author: gabrielsoto
- class simulations.util.NuclearTESLoadProfiles.NuclearTESLoadProfiles(filepath)[source]¶
Bases:
object
The LoadProfileFigures class is SEPARATE from the PostProcessing family of classes. This might in the future best be a part of the PostProcessing family… but doing this semi-quickly for the Model 1 Energies paper.
The class sets up all helper methods used to generate overlaid violin plots for load profiles of a given run. The given run is specified by:
Pref
tshours
tariff schedule
time horizons (both for SSC and Pyomo)
Data from these runs is assumed to be stored in a pickle file and contains data for a full year’s worth of simulation. I keep changing file names, so the filename is assumed to be an input (a separate script that creates this class will handle filename creation).
- create_violin_plot(ax, data, full_data, v_color='C0', hide_x=False)[source]¶
Creates a violin plot for each hour of the day
Method repurposed from https://matplotlib.org/stable/gallery/statistics/customized_violin.html Creates a violin plot from a list of lists for each of those sub-lists. In our case, the sub-lists are values for a given hour of the day across the full year (e.g., hour 0 from January to December). Also plots medians as a white dot, 1st-3rd quartiles in a black rectangle, and the full distribution in color specified by input.
- Inputs:
ax : Pyplot axis object data : list of lists v_color : string
- extract_data()[source]¶
Extracts raw data from Storage
This method extracts full year’s worth of data from storage dictionary and saves it as a member attribute of current object.
- restructure_array_by_hour()[source]¶
Restructures data arrays by hour of day
This method takes data (saved as member arrays of current object) and restructures it by hour of the day. That is, for each hour of the day, it populates a new array (24 x 365) with values for all, for example, midnights throughout the year.
- restructure_dict_by_season_and_weekday(data_)[source]¶
Restructures existing data arrays into a data dictionary
Data dictionary is split into Winter and Summer data. Those two are then split into WeekDay and WeekEnd data.
- Inputs:
data_ : ndarry of size 24 x 365
- Outputs:
data_arrays : dict
- violin_adjacent_values(vals, q1, q3)[source]¶
Helper method for violin plots to clip boundaries
Method taken from https://matplotlib.org/stable/gallery/statistics/customized_violin.html
simulations.util.PostProcessing module¶
Created on Tue Jun 1 13:11:44 2021
@author: gabrielsoto
- class simulations.util.PostProcessing.DispatchPlots(module, **kwargs)[source]¶
Bases:
simulations.util.PostProcessing.Plots
The Plots class is a part of the PostProcessing family of classes. It can output results from Pyomo Dispatch models.
Note that the DispatchPlots class must be initialized before using.
- __init__(module, **kwargs)[source]¶
Initializes the Plots module
The instantiation of this class receives a full Dispatch object, the module being one of the Pyomo Dispatch model created in the /neup-ies/simulations/dispatch directory. It also contains various inputs relating to cosmetic parameters for matplotlib plots.
- Inputs:
module (object) : object representing Pyomo Dispatch Model with results fsl (str) : fontsize for legend loc (str) : location of legend legend_offset(bool) : are we plotting legends off-axis? lp (int) : labelpad for axis labels lps (int) : labelpad for axis labels - short version fs (int) : fontsize for labels, titles, etc. lw (int) : linewidth for plotting x_shrink (float) : (legend_offset==True) amount to shrink axis to make room for legend
- plot_pyomo_cycle_bin(ax=None, title_label=None, plot_all_time=True, start_hr=0, end_hr=48, hide_x=False, x_legend=1.2, y_legend_L=1.0, y_legend_R=1.0)[source]¶
Method to plot power cycle binary data from Pyomo Dispatch on single plot
This method is used specifically to plot data from Dispatch simulation results pertaining to cycle binary values. Variables include whether power cycle is running (0 or 1), etc. Built-in options to plot legend off-axis.
- Inputs:
ax (object) : axis object to plot on plot_all_time(bool) : are we plotting all results or just a portion? title_label(str) : title name for plot start_hr (int) : (plot_all_time==False) hour used for starting index end_hr (int) : (plot_all_time==False) hour used for ending index hide_x(bool) : hiding the x-axis from this particular plot x_legend (float) : (legend_offset==True) x-offset defining left-most side of legend y_legend_L (float) : (legend_offset==True) y-offset of left y-axis plot y_legend_R (float) : (legend_offset==True) y-offset of right y-axis plot
- plot_pyomo_energy(ax=None, title_label=None, plot_all_time=True, start_hr=0, end_hr=48, hide_x=False, x_legend=1.2, y_legend_L=1.0, y_legend_R=1.0)[source]¶
Method to plot energy data from Pyomo Dispatch on single plot
This method is used specifically to plot energy data from Dispatch simulation results. Built-in options to plot legend off-axis.
- Inputs:
ax (object) : axis object to plot on plot_all_time(bool) : are we plotting all results or just a portion? title_label(str) : title name for plot start_hr (int) : (plot_all_time==False) hour used for starting index end_hr (int) : (plot_all_time==False) hour used for ending index hide_x(bool) : hiding the x-axis from this particular plot x_legend (float) : (legend_offset==True) x-offset defining left-most side of legend y_legend_L (float) : (legend_offset==True) y-offset of left y-axis plot y_legend_R (float) : (legend_offset==True) y-offset of right y-axis plot
- plot_pyomo_nuclear_bin(ax=None, title_label=None, plot_all_time=True, start_hr=0, end_hr=48, hide_x=False, x_legend=1.2, y_legend_L=1.0, y_legend_R=1.0)[source]¶
Method to plot nuclear binary data from Pyomo Dispatch on single plot
This method is used specifically to plot data from Dispatch simulation results pertaining to nuclear binary values. Variables include whether nuclear plant is running (0 or 1), etc. Built-in options to plot legend off-axis.
- Inputs:
ax (object) : axis object to plot on plot_all_time(bool) : are we plotting all results or just a portion? title_label(str) : title name for plot start_hr (int) : (plot_all_time==False) hour used for starting index end_hr (int) : (plot_all_time==False) hour used for ending index hide_x(bool) : hiding the x-axis from this particular plot x_legend (float) : (legend_offset==True) x-offset defining left-most side of legend y_legend_L (float) : (legend_offset==True) y-offset of left y-axis plot y_legend_R (float) : (legend_offset==True) y-offset of right y-axis plot
- plot_pyomo_power(ax=None, title_label=None, plot_all_time=True, start_hr=0, end_hr=48, hide_x=False, x_legend=1.2, y_legend_L=1.0, y_legend_R=1.0)[source]¶
Method to plot power and pricing data from Pyomo Dispatch on single plot
This method is used specifically to plot power data from Dispatch simulation results. Built-in options to plot legend off-axis.
- Inputs:
ax (object) : axis object to plot on plot_all_time(bool) : are we plotting all results or just a portion? title_label(str) : title name for plot start_hr (int) : (plot_all_time==False) hour used for starting index end_hr (int) : (plot_all_time==False) hour used for ending index hide_x(bool) : hiding the x-axis from this particular plot x_legend (float) : (legend_offset==True) x-offset defining left-most side of legend y_legend_L (float) : (legend_offset==True) y-offset of left y-axis plot y_legend_R (float) : (legend_offset==True) y-offset of right y-axis plot
- plot_pyomo_power_ramps(ax=None, title_label=None, plot_all_time=True, start_hr=0, end_hr=48, hide_x=False, x_legend=1.2, y_legend_L=1.0, y_legend_R=1.0)[source]¶
Method to plot power ramping data from Pyomo Dispatch on single plot
This method is used specifically to plot energy data from Dispatch simulation results. Built-in options to plot legend off-axis.
- Inputs:
ax (object) : axis object to plot on plot_all_time(bool) : are we plotting all results or just a portion? title_label(str) : title name for plot start_hr (int) : (plot_all_time==False) hour used for starting index end_hr (int) : (plot_all_time==False) hour used for ending index hide_x(bool) : hiding the x-axis from this particular plot x_legend (float) : (legend_offset==True) x-offset defining left-most side of legend y_legend_L (float) : (legend_offset==True) y-offset of left y-axis plot y_legend_R (float) : (legend_offset==True) y-offset of right y-axis plot
- class simulations.util.PostProcessing.OutputExtraction(module)[source]¶
Bases:
object
The OutputExtraction class is a part of the PostProcessing family of classes. It extracts outputs from SSC or Dispatch models. Can be called from other plotting classes to extract outputs.
- __init__(module)[source]¶
Initializes the OutputExtraction module
The instantiation of this class receives a full module object, the module being one of the NE2 modules in the /neup-ies/simulations/modules directory. or a Dispatch module.
- Inputs:
module (object) : object representing NE2 module class after simulations
- class simulations.util.PostProcessing.Plots(module, fsl='x-small', loc='best', legend_offset=False, lp=16, lps=12, fs=12, lw=2, x_shrink=0.85, x_legend=12, fE_min=- 0.05, fE_max=0.7)[source]¶
Bases:
object
The Plots class is a part of the PostProcessing family of classes. It can plot outputs from SSC model runs. This might be a Sisyphus-ian task as some of the parameters are very unique to whatever plot you are trying to make, but will do my best to provide basic structures and templates to work off of.
Note that the Plots class must be initialized before using.
- __init__(module, fsl='x-small', loc='best', legend_offset=False, lp=16, lps=12, fs=12, lw=2, x_shrink=0.85, x_legend=12, fE_min=- 0.05, fE_max=0.7)[source]¶
Initializes the Plots module
The instantiation of this class receives a full module object, the module being one of the NE2 modules in the /neup-ies/simulations/modules directory. It also contains various inputs relating to cosmetic parameters for matplotlib plots.
- Inputs:
module (object) : object representing NE2 module class after simulations fsl (str) : fontsize for legend loc (str) : location of legend legend_offset(bool) : are we plotting legends off-axis? lp (int) : labelpad for axis labels lps (int) : labelpad for axis labels - short version fs (int) : fontsize for labels, titles, etc. lw (int) : linewidth for plotting x_shrink (float) : (legend_offset==True) amount to shrink axis to make room for legend fE_min (float) : minimum fraction of TES energy for ylim fE_max (float) : maximum fraction of TES energy for ylim
- bar_plot_on_axis(ax, x_array, y_array, dx, label, alpha=0.5, color=None)[source]¶
Method to plot data on given axis as bar plot
The method receives as input an Axis or AxesSubplot object to plot on. It then plots the given x and y arrays as a line plot with given label and color. Results plotted as a bar plot.
- Inputs:
ax (object) : axis object to plot on x_array (ndarray) : array of values to plot on x-axis y_array (ndarray) : array of values to plot on y-axis dx (float) : width of bars label (str) : label name for specific line alpha (float) : transparency of bar plot (1 is fully opaque) color(str) : name of color to use for plot
- get_array(array_str, slicer)[source]¶
Method to slice through arrays
The method uses a list of array strings and the default getter method from Python to extract attributes from the instantiated NE2 module. It can also return just magnitudes and slice the output array.
- Inputs:
array_str (str) : string name for output array in NE2 module slicer (slice) : slice corresponding to desired simulation times
- Outputs:
array (ndarray) : sliced array of data
- get_slice(start_ind, end_ind)[source]¶
Method to create slice object
The method creates a slice object for desired simulation times from full data. This slice object is used elsewhere to slice through data arrays.
- Inputs:
start_ind (int) : starting index for simulation times end_ind (int) : ending index for simulation times
- Outputs:
slicer (slice) : slice corresponding to desired simulation times
- plot_SSC_generic(ax, array_list, label_list, y_label, lw_list=None, title_label=None, plot_all_time=True, start_hr=0, end_hr=48, is_bar_graph=False, return_extra=False, hide_x=False, days_on_x=False, left_axis=True)[source]¶
Method to plot generic SSC data
This method is used to plot any type of SSC data. It lives a level above the line/bar plotting methods, the ones that are “_on_axis”. This would be the middle level, at an even higher level would be specific methods to specify a list of arrays to plot. The method just redirects to either the line or bar plot and sets up a loop for all arrays to be plotted.
- Inputs:
ax (object) : axis object to plot on array_list (list) : list of array string names to plot label_list (list) : list of label string names for each array y_label (str) : label name for y-axis lw_list (list) : list of linewidths for each array title_label(str) : title name for plot plot_all_time(bool) : are we plotting all results or just a portion? start_hr (int) : (plot_all_time==False) hour used for starting index end_hr (int) : (plot_all_time==False) hour used for ending index is_bar_graph(bool) : are we plotting a bar graph instead of line graph? return_extra(bool) : returning extra outputs hide_x(bool) : hiding the x-axis from this particular plot left_axis (bool) : are we plotting on the left y-axis, not a twin axis?
- Outputs:
ax (object) : axis object to plot on d_slice (int) : (return_extra==True) slicer used for arrays t_plot (int) : (return_extra==True) array of times used as x-axis
- plot_SSC_massflow(ax=None, title_label=None, plot_all_time=True, start_hr=0, end_hr=48, hide_x=False, x_legend=1.2, y_legend_L=1.0, y_legend_R=1.0, days_on_x=False)[source]¶
Method to plot mass flow and defocus data on single plot
This method is used specifically to plot mass flow and defocus data from SSC simulation results. Built-in options to plot legend off-axis.
- Inputs:
ax (object) : axis object to plot on plot_all_time(bool) : are we plotting all results or just a portion? title_label(str) : title name for plot start_hr (int) : (plot_all_time==False) hour used for starting index end_hr (int) : (plot_all_time==False) hour used for ending index hide_x(bool) : hiding the x-axis from this particular plot x_legend (float) : (legend_offset==True) x-offset defining left-most side of legend y_legend_L (float) : (legend_offset==True) y-offset of left y-axis plot y_legend_R (float) : (legend_offset==True) y-offset of right y-axis plot
- plot_SSC_op_modes(ax=None, title_label=None, plot_all_time=True, start_hr=0, end_hr=48, hide_x=False, x_legend=1.2, y_legend_L=1.0, y_legend_R=1.0, days_on_x=False)[source]¶
Method to plot operating modes history on single plot
This method is used specifically to plot operating modes and relative pricing data from SSC simulation results. Built-in options to plot legend off-axis.
- Inputs:
ax (object) : axis object to plot on plot_all_time(bool) : are we plotting all results or just a portion? title_label(str) : title name for plot start_hr (int) : (plot_all_time==False) hour used for starting index end_hr (int) : (plot_all_time==False) hour used for ending index hide_x(bool) : hiding the x-axis from this particular plot x_legend (float) : (legend_offset==True) x-offset defining left-most side of legend y_legend_L (float) : (legend_offset==True) y-offset of left y-axis plot y_legend_R (float) : (legend_offset==True) y-offset of right y-axis plot
- plot_SSC_power_and_energy(ax=None, title_label=None, plot_all_time=True, start_hr=0, end_hr=48, hide_x=False, x_legend=1.2, y_legend_L=1.0, y_legend_R=1.0, days_on_x=False, left_axis=True)[source]¶
Method to plot power and energy data on single plot
This method is used specifically to plot power and energy data from SSC simulation results. Built-in options to plot legend off-axis.
- Inputs:
ax (object) : axis object to plot on plot_all_time(bool) : are we plotting all results or just a portion? title_label(str) : title name for plot start_hr (int) : (plot_all_time==False) hour used for starting index end_hr (int) : (plot_all_time==False) hour used for ending index hide_x(bool) : hiding the x-axis from this particular plot x_legend (float) : (legend_offset==True) x-offset defining left-most side of legend y_legend_L (float) : (legend_offset==True) y-offset of left y-axis plot y_legend_R (float) : (legend_offset==True) y-offset of right y-axis plot
- plot_SSC_temperatures(ax=None, title_label=None, plot_all_time=True, start_hr=0, end_hr=48, hide_x=False, x_legend=1.2, y_legend_L=1.0, y_legend_R=1.0)[source]¶
Method to plot temperature data on single plot
This method is used specifically to plot temperature data from SSC simulation results. Built-in options to plot legend off-axis.
- Inputs:
ax (object) : axis object to plot on plot_all_time(bool) : are we plotting all results or just a portion? title_label(str) : title name for plot start_hr (int) : (plot_all_time==False) hour used for starting index end_hr (int) : (plot_all_time==False) hour used for ending index hide_x(bool) : hiding the x-axis from this particular plot x_legend (float) : (legend_offset==True) x-offset defining left-most side of legend y_legend_L (float) : (legend_offset==True) y-offset of left y-axis plot y_legend_R (float) : (legend_offset==True) y-offset of right y-axis plot
- plot_on_axis(ax, x_array, y_array, label, lw, color=None)[source]¶
Method to plot data on given axis as line plot
The method receives as input an Axis or AxesSubplot object to plot on. It then plots the given x and y arrays as a line plot with given label and color. Results plotted as line plot.
- Inputs:
ax (object) : axis object to plot on x_array (ndarray) : array of values to plot on x-axis y_array (ndarray) : array of values to plot on y-axis label (str) : label name for specific line lw (float) : linewidth for plot color(str) : name of color to use for plot
simulations.util.PySSCWrapper module¶
Created on Fri May 21 16:00:31 2021
@author: gabrielsoto
- class simulations.util.PySSCWrapper.PySSCWrapper(json_name='model1', is_debug=True)[source]¶
Bases:
object
The PySSCWrapper class is a util class used to run PySSC from a given JSON script (similar to what we’re doing in the PySAM NE2 modules). The main use-case for this method is mixed-mode debugging:
choose an existing script from the /scripts directory that calls this method
run the script
PySSCWrapper class is initialized
PySSCWrapper creates PySSC data structures and modules
PySSC calls SSC
We can debug SSC if we’re running it through CodeLite or Eclipse
For more information: https://github.com/uw-esolab/docs/blob/main/sam/debugSSCwithPySSC_Linux_CodeLiteIDE.md
To ensure the debug version of SSC, look into the https://github.com/uw-esolab/neup-ies/build_debug_SAM bash script
- __init__(json_name='model1', is_debug=True)[source]¶
Initializes the PySSCWrapper module
This method initialized the PySSCWrapper module. If we intend to run in debug mode, the flag used as input ensures we point to the correct version of the SSC library (libSSCd.so file which is the Debug version rather than the Release version). The method also finds and extracts information from the specified JSON script.
- Inputs:
json_name (str) : name of JSON script with input data for module is_debug (bool) : flag to determine if running in debug mode
- create_API()[source]¶
Method to create and save a unique SSC API to self
This method also ensures we use the correct SSC library file, whether we need the Debug or Release version (both could be in play in different locations).
- generate_hash()[source]¶
Method to create unique hash for given JSON inputs
This method creates a unique, permanent hash for a given JSON script. That is, it gathers all of the JSON inputs (including SSC and PySAM inputs) from the designated script and converts both their keynames and values to strings. It collects all of these into a single string variable and then creates a new hexadecimal string or “hash” for that giant string. This serves as a unique identifier or “fingerprint” for all the values in the JSON script. This is then used later on as the file name containing outputs from this particular run. Any small changes to the JSON script will result in a drastically different hash, and therefore a new output file. If a simulation has already been run with the given JSON script, it can just pull results from the already created hash file instead of needlessly repeating the simulation.
- Returns
if True, a hash file currently exists with all given JSON inputs filepath (str):
absolute filepath to the hash file in outputs directory
- Return type
hash_exists (bool)
- get_array(out_str)[source]¶
Method to extract data from SSC results
This method gets SSC outputs and converts it to arrays.
- Inputs:
out_str (str) : string name of the desired output
- Outputs:
out_array (ndarray) : SSC result in array form
- init_fin_module()[source]¶
Method to initialize the Financial module within PySSC
This method creates the Financial module using SSC data from the SSC_dict within the specified JSON script.
- Outputs:
fin_module (int) : some sort of data structure for the Financial mod (idk, PySSC stuff) fin_module_name (str) : name of Financial module, or the cmod SSC file
- init_grid_module()[source]¶
Method to initialize the Grid module within PySSC
This method creates the Grid module using SSC data from csv files as well as from the SSC_dict within the specified JSON script.
- Outputs:
grid_module (int) : some sort of data structure for the Grid mod (idk, PySSC stuff) grid_module_name (str) : name of Grid module, or the cmod SSC file
- init_plant_module()[source]¶
Method to initialize the Plant module within PySSC
This method creates the Plant module using SSC data from csv files as well as from the SSC_dict within the specified JSON script.
- Outputs:
plant_module (int) : some sort of data structure for the Plant (idk, PySSC stuff) plant_module_name (str) : name of Plant module, or the cmod SSC file
- run_module(module, name)[source]¶
Method used to run a given SSC module through PySSC
Method adapted from LORE team (particularly the loop). It runs the given module (Plant, Grid, Financial) by calling SSC through the SSC API.
- Inputs:
module (int) : some sort of data structure for the Plant (idk, PySSC stuff) module_name (str) : name of Plant module, or the cmod SSC file
- Outputs:
module (int) : updated module with SSC results
- run_sim(run_dispatch_targets=False)[source]¶
Method to run full SSC simulation through PySSC
This method creates an SSC API, saves input data from the specified JSON script to it and runs a full SSC simulation through PySSC. Much like PySAM, it creates a Plant, Grid, and Financial module and runs each in order.
- set_ssc_data_from_dict(start_ind)[source]¶
Method used to extract SSC data from a dictionary in a JSON script
Method adapted from LORE team (particularly the loop). It checks the data type each entry of the JSON script SSC dictionary and uses the appropriate SSC API method to store the data.
- Inputs:
start_ind (int) : index of computer module (0: plant, 1: grid, 2: financial)
- Outputs:
ssc_module (int) : some sort of data structure for the Plant (idk, PySSC stuff) ssc_module_name (str) : name of Plant module, or the cmod SSC file
simulations.util.SSCHelperMethods module¶
Created on Fri May 7 10:50:27 2021
@author: gabrielsoto
- class simulations.util.SSCHelperMethods.SSCHelperMethods[source]¶
Bases:
object
The SSCHelperMethods class is a util class for any auxilliary methods that help us link up better with SSC or create better inputs for SSC. Typically for methods that can be used across all modules and dispatchers, so better to keep in one designated area.
- convert_to_pyomo_unit(param_str)[source]¶
Method to evaluate a Pyomo unit from a given Pint unit
This method was created because Pyomo Environment units and the Pint UnitRegistry use units in different ways and syntax. Pint seemed to have more functionality and use so I defaulted to using those in the generation and checking of Pyomo Parameters. Essentially what happens:
The entire params dictionary is taken as input as well as a single
string for a specific parameter.
A string representation of the unit(s) are created from the input
e.g. u.m/u.s -> ‘meter / second’
The algorithm below checks for any weirdness -e.g. are there multiple
units, are they being multiplied/divided? etc.
The algorithm then converts the string representation of the Pint unit
into the syntax for a Pyomo Environment unit.
If all goes well, it will return the evaluation of the Pyomo unit string,
so on the Return end of the function call it will return a Pyomo unit.
- Inputs:
params (dict) : dictionary of all Pyomo parameters to be used in optimization param_str (str) : single string to be extracted from params dictionary
- Outputs:
- cmd (evaluated string)evaluation of a string called unit_cmd representing
Pyomo unit syntax. If failed, return None.
- define_unit_registry()[source]¶
Method to define unique unit registry from Pint
This method creates a unique unit registry from the Pint Python package. This unit registry object is passed through classes to ensure that all use the same units.
- Outputs:
u_pint (obj) : pint UnitRegistry object
- estimate_receiver_pumping_parasitic(Tavg, dm_rec_design, SSC_dict, nonheated_length=0.2)[source]¶
Method to calculate pumping parasitic of receiver (written by LORE team)
- Inputs:
u (unitRegistry) : Pint unit registry Tavg (float Quant) : average temperature of plant, K dm_rec_design (float Quant) : power block thermal power input rating, units of MW SSC_dict (dict) : dictionary of SSC inputs nonheated_length (float) : non-heated length of total receiver height
- Outputs:
etap (float) : slope of linearized eta_p b (float) : intercept of linearized eta_p
- get_ambient_T_corrections_from_udpc_inputs(Tamb, ud_array)[source]¶
Method to calculate specific heat of some heat transfer fluid (written by LORE team)
- Inputs:
u (unitRegistry) : Pint unit registry Tamb (float) : ambient temperature, not units (intended to be C) ud_array (list of lists) : table of user defined data as nested lists
- Outputs:
etamult (float) : multiplication correction factor for eta wmult (float) : multiplication correction factor for w
- get_cp_htf(T, rec_htf, interp=None)[source]¶
Method to calculate specific heat of some heat transfer fluid (written by LORE team)
- Inputs:
u (unitRegistry) : Pint unit registry T (float Quant) : Temperature at which to find specific heat of HTF, in units of Kelvin rec_htf (int) : integer value representing HTF in SSC table
- Outputs:
cp (float Quant) : specific heat value in J/g/K
- get_linearized_ud_params(q_pb_design, SSC_dict)[source]¶
Method to calculate linearized user defined params (written by LORE team)
- Inputs:
ud_array (list of lists) : table of user defined data as nested lists q_pb_design (float Quant) : power block thermal power input rating, units of MW SSC_dict (dict) : dictionary of SSC inputs
- Outputs:
etap (float) : slope of linearized eta_p b (float) : intercept of linearized eta_p
- get_pc_persist_and_off_logs(plant, npts)[source]¶
Method to log the amount of time Power Cycle has been ON and OFF
This method uses SSC output data from the previous run to log how long the Power Cycle has been both ON and OFF. One of the two outputs will be populated in this method, and there are a bunch of logic statements to correctly log the respective length of time. Method adapted from LORE Team.
TODO: can we just input another dictionary instead of passing the full Plant?
- Inputs:
param_dict (dict) : dictionary of Pyomo dispatch parameters plant (obj) : the full PySAM Plant object. npts (int) : length of the SSC horizon
- Outputs:
disp_pc_persist0 (int) : length of time PC has been ON in the past segment disp_pc_off0 (int) : length of time PC has been OFF in the past segment
- get_rho_htf(T, rec_htf)[source]¶
Method to calculate density of some heat transfer fluid
This method calculates density at average temperature for a heat transfer fluid. In our case, we use molten salt. This method is copied from SSC, specifically the htf_props cpp method.
- Inputs:
u (unitRegistry) : Pint unit registry T (float Quant) : Temperature at which to find specific heat of HTF, in units of Kelvin rec_htf (int) : integer value representing HTF in SSC table
- Outputs:
rho (float Quant) : fluid density value in kg/m^3
- get_visc_htf(T, rec_htf)[source]¶
Method to calculate viscosity of some heat transfer fluid (written by LORE team)
- Inputs:
u (unitRegistry) : Pint unit registry T (float Quant) : Temperature at which to find specific heat of HTF, in units of Kelvin rec_htf (int) : integer value representing HTF in SSC table
- Outputs:
visc (float Quant) : viscosity value in Ns/m^2
simulations.util.SolarPlots module¶
Created on Fri Jul 16 16:15:50 2021
@author: gabrielsoto
- class simulations.util.SolarPlots.SolarDispatchPlots(module, **kwargs)[source]¶
Bases:
simulations.util.SolarPlots.SolarPlots
The Plots class is a part of the PostProcessing family of classes. It can output results from Pyomo Dispatch models.
Note that the DispatchPlots class must be initialized before using.
- __init__(module, **kwargs)[source]¶
Initializes the Plots module
The instantiation of this class receives a full Dispatch object, the module being one of the Pyomo Dispatch model created in the /neup-ies/simulations/dispatch directory. It also contains various inputs relating to cosmetic parameters for matplotlib plots.
- Inputs:
module (object) : object representing Pyomo Dispatch Model with results fsl (str) : fontsize for legend loc (str) : location of legend legend_offset(bool) : are we plotting legends off-axis? lp (int) : labelpad for axis labels lps (int) : labelpad for axis labels - short version fs (int) : fontsize for labels, titles, etc. lw (int) : linewidth for plotting x_shrink (float) : (legend_offset==True) amount to shrink axis to make room for legend
- plot_pyomo_energy(ax=None, title_label=None, plot_all_time=True, start_hr=0, end_hr=48, hide_x=False, x_legend=1.2, y_legend_L=1.0, y_legend_R=1.0)[source]¶
Method to plot energy data from Pyomo Dispatch on single plot
This method is used specifically to plot energy data from Dispatch simulation results. Built-in options to plot legend off-axis.
- Inputs:
ax (object) : axis object to plot on plot_all_time(bool) : are we plotting all results or just a portion? title_label(str) : title name for plot start_hr (int) : (plot_all_time==False) hour used for starting index end_hr (int) : (plot_all_time==False) hour used for ending index hide_x(bool) : hiding the x-axis from this particular plot x_legend (float) : (legend_offset==True) x-offset defining left-most side of legend y_legend_L (float) : (legend_offset==True) y-offset of left y-axis plot y_legend_R (float) : (legend_offset==True) y-offset of right y-axis plot
- plot_pyomo_power(ax=None, title_label=None, plot_all_time=True, start_hr=0, end_hr=48, hide_x=False, x_legend=1.2, y_legend_L=1.0, y_legend_R=1.0)[source]¶
Method to plot power and pricing data from Pyomo Dispatch on single plot
This method is used specifically to plot power data from Dispatch simulation results. Built-in options to plot legend off-axis.
- Inputs:
ax (object) : axis object to plot on plot_all_time(bool) : are we plotting all results or just a portion? title_label(str) : title name for plot start_hr (int) : (plot_all_time==False) hour used for starting index end_hr (int) : (plot_all_time==False) hour used for ending index hide_x(bool) : hiding the x-axis from this particular plot x_legend (float) : (legend_offset==True) x-offset defining left-most side of legend y_legend_L (float) : (legend_offset==True) y-offset of left y-axis plot y_legend_R (float) : (legend_offset==True) y-offset of right y-axis plot
- plot_pyomo_solar_bin(ax=None, title_label=None, plot_all_time=True, start_hr=0, end_hr=48, hide_x=False, x_legend=1.2, y_legend_L=1.0, y_legend_R=1.0)[source]¶
Method to plot solar binary data from Pyomo Dispatch on single plot
This method is used specifically to plot data from Dispatch simulation results pertaining to nuclear binary values. Variables include whether nuclear plant is running (0 or 1), etc. Built-in options to plot legend off-axis.
- Inputs:
ax (object) : axis object to plot on plot_all_time(bool) : are we plotting all results or just a portion? title_label(str) : title name for plot start_hr (int) : (plot_all_time==False) hour used for starting index end_hr (int) : (plot_all_time==False) hour used for ending index hide_x(bool) : hiding the x-axis from this particular plot x_legend (float) : (legend_offset==True) x-offset defining left-most side of legend y_legend_L (float) : (legend_offset==True) y-offset of left y-axis plot y_legend_R (float) : (legend_offset==True) y-offset of right y-axis plot
- class simulations.util.SolarPlots.SolarOutputExtraction(module)[source]¶
Bases:
util.PostProcessing.OutputExtraction
The OutputExtraction class is a part of the PostProcessing family of classes. It extracts outputs from SSC or Dispatch models. Can be called from other plotting classes to extract outputs.
- __init__(module)[source]¶
Initializes the OutputExtraction module
The instantiation of this class receives a full module object, the module being one of the NE2 modules in the /neup-ies/simulations/modules directory. or a Dispatch module.
- Inputs:
module (object) : object representing NE2 module class after simulations
- class simulations.util.SolarPlots.SolarPlots(module, **kwargs)[source]¶
Bases:
util.PostProcessing.Plots
The Plots class is a part of the PostProcessing family of classes. It can output results from SSCmodels. This might be a Sisyphus-ian task as some of the parameters are very unique to whatever plot you are trying to make, but will do my best to provide basic structures and templates to work off of.
Note that the Plots class must be initialized before using.
- __init__(module, **kwargs)[source]¶
Initializes the Plots module
The instantiation of this class receives a full module object, the module being one of the NE2 modules in the /neup-ies/simulations/modules directory. It also contains various inputs relating to cosmetic parameters for matplotlib plots.
- Inputs:
module (object) : object representing NE2 module class after simulations fsl (str) : fontsize for legend loc (str) : location of legend legend_offset(bool) : are we plotting legends off-axis? lp (int) : labelpad for axis labels lps (int) : labelpad for axis labels - short version fs (int) : fontsize for labels, titles, etc. lw (int) : linewidth for plotting x_shrink (float) : (legend_offset==True) amount to shrink axis to make room for legend
- plot_SSC_power_and_energy(ax=None, title_label=None, plot_all_time=True, start_hr=0, end_hr=48, hide_x=False, x_legend=1.2, y_legend_L=1.0, y_legend_R=1.0)[source]¶
Method to plot power and energy data on single plot
This method is used specifically to plot power and energy data from SSC simulation results. Built-in options to plot legend off-axis.
- Inputs:
ax (object) : axis object to plot on plot_all_time(bool) : are we plotting all results or just a portion? title_label(str) : title name for plot start_hr (int) : (plot_all_time==False) hour used for starting index end_hr (int) : (plot_all_time==False) hour used for ending index hide_x(bool) : hiding the x-axis from this particular plot x_legend (float) : (legend_offset==True) x-offset defining left-most side of legend y_legend_L (float) : (legend_offset==True) y-offset of left y-axis plot y_legend_R (float) : (legend_offset==True) y-offset of right y-axis plot