python - Traceback error and script can't read csv - Stack Overflow

I am getting a traceback most recent call last from a iteraction between dakota and python. I need to g

I am getting a traceback most recent call last from a iteraction between dakota and python. I need to give a csv file for python and dakota read, but when i start running it shows the the error traceback most recent call last.

The code works as follows:

  • When Csv file is fed as input it is send to the code function
  • The function makes the calculation, then returns to dakota and start the iteraction, detail im using python 3.11 and scipy 1.9.3

Here is the code for calculation which is imported (its the only part of it the real code have 3500 lines)

def ED0_takeOff(t, S):
        x, v = S
        dxdt = v
        T = self.trac_Available(v, rho)
        if fancy_way:
             Re = (self.c*v)/1.60E-5 # visc. cinemática do ar a 30°C
                try:
                    cl_perfil, cd_perfil = interp_coef(self.df_perfil, self.ao, Re)
                    #Cl_asa = Cl_correcao(self.df_perfil, Re, self.ao)
                    Cl_asa = cl_perfil*0.82 #perdas da asa finita.
                    Cd_asa = cd_perfil + self.K*(Cl_asa**2)
                    Cd_airplane = Cd_asa + self.C_D0
                    D = self.drag_Force(v, Cd_airplane, rho, Ground_Effect)  
                    R = self.mi * (self.W - self.lift_Force(v, Cl_asa, rho))    
                except:
                    print('Provide the aerodynamic profile dataframe in the class constructor.. Ex: zb.Airplane(df_perfil=df)')
        else:
             D = self.drag_Force(v, self.C_D, rho, Ground_Effect)  # Testar CLmax e CLn or CLLO
             R = self.mi * (self.W - self.lift_Force(v, self.CLLO, rho))
            dvdt = (T - D - R) / (self.M)
            return [dxdt, dvdt]


It is in the source.py where the error happens in cmd.

    # Compute the responses using the Dakota-provided variable values.
results[0].function = obj_1(params["Cr"], params["Af"], params["b"], params["L"])
results[1].function = obj_2(params["Cr"], params["Af"], params["b"], params["L"])

results[2].function = con_1(params["Cr"], params["Af"], params["b"], params["L"])
results[3].function = con_2(params["Cr"], params["Af"], params["b"], params["L"])
results[4].function = manouver_point(params["Cr"], params["Af"], params["b"], params["L"])

Here is the error :


Provide the aerodynamic profile dataframe in the class constructor. Ex: zb.Airplane(df_perfil=df)
Traceback (most recent call last): 

File "directory\source.py", line 143, in 

results[3].function = con_2(params["Cr"], params["Af"], params["b"], params["L"])

