From 2e1b05ee5bdc81254bae1c1f8d9efee2bea96e89 Mon Sep 17 00:00:00 2001 From: Tom Brown Date: Fri, 19 Jan 2018 12:16:08 +0100 Subject: [PATCH] components: Allow the addition of new types of component Pass DataFrame new_components to Network on __init__. Also store the sets of types of component on the network itself. --- pypsa/components.csv | 22 +++++++++++----------- pypsa/components.py | 34 +++++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/pypsa/components.csv b/pypsa/components.csv index d82aa4cdf..17b53b8c9 100644 --- a/pypsa/components.csv +++ b/pypsa/components.csv @@ -1,16 +1,16 @@ -component,list_name,description +component,list_name,description,type Network,networks,"Container for all components and functions which act upon the whole network." SubNetwork,sub_networks,"Subsets of buses and passive branches (i.e. lines and transformers) that are connected (i.e. synchronous areas)." Bus,buses,"Electrically fundamental node where x-port objects attach." Carrier,carriers,"Energy carrier, such as AC, DC, heat, wind, PV or coal. Buses have direct carriers and Generators indicate their primary energy carriers. The Carrier can track properties relevant for global constraints, such as CO2 emissions." GlobalConstraint,global_constraints,"Constraints for OPF that affect many components, such as CO2 emission constraints." -Line,lines,"Lines include distribution and transmission lines, overhead lines and cables." -LineType,line_types,"Standard line types with per length values for impedances." -Transformer,transformers,"2-winding transformer." -TransformerType,transformer_types,"Standard 2-winding transformer types." -Link,links,"Link between two buses with controllable active power - can be used for a transport power flow model OR as a simplified version of point-to-point DC connection OR as a lossy energy converter. NB: for a lossless bi-directional HVDC or transport link, set p_min_pu = -1 and efficiency = 1. NB: It is assumed that the links neither produce nor consume reactive power." -Load,loads,"PQ power consumer." -Generator,generators,"Power generator." -StorageUnit,storage_units,"Storage unit with fixed nominal-energy-to-nominal-power ratio." -Store,stores,"Generic store, whose capacity may be optimised." -ShuntImpedance,shunt_impedances,"Shunt y = g + jb." +Line,lines,"Lines include distribution and transmission lines, overhead lines and cables.",passive_branch +LineType,line_types,"Standard line types with per length values for impedances.",standard_type +Transformer,transformers,"2-winding transformer.",passive_branch +TransformerType,transformer_types,"Standard 2-winding transformer types.",standard_type +Link,links,"Link between two buses with controllable active power - can be used for a transport power flow model OR as a simplified version of point-to-point DC connection OR as a lossy energy converter. NB: for a lossless bi-directional HVDC or transport link, set p_min_pu = -1 and efficiency = 1. NB: It is assumed that the links neither produce nor consume reactive power.",controllable_branch +Load,loads,"PQ power consumer.",controllable_one_port +Generator,generators,"Power generator.",controllable_one_port +StorageUnit,storage_units,"Storage unit with fixed nominal-energy-to-nominal-power ratio.",controllable_one_port +Store,stores,"Generic store, whose capacity may be optimised.",controllable_one_port +ShuntImpedance,shunt_impedances,"Shunt y = g + jb.",passive_one_port diff --git a/pypsa/components.py b/pypsa/components.py index 8511c69c4..064705d0b 100644 --- a/pypsa/components.py +++ b/pypsa/components.py @@ -134,6 +134,8 @@ class Network(Basic): If True, do not read in PyPSA standard types into standard types DataFrames. csv_folder_name : string Name of folder from which to import CSVs of network data. Overrides import_name. + new_components : pandas.DataFrame + DataFrame with index of component name and columns of list_name and description kwargs Any remaining attributes to set @@ -197,7 +199,9 @@ class Network(Basic): adjacency_matrix = adjacency_matrix - def __init__(self, import_name=None, name="", ignore_standard_types=False, **kwargs): + def __init__(self, import_name=None, name="", ignore_standard_types=False, + new_components=None, + **kwargs): if 'csv_folder_name' in kwargs: logger.warning("The argument csv_folder_name for initiating Network() is deprecated, please use import_name instead.") @@ -220,14 +224,34 @@ def __init__(self, import_name=None, name="", ignore_standard_types=False, **kwa "components.csv"), index_col=0) + components = components.reindex(components.columns|["attrs"],axis=1) + + if new_components is not None: + components = pd.concat((components, new_components)) + + for c_type in ["passive_one_port", "controllable_one_port", + "passive_branch", "controllable_branch", "standard_type"]: + setattr(self, c_type + "_components", + set(components.index[components.type == c_type])) + + self.one_port_components = self.passive_one_port_components|self.controllable_one_port_components + + self.branch_components = self.passive_branch_components|self.controllable_branch_components + + #i.e. everything except "Network" + self.all_components = self.branch_components|self.one_port_components|self.standard_type_components|{"Bus", "SubNetwork", "Carrier", "GlobalConstraint"} + self.components = Dict(components.T.to_dict()) for component in self.components.keys(): - file_name = os.path.join(dir_name, - component_attrs_dir_name, - self.components[component]["list_name"] + ".csv") - attrs = pd.read_csv(file_name, index_col=0, na_values="n/a") + if type(self.components[component]["attrs"]) is pd.DataFrame: + attrs = self.components[component]["attrs"] + else: + file_name = os.path.join(dir_name, + component_attrs_dir_name, + self.components[component]["list_name"] + ".csv") + attrs = pd.read_csv(file_name, index_col=0, na_values="n/a") attrs['static'] = (attrs['type'] != 'series') attrs['varying'] = attrs['type'].isin({'series', 'static or series'})