Lv2_merged_pulse_methods.py
def do_demodulate(merging,data_id,par_file,E_trunc,PI1,PI2):
    """
    Using do_demodulate in binary_psr.py in Scott Ransom's PRESTO Python library to
    demodulate the time series for the merged event file!

    merging - True/False - whether to use merged data
    data_id - 10-digit ObsID or 6-digit ID for the merged event file
    par_file - orbital parameter file for input into binary_psr
    E_trunc - True/False - whether to do energy truncation
    PI1 - lower bound of PI (not energy in keV!) desired for the energy range
    PI2 - upper bound of PI (not energy in keV!) desired for the energy range
    """
    TIMEZERO = -1
    if type(data_id) != str:
        raise TypeError("data_id should be a string!")
    if len(data_id) != 6 and len(data_id) != 10:
        raise ValueError("data_id should have 6 or 10 digits in the string!")
    if E_trunc != True and E_trunc != False:
        raise ValueError("E_trunc (energy truncation) should either be True or False!")

    if merging == True:
        print("Doing demodulation, merging is True!")
        all_merged_dir = Lv0_dirs.NICERSOFT_DATADIR + 'merged_events/' #directory for the merged events
        merged_dir = all_merged_dir + 'merged' + data_id + '/'
        if E_trunc == True:
            old_file = merged_dir + 'merged' + data_id + '_nicersoft_bary_E' + str(PI1).zfill(4) + '-' + str(PI2).zfill(4) + '.evt'
        else:
            old_file = merged_dir + 'merged' + data_id + '_nicersoft_bary.evt'

    else:
        print("Doing demodulation, merging is False!")
        if E_trunc == True:
            old_file = Lv0_dirs.NICERSOFT_DATADIR + data_id + '_pipe/ni' + data_id + '_nicersoft_bary_E' + str(PI1).zfill(4) + '-' + str(PI2).zfill(4) + '.evt'
        else:
            old_file = Lv0_dirs.NICERSOFT_DATADIR + data_id + '_pipe/ni' + data_id + '_nicersoft_bary.evt'

    new_file = old_file[:-4] + '_demod.evt'
    subprocess.check_call(['cp',old_file,new_file])
    with fits.open(new_file,mode='update') as fitsfile_demod:
        MJDREFI = fitsfile_demod[1].header['MJDREFI'] #integer for MJD reference
        MJDREFF = fitsfile_demod[1].header['MJDREFF'] #float decimal for MJD reference

        times = fitsfile_demod[1].data['TIME'] #original time series
        gtis_start = fitsfile_demod[2].data['START'] #original GTI start times
        gtis_stop = fitsfile_demod[2].data['STOP'] #original GTI end times

        times_MJD = MJDREFI + MJDREFF + (times+TIMEZERO)/86400 #converting METs to MJD
        gtis_start_MJD = MJDREFI + MJDREFF + (gtis_start+TIMEZERO)/86400 #converting GTIs in METs to MJD
        gtis_stop_MJD = MJDREFI + MJDREFF + (gtis_stop+TIMEZERO)/86400 #converting GTIs in METs to MJD

        try:
            times_demod = binary_psr.binary_psr(par_file).demodulate_TOAs(times_MJD) #demodulated event times
            gtis_start_demod = binary_psr.binary_psr(par_file).demodulate_TOAs(gtis_start_MJD) #demodulated GTI start times
            gtis_stop_demod = binary_psr.binary_psr(par_file).demodulate_TOAs(gtis_stop_MJD) #demodulated GTI end times

            fitsfile_demod[1].data['TIME'] = (times_demod - MJDREFI - MJDREFF) * 86400 #convert back to METs
            fitsfile_demod[2].data['START'] = (gtis_start_demod - MJDREFI - MJDREFF) * 86400 #convert back to METs
            fitsfile_demod[2].data['STOP'] = (gtis_stop_demod - MJDREFI - MJDREFF) * 86400 #convert back to METs

            fitsfile_demod.flush()

        except ValueError:
            pass
    return

    Using do_demodulate in binary_psr.py in Scott Ransom's PRESTO Python library to
    demodulate the time series for the merged event file!

    merging - True/False - whether to use merged data
    data_id - 10-digit ObsID or 6-digit ID for the merged event file
    par_file - orbital parameter file for input into binary_psr
    E_trunc - True/False - whether to do energy truncation
    PI1 - lower bound of PI (not energy in keV!) desired for the energy range
    PI2 - upper bound of PI (not energy in keV!) desired for the energy range
    
