[docs]classHKPara(object):def__init__(self):self.rfpath=expanduser('~')self.hkpath=expanduser('~')self.hklist='hk.dat'self.hrange=np.arange(20,80,0.1)self.krange=np.arange(1.6,1.9,0.01)self.vp=6.3self.weight=(0.7,0.2,0.1)def__str__(self):head=['{}: {}'.format(k,v)fork,vinself.__dict__.items()]return'\n'.join(head)@propertydefhrange(self):returnself._hrange@hrange.setterdefhrange(self,value):ifnot(array_instance(value)orvalueisNone):raiseTypeError('Error type of hrange')else:self._hrange=value@propertydefkrange(self):returnself._krange@krange.setterdefkrange(self,value):ifnot(array_instance(value)orvalueisNone):raiseTypeError('Error type of krange')else:self._krange=value
[docs]defhkpara(cfg_file):hpara=HKPara()cf=configparser.ConfigParser()try:cf.read(cfg_file)exceptException:raiseFileNotFoundError('Cannot open configure file %s'%cfg_file)# para for FileIO sectionhpara.rfpath=check_path('rfpath',cf.get('FileIO','rfpath'))hpara.hkpath=cf.get('FileIO','hkpath')hpara.hklist=cf.get('FileIO','hklst')hmin=cf.getfloat('hk','hmin')hmax=cf.getfloat('hk','hmax')kmin=cf.getfloat('hk','kmin')kmax=cf.getfloat('hk','kmax')hpara.hrange=np.arange(hmin,hmax,0.1)hpara.krange=np.arange(kmin,kmax,0.01)vp=cf.get('hk','vp')ifvp!='':hpara.vp=float(vp)w1=cf.getfloat('hk','weight1')w2=cf.getfloat('hk','weight2')w3=cf.getfloat('hk','weight3')hpara.weight=(w1,w2,w3)returnhpara