File "directory\source.py", line 96, in con_2
    return Zb.takeOff_Distance_EDO(fancy_way=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "directory\zebraperformance.py", line 2360, in takeOff_Distance_EDO
    sol = solve_ivp(ED0_takeOff, t_span=(min(t), max(t)), y0=S_0, t_eval=t)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "directory\ivp.py", line 555, in solve_ivp
    solver = method(fun, t0, y0, tf, vectorized=vectorized, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "directory\rk.py", line 94, in __init__
    self.f = self.fun(self.t, self.y)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "directory\base.py", line 138, in fun
    return self.fun_single(t, y)
           ^^^^^^^^^^^^^^^^^^^^^
  File "directory\base.py", line 20, in fun_wrapped
    return np.asarray(fun(t, y), dtype=dtype)
                      ^^^^^^^^^
  File "directory\zebraperformance.py", line 2350, in ED0_takeOff
    dvdt = (T - D - R) / (self.M)
                ^
UnboundLocalError: cannot access local variable 'D' where it is not associated with a value

I am getting a traceback most recent call last from a iteraction between dakota and python. I need to give a csv file for python and dakota read, but when i start running it shows the the error traceback most recent call last.

The code works as follows:

  • When Csv file is fed as input it is send to the code function
  • The function makes the calculation, then returns to dakota and start the iteraction, detail im using python 3.11 and scipy 1.9.3

Here is the code for calculation which is imported (its the only part of it the real code have 3500 lines)

def ED0_takeOff(t, S):
        x, v = S
        dxdt = v
        T = self.trac_Available(v, rho)
        if fancy_way:
             Re = (self.c*v)/1.60E-5 # visc. cinemática do ar a 30°C
                try:
                    cl_perfil, cd_perfil = interp_coef(self.df_perfil, self.ao, Re)
                    #Cl_asa = Cl_correcao(self.df_perfil, Re, self.ao)
                    Cl_asa = cl_perfil*0.82 #perdas da asa finita.
                    Cd_asa = cd_perfil + self.K*(Cl_asa**2)
                    Cd_airplane = Cd_asa + self.C_D0
                    D = self.drag_Force(v, Cd_airplane, rho, Ground_Effect)  
                    R = self.mi * (self.W - self.lift_Force(v, Cl_asa, rho))    
                except:
                    print('Provide the aerodynamic profile dataframe in the class constructor.. Ex: zb.Airplane(df_perfil=df)')
        else:
             D = self.drag_Force(v, self.C_D, rho, Ground_Effect)  # Testar CLmax e CLn or CLLO
             R = self.mi * (self.W - self.lift_Force(v, self.CLLO, rho))
            dvdt = (T - D - R) / (self.M)
            return [dxdt, dvdt]


It is in the source.py where the error happens in cmd.

    # Compute the responses using the Dakota-provided variable values.
results[0].function = obj_1(params["Cr"], params["Af"], params["b"], params["L"])
results[1].function = obj_2(params["Cr"], params["Af"], params["b"], params["L"])

results[2].function = con_1(params["Cr"], params["Af"], params["b"], params["L"])
results[3].function = con_2(params["Cr"], params["Af"], params["b"], params["L"])
results[4].function = manouver_point(params["Cr"], params["Af"], params["b"], params["L"])

Here is the error :


Provide the aerodynamic profile dataframe in the class constructor. Ex: zb.Airplane(df_perfil=df)
Traceback (most recent call last): 

File "directory\source.py", line 143, in 

results[3].function = con_2(params["Cr"], params["Af"], params["b"], params["L"])

File "directory\source.py", line 96, in con_2
    return Zb.takeOff_Distance_EDO(fancy_way=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "directory\zebraperformance.py", line 2360, in takeOff_Distance_EDO
    sol = solve_ivp(ED0_takeOff, t_span=(min(t), max(t)), y0=S_0, t_eval=t)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "directory\ivp.py", line 555, in solve_ivp
    solver = method(fun, t0, y0, tf, vectorized=vectorized, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "directory\rk.py", line 94, in __init__
    self.f = self.fun(self.t, self.y)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "directory\base.py", line 138, in fun
    return self.fun_single(t, y)
           ^^^^^^^^^^^^^^^^^^^^^
  File "directory\base.py", line 20, in fun_wrapped
    return np.asarray(fun(t, y), dtype=dtype)
                      ^^^^^^^^^
  File "directory\zebraperformance.py", line 2350, in ED0_takeOff
    dvdt = (T - D - R) / (self.M)
                ^
UnboundLocalError: cannot access local variable 'D' where it is not associated with a value
Share Improve this question edited Mar 4 at 15:47 Erich Stuhr asked Mar 4 at 15:19 Erich StuhrErich Stuhr 135 bronze badges 7
  • detail i tried to change the format of the csv file using "0.0" and only 0.0 but no changes – Erich Stuhr Commented Mar 4 at 15:20
  • con_2 calls a function that depends on ED0_takeOff which then fails due to the missing dataframe. Add the DataFrame and check you didn't save it none somewhere – steve-ed Commented Mar 4 at 15:33
  • 1 can you reduce your code to a minimal fully runnable script and data that demonstrates the problem? – ysth Commented Mar 4 at 15:33
  • Can you also replace the Portuguese line above the error . Using Google translate it translates to "Provide the aerodynamic profile dataframe in the class constructor. Example: zb.Airplane(df_perfil=df)" – steve-ed Commented Mar 4 at 15:34
  • replaced, ill post the full error too – Erich Stuhr Commented Mar 4 at 15:45
 |  Show 2 more comments

1 Answer 1

Reset to default 0

You had variable D in else, but you can't reference D because it isn't created. For starters, your indentation isn't proper, python requires proper indentation to work. Both your D and R need to be set back one space. Should be reachable code.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745035828a4607511.html

相关推荐

  • python - Traceback error and script can't read csv - Stack Overflow

    I am getting a traceback most recent call last from a iteraction between dakota and python. I need to g

    11小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信