Using do_demodulate in binary_psr.py in Scott Ransom's PRESTO Python library to
demodulate the time series for the merged event file!


Using do_demodulate in binary_psr . py in Scott Ransom ' s PRESTO Python library to demodulate the time series for the merged event file!
def do_demodulate(merging,data_id,par_file,E_trunc,PI1,PI2):
    TIMEZERO = -1
    if type(data_id) != str:
        raise TypeError("data_id should be a string!")
    if len(data_id) != 6 and len(data_id) != 10:
        raise ValueError("data_id should have 6 or 10 digits in the string!")
    if E_trunc != True and E_trunc != False:
        raise ValueError("E_trunc (energy truncation) should either be True or False!")
    if merging == True:
        print("Doing demodulation, merging is True!")
        all_merged_dir = Lv0_dirs.NICERSOFT_DATADIR + 'merged_events/' 
        merged_dir = all_merged_dir + 'merged' + data_id + '/'
        if E_trunc == True:
            old_file = merged_dir + 'merged' + data_id + '_nicersoft_bary_E' + str(PI1).zfill(4) + '-' + str(PI2).zfill(4) + '.evt'
        else:
            old_file = merged_dir + 'merged' + data_id + '_nicersoft_bary.evt'
    else:
        print("Doing demodulation, merging is False!")
        if E_trunc == True:
            old_file = Lv0_dirs.NICERSOFT_DATADIR + data_id + '_pipe/ni' + data_id + '_nicersoft_bary_E' + str(PI1).zfill(4) + '-' + str(PI2).zfill(4) + '.evt'
        else:
            old_file = Lv0_dirs.NICERSOFT_DATADIR + data_id + '_pipe/ni' + data_id + '_nicersoft_bary.evt'
    new_file = old_file[:-4] + '_demod.evt'
    subprocess.check_call(['cp',old_file,new_file])
    with fits.open(new_file,mode='update') as fitsfile_demod:
        MJDREFI = fitsfile_demod[1].header['MJDREFI'] 
        MJDREFF = fitsfile_demod[1].header['MJDREFF'] 
        times = fitsfile_demod[1].data['TIME'] 
        gtis_start = fitsfile_demod[2].data['START'] 
        gtis_stop = fitsfile_demod[2].data['STOP'] 
        times_MJD = MJDREFI + MJDREFF + (times+TIMEZERO)/86400 
        gtis_start_MJD = MJDREFI + MJDREFF + (gtis_start+TIMEZERO)/86400 
        gtis_stop_MJD = MJDREFI + MJDREFF + (gtis_stop+TIMEZERO)/86400 
        try:
            times_demod = binary_psr.binary_psr(par_file).demodulate_TOAs(times_MJD) 
            gtis_start_demod = binary_psr.binary_psr(par_file).demodulate_TOAs(gtis_start_MJD) 
            gtis_stop_demod = binary_psr.binary_psr(par_file).demodulate_TOAs(gtis_stop_MJD) 
            fitsfile_demod[1].data['TIME'] = (times_demod - MJDREFI - MJDREFF) * 86400 
            fitsfile_demod[2].data['START'] = (gtis_start_demod - MJDREFI - MJDREFF) * 86400 
            fitsfile_demod[2].data['STOP'] = (gtis_stop_demod - MJDREFI - MJDREFF) * 86400 
            fitsfile_demod.flush()
        except ValueError:
            pass
    return
