/pvfit

PVfit: Photovoltaic (PV) Device Performance Measurement and Modeling

Primary LanguagePythonMIT LicenseMIT

pvfit

PVfit: Photovoltaic (PV) Device Performance Measurement and Modeling

IMPORTANT: This code is pre-release, and so the code organiztion and Application Programming Interface (API) should be expected to change without warning.

NOTICE: We are in the process of open-sourcing the single-diode equation (SDE) and single-diode model (SDM) fitting algorithms (🎉), and thus moving the related code here. The SDE move is reasonably complete, but the code for SDM model fitting is not yet finalized on the main branch. Likewise, the documentation badly needs updating, so for now we refer users to the demos/getting_started.py modules in the various subpackages.

CI

Code style: black

So What Can PVfit Do for Me?

PVfit is currently focused on direct-current (DC) PV module performance measurement and modeling. Following the standardized technical approach of most accredited PV calibration laboratories for measuring current-voltage (I-V) curves using PV reference devices, PVfit makes considerable use of the effective irradiance ratio (F = Isc / Isc0 = M * Isc,ref / Isc0,ref) to quantify the effective irradiance on a PV device, in contrast to the common use of MET-station data. PVfit also supports inference of effective-irradiance ratio and cell temperature directly from I-V data, see (poster). See this paper for a more detailed introduction. Email Mark Campanelli to be added to the PVfit Slack channel, where you can chat realtime about your quesitons/applications. This open-source code complements a model calibration service (e.g., single-diode model parameter fitting from I-V curve data) available at https://pvfit.app and via a REST API.

See the demos/getting_started.py in individual subpackages to get started with specific functionalities—

We still need to improve test coverage for certain subpackages, esp.the simple SDM.

Up and Running in 5 Minutes

pvfit minimally requires python>=3.10,<3.13 with numpy and scipy. It is tested with CPython on recent versions of Ubuntu, macOS, and Windows. We suggest using a suitable Python virtual environment that provides pip.

Download, Install, and Verify Package (non-editable mode)

This package will not be available on PyPI until the application programming interface (API) is deemed stable and sufficiently tested and documented. Meanwhile, install the latest code directly from the GitHub repo using a sufficiently recent version of pip and setuptools—

python -m pip install --upgrade pip setuptools
python -m pip install git+https://github.com/markcampanelli/pvfit#egg=pvfit[demo]

NOTES:

  • You may want to install your own optimized versions of numpy and scipy (e.g., using conda), otherwise this setup will grab the default versions from PyPI.
  • The demo option adds the matplotlib package in order to run all the provided demonstrations in the demos directories.

Verify your installation—

python -c "from pvfit import __version__; print(__version__)"

which should print something similar to—

0.1.dev9+gadf7f38.d20190812

Likewise, stay up to date with the latest code changes using—

python -m pip install --upgrade git+https://github.com/markcampanelli/pvfit#egg=pvfit[demo]

You should now be able to explore PVfit's functionality with the getting_started.py modules in the various demos directories of the various subpackages.

Developer Notes

Download, Install, and Verify Package with Developer and Testing Dependencies (editable mode)

Clone this repo using your preferred git method, and go to the repo's root directory.

Install pvfit with all extras in editable (development) mode with pip—

python -m pip install --upgrade pip setuptools
python -m pip install -e .[demo,dev,docs,test]

This also installs the libraries needed to test, develop the code demonstrations, and build documentation and source and wheel distributions.

Verify your installation—

python -c "from pvfit import __version__; print(__version__)"

which should print something similar to—

0.1.dev9+gadf7f38.d20190812

Next, make sure that the tests are passing.

Test with Coverage

From the root directory—

python -m pytest --doctest-modules --cov=pvfit --cov-report=html:htmlcov tests

The root of the generated coverage report is at artifacts/test/htmlcov/index.html (not committed).

Build Documentation

From the docs subdirectory—

sphinx-apidoc -f -o . ../pvfit ../*_test.py

then—

make html

The root of the generated documentation is at docs/_build/html/pvfit.html (not committed).

Distribute, inc. with Nuitka

PEP-517-compliant build is used to generate distributions using setuptools as the build backend (specified in pyproject.toml). From the repo root, execute--

python -m build

Pure-Python *.whl and *.tar.gz files are placed in the dist directory (not committed).

Alternatively, nuitka can be used to transpile the Python source code into faster-executing, compiled C code with the same Python interface. With an appropriate setup for Nuitka (compilers, etc.), swap the [build-system] table in the pyproject.toml, then--

python -m build

A platfrom-specific *.whl file is placed in the dist directory (not committed). The included Python extension module has the same interface. Users may wish to remove tests and demos before generating such wheel files.

Finally, the distribution manifests (cf. MANIFEST.in) are checked using--

python -m check_manifest

Dependencies

Currently, numpy and scipy are the only runtime dependencies. In order to ensure a straightforward, consistent, and well-tested API, the decision has been made to avoid any dependecy of the core code on pandas. However, a design goal is for straightforward integration with consumers that use pandas, e.g., integrating computations with Series and DataFrame objects. To avoid bloat, we also avoid dependency on plotting libraries such as matplotlib. Any new dependencies or version ranges should be appropriately recorded in pyproject.toml.

Coding Requirements and Style

  • Unit testing is a must, with a "collocation" scheme, i.e., module_test.py to test module.py in the same directory. 100% code coverage is the goal.
  • Type hints should be used throughout (WIP).
  • pylint is used for linting, with black's default 88-character line limit (configured in pyproject.toml). Check before committing code using--
python -m pylint .

Skip troublesome lines (sparingly) with the suffix # pylint: disable=<code>.

  • black is used to autoformat code. Autoformat before committing code, using--
python -m black .

About the Author and Maintainer

The author and maintainer of this code is Mark Campanelli, the proprietor of Intelligent Measurement Systems LLC (IMS), in Bozeman, MT, USA. Your suggestions/bug reports, questions/discussions, and contributions are welcome.