Esempio n. 1
0
        def getDataHDF5():
            print('\nWill read data from HDF5')

            inputHDF5 = self.dataInfo['Input Data']['HDF5 File']
            h5_file = h5py.File(inputHDF5, 'r')

            for mom in self.moms:
                mTag = tags.momString(mom)
                mh5Tag = tags.momH5(mom)
                t0List = self.dSetAttr[mTag]['t0']
                tsepList = self.dSetAttr[mTag]['tsep']
                dispList = self.dSetAttr[mTag]['disp']
                Nrows = self.dSetAttr[mTag]['Nrows']

                for ri in self.RI:
                    self.plainData[ri][mTag] = {}

                    for z3 in dispList:
                        dispTag = tags.disp(z3)
                        for tsep in tsepList:
                            tsepTag = tags.tsep(tsep)
                            for t0 in t0List:
                                t0Tag = tags.t0(t0)
                                for iop, opPair in enumerate(
                                        self.dSetAttr[mTag]['intOpList']):
                                    opTag = tags.src_snk(opPair)
                                    for row in range(1, Nrows + 1):
                                        rowTag = tags.row(row)
                                        for gamma in self.gammaList:
                                            insTag = tags.insertion(gamma)

                                            dkey = (tsep, t0, z3, iop, row,
                                                    gamma)

                                            dset = 'plain/%s/%s/%s/%s/%s/%s/%s/%s/data' % (
                                                mh5Tag, dispTag, tsepTag,
                                                t0Tag, opTag, rowTag, insTag,
                                                ri)
                                            self.plainData[ri][mTag][
                                                dkey] = np.array(h5_file[dset])

                print('Reading three-point data for momentum %s completed.' %
                      (mTag))
Esempio n. 2
0
        def dumpHDF5(fitSeq,h5_file):
            fType = fitSeq['Type']
            fLabel = fitSeq['Label']

            for mom in self.momAvg:
                mTag = tags.momString(mom)
                mh5Tag = tags.momH5(mom)
                tsepList = self.dSetAttr3pt[mTag]['tsep']
                dispListAvg = self.dispAvg[mTag]
                
                for z3 in dispListAvg:
                    dispTag = tags.disp(z3)
                    for gamma in self.gammaList:
                        insTag = tags.insertion(gamma)
                        for tsep in tsepList:
                            dkey = (tsep,z3,gamma)
                            tsepTag = tags.tsep(tsep)
                            fAttr = self.fitAttr[mTag][tsep]

                            for ri in self.RI:
                                # Write optimalFitValues
                                group = '%s/%s/%s/%s/%s'%(ri,mh5Tag,dispTag,insTag,tsepTag)
                                dset_name = 'OptimalFitRanges/' + group
                                h5_file.create_dataset(dset_name, data = np.array([self.optimalFit[fLabel][ri][mTag][dkey]]))

                                for nf in range(fAttr['Nfits']):
                                    tstart = fAttr['nf=%d'%(nf)]['tstart']
                                    tstop  = fAttr['nf=%d'%(nf)]['tstop']
                                    h5LabelNf = 'nf%d_%d-%d'%(nf,tstart,tstop)

                                    group = '%s/%s/%s/%s/%s/%s'%(ri,mh5Tag,dispTag,insTag,tsepTag,h5LabelNf)
                                    dset_name_Mbins = 'MatElem/bins/' + group 
                                    dset_name_Mmean = 'MatElem/mean/' + group 
                                    dset_name_chiBins = 'chiSquare/bins/' + group 
                                    dset_name_chiMean = 'chiSquare/mean/' + group 

                                    h5_file.create_dataset(dset_name_Mbins, data = self.Mbins[fLabel][ri][mTag][dkey][nf])
                                    h5_file.create_dataset(dset_name_Mmean, data = self.Mmean[fLabel][ri][mTag][dkey][nf],dtype='f')
                                    h5_file.create_dataset(dset_name_chiBins, data = self.chiBins[fLabel][ri][mTag][dkey][nf])
                                    h5_file.create_dataset(dset_name_chiMean, data = self.chiMean[fLabel][ri][mTag][dkey][nf],dtype='f')
            # End for momentum
            print('Plateau fitting data for type = %s, label = %s written in HDF5.'%(fType,fLabel))
