Example #1
0
def imp_spec(FP, xcal='nm', normalize=False, axis=(0, 1)):
    """importing spectrum, calibrating to angular frequency (if input is in nm)
    return [angular frequency in 2*Pi*Hz, normalized field (sqrt(intensity))]"""
    try:
        if FP[-4:] == 'spec':
            """load akspec file"""
            axis = (0, 4)
            Sp = np.loadtxt(FP, skiprows=8)
            ind0 = Sp < np.zeros(Sp.shape)
            Sp[ind0] = 0
        elif FP[-3:] == 'txt' or FP[
                -3:] == 'dat':  #standard case with a pure 2 colomn data
            if open(FP, 'r').readline() == 'Wavelength\tIntensity\n':
                """file saved by a Wavescan (two column)"""
                Sp = Wavescan(FP, xout='nm')
            else:
                L = np.fromstring(open(FP, 'r').readline(), sep='\t')
                if len(L) == 2:
                    Sp = np.loadtxt(FP)
                else:
                    raise ER.SL_exception(
                        'unknown fundamental spectrum file format')
        elif FP[-11:] == 'IntSpectrum':
            """load Sfrogger spectrum"""
            axis = (0, 1)
            Sp = np.loadtxt(FP, skiprows=1)

            xcal = 'PHz'
        else:
            raise ER.SL_exception('unknown fundamental spectrum file format')
    except OSError as er:
        raise ER.ReadError(er)
    else:
        if xcal == 'nm':
            Sp1 = Sp[:, (axis[0], axis[1])]
            Sp1[:, 0] = 2 * Pi * c / Sp1[:, 0] * 10**9
            Sp1[:, 1] = np.abs(Sp1[:, 1])**0.5
            Sp1 = Sp1[::-1]
        elif xcal == 'THz':
            Sp1 = Sp[:, (axis[0], axis[1])]
            Sp1[:, 0] = 2 * Pi * Sp1[:, 0] * 10**12
            Sp1[:, 1] = np.abs(Sp1[:, 1])**0.5
        elif xcal == 'PHz':
            Sp1 = Sp[:, (axis[0], axis[1])]
            Sp1[:, 0] = 2 * Pi * Sp1[:, 0] * 10**15
            Sp1[:, 1] = np.abs(Sp1[:, 1])**0.5
        else:
            print("unknown x calibration")
            raise ER.CalibrationError(FP)
        if normalize:
            Sp1[:, 1] = Sp1[:, 1] / (Sp1[:, 1]).max()
        return Sp1
Example #2
0
 def transpose_frog(self):
     if not self.Args['frog_file'] == '':
         if len(self.Results['frog_load']) == 0:
             self.showerror(ER.SL_exception('no FROG loaded yet'))
         else:
             self.Results['frog_in'] = np.transpose(self.Results['frog_in'])
         self.showFROGex()
Example #3
0
    def set_wavelength(self):
        self.error_message.setPlaceholderText('')  #clear errors

        if self.checkmaxwavelength.isChecked(
        ) or self.checkminwavelength.isChecked():
            if self.Args['frog_file'][-3:] == 'frg' or self.Args['frog_file'][
                    -4:] == 'frog':
                self.error_message.setPlaceholderText(
                    'Not an error. Note that frg file is assumed to be proparly prepared, thus wavelength limits and delay correction are not applied to it. (though symmetrization and background substraction do work)'
                )
            else:
                self.Args['MaxWavelength'] = self.maxwavelength.value()
                self.Args['MinWavelength'] = self.minwavelength.value()
                if not self.Args['frog_file'] == '':
                    if self.checkmaxwavelength.isChecked():
                        Wmin = np.max([
                            2 * Pi * c / self.Args['MaxWavelength'] * 10**9 *
                            10**-15, self.Results['W_load'][0]
                        ])
                    else:
                        Wmin = self.Results['W_load'][0]
                    if self.checkminwavelength.isChecked():
                        Wmax = np.min([
                            2 * Pi * c / self.Args['MinWavelength'] * 10**9 *
                            10**-15, self.Results['W_load'][-1]
                        ])
                    else:
                        Wmax = self.Results['W_load'][-1]

                    if Wmin >= Wmax:
                        self.showerror(
                            ER.SL_exception(
                                'max wavelenghth has to be smaller than min wavelength'
                            ))
                        Wmin0 = Wmin
                        Wmin = Wmax
                        Wmax = Wmin0

                    ind = np.logical_and(self.Results['W_load'] >= Wmin,
                                         self.Results['W_load'] <= Wmax)
                    self.Results['W'] = np.copy(self.Results['W_load'][ind])
                    self.Results['frog_in_0'] = self.Results['frog_load'][:,
                                                                          ind]
                    self.remove_bkg()
                    self.showFROGex()
        else:
            if not self.Args['frog_file'] == '':
                self.Results['W'] = np.copy(self.Results['W_load'])
                self.Results['frog_in_0'] = self.Results['frog_load']
                self.remove_bkg()
                self.showFROGex()
        self.Results['frog_in_processed?'] = False
