From bc7584aa83ac709d9b92155f2efa189814bf5f95 Mon Sep 17 00:00:00 2001 From: Tom Brown Date: Wed, 30 Nov 2016 11:44:28 +0100 Subject: [PATCH] io, pf: Change order of components read in; better slack reporting --- pypsa/io.py | 4 ++-- pypsa/pf.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pypsa/io.py b/pypsa/io.py index ad026c975..728f6c9c8 100644 --- a/pypsa/io.py +++ b/pypsa/io.py @@ -339,8 +339,8 @@ def import_from_csv_folder(network, csv_folder_name, encoding=None): if "weightings" in df.columns: network.snapshot_weightings = df["weightings"].reindex(network.snapshots) - #now read in other components - for cls in pypsa.components.component_types - {pypsa.components.SubNetwork}: + #now read in other components; make sure buses and carriers come first + for cls in sorted(pypsa.components.component_types - {pypsa.components.SubNetwork},key=lambda cls:cls.__name__): list_name = cls.list_name diff --git a/pypsa/pf.py b/pypsa/pf.py index 6227f8152..bbfb2af1c 100644 --- a/pypsa/pf.py +++ b/pypsa/pf.py @@ -414,18 +414,18 @@ def find_slack_bus(sub_network): if len(slacks) == 0: sub_network.slack_generator = gens.index[0] sub_network.network.generators.loc[sub_network.slack_generator,"control"] = "Slack" - logger.debug("No slack generator found, using %s as the slack generator", sub_network.slack_generator) + logger.debug("No slack generator found in sub-network {}, using {} as the slack generator".format(sub_network.name, sub_network.slack_generator)) elif len(slacks) == 1: sub_network.slack_generator = slacks[0] else: sub_network.slack_generator = slacks[0] sub_network.network.generators.loc[slacks[1:],"control"] = "PV" - logger.debug("More than one slack generator found, taking %s to be the slack generator", sub_network.slack_generator) + logger.debug("More than one slack generator found in sub-network {}, using {} as the slack generator".format(sub_network.name, sub_network.slack_generator)) sub_network.slack_bus = gens.bus[sub_network.slack_generator] - logger.info("Slack bus is %s" % sub_network.slack_bus) + logger.info("Slack bus for sub-network {} is {}".format(sub_network.name, sub_network.slack_bus)) def find_bus_controls(sub_network):