Skip to content

Commit

Permalink
components: Allow the addition of new types of component
Browse files Browse the repository at this point in the history
Pass DataFrame new_components to Network on __init__.

Also store the sets of types of component on the network itself.
  • Loading branch information
nworbmot committed Jan 19, 2018
1 parent 5ea2f0e commit 2e1b05e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
22 changes: 11 additions & 11 deletions pypsa/components.csv
Original file line number Diff line number Diff line change
@@ -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
34 changes: 29 additions & 5 deletions pypsa/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.")
Expand All @@ -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'})
Expand Down

0 comments on commit 2e1b05e

Please sign in to comment.