def Multi_Gaussian_Ratings(pfd, debug=False): """ Calculate ratings that depend on a fit of multiple Gaussian profile components. Parameters ---------- pfd : class An instance of the prepfold.pfd class debug : boolean If True, plot the profile and best-fit Gaussians Returns ------- names : list A list of ratings names ratings : list A list of ratings values """ # The ratings names name1 = "Number_of_Gaussians" name2 = "Pulse_Width_Rating" # De-disperse the profile at the best DM pfd.dedisperse(DM=pfd.bestdm, doppler=1) # Internally rotate the data cube so that is aligned with best fold values pfd.adjust_period() # Get the best fold profile profile = N.sum(N.sum(pfd.profs, axis=1), axis=0) # Get the period from bestprof, if it exists if hasattr(pfd.bestprof, "p0"): P0 = pfd.bestprof.p0 # Otherwise use the barycentric or topocentric folding periods else: if pfd.bary_p1 != 0.0: P0 = pfd.bary_p1 elif pfd.topo_p1 != 0.0: P0 = pfd.topo_p1 # Get the center observing frequency f_ctr = (pfd.hifreq + pfd.lofreq)/2 # Fit up to MAX_GAUSSIANS Gaussians to the profile gaussian_params, red_chi2, ngaussians = \ PT.fit_gaussians_presto(profile, pfd.avgprof, N.sqrt(pfd.varprof), MAX_GAUSSIANS, F_STAT_THRESHOLD) if debug: phases = N.arange(pfd.proflen, dtype=N.float)/pfd.proflen gaussians = PT.make_gaussians_presto(gaussian_params, pfd.proflen) PL.plot(phases, profile) PL.plot(phases, gaussians) PL.show() # Create a list for storing the FWHMs of the Gaussians fwhms = [] # If we were able to fit at least one Gaussian... if ngaussians != 0: # Get and store the FWHM for each Gaussian for nn in xrange(ngaussians): fwhms.append(gaussian_params[1+3*nn+1]) # Calculate the DM smearing time dm_smear_sec = PU.dm_smear(pfd.bestdm, pfd.chan_wid, f_ctr) # Calculate the expected minimum pulse width width_phase = N.sqrt(dm_smear_sec**2 + pfd.dt**2)/P0 # Compare the expected minimum and actual pulse widths width_ratio = width_phase/min(fwhms) # If no Gaussians could be fit to the profile, store bogus metrics else: width_ratio = -1.0 # Store the ratings rating1 = ngaussians rating2 = width_ratio return [name1,name2],[rating1,rating2]
def Multi_Gaussian_Ratings(pfd, debug=False): """ Calculate ratings that depend on a fit of multiple Gaussian profile components. Parameters ---------- pfd : class An instance of the prepfold.pfd class debug : boolean If True, plot the profile and best-fit Gaussians Returns ------- names : list A list of ratings names ratings : list A list of ratings values """ # The ratings names name1 = "Number_of_Gaussians" name2 = "Pulse_Width_Rating" # De-disperse the profile at the best DM pfd.dedisperse(DM=pfd.bestdm, doppler=1) # Internally rotate the data cube so that is aligned with best fold values pfd.adjust_period() # Get the best fold profile profile = N.sum(N.sum(pfd.profs, axis=1), axis=0) # Get the period from bestprof, if it exists if hasattr(pfd.bestprof, "p0"): P0 = pfd.bestprof.p0 # Otherwise use the barycentric or topocentric folding periods else: if pfd.bary_p1 != 0.0: P0 = pfd.bary_p1 elif pfd.topo_p1 != 0.0: P0 = pfd.topo_p1 # Get the center observing frequency f_ctr = (pfd.hifreq + pfd.lofreq) / 2 # Fit up to MAX_GAUSSIANS Gaussians to the profile gaussian_params, red_chi2, ngaussians = \ PT.fit_gaussians_presto(profile, pfd.avgprof, N.sqrt(pfd.varprof), MAX_GAUSSIANS, F_STAT_THRESHOLD) if debug: phases = N.arange(pfd.proflen, dtype=N.float) / pfd.proflen gaussians = PT.make_gaussians_presto(gaussian_params, pfd.proflen) PL.plot(phases, profile) PL.plot(phases, gaussians) PL.show() # Create a list for storing the FWHMs of the Gaussians fwhms = [] # If we were able to fit at least one Gaussian... if ngaussians != 0: # Get and store the FWHM for each Gaussian for nn in xrange(ngaussians): fwhms.append(gaussian_params[1 + 3 * nn + 1]) # Calculate the DM smearing time dm_smear_sec = PU.dm_smear(pfd.bestdm, pfd.chan_wid, f_ctr) # Calculate the expected minimum pulse width width_phase = N.sqrt(dm_smear_sec**2 + pfd.dt**2) / P0 # Compare the expected minimum and actual pulse widths width_ratio = width_phase / min(fwhms) # If no Gaussians could be fit to the profile, store bogus metrics else: width_ratio = -1.0 # Store the ratings rating1 = ngaussians rating2 = width_ratio return [name1, name2], [rating1, rating2]
def Single_Gaussian_Ratings(pfd, debug=False): """ Calculate ratings that depend on the fit of a single Gaussian profile component. Parameters ---------- pfd : class An instance of the prepfold.pfd class debug : boolean If True, plot the profile and best-fit Gaussian Returns ------- names : list A list of ratings names ratings : list A list of ratings values """ # The rating names name1 = "Gaussian_Amplitude" name2 = "Gaussian_Width" name3 = "Gaussian_Phase" name4 = "Gaussian_GoF" name5 = "Fraction_Good_Subints" name6 = "Subints_SNR_StdDev" name7 = "Fraction_Good_Subbands" name8 = "Subbands_SNR_StdDev" # De-disperse the profile at the best DM pfd.dedisperse(DM=pfd.bestdm, doppler=1) # Internally rotate the data cube so that is aligned with best fold values pfd.adjust_period() # Get the subints, subbands, and profile subints = N.sum(pfd.profs, axis=1) subbands = N.sum(pfd.profs, axis=0) profile = N.sum(subints, axis=0) # Fit a gaussian to the profile gaussian_params, red_chi2, ngaussians = \ PT.fit_gaussians_presto(profile, pfd.avgprof, N.sqrt(pfd.varprof), 1, F_STAT_THRESHOLD) # If we were able to fit a Gaussian... if ngaussians != 0: # Parse the Gaussian parameters amplitude = gaussian_params[1] fwhm = gaussian_params[2] phase = gaussian_params[3] # Get the on-pulse and off-pulse bins on_pulse_bins,off_pulse_bins = \ PT.calc_on_pulse_region(profile,gaussian_params) # Get the persistence metrics frac_good_subints,subints_snr_std = \ calc_persistence_metrics(subints,on_pulse_bins,off_pulse_bins) # Get the broadbandedness metrics frac_good_subbands,subbands_snr_std = \ calc_broadbandedness_metrics(subbands,on_pulse_bins,off_pulse_bins) if debug: phases = N.arange(pfd.proflen, dtype=N.float)/pfd.proflen gaussians = PT.make_gaussians_presto(gaussian_params, pfd.proflen) print len(on_pulse_bins)/float(pfd.proflen) PL.plot(phases, profile, "k") PL.plot(phases, gaussians, "b") PL.axvline(on_pulse_bins[0]/float(pfd.proflen), c="g") PL.axvline(on_pulse_bins[-1]/float(pfd.proflen), c="r") PL.show() # If no Gaussians could be fit to the profile, store bogus metrics else: amplitude = 0.0 fwhm = 0.0 phase = -1.0 frac_good_subints = -1.0 frac_good_subbands = -1.0 subints_snr_std = -1.0 subbands_snr_std = -1.0 # Store the ratings values rating1 = amplitude rating2 = fwhm rating3 = phase rating4 = red_chi2 rating5 = frac_good_subints rating6 = subints_snr_std rating7 = frac_good_subbands rating8 = subbands_snr_std return [name1,name2,name3,name4,name5,name6,name7,name8],\ [rating1,rating2,rating3,rating4,rating5,rating6,rating7,rating8]
def Single_Gaussian_Ratings(pfd, debug=False): """ Calculate ratings that depend on the fit of a single Gaussian profile component. Parameters ---------- pfd : class An instance of the prepfold.pfd class debug : boolean If True, plot the profile and best-fit Gaussian Returns ------- names : list A list of ratings names ratings : list A list of ratings values """ # The rating names name1 = "Gaussian_Amplitude" name2 = "Gaussian_Width" name3 = "Gaussian_Phase" name4 = "Gaussian_GoF" name5 = "Fraction_Good_Subints" name6 = "Subints_SNR_StdDev" name7 = "Fraction_Good_Subbands" name8 = "Subbands_SNR_StdDev" # De-disperse the profile at the best DM pfd.dedisperse(DM=pfd.bestdm, doppler=1) # Internally rotate the data cube so that is aligned with best fold values pfd.adjust_period() # Get the subints, subbands, and profile subints = N.sum(pfd.profs, axis=1) subbands = N.sum(pfd.profs, axis=0) profile = N.sum(subints, axis=0) # Fit a gaussian to the profile gaussian_params, red_chi2, ngaussians = \ PT.fit_gaussians_presto(profile, pfd.avgprof, N.sqrt(pfd.varprof), 1, F_STAT_THRESHOLD) # If we were able to fit a Gaussian... if ngaussians != 0: # Parse the Gaussian parameters amplitude = gaussian_params[1] fwhm = gaussian_params[2] phase = gaussian_params[3] # Get the on-pulse and off-pulse bins on_pulse_bins,off_pulse_bins = \ PT.calc_on_pulse_region(profile,gaussian_params) # Get the persistence metrics frac_good_subints,subints_snr_std = \ calc_persistence_metrics(subints,on_pulse_bins,off_pulse_bins) # Get the broadbandedness metrics frac_good_subbands,subbands_snr_std = \ calc_broadbandedness_metrics(subbands,on_pulse_bins,off_pulse_bins) if debug: phases = N.arange(pfd.proflen, dtype=N.float) / pfd.proflen gaussians = PT.make_gaussians_presto(gaussian_params, pfd.proflen) print len(on_pulse_bins) / float(pfd.proflen) PL.plot(phases, profile, "k") PL.plot(phases, gaussians, "b") PL.axvline(on_pulse_bins[0] / float(pfd.proflen), c="g") PL.axvline(on_pulse_bins[-1] / float(pfd.proflen), c="r") PL.show() # If no Gaussians could be fit to the profile, store bogus metrics else: amplitude = 0.0 fwhm = 0.0 phase = -1.0 frac_good_subints = -1.0 frac_good_subbands = -1.0 subints_snr_std = -1.0 subbands_snr_std = -1.0 # Store the ratings values rating1 = amplitude rating2 = fwhm rating3 = phase rating4 = red_chi2 rating5 = frac_good_subints rating6 = subints_snr_std rating7 = frac_good_subbands rating8 = subbands_snr_std return [name1,name2,name3,name4,name5,name6,name7,name8],\ [rating1,rating2,rating3,rating4,rating5,rating6,rating7,rating8]