Ejemplo n.º 1
0
 def interpulse_align(self):
     """
     Align the pulse such that the main pulse is at phase=0.25
     and the interpulse is at phase = 0.75
     """
     self.data = np.roll(u.center_max(self.data), -len(self.data) // 4)
     return self
Ejemplo n.º 2
0
 def center_align(self):
     """
     Align the pulse such that the peak is in the center
     """
     self.data = u.center_max(self.data)
     return self
Ejemplo n.º 3
0
 def interpulse_align(self):
     """
     Align the pulse such that the main pulse is at phase=0.25 and the interpulse is at phase = 0.75
     """
     self.data = np.roll(u.center_max(self.data),-len(self.data)//4)
     return self
Ejemplo n.º 4
0
 def center_align(self):
     """
     Align the pulse such that the peak is in the center
     """
     self.data = u.center_max(self.data)
     return self
Ejemplo n.º 5
0
    def __init__(self,filename,NCHAN = NCHAN,templatefilename=None,windowsize=256,prepare = True,**kwargs):
        name , file_extension = os.path.splitext(filename)
        path , self.name = os.path.split(name)
        self.fullname = "%s%s" % (self.name,file_extension)
        if file_extension == '.npz':
            self.npz = np.load(filename)
        #if file_extension == '.fits' or file_extension == '.zap':
        else:
            self.npz = None
        #else:
        #    raise RuntimeError('File has improper extension for Quicklook, and this code will not work')

        self.NCHAN = NCHAN
        
        name, file_extension = os.path.splitext(filename)
        self.filename = filename
        self.templatefilename = templatefilename
        self.windowsize = windowsize
        
        self.ds = None #is all this necessary?
        self.ss = None
        self.acf2d = None
        self.profiles = None
        self.difference_profiles = None
        self.SS_xaxis = None
        self.SS_yaxis = None
        self.ACF2D_xaxis = None
        self.ACF2D_yaxis = None
        self.peak_DM = None
        self.DM_arr = None
        self.calculated_DM = None
        
        
        if self.templatefilename is not None:
                artemp = Archive(self.templatefilename, prepare=False,lowmem=True) #force lowmem?
                artemp.pscrunch()
                temp = u.normalize(u.center_max(artemp.getData()),simple=True)
                self.sptemp = SinglePulse(temp,windowsize=windowsize)
        
        if self.npz is None:
            self.ar = Archive(self.filename, prepare=prepare)
            self.F = self.ar.getAxis('F')
            # temporary holdover from archive.py frequency issues
            #if self.F[0] > self.F[-1]:
            #    self.F = self.F[::-1]
            self.T = self.ar.getAxis('T')
            self.data = self.ar.getData()
    
            #self.calculateAverageProfile()
            
            #calculateAverageProfile
            self.ar.tscrunch()
            self.ar.fscrunch()
            avgprof = self.ar.getData()
            imax = np.argmax(avgprof)
            self.average_profile = u.center_max(avgprof) #not normalized!
            
            if self.templatefilename is None:
                self.spavgprof = SinglePulse(self.average_profile,windowsize=windowsize)
                self.sptemp = SinglePulse(u.normalize(self.average_profile),mpw=self.spavgprof.mpw,opw=self.spavgprof.opw)
            else:
                self.spavgprof = SinglePulse(self.average_profile,mpw=self.sptemp.mpw,opw=self.sptemp.opw)
        
            self.spavgprof.remove_baseline()
            
            #Reset archive
            self.ar.reset()
    
            self.nbins = len(self.average_profile)
            alignval = self.nbins/2 - imax
            self.data = np.roll(self.data,alignval)
            self.DM0 = self.ar.getDM()
        
        else:
            self.F = self.npz['frequency']
            self.T = self.npz['time']
            self.average_profile = self.npz['average_profile'][0,:] #is it bad that we need to do this?
            if self.templatefilename is None:
                self.spavgprof = SinglePulse(self.average_profile,windowsize=windowsize)
                self.sptemp = SinglePulse(u.normalize(self.average_profile),mpw=self.spavgprof.mpw,opw=self.spavgprof.opw)
            else:
                self.spavgprof = SinglePulse(self.average_profile,mpw=self.sptemp.mpw,opw=self.sptemp.opw)
            self.spavgprof.remove_baseline()
            self.nbins = len(self.average_profile)
            self.DM0 = self.npz['DM']
            self.peak_DM = self.npz['peak_DM']
            self.DM_arr = self.npz['DM_arr']
        
        if len(self.F) % self.NCHAN != 0:
            str(len(self.F)) + '%' + str(self.NCHAN) + '=' + str( len(self.F) % self.NCHAN )
            raise UserWarning('Number of frequency channels in file is not multiple of your provided NCHAN')