Skip to main content

Electrical model fitting to impedance data

Project description

Introduction

This Python module is for fitting electrical models to measured impedance data. It also includes a command-line program to assist with automated fitting.

Installation

The easiest way is using the command line command:

$ pip install .

zfit

Here's an example of how model fitting can be performed using a Python script:

from zfitpy import zfit

net = "(CPE('K', 'alpha') | R('R2')) + R('R1')"
ranges = {'R1': (1e-3, 1e3), 'K': (1e-3, 1e3), 'alpha': (-1, 1), 'R2': (100, 1e4)}

data, fitmodel = zfit('E4990A-example1.csv', net, ranges, Ns=10)
print(fitmodel)
print(fitmodel.error)

Here Ns specifies the number of steps in each search range. It can be explicitly defined for each search range, for example,

ranges = {'R1': (1e-3, 1e3, 10), 'K': (1e-3, 1e3, 20), 'alpha': (-1, 1), 'R2': (100, 1e4)}

The error between the measured data and best-fit model can be plotted using:

from zfitpy import Plotter
plotter = Plotter()
plotter.Z_error(data, fitmodel)

Note, a parameter names cannot be a substring of another parameter name, i.e., 'R' cannot be used if there is a parameter 'R1'.

zfitpy

zfitpy is a command-line Python program. It is designed for fitting electrical models to impedance data. For example:

   $ zfitpy --net "L('L1') + (R('R1') | (L('L2') + R('R2')))" --ranges="{'R1':(0,5e3),'L1':(1e-3,20e-3),'R2':(0,0.1),'L2':(1e-3,20e-3)}" --input demo/E4990A-example1.csv --plot-error

The network is specified using Lcapy notation for networks. This example uses a network comprised of a parallel combination of RL series networks. The network can be drawn using:

   $ zfitpy --net "L('L1') + (R('R1') | (L('L2') + R('R2')))" --draw

The network in this example has four parameters: R1, L1, R2, and L2. A brute force search is performed for each component using the specified ranges; this is refined with a finishing search. The ranges are specified as a Python dictionary, keyed by component name, with the range for each component specified as a tuple. The number of steps in each range is 20 can be altered with the --steps option.

The impedance of the data and model can be plotted using:

   $ zfitpy --plot-fit --net "L('L1') + (R('R1') | (L('L2') + R('R2')))" --ranges="{'R1':(0,5e3),'L1':(1e-3,20e-3),'R2':(0,0.1),'L2':(1e-3,20e-3)}" --input demo/E4990A-example1.csv

The impedance error between the data and model can be plotted using:

   $ zfitpy --plot-error --net "L('L1') + (R('R1') | (L('L2') + R('R2')))" --ranges="{'R1':(0,5e3),'L1':(1e-3,20e-3),'R2':(0,0.1),'L2':(1e-3,20e-3)}" --input demo/E4990A-example1.csv

Here's another network using a constant phase element (CPE).

   $ zfitpy --net "(CPE('K', 'alpha') | R('R2')) + R('R1')" --draw

   $ zfitpy --plot-error --net "(CPE('K', 'alpha') | R('R2')) + R('R1')"  --ranges="{'R1':(0,1e3),'K':(1e-3,1e3),'alpha':(-1,1),'R2':(1e2,1e4)}" --input demo/E4990A-example1.csv

The data format for the plots depends on the extension. matplotlib is used for the plotting and so the pdf, png, pgf, and jpg formats are all supported. For example:

   $ zfitpy --net "CPE('K', 'alpha')" --draw --output CPE.png

The data can be plotted without fitting if the ranges option is not specified. For example:

   $ zfitpy --plot-data --input demo/E4990A-example1.csv

A Nyquist plot is generated if the --nyquist option is specified. Magnitude and phase is plotted is the --magphase option is specified. The plot style can be altered using the --style option to specify a Matplotlib style file.

Other command line options for zfitpy can be found with the --help option.

Here's another example that loads the network and ranges from files. It uses a Matplotlib style file and annotates the title with the model, the optimization method, and the rms error.

   $ zfitpy --net RL2.net --ranges=RL2.ranges --input data/data.csv --plot-error --method='brute' --title='%model, %method, %rmse' --style=z.mplstyle --output RL2-brute.pdf

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zfitpy-0.5.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

zfitpy-0.5.0-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file zfitpy-0.5.0.tar.gz.

File metadata

  • Download URL: zfitpy-0.5.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.6.9

File hashes

Hashes for zfitpy-0.5.0.tar.gz
Algorithm Hash digest
SHA256 4211798210ef81e5c0f83829ec0676a657453f9af17f108acae8edff5944aff0
MD5 a88502fdcc39734ac7e7a19cbf6ae38d
BLAKE2b-256 3c262f292fb721cd6eb3d755512ff7904b3be3e5c329e7232058de68d8e2aa8a

See more details on using hashes here.

File details

Details for the file zfitpy-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: zfitpy-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.6.9

File hashes

Hashes for zfitpy-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b55f5bb41e7a2728c906f441ac0c344fa1ff267e8f1d8c83eb43e5959b77a41
MD5 f06aa250c9cb4367a283d9001e52961c
BLAKE2b-256 158f6752a7b2794e4dfbf3a3d92a5b060d2a5a354f961a73ae93343c6e1a0b62

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page