예제 #1
0
 def __init__(self, file_path, **kwargs):
     """Constructor.
     """
     self.event_file = xEventFile(file_path)
     self.event_data = self.event_file.event_data
     self.kwargs = kwargs
     self.process_kwargs()
예제 #2
0
def analyze():
    """Analyze the data.
    """
    logger.info('Opening output file %s...' % ANALYSIS_FILE_PATH)
    analysis_file = open(ANALYSIS_FILE_PATH, 'w')
    for i, (_min, _max) in enumerate(zip(TIME_BINNING[:-1],
                                         TIME_BINNING[1:])):
        _mcube = xBinnedModulationCube(_mcube_file_path(i))
        _mcube.fit()
        _fit_results = _mcube.fit_results[0]
        _sel_file = xEventFile(_sel_file_path(i))
        _time = numpy.average(_sel_file.event_data['TIME'])
        _sel_file.close()
        _time_errp = _max - _time
        _time_errm = _time - _min
        _pol_deg = _fit_results.polarization_degree
        _pol_deg_err = _fit_results.polarization_degree_error
        _pol_angle = _fit_results.phase
        _pol_angle_err = _fit_results.phase_error
        _spec_fitter = PIPELINE.xpxspec(_pha1_file_path(i), plot=False)
        (_index, _index_err), (_norm, _norm_err) = _spec_fitter.fit_parameters()
        # The division by the phase interval is a workaround and we should
        # keep track of that in xpselect.
        _norm /= (_max - _min)
        _norm_err /= (_max - _min)
        _data = (_time, _time_errp, _time_errm, _pol_deg, _pol_deg_err,
                 _pol_angle, _pol_angle_err, _index, _index_err, _norm,
                 _norm_err)
        _fmt = ('%.4e   ' * len(_data)).strip()
        _fmt = '%s\n' % _fmt
        _line = _fmt % _data
        analysis_file.write(_line)
    analysis_file.close()
예제 #3
0
def analyze():
    """Analyze the data.
    """
    logger.info('Opening output file %s...' % ANALYSIS_FILE_PATH)
    analysis_file = open(ANALYSIS_FILE_PATH, 'w')
    for i, (_min, _max) in enumerate(zip(TIME_BINNING[:-1], TIME_BINNING[1:])):
        _mcube = xBinnedModulationCube(_mcube_file_path(i))
        _mcube.fit()
        _fit_results = _mcube.fit_results[0]
        _sel_file = xEventFile(_sel_file_path(i))
        _time = numpy.average(_sel_file.event_data['TIME'])
        _sel_file.close()
        _time_errp = _max - _time
        _time_errm = _time - _min
        _pol_deg = _fit_results.polarization_degree
        _pol_deg_err = _fit_results.polarization_degree_error
        _pol_angle = _fit_results.phase
        _pol_angle_err = _fit_results.phase_error
        _spec_fitter = PIPELINE.xpxspec(_pha1_file_path(i), plot=False)
        (_index, _index_err), (_norm,
                               _norm_err) = _spec_fitter.fit_parameters()
        # The division by the phase interval is a workaround and we should
        # keep track of that in xpselect.
        _norm /= (_max - _min)
        _norm_err /= (_max - _min)
        _data = (_time, _time_errp, _time_errm, _pol_deg, _pol_deg_err,
                 _pol_angle, _pol_angle_err, _index, _index_err, _norm,
                 _norm_err)
        _fmt = ('%.4e   ' * len(_data)).strip()
        _fmt = '%s\n' % _fmt
        _line = _fmt % _data
        analysis_file.write(_line)
    analysis_file.close()
예제 #4
0
파일: binning.py 프로젝트: pabell/ximpol
 def __init__(self, file_path, **kwargs):
     """Constructor.
     """
     self.event_file = xEventFile(file_path)
     self.event_data = self.event_file.event_data
     self.kwargs = kwargs
     self.process_kwargs()
예제 #5
0
def calcMDP():
    nebula_file = xEventFile(NEBULA_FILE_PATH)
    nebula_counts = nebula_file.num_events()
    
    for i, (_min, _max) in enumerate(PHASE_BINS):
        pulse_diff = numpy.fabs(_max -_min)
        
        pulsar_phase_file = xEventFile(_sel_file_path(i))
        pulsar_phase_counts = pulsar_phase_file.num_events()
        scaled_nebula_counts = pulse_diff*nebula_counts
        
        count_sqrt = numpy.sqrt(pulsar_phase_counts + scaled_nebula_counts)
        count_ratio = count_sqrt/pulsar_phase_counts
        modf_ave = 0.3 #Just using a random value picked by hand
        mdp = (4.292/modf_ave)*count_ratio
        print "Pulsar phase: %s Pulsar counts:%s Nebula counts (in 15 arcsec) %s MDP:%s"%(PHASE_BINS[i], pulsar_phase_counts, scaled_nebula_counts, mdp)
def _phase_binning():
    """Read the input event file and create an equipopulated binning in the
    pulsar phase.
    """
    if EQP_BINNING:
        evt_file = xEventFile(EVT_FILE_PATH)
        phase = evt_file.event_data['PHASE']
        return xEventBinningBase.equipopulated_binning(NUM_PHASE_BINS, phase,
                                                       0., 1.)
    else:
        return numpy.linspace(0., 1., NUM_PHASE_BINS)