def do_demodulate ( merging , data_id , par_file , E_trunc , PI1 , PI2 ) : TIMEZERO = - 1 if type ( data_id ) != str : raise TypeError ( "data_id should be a string!" ) if len ( data_id ) != 6 and len ( data_id ) != 10 : raise ValueError ( "data_id should have 6 or 10 digits in the string!" ) if E_trunc != True and E_trunc != False : raise ValueError ( "E_trunc (energy truncation) should either be True or False!" ) if merging == True : print ( "Doing demodulation, merging is True!" ) all_merged_dir = Lv0_dirs . NICERSOFT_DATADIR + 'merged_events/' merged_dir = all_merged_dir + 'merged' + data_id + '/' if E_trunc == True : old_file = merged_dir + 'merged' + data_id + '_nicersoft_bary_E' + str ( PI1 ) . zfill ( 4 ) + '-' + str ( PI2 ) . zfill ( 4 ) + '.evt' else : old_file = merged_dir + 'merged' + data_id + '_nicersoft_bary.evt' else : print ( "Doing demodulation, merging is False!" ) if E_trunc == True : old_file = Lv0_dirs . NICERSOFT_DATADIR + data_id + '_pipe/ni' + data_id + '_nicersoft_bary_E' + str ( PI1 ) . zfill ( 4 ) + '-' + str ( PI2 ) . zfill ( 4 ) + '.evt' else : old_file = Lv0_dirs . NICERSOFT_DATADIR + data_id + '_pipe/ni' + data_id + '_nicersoft_bary.evt' new_file = old_file [ : - 4 ] + '_demod.evt' subprocess . check_call ( [ 'cp' , old_file , new_file ] ) with fits . open ( new_file , mode = 'update' ) as fitsfile_demod : MJDREFI = fitsfile_demod [ 1 ] . header [ 'MJDREFI' ] MJDREFF = fitsfile_demod [ 1 ] . header [ 'MJDREFF' ] times = fitsfile_demod [ 1 ] . data [ 'TIME' ] gtis_start = fitsfile_demod [ 2 ] . data [ 'START' ] gtis_stop = fitsfile_demod [ 2 ] . data [ 'STOP' ] times_MJD = MJDREFI + MJDREFF + ( times + TIMEZERO ) / 86400 gtis_start_MJD = MJDREFI + MJDREFF + ( gtis_start + TIMEZERO ) / 86400 gtis_stop_MJD = MJDREFI + MJDREFF + ( gtis_stop + TIMEZERO ) / 86400 try : times_demod = binary_psr . binary_psr ( par_file ) . demodulate_TOAs ( times_MJD ) gtis_start_demod = binary_psr . binary_psr ( par_file ) . demodulate_TOAs ( gtis_start_MJD ) gtis_stop_demod = binary_psr . binary_psr ( par_file ) . demodulate_TOAs ( gtis_stop_MJD ) fitsfile_demod [ 1 ] . data [ 'TIME' ] = ( times_demod - MJDREFI - MJDREFF ) * 86400 fitsfile_demod [ 2 ] . data [ 'START' ] = ( gtis_start_demod - MJDREFI - MJDREFF ) * 86400 fitsfile_demod [ 2 ] . data [ 'STOP' ] = ( gtis_stop_demod - MJDREFI - MJDREFF ) * 86400 fitsfile_demod . flush ( ) except ValueError : pass return
Using do_demodulate in binary_psr.py in Scott Ransom's PRESTO Python library to
demodulate the time series for the merged event file!
Using do_demodulate in binary_psr . py in Scott Ransom ' s PRESTO Python library to demodulate the time series for the merged event file!
"""
    Using do_demodulate in binary_psr.py in Scott Ransom's PRESTO Python library to
    demodulate the time series for the merged event file!

    merging - True/False - whether to use merged data
    data_id - 10-digit ObsID or 6-digit ID for the merged event file
    par_file - orbital parameter file for input into binary_psr
    E_trunc - True/False - whether to do energy truncation
    PI1 - lower bound of PI (not energy in keV!) desired for the energy range
    PI2 - upper bound of PI (not energy in keV!) desired for the energy range
    """ #directory for the merged events #integer for MJD reference #float decimal for MJD reference #original time series #original GTI start times #original GTI end times #converting METs to MJD #converting GTIs in METs to MJD #converting GTIs in METs to MJD #demodulated event times #demodulated GTI start times #demodulated GTI end times #convert back to METs #convert back to METs #convert back to METs
merging
data_id
par_file
E_trunc
PI1
PI2