forked from PyPSA/PyPSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging-demo.py
More file actions
48 lines (32 loc) · 1.2 KB
/
Copy pathlogging-demo.py
File metadata and controls
48 lines (32 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
## Demonstrate usage of logging
#
# PyPSA uses the Python standard library [logging](https://docs.python.org/3/library/logging.html).
#
# This script shows how to use it and control the logging messages from different modules.
#
# Available as a Jupyter notebook at https://pypsa.readthedocs.io/en/latest/examples/logging-demo.ipynb.
# logging.basicConfig() needs to be called BEFORE importing PyPSA
# The reason is that logging.basicConfig() can only be called
# once, and it is already called in pypsa.__init__.py; further
# calls are ignored.
# Choices are ERROR, WARNING, INFO, DEBUG
import logging
logging.basicConfig(level=logging.ERROR)
import os
import pypsa
csv_folder_name = (
os.path.dirname(pypsa.__file__) + "/../examples/ac-dc-meshed/ac-dc-data/"
)
network = pypsa.Network(csv_folder_name=csv_folder_name)
out = network.lopf()
out = network.lpf()
# now turn on warnings just for OPF module
pypsa.opf.logger.setLevel(logging.WARNING)
out = network.lopf()
# now turn on all messages for the PF module
pypsa.pf.logger.setLevel(logging.DEBUG)
out = network.lpf()
# now turn off all messages for the PF module again
pypsa.pf.logger.setLevel(logging.ERROR)
out = network.lpf()