0

I am trying to calculate cpmx, hmx, smpx, tmpx and smvx by doing simple interpolation after loading the data from excel into pandas dataframe.

While calling the function with cpmx=absmatdata(1,0,0,0,44.011,100) I see:

'numpy.ndarray' object is not callable

Any idea how to go about this?

Here is my code:

import numpy as np
import pandas as pd

def absmatdata(a,b,c,d,material,tmp_ref):
    material_map = {2.016: 'H2', 28.016: 'N2', 32.000: 'O2', 32.065: 'S',
                18.016: 'H2O', 64.065: 'SO2', 12.001: 'C Graphite', 
                28.011: 'CO', 44.011: 'CO2', 16.043: 'CH4', 30.070: 'C2H6',
                44.097: 'C3H8', 58.124: 'C4H10'}
    if material in material_map:
        df = pd.read_excel('F:\MAschinenbau\Bachelorarbeit\ABSMAT.xlsx',sheet_name=material_map[material])        
    else:
        print('No data for this material available')    
        df = [list(np.arange(0,1100,100)),list(np.arange(0,11,1)),list(np.arange(0,11,1)),list(np.arange(0,11,1)),list(np.arange(0,11,1))]
    tmp = df.values[:,0]
    cpm = df.values[:,1]
    hm = df.values[:,2]
    smp = df.values[:,3]
    smv = df.values[:,4]
    tn = np.size(df)
    tmp0 = tmp_ref
    tmpx = a
    cpmx = 0
    hmx = b
    smpx = c
    smvx = d
    if a==0 and b==0 and c==0 and d==0:
        print('All values are zero')
    elif a!=0 and b==0 and c==0 and d==0:
        print('T interpolation')
        for i in range(0,tn-1):
            if tmpx > tmp(i) and tmpx <= tmp(i+1):
                int_fak = (tmpx-tmp(i))/(tmp(i+1)-tmp(i))
                cpmx = cpm(i) + int_fak*(cpm(i+1)-cpm(i))
                hmx = hm(i) + int_fak*(hm(i+1)-hm(i))
                smpx = smp(i) + int_fak*(smp(i+1)-smp(i))
                smvx = smv(i) + int_fak*(smv(i+1)-smv(i))
    return tmpx, cpmx, hmx, smpx, smvx
9
  • If you have a stacktrace, then include it in your question Commented Nov 6, 2018 at 10:07
  • Which line rise the error? Can you provide F:\MAschinenbau\Bachelorarbeit\ABSMAT.xlsx ? Or atleast error message? Commented Nov 6, 2018 at 10:13
  • Maybe you re-use the name "absmatdata" ? Commented Nov 6, 2018 at 10:15
  • 1
    The error message is correctly describing the problem. You write expressions like tmp(i) which makes python believe you want to call a function tmp (which is a numpy array) with argument i. Since numpy arrays are not supposed to be called as a function the error occures. You have to use square brackets for indexing []. this is Python, not MATLAB Commented Nov 6, 2018 at 10:16
  • Thanks, I am trying to edit my question to add stacktrace Commented Nov 6, 2018 at 10:17

1 Answer 1

1
  • You set df to DataFrame

  • You set tmp = df.values[:,0]

  • You have numpy.ndarry at tmp

  • You have to get its items with [] not with ()

Your loop part

 if tmpx > tmp(i) and tmpx <= tmp(i+1):
                 int_fak = (tmpx-tmp(i))/(tmp(i+1)-tmp(i))
                 cpmx = cpm(i) + int_fak*(cpm(i+1)-cpm(i))
                 hmx = hm(i) + int_fak*(hm(i+1)-hm(i))
                 smpx = smp(i) + int_fak*(smp(i+1)-smp(i))
                 smvx = smv(i) + int_fak*(smv(i+1)-smv(i))

Should change with

if tmpx > tmp[i] and tmpx <= tmp[i+1]:
                int_fak = (tmpx-tmp[i])/(tmp[i+1]-tmp[i])
                cpmx = cpm[i] + int_fak*(cpm[i+1]-cpm[i])
                hmx = hm[i] + int_fak*(hm[i+1]-hm(i))
                smpx = smp[i] + int_fak*(smp[i+1]-smp[i])
                smvx = smv[i] + int_fak*(smv[i+1]-smv[i])

Also you need to change your tn to

tn = np.size(df.values[:,0])
Sign up to request clarification or add additional context in comments.

7 Comments

Thank you @Ihsan Cemil Cicek, I changes the round brackets to square brackets.The error has now gone. But now I have a new error "index 38 is out of bounds for axis 0 with size 38" in the line "if tmpx > tmp[i] and tmpx <= tmp[i+1]:". Does it has anything to do with number of rows ? the excel file has 38 rows and 5 columns, it is an 38x5 array
index 38 is [37] actually you should start with [0] index.
which line you mean [0] ?
I could not able to find solution can you provide excel file?
Dropbox, Drive or something like that.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.