ECSHackWeek / impedance.py

A Python package for working with electrochemical impedance data
MIT License
212 stars 103 forks source link

[DATA] Biologic MPR files #132

Closed petermattia closed 4 years ago

petermattia commented 4 years ago

Hey @mdmurbach -- this package is awesome. Great work to you and the other contributors.

In addition to MPT files (which are manually exported from Bio-logic's ECLab), it would be awesome to be able to read in the binary MPR files saved by ECLab as well. This functionality would allow users to avoid ECLab altogether for postprocessing.

Fortunately, the galvani package has MPR reading functionality in its BioLogic.py file. The PyPI release lags the repo, so I simply downloaded BioLogic.py and placed it in the same directory.

Here is a sample file: test.mpr.zip

I have a template function here that works, but this function could probably use more input validation.

from BioLogic import MPRfile # local version; use galvani package if it's updated

def read_mpr(filename):
    """
    Function for reading the .mpr file from Biologic
    EC-lab software

    Parameters
    ----------
    filename: string
        Filename of .mpr file to extract impedance data from

    Returns
    -------
    frequencies : np.ndarray
        Array of frequencies
    impedance : np.ndarray of complex numbers
        Array of complex impedances
    """

    file = MPRfile(filename) # MPRfile class located in BioLogic.py from galvani package
    df = pd.DataFrame(file.data) # MPR file

    # Convert to numpy
    f = df['freq/Hz'].to_numpy()
    Z = df['Re(Z)/Ohm'].to_numpy() - 1j*df['-Im(Z)/Ohm'].to_numpy()

    # Convert from complex64 to complex
    Z = Z.astype(complex)

    return f, Z
petermattia commented 4 years ago

Sorry, didn't realize this is a duplicate issue -- I'll close this.