Esempio n. 3
0
    def writeHDF5(self):
        h5_file = h5py.File(self.dataInfo['HDF5 Output File'], 'w')

        for mom in self.momAvg:
            mTag = tags.momString(mom)
            mh5Tag = tags.momH5(mom)

            tsepList = self.dSetAttr3pt[mTag]['tsep']
            tsepList_rs = self.dSetAttr3pt[mTag]['tsep'][:-1]
            dispListAvg = self.dispAvg[mTag]
            Ntsep = len(tsepList)
            Ntsep_rs = len(tsepList_rs)

            for z3 in dispListAvg:
                dispTag = tags.disp(z3)
                for gamma in self.gammaList:
                    insTag = tags.insertion(gamma)
                    for ri in self.RI:

                        sumRatioH5 = (np.zeros(Ntsep), np.zeros(Ntsep),
                                      np.zeros(Ntsep))
                        for its, tsep in enumerate(tsepList):
                            dkey = (tsep, z3, gamma)
                            tsepTag = tags.tsep(tsep)

                            # Write the plain ratio bins and mean
                            rType = 'plain'
                            group = '%s/%s/%s/%s/%s/%s' % (
                                rType, mh5Tag, tsepTag, dispTag, insTag, ri)
                            dset_name_bins = 'bins/' + group
                            dset_name_mean = 'mean/' + group

                            h5_file.create_dataset(
                                dset_name_bins,
                                data=self.bins[rType][ri][mTag][dkey])
                            h5_file.create_dataset(
                                dset_name_mean,
                                data=self.mean[rType][ri][mTag][dkey],
                                dtype='f')
                            #---------------------------------------------------------------

                            # Write the summed ratio bins
                            rType = 'sum'
                            group = '%s/%s/%s/%s/%s/%s' % (
                                rType, mh5Tag, tsepTag, dispTag, insTag, ri)
                            dset_name_bins = 'bins/' + group
                            h5_file.create_dataset(
                                dset_name_bins,
                                data=self.bins[rType][ri][mTag][dkey])

                            # Convert the summed ratio mean into arrays that depend on tsep
                            sumRatioH5[0][its] = tsep  # tsep (x)
                            sumRatioH5[1][its] = self.mean[rType][ri][mTag][
                                dkey][0]  # ratio mean  (y)
                            sumRatioH5[2][its] = self.mean[rType][ri][mTag][
                                dkey][1]  # ratio error (y-error)
                        # End for tsep

                        # Write the summed ratio means
                        rType = 'sum'
                        group = '%s/%s/%s/%s/%s' % (rType, mh5Tag, dispTag,
                                                    insTag, ri)
                        dset_name_mean = 'mean/' + group
                        h5_file.create_dataset(dset_name_mean,
                                               data=sumRatioH5,
                                               dtype='f')
                        #-----------------------------

                        # Reduced-summed ratio
                        rSumRatioH5 = (np.zeros(Ntsep_rs), np.zeros(Ntsep_rs),
                                       np.zeros(Ntsep_rs))
                        for its, tsep in enumerate(tsepList_rs):
                            dkey = (tsep, z3, gamma)
                            tsepTag = tags.tsep(tsep)

                            # Write the summed ratio bins
                            rType = 'r-sum'
                            group = '%s/%s/%s/%s/%s/%s' % (
                                rType, mh5Tag, tsepTag, dispTag, insTag, ri)
                            dset_name_bins = 'bins/' + group
                            h5_file.create_dataset(
                                dset_name_bins,
                                data=self.bins[rType][ri][mTag][dkey])

                            # Convert the reduced-summed ratio mean into arrays that depend on tsep
                            rSumRatioH5[0][its] = tsep  # tsep (x)
                            rSumRatioH5[1][its] = self.mean[rType][ri][mTag][
                                dkey][0]  # ratio mean  (y)
                            rSumRatioH5[2][its] = self.mean[rType][ri][mTag][
                                dkey][1]  # ratio error (y-error)
                        # End for tsep

                        # Write the reduced-summed ratio means
                        rType = 'r-sum'
                        group = '%s/%s/%s/%s/%s' % (rType, mh5Tag, dispTag,
                                                    insTag, ri)
                        dset_name_mean = 'mean/' + group
                        h5_file.create_dataset(dset_name_mean,
                                               data=rSumRatioH5,
                                               dtype='f')
                    #-----------------------------
        # End for momentum

        h5_file.close()
        print('Ratio data written in HDF5.')
