PyEIS icon indicating copy to clipboard operation
PyEIS copied to clipboard

AttributeError: 'Series' object has no attribute 'real' using EIS_plot method

Open swsyoon opened this issue 4 years ago • 6 comments

I was able to fit an experimental data using ex.EIS_fit(params=params, circuit='R-RQ-RQ',weight_func='modulus')

However when I tried to plot the data using ex2.EIS_plot(legend='potential', bode='log', fitting='on'), it generates the error.

  File "~\Miniconda3\envs\impedance\lib\site-packages\PyEIS\PyEIS.py", line 4701, in EIS_plot
    ax.plot(self.circuit_fit[i].real, -self.circuit_fit[i].imag, lw=0, marker='o', ms=8, mec='r', mew=1, mfc='none', label='')

  File "~\Miniconda3\envs\impedance\lib\site-packages\pandas\core\generic.py", line 5136, in __getattr__
    return object.__getattribute__(self, name)

AttributeError: 'Series' object has no attribute 'real'

I am using python 3.7.9 in windows 10.

swsyoon avatar Sep 15 '20 16:09 swsyoon

Having the same problem when I follow the anexed tutorial (Doing this on Python 3.9.2).

I guess it has to do that the column is named 're' instead of 'real'? Seems to me that is fitting correctly, but fails at the moment it tries to plot.

mfjimenezmoreno avatar Jun 16 '21 04:06 mfjimenezmoreno

It is same issue as an "Error using Lin_kk function"

I've fixed the this issue, but have no authority of "pull request" but I've tested attached code, works well.

Reason why issue happened is self.KK_circuit_fit[i].real and self.KK_circuit_fit[i].imag not aligned to array data format.

so it should be changed following (I'm in office so not possible to upload the screen shot and code)

       #changed by Gim
        length_of_kk_circuit_fit = len(self.KK_circuit_fit[i])
        KK_circuit_fit_real = []
        KK_circuit_fit_imag = []
        for idx in range(length_of_kk_circuit_fit):
            KK_circuit_fit_real.append(self.KK_circuit_fit[i][idx+length_of_kk_circuit_fit].real)
            KK_circuit_fit_imag.append(self.KK_circuit_fit[i][idx + length_of_kk_circuit_fit].imag)

        KK_circuit_fit_real = np.array(KK_circuit_fit_real)
        KK_circuit_fit_imag = np.array(KK_circuit_fit_imag)
        self.KK_rr_re.append(residual_real(re=self.df[i].re, fit_re=KK_circuit_fit_real, fit_im=-KK_circuit_fit_imag))#relative residuals for the real part
        self.KK_rr_im.append(residual_imag(im=self.df[i].im, fit_re=KK_circuit_fit_real, fit_im=-KK_circuit_fit_imag)) #relative residuals for the imag part
        # changed by Gim
        
        #original source code
        #self.KK_rr_re.append(residual_real(re=self.df[i].re, fit_re=self.KK_circuit_fit[i].real, fit_im=-self.KK_circuit_fit[i].imag)) #relative residuals for the real part
        #self.KK_rr_im.append(residual_imag(im=self.df[i].im, fit_re=self.KK_circuit_fit[i].real, fit_im=-self.KK_circuit_fit[i].imag)) #relative residuals for the imag part

gimdeokhwan avatar Aug 20 '21 02:08 gimdeokhwan

One solution is to change the 4701 entry from (original) ax.plot(self.circuit_fit[i].real, -self.circuit_fit[i].imag, lw=0, marker='o', ms=8, mec='r', mew=1, mfc='none', label='') to (my solution) ax.plot(self.circuit_fit[i].values.real, -self.circuit_fit[i].values.imag, lw=0, marker='o', ms=8, mec='r', mew=1, mfc='none', label='')

FabianPascher avatar Jan 24 '22 14:01 FabianPascher

One solution is to change the 4701 entry from (original) ax.plot(self.circuit_fit[i].real, -self.circuit_fit[i].imag, lw=0, marker='o', ms=8, mec='r', mew=1, mfc='none', label='') to (my solution) ax.plot(self.circuit_fit[i].values.real, -self.circuit_fit[i].values.imag, lw=0, marker='o', ms=8, mec='r', mew=1, mfc='none', label='')

@FabianPascher I want to apply your solution, I need to fit experimental data as well and I need to fix the same issue. Please reply if you are able to see my comment.

DouglasGuillen99 avatar Jun 10 '22 19:06 DouglasGuillen99

It is same issue as an "Error using Lin_kk function"

I've fixed the this issue, but have no authority of "pull request" but I've tested attached code, works well.

Reason why issue happened is self.KK_circuit_fit[i].real and self.KK_circuit_fit[i].imag not aligned to array data format.

so it should be changed following (I'm in office so not possible to upload the screen shot and code)

       #changed by Gim
        length_of_kk_circuit_fit = len(self.KK_circuit_fit[i])
        KK_circuit_fit_real = []
        KK_circuit_fit_imag = []
        for idx in range(length_of_kk_circuit_fit):
            KK_circuit_fit_real.append(self.KK_circuit_fit[i][idx+length_of_kk_circuit_fit].real)
            KK_circuit_fit_imag.append(self.KK_circuit_fit[i][idx + length_of_kk_circuit_fit].imag)

        KK_circuit_fit_real = np.array(KK_circuit_fit_real)
        KK_circuit_fit_imag = np.array(KK_circuit_fit_imag)
        self.KK_rr_re.append(residual_real(re=self.df[i].re, fit_re=KK_circuit_fit_real, fit_im=-KK_circuit_fit_imag))#relative residuals for the real part
        self.KK_rr_im.append(residual_imag(im=self.df[i].im, fit_re=KK_circuit_fit_real, fit_im=-KK_circuit_fit_imag)) #relative residuals for the imag part
        # changed by Gim
        
        #original source code
        #self.KK_rr_re.append(residual_real(re=self.df[i].re, fit_re=self.KK_circuit_fit[i].real, fit_im=-self.KK_circuit_fit[i].imag)) #relative residuals for the real part
        #self.KK_rr_im.append(residual_imag(im=self.df[i].im, fit_re=self.KK_circuit_fit[i].real, fit_im=-self.KK_circuit_fit[i].imag)) #relative residuals for the imag part

@gimdeokhwan I want to apply your solution, I need to fit experimental data as well and I need to fix the same issue. Please reply if you are able to see my comment.

DouglasGuillen99 avatar Jun 10 '22 19:06 DouglasGuillen99

One solution is to change the 4701 entry from (original) ax.plot(self.circuit_fit[i].real, -self.circuit_fit[i].imag, lw=0, marker='o', ms=8, mec='r', mew=1, mfc='none', label='') to (my solution) ax.plot(self.circuit_fit[i].values.real, -self.circuit_fit[i].values.imag, lw=0, marker='o', ms=8, mec='r', mew=1, mfc='none', label='')

@FabianPascher I've applied your solution and it worked. Note that one needs to change self.circuit_fit[i] to self.circuit_fit[i].values for all occurances in this file.

zleung9 avatar Mar 08 '23 19:03 zleung9