我该如何解决如何解决AttributeError:'dict'对象没有属性'nemitx'错误和Keyerror?
AttributeError: 'dict' object has no attribute 'nemitx' error and Keyerror?
class TwissGaussBeam(GaussBeam):
'''__init__(self, twiss, N=1000, pos=np.array([0, 0, 0, 0, 0, 1]),
Q=1e-9, chargesign=-1, restmass=ele_mass)
Create a multi-particle beam with a Gaussian spread in each of the
6 dimensions. The statistics of the beam distribution are calculated
from the Twiss parameters in twiss.'''
def __init__(self, twiss, N=100000, pos=np.array([0, 0, 0, 0, 0, 1]),
Q=1e-12, chargesign=-1, restmass=ele_mass):
P = pos[5]
gammasquared = ((P*1e6)**2 + restmass**2)/restmass**2
betagamma = np.sqrt(gammasquared - 1)
sig = np.zeros(6)
sig[0] = np.sqrt((twiss.nemitx/betagamma) * twiss.betax)
sig[1] = np.sqrt((twiss.nemitx/betagamma)/twiss.betax)
sig[2] = np.sqrt((twiss.nemity/betagamma) * twiss.betay)
sig[3] = np.sqrt((twiss.nemity/betagamma)/twiss.betay)
sig[4] = twiss.sigz
sig[5] = twiss.sigP
错误信息是由于Python不认为特维斯对象具有nemitx成员。解决方案是解决这个问题。我真的把时间花在了谷歌的“twiss”和“twiss multi particle beam”上面,因为你没有告诉我们任何关于这个被传入的小东西的东西,它几乎不可能帮助你。请阅读[问],并给我们足够的信息,如[mcve],以便我们可以帮助您。 –
对不起,我没有提供足够的信息。下次我会考虑你的观点并感谢你的时间 – Lauren
欢迎您在问题中加入必要的信息,所以问题和答案预计会反复改进,没有人会写出完美的第一个问题,如果您确实发现Michael的答案是有用的,请立即投票或接受它。 –