Esempio n. 4
0
    def writeHDF5(self):
        h5_file = h5py.File(self.dataInfo['HDF5 Output File'], 'w')

        # Write the Pz- and z3-averaged data
        for mom in self.momAvg:
            mTag = tags.momString(mom)
            mh5Tag = tags.momH5(mom)

            tsepList = self.dSetAttr[mTag]['tsep']
            dispListAvg = self.dispAvg[mTag]

            for z3 in dispListAvg:
                dispTag = tags.disp(z3)
                for tsep in tsepList:
                    tsepTag = tags.tsep(tsep)
                    for gamma in self.gammaList:
                        insTag = tags.insertion(gamma)
                        dkeyAvg = (tsep, z3, gamma)

                        # Write the averaged data
                        for ri in self.RI:
                            avg_group = 'fullavg/%s/%s/%s/%s/%s' % (
                                mh5Tag, dispTag, tsepTag, insTag, ri)
                            dset_name_data = avg_group + '/data'
                            dset_name_bins = avg_group + '/bins'
                            dset_name_mean = avg_group + '/mean'
                            h5_file.create_dataset(
                                dset_name_data,
                                data=self.data[ri][mTag][dkeyAvg])
                            h5_file.create_dataset(
                                dset_name_bins,
                                data=self.bins[ri][mTag][dkeyAvg])
                            h5_file.create_dataset(
                                dset_name_mean,
                                data=self.mean[ri][mTag][dkeyAvg],
                                dtype='f')
        #--------------------------------------

        for mom in self.moms:
            mTag = tags.momString(mom)
            mh5Tag = tags.momH5(mom)
            t0List = self.dSetAttr[mTag]['t0']
            tsepList = self.dSetAttr[mTag]['tsep']
            dispList = self.dSetAttr[mTag]['disp']
            Nrows = self.dSetAttr[mTag]['Nrows']

            for z3 in dispList:
                dispTag = tags.disp(z3)
                for tsep in tsepList:
                    tsepTag = tags.tsep(tsep)
                    for gamma in self.gammaList:
                        insTag = tags.insertion(gamma)
                        dkeyAvg = (tsep, z3, gamma)

                        # Write Avg data
                        for ri in self.RI:
                            avg_group = 'avg/%s/%s/%s/%s/%s' % (
                                mh5Tag, dispTag, tsepTag, insTag, ri)
                            dset_name_avgData = avg_group + '/data'
                            dset_name_avgBins = avg_group + '/bins'
                            dset_name_avgMean = avg_group + '/mean'

                            h5_file.create_dataset(
                                dset_name_avgData,
                                data=self.avgData[ri][mTag][dkeyAvg])
                            h5_file.create_dataset(
                                dset_name_avgBins,
                                data=self.avgBins[ri][mTag][dkeyAvg])
                            h5_file.create_dataset(
                                dset_name_avgMean,
                                data=self.avgMean[ri][mTag][dkeyAvg],
                                dtype='f')

                        for t0 in t0List:
                            t0Tag = tags.t0(t0)
                            for iop, opPair in enumerate(
                                    self.dSetAttr[mTag]['intOpList']):
                                opTag = tags.src_snk(opPair)
                                for row in range(1, Nrows + 1):
                                    rowTag = tags.row(row)
                                    dkey = (tsep, t0, z3, iop, row, gamma)

                                    # Write the plain data
                                    for ri in self.RI:
                                        plain_group = 'plain/%s/%s/%s/%s/%s/%s/%s/%s' % (
                                            mh5Tag, dispTag, tsepTag, insTag,
                                            t0Tag, opTag, rowTag, ri)
                                        dset_name_plainData = plain_group + '/data'
                                        dset_name_plainBins = plain_group + '/bins'
                                        dset_name_plainMean = plain_group + '/mean'

                                        h5_file.create_dataset(
                                            dset_name_plainData,
                                            data=self.plainData[ri][mTag]
                                            [dkey])
                                        h5_file.create_dataset(
                                            dset_name_plainBins,
                                            data=self.plainBins[ri][mTag]
                                            [dkey])
                                        h5_file.create_dataset(
                                            dset_name_plainMean,
                                            data=self.plainMean[ri][mTag]
                                            [dkey],
                                            dtype='f')
        #--------------------------------------

        h5_file.close()
        print('Three-point function data written in HDF5.')
