首页 > 解决方案 > AttributeError:“钻孔”对象没有属性“深度”

问题描述

问题是:

%cd e:\IceChrono import sys sys.argv=['IceChrono.py','AICC2012-VLR'] exec(open('IceChrono.py').read()) e:\IceChrono Parameters directory is:  AICC2012-VLR/ Initialization of drilling EDC Traceback (most recent call last):
  File "<ipython-input-32-7479f156abda>", line 4, in <module>
    exec(open('IceChrono.py').read())
  File "<string>", line 92, in <module>
  File "<string>", line 64, in init
AttributeError: 'Drilling' object has no attribute 'depth'

问题的部分代码是:

def gaussian(x):
    return np.exp(-x**2/2)

class Drilling:

    def __init__(self, dlabel,):
        self.label=dlabel

    def init(self):

#        print 'Initialization of drilling '+self.label

        self.accu_prior_rep='staircase'

        #execfile(datadir+'/parameters-AllDrillings.py')
        exec(open(datadir+'/parameters-AllDrillings.py').read())
        #execfile(datadir+self.label+'/parameters.py')
        exec(open(datadir+'/parameters-AllDrillings.py').read())

        self.depth_mid=(self.depth[1:]+self.depth[:-1])/2
        self.depth_inter=(self.depth[1:]-self.depth[:-1])

## We set up the raw model

        if self.calc_a:
            readarray=np.loadtxt(datadir+self.label+'/isotopes.txt')
            if (np.size(readarray)==np.shape(readarray)[0]): readarray.resize(1, np.size(readarray))
            self.iso_depth=readarray[:,0]
            if self.calc_a_method=='fullcorr':
                self.iso_d18Oice=readarray[:,1]
                self.d18Oice=interp.stair_aver(self.depth, self.iso_depth, self.iso_d18Oice)
                self.iso_deutice=readarray[:,2]
                self.deutice=interp_stair_aver(self.depth, self.iso_depth, self.iso_deutice)
                self.iso_d18Osw=readarray[:,3]
                self.d18Osw=interp.stair_aver(self.depth, self.iso_depth, self.iso_d18Osw)
                self.excess=self.deutice-8*self.d18Oice   # dans Uemura : d=excess
                self.a=np.empty_like(self.deutice)
                self.d18Oice_corr=self.d18Oice-self.d18Osw*(1+self.d18Oice/1000)/(1+self.d18Osw/1000)   #Uemura (1)
                self.deutice_corr=self.deutice-8*self.d18Osw*(1+self.deutice/1000)/(1+8*self.d18Osw/1000)   #Uemura et al. (CP, 2012) (2) 
                self.excess_corr=self.deutice_corr-8*self.d18Oice_corr
                self.deutice_fullcorr=self.deutice_corr+self.gamma_source/self.beta_source*self.excess_corr
            elif self.calc_a_method=='deut':
                self.iso_deutice=readarray[:,1]
                self.deutice_fullcorr=interp_stair_aver(self.depth, self.iso_depth, self.iso_deutice)
            elif selc.calc_a_method=='d18O':
                self.d18Oice=readarray[:,1]
                self.deutice_fullcorr=8*interp_stair_aver(self.depth, self.iso_depth, self.iso_d18Oice)
            else:
                print ('Accumulation method not recognized')
                quit()
        else:
            readarray=np.loadtxt(datadir+self.label+'/accu-prior.txt')
            if (np.size(readarray)==np.shape(readarray)[0]): readarray.resize(1, np.size(readarray))
            self.a_depth=readarray[:,0]
            self.a_a=readarray[:,1]
            if readarray.shape[1]>=3:
                self.a_sigma=readarray[:,2]
            if self.accu_prior_rep=='staircase':
                self.a_model=interp_stair_aver(self.depth, self.a_depth, self.a_a)
            elif self.accu_prior_rep=='linear':
                self.a_model=interp_lin_aver(self.depth, self.a_depth, self.a_a)
            else:
                print ('Representation of prior accu scenario not recognized')
            self.a=self.a_model

该程序的链接是:这里

我正在运行一个程序,但遇到了错误。我进行了以下修改,但仍然出现错误。

  1. IceChrono.py程序和IceChronoClasses.py程序中的第25、90、104、112、114、117、120、123、125、128、131、133、135、137、139、151、163行后面的内容第91、105、180、199、204、205、526、527行的print要加(),代表输出字符串格式
  2. 程序中的第 19 行IceChrono.py替换start_time = time.clock ()time.perf_counterortime.process_time
  3. 使用程序中的第35和45行以及IceChrono.py程序中的第59和60行IceChronoClasses.py替换execfile (filename)为exec(open (filename) .read ())

标签: pythonanaconda

解决方案


似乎您尚未self.depth在班级的任何地方初始化(分配给)该属性。


推荐阅读