Example #4
0
def imp_time(FP, xcal='fs', normalize=True, axis=(0, 1)):
    """import temporal pulse profile"""

    try:
        if FP[-7:] == 'IntTime':
            """load Sfrogger data"""
            axis = (0, 1)
            Sp = np.loadtxt(FP, skiprows=1)

        else:
            raise ER.SL_exception('unknown temporal file format')
    except OSError as er:
        raise ER.ReadError(er)
    else:
        if xcal == 'fs':
            return Sp
        else:
            print("unknown x calibration")
Example #5
0
    def readparam(self):
        """read parameters for the reconstruction"""
        self.Args['G_goal'] = self.goal.value()
        self.Args['ret_iterations'] = self.iternumber.value()
        self.Args['fix_fund_spec'] = self.fix_fund_spec.isChecked()
        self.Args['use_fund_spec'] = self.use_fund_spec.isChecked()

        self.progressBar.setMaximum(self.Args['ret_iterations'])
        self.progressBar.setMinimum(0)

        self.Args['max size'] = int(self.size.value())
        self.Args['parallel'] = False
        self.Args['symmetrization'] = self.check_symmetry.isChecked()
        self.Args['multi_grid'] = self.multi_grid.isChecked()

        if self.check_flatPH.isChecked():
            self.Args['init_phase'] = 'random'
        elif self.check_flatPH.isChecked():
            self.Args['init_phase'] = 'flat'
        elif self.check_flatPH.isChecked():
            self.Args['init_phase'] = 'GDD'

        if self.Args['frog_file'] == '':
            raise ER.SL_exception('no FROG file is loaded')
Example #6
0
def width(X, Y, method='FWHM'):
    """computed the width (for example pulse duration of spectrum width) of a data set.
    data are expected to be 1d np.array"""
    if len(Y) > 0:
        M = Y.max()
        if method == 'FWHM':
            """in case of mutiple peaks, the maximum width will be returned"""
            # NM=Y.argmax()
            # N1=NM
            # N2=NM
            # for i in range(NM-1,-1,-1):
            #     if Y[i] > M/2: N1=i
            # for i in range(NM+1,len(Y)):
            #     if Y[i] > M/2: N2=i
            level = 0.5
            ind = Y > M * level
            indx = np.where(ind == True)
            N1 = indx[0][0]
            N2 = indx[0][-1]
            # print(X[N1],X[N2])
            # print(Y[N1]/M,Y[N2]/M)
            # print(Y[N1-1]/M,Y[N2+1]/M)

        elif method == 'e**-2':
            level = np.exp(-2)
            ind = Y > level * M
            indx = np.where(ind == True)
            N1 = indx[0][0]
            N2 = indx[0][-1]
            # print(X[N1],X[N2])
        elif method == 'e**-1':
            level = np.exp(-1)
            ind = Y > level * M
            indx = np.where(ind == True)
            N1 = indx[0][0]
            N2 = indx[0][-1]
            # print(X[N1],X[N2])

        elif method == '4sigma':
            Xmean = np.sum(X * Y) / np.sum(Y)
            sigmaX = (np.sum((X - Xmean)**2 * Y) / np.sum(Y))**0.5
            Width = 4 * sigmaX
        else:
            raise ER.SL_exception('unknown method')

        if method == '4sigma':
            return Width
        else:
            if N1 - 1 > 0:
                if Y[N1 - 1] == M * level:
                    X1 = X[N1 - 1]
                else:
                    y1 = Y[N1 - 1]
                    y2 = Y[N1]
                    x1 = X[N1 - 1]
                    x2 = X[N1]
                    # print(y1)
                    # print((M*level-y1)/(y2-y1))
                    X1 = x1 + (M * level - y1) / (y2 - y1) * (
                        x2 - x1
                    )  #linear interpolation for accuracy improvement
            else:
                X1 = X[0]

            if N2 + 1 < len(Y) - 1:
                if Y[N2 + 1] == M * level:
                    X2 = X[N2 + 1]
                else:
                    y1 = Y[N2]
                    y2 = Y[N2 + 1]
                    x1 = X[N2]
                    x2 = X[N2 + 1]
                    X2 = x1 + (M * level - y1) / (y2 - y1) * (
                        x2 - x1
                    )  #linear interpolation for accuracy improvement
            else:
                X2 = X[-1]

            Width = np.abs(X2 - X1)
            return Width

    else:
        raise ER.SL_exception('no data for width calculation')
