Code Documentation
generator.py
The generator module of Copper deals with generating performance curves. It currently uses a genetic algorithm to find sets of curves that match user equipment definitions.
- class copper.generator.Generator(equipment, method='best_match', pop_size=100, tol=0.005, max_gen=300, vars='', sFac=0.5, retain=0.2, random_select=0.1, mutate=0.95, bounds=(6, 10), base_curves=[], random_seed=None, num_nearest_neighbors=10, max_restart=None)[source]
Bases:
object
- check_gradients()[source]
Check if the objective of the gradient of the three curves are monotonic and have the sign we expect.
- Returns:
Verification result
- Return type:
- compute_grad(x, y, sign_val, threshold=1e-05)[source]
Check, for a single curve, if the gradient has the sign we expect. called by check_gradients.
- Returns:
Verification result
- Return type:
- determine_full_load_fitness(set_of_curves)[source]
Determine the full load fitness of a set of curves
- Parameters:
set_of_curves (copper.curves.SetofCurves) – Set of curves
- Returns:
Fitness score
- Return type:
- determine_normalization_fitness(set_of_curves)[source]
Determine the normalization fitness of a set of curves (e.g. are they normalized at rated/reference conditions?)
- Parameters:
set_of_curves (copper.curves.SetofCurves) – Set of curves
- Returns:
Fitness score
- Return type:
- determine_part_load_fitness(set_of_curves)[source]
Determine the part load fitness of a set of curves
- Parameters:
set_of_curves (copper.curves.SetofCurves) – Set of curves
- Returns:
Fitness score
- Return type:
- evolve_population(pop)[source]
Evolve population to create a new generation.
- Parameters:
pop (list) – Population of individual, i.e. list of curves
- fitness_scale_grading(pop, scaling=True)[source]
Calculate fitness, scale, and grade for a population.
- generate_population(curves)[source]
Generate population of sets of curves.
- Parameters:
curves (copper.curves.SetofCurves) – Initial set of curves to be modified by the algorithm
- Returns:
Verification result
- Return type:
- generate_set_of_curves(verbose=False, agg_only=False)[source]
Generate set of curves using genetic algorithm.
- Parameters:
verbose (str) – Output results at each generation.
- Returns:
Set of curves
- Return type:
- get_random()[source]
Generate random number between two bounds.
- Returns:
Randomly generated value
- Return type:
- individual(curves)[source]
Create new individual.
- Parameters:
curves (copper.curves.SetofCurves) – Initial set of curves to be modified by the algorithm
- Returns:
New set of curves randomly modified
- Return type:
- is_target_met()[source]
Check if the objective of the optimization through the algorithm have been met.
- Returns:
Verification result
- Return type:
- perform_crossover(parents)[source]
Crossover best individuals.
- Parameters:
parents (list) – List of best performing individuals of the generation
- perform_mutation(individual)[source]
Mutate individual.
- Parameters:
individual (copper.curves.SetofCurves) – Set of curves
- Returns:
Modified indivudal
- Return type:
- run_ga(curves, verbose=False)[source]
Run genetic algorithm.
- Parameters:
curves (copper.curves.SetofCurves) – Initial set of curves to be modified by the algorithm
verbose (str) – Output results at each generation.
- Returns:
Final population of sets of curves
- Return type:
curves.py
The curves module of Copper handles all operations and manipulation related to curves, set of curves, and sets of curves.
- class copper.curves.Curve(eqp, c_type)[source]
Bases:
object
- compute_grad(x, y, sign_val, threshold=1e-05)[source]
Check, for a single curve, if the gradient has the sign we expect. called by check_gradients.
- Returns:
Verification result
- Return type:
- get_out_reference(eqp)[source]
Return the reference output of a curve.
- Parameters:
eqp – Equipment
- Returns:
Curve output at reference conditions
- Return type:
- nb_coeffs()[source]
Find number of curve coefficients.
- Returns:
Number of curve coefficients
- Return type:
- class copper.curves.SetofCurves[source]
Bases:
object
- get_data_for_plotting(curve, norm)[source]
Retrieve equipment specific data for plotting set of curves.
- list_to_dict()[source]
Convert curves from the set from a list to a dictionary (the key being the output variable type).
- Returns:
Dictionary of Copper curve objects
- Return type:
- plot(out_var=[], axes=[], norm=False, color='Black', alpha=0.3)[source]
Plot a set of curves.
- Parameters:
out_var (list) – List of the output variables to plot, e.g. eir-f-t, eir-f-plr, cap-f-t. Refer to JSON files structure for other output variables
axes (matplotlib.pyplot.axes) – Matplotlib pyplot axes
norm (bool) – Normalize plot to reference values
color (str) – Set of curves color
alpha (float) – Transparency of the curves (0-1).
- Returns:
Plotting success
- Return type:
- class copper.curves.SetsofCurves(eqp, sets)[source]
Bases:
object
- check_vars_in_dictionary(vars, target_attr)[source]
Function to check that the vars specified by the user exists in ‘target_attr’.
- get_aggregated_set_of_curves(method='weighted_average', N=None, ranges={}, misc_attr={})[source]
Determine sets of curves based on aggregation.
- Parameters:
method (str) – Type of aggregation, currently supported: ‘average’, ‘median’, ‘weighted_average’, and ‘NN_weighted_average’ as in nearest neighbor weighted average.
N (int) – Number of neighbor used to the aggregation, only used when the method is ‘NN_weighted_average’.
ranges (dict) – Dictionary that defines the ranges of values for each independent variable used to calculate aggregated dependent variable values.
misc_attr (dict) – Dictionary that provides values for the aggregated set of curves.
- Returns:
Aggregated set of curves
- Return type:
- l2_norm(df, target_attr, weights, vars=['full_eff', 'ref_cap'])[source]
Perform L2 normalization.
- Parameters:
df (pandas.DataFrame) – Dataframe containing the attributes of different equipments for a given equipment type
target_attr (dict) – Target equipment attribute
weights (list) – List of weights, must have the same dimensions as vars
vars (list) – List of string containing variable names to compute the L2 normalization
- Returns:
L2 scores (same size as df)
- Return type:
numpy.array
- nearest_neighbor_sort(target_attr=None, vars=[], N=None)[source]
This function performs the weighted average and the nearest neighbor approach.
- Parameters:
target_attr (dict) – Target attributes we want to match
vars (list) – The variables we want to use to compute our l2 score. note COP will be added
N (int) – Indicates the number of nearest neighbors to consider. N=None for weighted_average
df (pandas.DataFrame) – Pandas dataframe with selected chiller names and the associated weightings
- Returns:
Index of set_of_curve that should be the closest fit
- Return type:
- normalize_vars(df, target_attr=None, vars=['ref_cap', 'full_eff'], epsilon=1e-05, weights=None, N=None)[source]
Normalize curve outputs.
- Parameters:
df (pandas.DataFrame) – Input dataframe containing the variable inputs
target_attr (dict) – Reference targets with respect to which l2 score needs to computed
vars (list) – List of strings for variables we want to normalize
weights (list) – Weights associated with each variable in vars
N (int) – Number of nearest neighbors. It should be none unless method is ‘NN_weighted_average’
- Returns:
Dataframe with added columns with normalized variables, dict with added normalized values of var in vars, index of the best curve
- Return type:
library.py
This is the library module of Copper. It contains functions used to parse the JSON library files.
- class copper.library.Library(path='/home/runner/work/copper/copper/copper/data/chiller_curves.json', rating_std='', export=False)[source]
Bases:
object
- content()[source]
Content of a library in a dict format.
- Returns:
Dictionary of the data contained in a library
- Return type:
- find_base_curves(filters, eqp)[source]
Find an existing equipment curve that best matches the equipment.
- Parameters:
filters (list) – List of filters, represented by tuples (field, val)
eqp – Instance of the equipment in Copper (e.g. copper.chiller.Chiller)
- Returns:
Set of curves object
- Return type:
- find_equipment(filters=[])[source]
Find equipment matching specified filter in the curve library.
Special filter characters:
~! means “all except…”
! means “do not include…”
~ means “include…”
- find_set_of_curves_from_lib(filters=[], part_eff_flag=False)[source]
Retrieve sets of curves from a library matching specific filters.
- get_best_match(eqp, matches)[source]
Find the set of curves matching the equipment characteristics the best.
- get_set_of_curves_by_name(name)[source]
Retrieve set of curves from the library by name.
- Parameters:
name (str) – Curve name
- Returns:
Set of curves object
- Return type:
units.py
The conversion module of Copper handles simple unit conversions to avoid creating additional dependencies.
equipment.py
This is the equipment module of Copper. The module includes function that can be used by all types of equipment included in Copper.
- class copper.equipment.Equipment[source]
Bases:
object
- generate_set_of_curves(method='best_match', pop_size=100, tol=0.0025, max_gen=300, vars='', sFac=0.5, retain=0.2, random_select=0.1, mutate=0.95, bounds=(6, 10), base_curves=[], random_seed=None, verbose=False, export_path='', export_format='json', export_name='', num_nearest_neighbors=10, max_restart=None, agg_only=False)[source]
Generate a set of curves for a particular equipment.
- Parameters:
method (str) – Method used to generate the set of curves: best_match, nearest_neighbor, or weighted_average
pop_size (int) – Population size used by the genetic algorithm
tol (float) – Tolerance used by the genetic algorithm to determine if the proposed solution is acceptable The lower, the more stringent
max_gen (int) – Maximum number of generation
vars (list()) – List of variable to run the alorithm on
sFac (float) – Linear fitness normalization factor, the higher the more aggressive the normalization will be
retain (float) – Probability of retaining an individual in the next generation
random_select (float) – Probability of randomly selecting an individual to be part of the next generation
mutate (float) – Probability of an individual to be mutated in the next generation
bounds (tuple()) – Random modification bounds
random_seed (int) – Integer that is used to inialize the random number generator, this should be used when identical results are needed from one run to another
- Returns:
Set of curves object generated by the genetic algorithm that matches the definition
- Return type:
chiller.py
This is the chiller module of Copper. The module handles all calculations and data manipulation related to chillers.
- class copper.chiller.Chiller(ref_cap, ref_cap_unit, full_eff, full_eff_unit, compressor_type, condenser_type, compressor_speed, part_eff=0, part_eff_unit='', part_eff_ref_std='ahri_550/590', part_eff_alt=0, part_eff_unit_alt='', part_eff_ref_std_alt='ahri_550/590', full_eff_alt=0, full_eff_unit_alt='', set_of_curves=[], model='ect_lwt', sim_engine='energyplus', min_unloading=0.1, min_plr=None)[source]
Bases:
Equipment
- calc_eff_ect(cap_f_t, eir_f_t, eir_f_plr, eir_ref, ect, lwt, load)[source]
Calculate chiller efficiency using the ECT-based model for a specific ECT and load value (percentage load).
- Parameters:
cap_f_t (Curve) – Capacity curve modifier as a function of temperature (LWT and ECT)
eir_f_t (Curve) – Energy Input Ratio curve modifier as a function of temperature (LWT and ECT)
eir_f_plr (Curve) – Energy Input Ratio curve modifier as a function of part load ratio
eir_ref (float) – Reference EIR
ect (float) – Entering condenser temperature in deg. C
lwt (float) – Leaving water temperature in deg. C
load (float) – Percentage load, as defined in AHRI 550/590
- calc_rated_eff(eff_type, unit='kW/ton', output_report=False, alt=False)[source]
Calculate chiller efficiency.
- cond_inlet_temp_residual(lct, args)[source]
Calculate the enetering condenser temperature residual based on a leaving condenser temperature.
- convert_to_deg_c(unit='degF')
Helper function to convert equipment data to degree F.
- generate_set_of_curves(method='best_match', pop_size=100, tol=0.0025, max_gen=300, vars='', sFac=0.5, retain=0.2, random_select=0.1, mutate=0.95, bounds=(6, 10), base_curves=[], random_seed=None, verbose=False, export_path='', export_format='json', export_name='', num_nearest_neighbors=10, max_restart=None, agg_only=False)
Generate a set of curves for a particular equipment.
- Parameters:
method (str) – Method used to generate the set of curves: best_match, nearest_neighbor, or weighted_average
pop_size (int) – Population size used by the genetic algorithm
tol (float) – Tolerance used by the genetic algorithm to determine if the proposed solution is acceptable The lower, the more stringent
max_gen (int) – Maximum number of generation
vars (list()) – List of variable to run the alorithm on
sFac (float) – Linear fitness normalization factor, the higher the more aggressive the normalization will be
retain (float) – Probability of retaining an individual in the next generation
random_select (float) – Probability of randomly selecting an individual to be part of the next generation
mutate (float) – Probability of an individual to be mutated in the next generation
bounds (tuple()) – Random modification bounds
random_seed (int) – Integer that is used to inialize the random number generator, this should be used when identical results are needed from one run to another
- Returns:
Set of curves object generated by the genetic algorithm that matches the definition
- Return type:
- get_chiller_curves()[source]
Retrieve chiller curves from the chiller set_of_curves attribute.
- Returns:
Dictionary of the curves associated with the chiller object
- Return type:
- get_curves_from_lib(lib, filters)[source]
Function to get the sort from the library based on chiller filters.
- Parameters:
lib (copper.library.Library) – Chiller library object
filters (list) – List of tuples containing the relevant filter keys and values
- Returns:
List of set of curves object corresponding to seed curves
- Return type:
- get_eir_ref(alt)
Get the reference EIR (energy input ratio) of an equipment.
- get_lct(ect, args)[source]
Determine a chiller’s leaving condenser temperature based on a entering condenser temperature. The temperature should be determine by iteration, a secant root finding methods is used.
- get_lib_and_filters(lib_path='/home/runner/work/copper/copper/copper/data/chiller_curves.json')[source]
Get chiller library object and chiller specific filters.
:param str lib_path:Full path of json library :return: Chiller library object and filters :rtype: list
- get_ranges()[source]
Get applicable range of values for independent variables of the chiller model.
- Returns:
Range of values, and values used for normalization (reference/rated values)
- Return type:
- get_ref_cond_flow_rate()[source]
Function to compute the reference condenser flow rate given ref_cap, full_eff, ref_lct and ref_lwt
- Returns:
Reference condenser flow rate
- Return type:
- get_ref_values(out_var)
Get equipment reference/rated independent variables values (temperature and part load ratio) for an output variable (e.g., eir-f-t, eir-f-plr, cap-f-t).
- get_seed_curves(lib=None, filters=None, csets=None)[source]
Function to generate seed curves specific to a chiller and sets relevant attributes (misc_attr, ranges).
- Parameters:
lib (copper.library.Library) – Chiller library object
fitlers (list) – List of tuples containing the filter keys and values
csets (list) – List of set of curves object corresponding to selected chillers from library
- Return type:
schema.py
Validation of the CLI input files.