Note

You can download this example as a Jupyter notebook or start it in interactive mode.

Demonstrate usage of logging

PyPSA uses the Python standard library logging. This notebook shows how to use it and control the logging messages from different modules.

One can set the logging level to different values like ERROR, WARNING, INFO, DEBUG. This works independently for separate module.

We start by setting the basic logging level to ERROR.

[1]:
import pypsa, os
import logging

logging.basicConfig(level=logging.ERROR)
[2]:
network = pypsa.examples.ac_dc_meshed(from_master=True)
[3]:
out = network.lopf()

Now turn on infos just for OPF module.

[4]:
pypsa.opf.logger.setLevel(logging.INFO)
[5]:
out = network.lopf()

Now turn on warnings just for OPF module

[6]:
pypsa.opf.logger.setLevel(logging.WARNING)
[7]:
out = network.lopf()

Now turn on all messages for the PF module

[8]:
pypsa.pf.logger.setLevel(logging.DEBUG)
[9]:
out = network.lpf()
DEBUG:pypsa.pf:Slack bus for sub-network 0 is Manchester
DEBUG:pypsa.pf:Slack bus for sub-network 1 is Norwich DC
DEBUG:pypsa.pf:Slack bus for sub-network 2 is Frankfurt
DEBUG:pypsa.pf:Slack bus for sub-network 3 is Norway
DEBUG:pypsa.pf:Slack bus for sub-network 0 is Manchester
INFO:pypsa.pf:Performing linear load-flow on AC sub-network SubNetwork 0 for snapshot(s) DatetimeIndex(['2015-01-01 00:00:00', '2015-01-01 01:00:00',
               '2015-01-01 02:00:00', '2015-01-01 03:00:00',
               '2015-01-01 04:00:00', '2015-01-01 05:00:00',
               '2015-01-01 06:00:00', '2015-01-01 07:00:00',
               '2015-01-01 08:00:00', '2015-01-01 09:00:00'],
              dtype='datetime64[ns]', name='snapshot', freq=None)
DEBUG:pypsa.pf:Slack bus for sub-network 1 is Norwich DC
INFO:pypsa.pf:Performing linear load-flow on DC sub-network SubNetwork 1 for snapshot(s) DatetimeIndex(['2015-01-01 00:00:00', '2015-01-01 01:00:00',
               '2015-01-01 02:00:00', '2015-01-01 03:00:00',
               '2015-01-01 04:00:00', '2015-01-01 05:00:00',
               '2015-01-01 06:00:00', '2015-01-01 07:00:00',
               '2015-01-01 08:00:00', '2015-01-01 09:00:00'],
              dtype='datetime64[ns]', name='snapshot', freq=None)
DEBUG:pypsa.pf:Slack bus for sub-network 2 is Frankfurt
INFO:pypsa.pf:Performing linear load-flow on AC sub-network SubNetwork 2 for snapshot(s) DatetimeIndex(['2015-01-01 00:00:00', '2015-01-01 01:00:00',
               '2015-01-01 02:00:00', '2015-01-01 03:00:00',
               '2015-01-01 04:00:00', '2015-01-01 05:00:00',
               '2015-01-01 06:00:00', '2015-01-01 07:00:00',
               '2015-01-01 08:00:00', '2015-01-01 09:00:00'],
              dtype='datetime64[ns]', name='snapshot', freq=None)
DEBUG:pypsa.pf:Slack bus for sub-network 3 is Norway
INFO:pypsa.pf:Performing linear load-flow on AC sub-network SubNetwork 3 for snapshot(s) DatetimeIndex(['2015-01-01 00:00:00', '2015-01-01 01:00:00',
               '2015-01-01 02:00:00', '2015-01-01 03:00:00',
               '2015-01-01 04:00:00', '2015-01-01 05:00:00',
               '2015-01-01 06:00:00', '2015-01-01 07:00:00',
               '2015-01-01 08:00:00', '2015-01-01 09:00:00'],
              dtype='datetime64[ns]', name='snapshot', freq=None)

Now turn off all messages for the PF module again

[10]:
pypsa.pf.logger.setLevel(logging.ERROR)
[11]:
out = network.lpf()