def __init__(self, Info={}, thissym='Not Set', thiscol='Not Set', thisshift=0.0, name='', LLname='', Auto=True): ## A infront of variable is for Ahmed file convention ## Initialising plotting parameters self.thisshift = thisshift self.thiscol = thiscol self.thissym = thissym # Opboot { it } bs self.alphaAvg = ODNested() self.alphaStd = ODNested() ## kappa up down (in integer form) if 'kud' in list(Info.keys()): self.kud = 'kud' + str(Info['kud']) else: self.kud = '' ## kappa strange (in integer form) if 'ks' in list(Info.keys()): self.ks = 'ks' + str(Info['ks']) else: self.ks = '' ## Current obersvables are TopCharge and Weinberg if 'Observable' in list(Info.keys()): self.Observ = Info['Observable'] else: self.Observ = 'TopCharge' ## default to TopCharge self.latparams = mp.LatticeParameters(Info=Info) self.latparams.LoadPickle() if self.Observ == 'TopCharge': self.thisconv = chitcoeff(self.latparams.nt, self.latparams.nxyz, self.latparams.latspace, 'QQ') else: self.thisconv = chitcoeff(self.latparams.nt, self.latparams.nxyz, self.latparams.latspace, 'WW') ## Ahmed only gave me a single flow time result, this will be changed when he gives me all flow times. if 'flowtime' in list(Info.keys()): self.flowtime = Info['flowtime'] else: self.flowtime = 't_f6.00' ## default to read all flow times self.kappafolder = 'Kud0' + self.kud.replace( 'kud', '') + 'Ks0' + self.ks.replace('ks', '') self.AObserv = self.Observ.lower().replace('weinberg', 'weinopp') self.Akud = self.kud.replace('kud', 'K')[:-2] self.Aflowtime = self.flowtime.replace('t_f', '').replace('.', '') self.Auto = Auto self.SetCustomName(name, LLname) thisdir = outputdir + '/AhmedResults/' if self.Auto: self.readdir = thisdir + 'ratio_' + self.AObserv + '_' + self.Akud + '_at_flow_time_' + self.Aflowtime + '/' else: self.readdir = thisdir + 'ratio_boot_' + self.AObserv + '_' + self.Akud + '_at_flow_time_' + self.Aflowtime + '/' self.thisfile = 'Tauint_at_flow_time_' + self.Aflowtime + 'time_value_dvalue.txt'
def SetMass(self, mass): self.mass = ODNested() if isinstance(mass, TwoPointCorr): if 'boot' not in mass.C2_Fit_Stats: raise IOError( 'C2_Fit_Stats in TwoPointCorr not calculated, please run Fit() on TwoPointCorr instance' ) for (istate, ip), fitdata in mass.C2_Fit_Stats['boot'].items(): if ip != 'p000': continue ifitr, this_data = fitdata.GetMaxFitr() self.mass['C2_' + '_'.join([istate, ifitr])] = this_data.iloc[ 0].fit_data['Params']['Energy'] elif isinstance(mass, Fitting): if 'Energy' not in list(mass.fit_data['Params'].keys()): print(list(mass.fit_data['Params'].keys())) raise IOError('Fitting class instance has no parameter Energy') self.mass['C2_' + mass.name] = mass.fit_data['Params']['Energy'] elif isinstance(mass, BootStrap): self.mass['C2_' + mass.name] = mass elif mass == 'Not Set': self.mass = 'Not Set' else: raise IOError( 'mass input type not recognisied (see FormFactors.py, SetMass())' )
list,vals = zip(*[[y,x] for y,x in sorted(zip(list,vals))]) list vals import numpy as np str.zfill() zfill(10) n=5 print(f'{n:03}') from MiscFuns import ODNested print('abc',end='') alpha = ODNested() alpha['one']['two'] = 5 alpha.values()[0].values()[0] from uncertainties import ufloat this_val = ufloat(0.0005,0.0025) print r'${:.1eSL}$'.format(this_val) print 'a\rightarrow'.replace('\rightarrow','RIGHTARROW') 1.0 == 1.0000000000000001 xvalssize = (5,5) xdata_1 = np.array([range(xvalssize[1]) for _ in range(xvalssize[0])]) xdata_2 = xdata_1.swapaxes(0,1).flatten() xdata_1 = xdata_1.flatten()
def __init__(self, Info={}, thissym='Not Set', thiscol='Not Set', thisshift=0.0, name='', LLname=''): ## A infront of variable is for Ahmed file convention ## Initialising plotting parameters self.thisshift = thisshift self.thiscol = thiscol self.thissym = thissym # Opboot { it } bs self.Chi2Avg = ODNested() self.Chi2Std = ODNested() ## kappa up down (in integer form) if 'kud' in list(Info.keys()): self.kud = 'kud' + str(Info['kud']) else: self.kud = '' ## kappa strange (in integer form) if 'ks' in list(Info.keys()): self.ks = 'ks' + str(Info['ks']) else: self.ks = '' ## Current obersvables are TopCharge and Weinberg if 'Observable' in list(Info.keys()): self.Observ = Info['Observable'] else: self.Observ = 'TopCharge' ## default to TopCharge self.latparams = mp.LatticeParameters(Info=Info) self.latparams.LoadPickle() if 'TopCharge' in self.Observ: self.thisconv = chitcoeff(self.latparams.nt, self.latparams.nxyz, self.latparams.latspace, 'QQ') else: self.thisconv = chitcoeff(self.latparams.nt, self.latparams.nxyz, self.latparams.latspace, 'WW') # ## this is used display only these flowtimes, Still reads and writes all # if 'tflowlist' in Info.keys(): self.tflowlist = Info['tflowlist'] # else: self.tflowlist = defxlimOp ## default to read all flow times # listout = [] # for ict,itflow in enumerate(self.tflowlist): # if 't_f' not in str(itflow): # listout.append(tflowstr(itflow)) # else: # listout.append(itflow) # self.tflowfloat = [untflowstr(itflow) for itflow in listout] # self.tflowlist = np.array(listout) self.kappafolder = 'Kud0' + self.kud.replace( 'kud', '') + 'Ks0' + self.ks.replace('ks', '') if 'topcharge' in self.Observ.lower().replace('weinberg', 'weinopp'): self.AObserv = 'topcharge' elif 'weinopp' in self.Observ.lower().replace('weinberg', 'weinopp'): self.AObserv = 'weinopp' self.Akud = self.kud.replace('kud', '')[:-2] self.SetCustomName(name, LLname) thisdir = outputdir + '/AhmedResults/' self.readdir = thisdir + self.AObserv + self.Akud + '/' self.thisfile = self.AObserv + self.Akud + '.txt'
def Write(self): def FixDictArray(thislist, ikey): outDict = OrderedDict() for ic, ilist in enumerate(thislist): outDict[ikey + str(ic + 1)] = ilist return outDict self.outDict = ODNested() self.outDict['Type'] = self.currtype self.outDict['FFparams'] = FixDictArray(self.ffpars, 'FF') self.outDict['tflowlist'] = FixDictArray(self.tflowlist, 'flow') ## TODO, output more information about momenta if you would like self.outDict['nt'] = self.nt self.outDict['nxyz'] = self.nxyz self.outDict['q2max'] = self.qparams.mom2max self.outDict['q2min'] = self.qparams.mom2min self.outDict['pp2max'] = self.ppparams.mom2max self.outDict['pp2min'] = self.ppparams.mom2min excel_params = pa.Series(deepcopy(self.outDict)) firstkey = list(self.mass.keys())[0] excel_params['massAvg_' + firstkey] = list(self.mass.values())[0].Avg excel_params['massStd_' + firstkey] = list(self.mass.values())[0].Std for icFF, iFF in excel_params['FFparams'].items(): excel_params[icFF] = iFF for ictflow, itflow in excel_params['tflowlist'].items(): excel_params[ictflow] = itflow del excel_params['FFparams'] del excel_params['tflowlist'] if self.doflow: for itflow in self.tflowlist: firstdata = list(self.alpha[itflow].values())[0] if isinstance(firstdata, BootStrap): excel_params['AlphaAvg_' + firstkey + '_' + itflow] = firstdata.Avg else: excel_params['AlphaAvg_' + firstkey + '_' + itflow] = firstdata for itflow in self.tflowlist: firstdata = list(self.alpha[itflow].values())[0] if isinstance(firstdata, BootStrap): excel_params['AlphaStd_' + firstkey + '_' + itflow] = firstdata.Std for ikey, massdata in self.mass.items(): if isinstance(massdata, BootStrap): self.outDict['mass'][ikey] = AvgStdToFormat( massdata.Avg, massdata.Std) else: self.outDict['mass'][ikey] = massdata if self.doflow: for itflow, alphatflow in self.alpha.items(): firstalpha = list(alphatflow.values())[0] alpha_key = list(alphatflow.keys())[0] if isinstance(firstalpha, BootStrap): self.outDict['alpha'][alpha_key][itflow] = AvgStdToFormat( firstalpha.Avg, firstalpha.Std) else: self.outDict['alpha'][alpha_key][itflow] = firstalpha if self.doflow: for (gammakey, ipp, iq, imass, itflow, ipar), paramdata in self.items(): thisqsqrd = self.qparams.Getpsqrdform(iq, pre='q') ## TODO, this is incorrectly order with respect to qsqrd, need to write function to fix this somewhere ## also, you can play around with the ordering of keys to get the formating you like !! # self.outDict[imass][ipp][itflow][self.qparams.Getpsqrdform(iq,pre='q')]['Coeff_of_'+ipar]['_'.join([gammakey,iq])] = AvgStdToFormat(paramdata.Avg,paramdata.Std) try: self.outDict['Equations'][imass][ipp][itflow][thisqsqrd][ '_'.join([gammakey, iq])] += ' (' + AvgStdToFormat( paramdata.Avg, paramdata.Std, dec=5, numlen=8) + ') ' + ipar + ' +' except Exception as err: self.outDict['Equations'][imass][ipp][itflow][thisqsqrd][ '_'.join([gammakey, iq])] = ' (' + AvgStdToFormat( paramdata.Avg, paramdata.Std, dec=5, numlen=8) + ') ' + ipar + ' +' if ipar == self.ffpars[-1]: self.outDict['Equations'][imass][ipp][itflow][thisqsqrd][ '_'.join([gammakey, iq])] = self.outDict['Equations'][ imass][ipp][itflow][thisqsqrd]['_'.join( [gammakey, iq])][:-1] else: for (gammakey, ipp, iq, imass, ipar), paramdata in self.items(): thisqsqrd = self.qparams.Getpsqrdform(iq, pre='q') ## TODO, this is incorrectly order with respect to qsqrd, need to write function to fix this somewhere ## also, you can play around with the ordering of keys to get the formating you like !! try: self.outDict['Equations'][imass][ipp][thisqsqrd]['_'.join( [gammakey, iq])] += ' (' + AvgStdToFormat( paramdata.Avg, paramdata.Std, dec=5, numlen=8) + ') ' + ipar + ' +' except Exception as err: self.outDict['Equations'][imass][ipp][thisqsqrd]['_'.join( [gammakey, iq])] = ' (' + AvgStdToFormat( paramdata.Avg, paramdata.Std, dec=5, numlen=8) + ') ' + ipar + ' +' if ipar == self.ffpars[-1]: self.outDict['Equations'][imass][ipp][thisqsqrd]['_'.join([ gammakey, iq ])] = self.outDict['Equations'][imass][ipp][thisqsqrd][ '_'.join([gammakey, iq])][:-1] if self.doflow: for (gammakey, ipp, iq, imass, itflow, ipar), paramdata in self.iteritemsRed(): thisqsqrd = self.qparams.Getpsqrdform(iq, pre='q') ## TODO, this is incorrectly order with respect to qsqrd, need to write function to fix this somewhere ## also, you can play around with the ordering of keys to get the formating you like !! # self.outDict[imass][ipp][itflow][self.qparams.Getpsqrdform(iq,pre='q')]['Coeff_of_'+ipar]['_'.join([gammakey,iq])] = AvgStdToFormat(paramdata.Avg,paramdata.Std) try: self.outDict['Equations_Reduced'][imass][ipp][itflow][ thisqsqrd]['_'.join( [gammakey, iq])] += ' (' + AvgStdToFormat( paramdata.Avg, paramdata.Std, dec=5, numlen=8) + ') ' + ipar + ' +' except Exception as err: self.outDict['Equations_Reduced'][imass][ipp][itflow][ thisqsqrd]['_'.join( [gammakey, iq])] = ' (' + AvgStdToFormat( paramdata.Avg, paramdata.Std, dec=5, numlen=8) + ') ' + ipar + ' +' if ipar == self.ffpars[-1]: self.outDict['Equations_Reduced'][imass][ipp][itflow][ thisqsqrd]['_'.join([ gammakey, iq ])] = self.outDict['Equations_Reduced'][imass][ipp][ itflow][thisqsqrd]['_'.join([gammakey, iq])][:-1] else: for (gammakey, ipp, iq, imass, ipar), paramdata in self.iteritemsRed(): thisqsqrd = self.qparams.Getpsqrdform(iq, pre='q') ## TODO, this is incorrectly order with respect to qsqrd, need to write function to fix this somewhere ## also, you can play around with the ordering of keys to get the formating you like !! try: self.outDict['Equations_Reduced'][imass][ipp][thisqsqrd][ '_'.join([gammakey, iq])] += ' (' + AvgStdToFormat( paramdata.Avg, paramdata.Std, dec=5, numlen=8) + ') ' + ipar + ' +' except Exception as err: self.outDict['Equations_Reduced'][imass][ipp][thisqsqrd][ '_'.join([gammakey, iq])] = ' (' + AvgStdToFormat( paramdata.Avg, paramdata.Std, dec=5, numlen=8) + ') ' + ipar + ' +' if ipar == self.ffpars[-1]: self.outDict['Equations_Reduced'][imass][ipp][thisqsqrd][ '_'.join([gammakey, iq])] = self.outDict['Equations_Reduced'][ imass][ipp][thisqsqrd]['_'.join( [gammakey, iq])][:-1] ## Write human readable file with data WriteXml(self.HumanFile, {'Results': self.outDict}) WriteExcel(self.ExcelFile, {'FF_results': deepcopy(self.param_Stats)}, params=excel_params) ## pickles rest of data for reading self.RemoveFuns() WritePickle(self.PickleFile, self.__dict__) self.GetFuns()
def SetAlpha(self, alpha, tflowlist): self.alpha = ODNested() self.tflowlist = tflowlist if isinstance(alpha, NNQFullCorr): # if self.kappafolder not in ['',alpha.kappafolder+'/']: # raise IOError('kappa folders used in FormFact (from FormFactors.py) have changed, check alpha and mass used.') # self.kappafolder = alpha.kappafolder + '/' # self.SetCustomName(string=self.name) if 'boot' not in alpha.NNQFull_Fit_Stats: raise IOError( 'No fits have been performed on the AlphaFull object passed to Form Factors' ) for itflow in tflowlist: if ('p000', itflow) not in alpha.NNQFull_Fit_Stats['boot'].index: print(alpha.NNQFull_Fit_Stats['boot']) raise IOError( 'No zero momentum found in NNQFull_Fit_Stats in TwoPointCorr, try running Fit()' ) ifitr, this_data = alpha.NNQFull_Fit_Stats.at[( 'p000', itflow), 'boot'].GetMaxFitr() ifitr = ifitr.replace('fittwor', 'tsumfitr') self.alpha[itflow][ 'alpha_' + ifitr] = this_data.iloc[0].fit_data['Params'].iloc[0] return elif isinstance(alpha, NNQCorr): # if self.kappafolder not in ['',alpha.kappafolder+'/']: # raise IOError('kappa folders used in FormFact (from FormFactors.py) have changed, check alpha and mass used.') # self.kappafolder = alpha.kappafolder + '/' # self.SetCustomName(string=self.name) if 'boot' not in alpha.NNQ_Fit_Stats: raise IOError( 'No fits have been performed on the Alpha object passed to Form Factors' ) for itflow in tflowlist: if ('p000', itflow) not in alpha.NNQ_Fit_Stats['boot'].index: print(alpha.NNQ_Fit_Stats['boot']) raise IOError( 'No zero momentum found in NNQ_Fit_Stats in TwoPointCorr, try running Fit()' ) ifitr, this_data = alpha.NNQ_Fit_Stats.at[('p000', itflow), 'boot'].GetMaxFitr() self.alpha[itflow][ 'alpha_' + ifitr] = this_data.iloc[0].fit_data['Params'].iloc[0] return try: firstflow = list(alpha.keys())[0] if isinstance(alpha[firstflow], Fitting): for itflow in tflowlist: if itflow not in list(alpha.keys()): raise IOError( 'No tflow found in alpha.keys(), alpha can be dictionary with tflows' ) if 'Energy' not in list(alpha.fit_data['Params'].keys()): print(list(alpha[itflow].fit_data['Params'].keys())) raise IOError( 'Fitting class instance has no parameter Energy') self.alpha[itflow][ 'alpha_' + alpha.name] = alpha.fit_data['Params'].iloc[0] elif isinstance(alpha[firstflow], BootStrap): for itflow in tflowlist: if itflow not in list(alpha.keys()): raise IOError( 'No tflow found in alpha.keys(), alpha can be dictionary with tflows' ) self.alpha[itflow]['alpha_' + alpha.name] = alpha except Exception as err: if alpha == 'No Alpha' or alpha == 'PreDef': self.alpha = 'Not Set' elif self.alpha != 'Not Set': print(type(alpha)) if isinstance(alpha, str): print(alpha) raise IOError( 'alpha input type not recognisied (see FormFactors.py, SetAlpha())' )