1. Getting Started¶
This section describes how to get started with PFNET in Python. In particular, it covers prerequisites and installation, and provides a simple example that shows how to use this package.
1.1. Prerequisites¶
Before installing the PFNET Python module, the following tools are needed:
- Linux and macOS:
- Windows:
1.2. Installation¶
After the prerequisites for the appropriate operating system have been obtained, the PFNET Python module can be installed by executing the following commands on the terminal or Anaconda prompt:
pip install numpy cython
pip install pfnet
To install the module from source, the code can be obtained from https://github.com/ttinoco/PFNET.py, and then the following commands can be executed on the terminal or Anaconda prompt from the root directory of the package:
pip install numpy cython
python setup.py install
Running the unit tests can be done with:
pip install nose
python setup.py build_ext --inplace
nosetests -s -v
1.3. Example¶
As a simple example of how to use the PFNET Python module, consider the task of constructing a power network from a MATPOWER power flow file and computing the average bus degree. This can be done as follows:
>>> import pfnet
>>> import numpy as np
>>> net = pfnet.PyParserMAT().parse('ieee14.m')
>>> print(np.average([bus.degree for bus in net.buses]))
2.86
In this example, is it assumed that the Python interpreter is started in a directory where the sample case ieee14 is located.