예제 #7
0
def _phase_binning():
    """Read the input event file and create an equipopulated binning in the
    pulsar phase.
    """
    if EQP_BINNING:
        evt_file = xEventFile(EVT_FILE_PATH)
        phase = evt_file.event_data['PHASE']
        return xEventBinningBase.equipopulated_binning(NUM_PHASE_BINS, phase,
                                                       0., 1.)
    else:
        return numpy.linspace(0., 1., NUM_PHASE_BINS)
예제 #8
0
파일: J1708.py 프로젝트: lucabaldini/ximpol
def analyze():
    """
    """
    if os.path.exists(ANALYSIS_FILE_PATH):
        logger.info('%s exists, delete it if you want to recreate it.' %\
                    ANALYSIS_FILE_PATH)
        return
    modf = load_mrf('xipe_goal')
    logger.info('Opening output file %s...' % ANALYSIS_FILE_PATH)
    analysis_file = open(ANALYSIS_FILE_PATH, 'w')
    for i, (_min, _max) in enumerate(PHASE_BINNING):
        _evt_file = xEventFile(_sel_file_path(i))
        _energy = _evt_file.event_data['ENERGY']
        _phase = _evt_file.event_data['PHASE']
        exp = (polarization_degree(_energy, _phase, 0, 0)*modf(_energy)).sum()/\
              modf(_energy).sum()
        _mcube = xBinnedModulationCube(_mcube_file_path(i))
        _mcube.fit()
        _fit_results = _mcube.fit_results[-1]
        print _fit_results
        print exp
        print polarization_degree(_mcube.emean[-1], _phase, 0, 0)
        raw_input()
        _phase = 0.5*(_min + _max)
        _phase_err = 0.5*(_max - _min)
        _pol_deg = _fit_results.polarization_degree
        _pol_deg_err = _fit_results.polarization_degree_error
        _pol_angle = _fit_results.phase
        _pol_angle_err = _fit_results.phase_error
        _data = (_phase, _phase_err, _pol_deg, _pol_deg_err, _pol_angle,
                 _pol_angle_err)
        _fmt = ('%.4e   ' * len(_data)).strip()
        _fmt = '%s\n' % _fmt
        _line = _fmt % _data
        analysis_file.write(_line)
    analysis_file.close()
예제 #9
0
def run():
    outfile = PIPELINE.chandra2ximpol(
        INPUT_FILE_PATH, acis=ACIS, seed=SEED, duration=TIME, regfile=REG_FILE_PATH, configfile=CONFIG_FILE_PATH
    )
    cmap_file = PIPELINE.xpbin(outfile, algorithm=ALGORITHM[1], nxpix=512, nypix=512, binsz=1.25)
    # outfile = PIPELINE.xpselect(outfile, ra=RA, dec=DEC, rad=RAD)
    # outfile = PIPELINE.xpselect(outfile, ra=RA_CORE, dec=DEC_CORE, rad=RAD_PSF)
    outfile = PIPELINE.xpselect(outfile, ra=RA_JET, dec=DEC_JET, rad=RAD_PSF)
    mod_file = PIPELINE.xpbin(outfile, algorithm=ALGORITHM[0], emin=EMIN, emax=EMAX, ebins=EBINS)

    mod_cube = xBinnedModulationCube(mod_file)
    mod_cube.fit()

    event = xEventFile(outfile)
    energy = event.event_data["ENERGY"]
    src_id = event.event_data["MC_SRC_ID"]
    jet_tot = 0
    core_tot = 0
    bkg_tot = 0
    mu_tot = 0.0
    for i in range(0, len(mod_cube.emax)):
        mask_jet = (energy > mod_cube.emin[i]) * (energy < mod_cube.emax[i]) * (src_id == 1)
        mask_bkg = (energy > mod_cube.emin[i]) * (energy < mod_cube.emax[i]) * (src_id == 0)
        mask_core = (energy > mod_cube.emin[i]) * (energy < mod_cube.emax[i]) * (src_id == 2)
        cnts_jet = len(energy[mask_jet])
        cnts_bkg = len(energy[mask_bkg])
        cnts_core = len(energy[mask_core])
        jet_tot += cnts_jet
        bkg_tot += cnts_bkg
        core_tot += cnts_core
        cnts_tot = cnts_jet + cnts_bkg + cnts_core
        mu_tot += mod_cube.effective_mu[i] * cnts_tot
        mdp = mdp99(mod_cube.effective_mu[i], cnts_jet, cnts_bkg + cnts_core)
        logger.info(
            "%.2f--%.2f keV: %d jet counts (%.1f%%) in %d s, mu %.3f, MDP %.2f%%"
            % (
                mod_cube.emin[i],
                mod_cube.emax[i],
                cnts_jet,
                100 * cnts_jet / float(cnts_tot),
                TIME,
                mod_cube.effective_mu[i],
                100 * mdp,
            )
        )
        # print cnts_jet, cnts_bkg, cnts_core
    if EBINS > 1:
        cnts_tot = jet_tot + bkg_tot + core_tot
        mu_tot /= cnts_tot
        mdp_tot = mdp99(mu_tot, jet_tot, bkg_tot + core_tot)
        logger.info(
            "%.2f--%.2f keV: %d jet counts (%.1f%%) in %d s, mu %.3f, MDP %.2f%%"
            % (
                mod_cube.emin[0],
                mod_cube.emax[len(mod_cube.emax) - 1],
                jet_tot,
                100 * jet_tot / float(cnts_tot),
                TIME,
                mu_tot,
                100 * mdp_tot,
            )
        )
        # print jet_tot, bkg_tot, core_tot
    if PLOT is True:
        plot(cmap_file)
        plt.show()
    logger.info("Done.")