Example #7
0
def load_frog(file):
    """loads a FROG scan"""
    
    if file[-3:]=='txt' or file[-3:]=='dat':
        """for program generated frogs (basically for test purposes)"""
        try:
            T0=open(file,'r').readline()
            T=np.fromstring(T0,sep='\t')
            Sp=np.genfromtxt(file,skip_header=1)
        except OSError as er:
            raise ER.ReadError(er)
        else:
            W=2*Pi*c/Sp[0]*10**9*10**-15
            frog=Sp[1:]
            frog=frog/frog.max()
            return (T, W, frog)
           
    elif file[-21:]=='akSpecScantransformed':
        """for files saved by akXFROG soft and preprocessed to akSpecScantransformed"""
        try:
            M0=open(file,'r').readline()
            M=np.fromstring(M0,sep='\t') #motor positions
            T=(M-M[0])/c*10**-9*10**15 #delays
            Sp=np.genfromtxt(file,skip_header=1)
        except OSError as er:
            raise ER.ReadError(er)
        else:
            W=2*Pi*c/Sp[0]*10**9*10**-15 #frequencies
            ind=W.argsort()
            W=W[ind]
            Sp1=Sp[1:]
            frog=Sp1[:,ind] #frog data
            frog=frog/frog.max()
            return (T, W, frog)
        
    elif file[-11:]=='txtSpecScan':
        """for files saved by akvlXFROG_txt soft directly"""
        try:
            M0=open(file,'r').readline()
            T=np.fromstring(M0,sep='\t') #delays in fs
            Sp=np.genfromtxt(file,skip_header=1)
        except OSError as er:
            raise ER.ReadError(er)
        else:
            W=2*Pi*c/Sp[0]*10**9*10**-15 #frequencies
            ind=W.argsort()
            W=W[ind]
            Sp1=Sp[1:]
            frog=Sp1[:,ind] #frog data
            frog=frog/frog.max()
            return (T, W, frog)
        
    elif file[-4:]=='frog':
        """for files saved by Sfrogger"""
        try:
            M0=open(file,'r').readline()
            T=np.fromstring(M0,sep='\t') #delays in fs
            Sp=np.genfromtxt(file,skip_header=1)
        except OSError as er:
            raise ER.ReadError(er)
        else:
            W=2*Pi*Sp[0] #frequencies
            frog=Sp[1:] #frog data
            return (T, W, frog)
        
    elif file[-3:]=='frg':
        """for files prepared as for Trebino frogger"""
        try:
            par=np.fromstring(open(file,'r').readline(),sep='\t')
            Nbin=int(par[0])
            dt=par[2]
            dw=par[3]
            W0=par[4]*2*Pi
            Sp=np.genfromtxt(file,skip_header=1)
        except OSError as er:
            raise ER.ReadError(er)
        else:
            frog=np.transpose(Sp.reshape((Nbin,Nbin)))
            frog=frog/frog.max()
            #zero negative values
            ind0=frog < np.zeros(frog.shape)
            frog[ind0]=0
            
            T=dt*np.array([i-Nbin/2 for i in range(Nbin)])
            W=W0+dw*2*Pi*np.array([i-Nbin/2 for i in range(Nbin)])
            
            return (T, W, frog)
    elif file[-9:]=='frgav.npy':
        """for averaged frog traces"""
        In=np.load(file)
        W=In[0,1:]
        T=In[1:,0]
        frog=In[1:,1:]
        return (T, W, frog)
    else:
        raise ER.SL_exception('unknown file format')