Home > Net >  function() missing 4 required positional arguments
function() missing 4 required positional arguments

Time:10-17

The problem shows in line 90.

I think the main problem is with the dataframe. So after calculating values from function I return a data frame. the function is used in a for loop to generate different lines such as this given below.

Representative plot: I have been trying a few clues but it is still not working

enter image description here

import math as m
import matplotlib.pyplot as plt
import pandas as pd

#tst=529
#temp=524
#dtube=0.41

def function(ConstantA,ConstantB,tst,temp,dtube):
# variables and constants
    k0 = 38.9
    e = 90000
    lambd=-328200
    dp=0.003;roecat= 1670; porosity=0.4; cpa=95.2; cpb=32; cpc= 102.81;cpc= 71; ma=28;mb=32;mc=44;md=16; viscosity=0.25e-4;tst=tst;
    dtube=dtube;ntube=25000; ltube= 9.8288; dw=1;wplot=0; yar=0;ybr=0;np=0;pi=3.1416; areacstube= pi * (dtube ** 2) / 4; wmaxtube=ltube * areacstube * roecat;wmax=wmaxtube * ntube;
    # Initial conditions
    w=0; fc=0; fa0=0.8125; fb0=0.26;fd0=2.175;fr=0;temp=temp; p=17; fain=fr * yar fa0; fbin=fr * ybr fb0;fdin=fd0;

    # Integration loop
    # Bring arrays outside so it would not get overwritten while inside the loop
    wp = []
    tempp = []
    pp = []
    yap = []
    ycp = []

    # np = 0    Remove, no need to track indices when appending in Python
    while w < wmax:
        fa=fain-fc; fb=fbin-fc; fd=fdin; ya=fa / (fa fb fc fd); yb=fb / (fa fb fc fd); yc=fc / (fa fb fc fd); yd=fd / (fa fb fc fd);
        k=k0*m.exp(-e / 8.314 / temp);rate=k*(ya*p)**0.5*(yb*p)**0.7;
        roegasmolar=p / (temp * 1.01325 * 82.057e-3); flowvoltube= (fa fb fc fd) / roegasmolar / ntube;
        maverage=ya * ma yb * mb yc * mc  yd * md; roegas=roegasmolar * maverage;
        vel=flowvoltube / areacstube; reynolds=dp * vel * roegas / viscosity;
        friction= (1-porosity) * (1.75 150 * (1-porosity) / reynolds) / (porosity ** 3);
        u= ConstantA   ConstantB * reynolds / dp
        #u=0.01545 0.6885e-6 * reynolds / dp;
        #u=0.6


   # Save for plotting
        if w >= wplot:
            # Just removed ';' and used newline so it looks cleaner
            wp.append(w/100)
            tempp.append(temp)
            pp.append(p)
            yap.append(ya*100)
            ycp.append(yc*100)
            wplot = wplot   10

        # Deriyative evaluation
        dfcdw = rate
        dpdw = friction * ltube * roegas * (vel ** 2) / (dp * wmax * 1e5)
        dtempdw = (- lambd * rate-4 * u * (temp-tst) / (roecat * dtube)) / (cpa * fa cpb * fb cpc * fc)

        # Integration
        fc = fc   dfcdw * dw
        temp = temp   dtempdw * dw
        p = p   dpdw * dw
        w = w   dw

        if p < 10:
            break
#df = pd.DataFrame(wp,tempp,ycp,yap,pp)
    print(type(pp))
    all = pd.DataFrame({'wp': wp,'tempp': tempp,'ycp': ycp,'yap': yap,'pp': pp,})
    return all

data = {
    'ConstantA': [0.01545, 0.6, 0.6, 0.6, 0.6],
    'ConstantB': [0.6885e-6, 0, 0, 0, 0],
    'tst': [523, 529, 531, 527, 533],
    'temp': [523, 524, 524, 524, 524],
    'dtube': [0.041, 0.041, 0.041, 0.041, 0.041]
}

df2 = pd.DataFrame(data)

fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)
fig.suptitle('Cooled;Tst=523')
ax1.set_ylabel('T(K)')
ax2.set_ylabel('y(C%)')
ax3.set_ylabel('yA ()')
ax3.set_xlabel('w (1000 ka)')
ax4.set_ylabel('E (bar)')
ax4.set_xlabel('w (1000 kg)')

# `for`-loop

for index, row in df2.iterrows():
    plot3 = function(row)

    ax1.plot(plot3['wp'], plot3['tempp'])
    ax2.plot(plot3['wp'], plot3['ycp'])
    ax3.plot(plot3['wp'], plot3['yap'])
    ax4.plot(plot3['wp'], plot3['pp'])

# after `for`-loop

plt.tight_layout()  # Automatic adjustment of pyplot so ylabels dont overlap
plt.subplots_adjust(top=0.9)  # Adjust plots to put space beween title and subplot
plt.show()





#for index, row in df2.iterrows():
#   plot3.apppend(plot(row['ConstantA'], row['ConstantB'],row['tst'], row['temp'],row['dtube']))

CodePudding user response:

You are calling function(row), which only includes one argument of the required 5 (which are ConstantA,ConstantB,tst,temp,dtube).

If you would like to unpack each item in the row so that if corresponds to each argument, you can do function(*row) instead.

  • Related