Esempio n. 5
0
        def getDataASCII():
            print('\nWill read data from ASCII files')

            mainDir = self.dataInfo['Input Data']['Main Directory']

            for mom in self.moms:
                mTag = tags.momString(mom)
                mFTag = tags.momFile(mom)
                t0List = self.dSetAttr[mTag]['t0']
                tsepList = self.dSetAttr[mTag]['tsep']
                dispList = self.dSetAttr[mTag]['disp']
                Nrows = self.dSetAttr[mTag]['Nrows']
                Ncfg = self.dSetAttr[mTag]['Ncfg']
                phaseInfo = self.dSetAttr[mTag]['Phase Info']

                # Determine phase tag based on momentum sign
                if list(phaseInfo.keys())[0] == 'unphased':
                    phFile = phaseInfo['unphased']
                    phDir = 'unphased'
                elif list(phaseInfo.keys())[0] == 'phased':
                    phFile = phaseInfo['phased']['Plus'] if mom[
                        2] >= 0 else phaseInfo['phased']['Minus']
                    phDir = 'phased/' + phFile
                else:
                    raise ValueError(
                        'Supported Phase Tag keys are ["unphased","phased"]')

                for ri in self.RI:
                    self.plainData[ri][mTag] = {}

                for tsep in tsepList:
                    Nt = tsep
                    tsepTag = tags.tsep(tsep)
                    for t0 in t0List:
                        t0Tag = tags.t0(t0)
                        fileDir = ioForm.getThreePointDirASCII(
                            mainDir, phDir, t0Tag, tsepTag, mFTag)
                        print(
                            'Reading three-point data for momentum %s, tsep = %d, t0 = %d'
                            % (mTag, tsep, t0))
                        for z3 in dispList:
                            dispTag = tags.disp(z3)
                            for iop, opPair in enumerate(
                                    self.dSetAttr[mTag]['intOpList']):
                                srcOp, snkOp = opPair
                                for row in range(1, Nrows + 1):

                                    for gamma in self.gammaList:
                                        dkey = (tsep, t0, z3, iop, row, gamma)

                                        # Determine gamma matrix name and row
                                        insOp, insRow = gmat.insertionMap(
                                            gamma)

                                        fileName = ioForm.getThreePointFileNameASCII(
                                            phFile, t0Tag, tsepTag, srcOp,
                                            snkOp, row, insOp, insRow, mFTag,
                                            dispTag, self.Nvec)
                                        fileRead = '%s/%s' % (fileDir,
                                                              fileName)

                                        rawData = np.zeros((Ncfg, Nt),
                                                           dtype=np.complex128)
                                        with open(fileRead) as fp:
                                            line = fp.readlines()
                                            c = 0
                                            for n in line:
                                                it = c % Nt
                                                icfg = c // Nt
                                                rawData[icfg, it] = complex(
                                                    np.float128(n.split()[1]),
                                                    np.float128(n.split()[2]))
                                                c += 1
                                        # Done reading file

                                        self.plainData['Re'][mTag][
                                            dkey] = rawData.real
                                        self.plainData['Im'][mTag][
                                            dkey] = rawData.imag

                print('Reading three-point data for momentum %s completed.\n' %
                      (mTag))