def prepare_file(self, file):
        """
        Prepares the PSRFITS file in the correct format for the program.
        """

        try:
            hdul = fits.open(file)
        except OSError:
            return -1

        name = hdul[0].header['SRC_NAME']
        fe = hdul[0].header['FRONTEND']
        if hdul[0].header[
                'OBS_MODE'] != "PSR" or name != self.psr_name or fe != self.frontend:
            hdul.close()
            return -1
        hdul.close()

        ar = Archive(file, verbose=self.verbose)
        ar.tscrunch(nsubint=1)
        ar.fscrunch(nchan=1)
        n = 1
        nbin = ar.getNbin()
        data = ar.getData()

        return np.copy(data), n, nbin
Пример #2
0
    def prepare_file(self, file):
        """
        Prepares the PSRFITS file in the correct format for the program.
        """

        try:
            hdul = fits.open(file)
        except:
            return -1

        name = hdul[0].header['SRC_NAME']
        fe = hdul[0].header['FRONTEND']
        mjd = hdul[0].header['STT_IMJD']
        if hdul[0].header['OBS_MODE'] != "PSR" or name != self.psr_name:
            hdul.close()
            return -1
        hdul.close()

        tmp_fn = "{0}_{1}_nchan{2}_template.npy".format(
            self.psr_name, fe, self.subbands)
        try:
            template = self.load_template(self.temp_dir, tmp_fn)
        except TemplateLoadError:
            print("Template not found")
            reply = str(input("Would you like to make a suitable one? (y / n)")
                        ).lower().strip()
            if reply[0] == 'y':
                temp = FD_Template(self.psr_name,
                                   fe,
                                   self.subbands,
                                   template_dir="templates",
                                   verbose=self.verbose,
                                   *self.dirs)
                template = temp.make_template()
            else:
                raise TemplateLoadError(
                    "You can make a suitable template via the following command: python template_builder.py psr_name -b [frontend] -d [dirs]"
                )

        ar = Archive(file, verbose=self.verbose)
        ar.tscrunch(nsubint=self.epochs)
        ar.fscrunch(nchan=self.subbands)

        return ar, template, fe, mjd
Пример #3
0
    #for i in np.arange( ar.getNsubint() ):
    #    data_lin = np.append( data_lin, data[ i, 324, : ] )
    #data = np.reshape( data, ( num_profs * ar.getNbin() ) )

    # D_FAC = 32
    # for i in range(D_FAC):
    #     st, ed = i*(chan // D_FAC), (i + 1)*(chan // D_FAC)
    #     fig = plt.figure( figsize = (7, 7) )
    #     ax = fig.add_subplot(111)
    #     cmap = plt.cm.Blues
    #     ax.imshow( rms.T[st:ed, :], cmap = cmap, interpolation = 'nearest', extent = [ 0, ch, ed, st ], aspect = 'auto', norm = clr.Normalize( vmin = 0, vmax = np.amax(rms) ) )
    #     fig.colorbar( plt.cm.ScalarMappable( norm = clr.Normalize( vmin = 0, vmax = np.amax(rms) ), cmap = cmap ), ax = ax )
    #     cid = fig.canvas.mpl_connect('key_press_event', on_key)
    #
    #     #fig.canvas.mpl_disconnect(cid)
    #     #ax.plot( np.linspace( 1, num_profs, num = sub_pol * ar.getNbin() ), data_lin, linewidth = 0.1, color = 'k' )
    #     #ax.set_ylim( -630, 630 )
    #     #for i in np.arange( 1, num_profs + 1 ):
    #     #    if (i % ar.getNsubint()) == 0:
    #     #        ax.axvline( i, linewidth = 0.2, color = 'r' )
    #     #ax.set_xlim( 2400, 2600 )
    #
    #     plt.show()
    #     fig.canvas.mpl_disconnect(cid)

    ar.tscrunch()
    ar.fscrunch()
    ar.plot()
    exit()
    ar.imshow(origin='upper')