TypeError: init() missing 3 required positional arguments: 'z', 'EGeV', and 'tau'
我在运行一个名为ebltable的python模块的案例时,出现以上报错。
这里有ebltable模块完整的功能解释及案例。https://github.com/me-manu/ebltable/blob/master/examples/example.py
我就想完整的运行案例的python文件。
# Example script to calculate the gamma-ray attenuation
# given a certain EBL model and a source at a redshift z
# ------ Imports --------------- #
from ebltable.tau_from_model import OptDepth as OD
import numpy as np
import matplotlib.pyplot as plt
# ------------------------------ #
# initialize the optical depth class
# the model keyword specifies the EBL model to be used.
#Supported EBL models:
# Name: Publication:
# franceschini Franceschini et al. (2008) http://www.astro.unipd.it/background/
# kneiske Kneiske & Dole (2010)
# dominguez Dominguez et al. (2011)
# inuoe Inuoe et al. (2013) http://www.slac.stanford.edu/~yinoue/Download.html
# gilmore Gilmore et al. (2012) (fiducial model)
# Note: make sure that you have set the environment variable EBL_FILE_PATH
# by e.g.
# export EBL_FILE_PATH=/path/to/repro/ebl/ebl_model_files
tau = OD(model = 'franceschini')
# Source redshift
z = 0.2
# array with energies in TeV
ETeV = np.logspace(-1,1,50)
# calculating the optical depth for a redshift z and TeV energies
# this returns a two dimensional array with dimensions
# of the redshift array times dimensions of the energy array.
# Since z is a scalar here, it will return a 1 x 50 dim array.
t = tau.opt_depth_array(z,ETeV)
# calculate the energy in TeV for which we reach an optical depth of 1:
tauLim = 1.
ETeV_tEq1 = 10.**tau.opt_depth_Inverse(z,tauLim) / 1e3
# note that this function call only supports scalar input
# PLOT THE RESULT
# plot the expected attenuation
ax = plt.subplot(111)
plt.loglog(ETeV, np.exp(-1. * t[0]), lw = 2., ls = '-', label = '$z = {0:.2f}$'.format(z))
plt.axvline(ETeV_tEq1, ls = '--', label = r'$\tau = {0:.2f}$'.format(tauLim))
plt.xlabel('Energy (TeV)')
plt.ylabel('Attenuation')
plt.legend(loc = 3)
plt.show()
Traceback (most recent call last):
File "C:\Users\89554\Desktop\EBl.py", line 23, in
tau = OD(model = 'franceschini')
TypeError: init() missing 3 required positional arguments: 'z', 'EGeV', and 'tau'
在查询大多数相同的报错后,发现最多的就是说继承类错误,没有传参。但我在查看调用的源文件的时候,是正确传参了的。
再有我以为是我的环境变量没有改对,结果换了两个系统改了两次都是,还是这个报错。
😭
完整的运行ebltable的python案例代码。
这里有ebltable模块完整的功能解释及案例。https://github.com/me-manu/ebltable/blob/master/examples/example.py
我就想完整的运行案例的python文件。
比心😭
在23行,
tau = OD(model = 'franceschini')
去看这个OD源代码的init方法,看看有哪些必须要传的参数,你就给他传进去,案例有可能是错的,自己试试看
比如
tau = OD(model = 'franceschini', z="", EGeV="", tau=""),然后看看还报什么错,先把这个必传的报错解决了,再看一下其他的错误