Lv1_ngc300_mathgrp_pha.py
def combine_back(init_back_array,fake_spec,T0,Porb):
    """
    Given a timing model/ephemeris, figure out which orbital phase the events in a
    background spectrum/event file are in (defined by some centroid time), then
    write a mathpha command combining those files appropriately in rate space

    init_back_array - array of input background file
    fake_spec - array of files split by orbital phase
    T0 - reference time ; deepest point of eclipse
    Porb - orbital period in days
    """
    command_file = open(Lv0_dirs.NGC300_2020 + '3C50_X1_mathpha.go','w')

    for i in tqdm(range(len(init_back_array))):
        init_back = init_back_array[i]
        gti_no = init_back[-8:-4]
        init_cl = Lv0_dirs.NGC300_2020 + 'cl50/pha/cl50_' + gti_no + '.pha'

        backfile = str(pathlib.Path(init_back).name)
        comb_spec_folder = Lv0_dirs.NGC300_2020 + 'bg_cl50/xpha/'

        tstart = fits.open(init_cl)[1].header['TSTART']
        tstop = fits.open(init_cl)[1].header['TSTOP']
        centroid_t = fits.open(init_cl)[1].header['MJDREFI'] + fits.open(init_cl)[1].header['MJDREFF'] + ((tstart+tstop)/2)/86400

        #first assuming the timing model, determine how much time (in d) has passed
        orb_phase = (centroid_t-T0)%Porb/Porb

        if (orb_phase >= 0.0 and orb_phase <= 0.20) or (orb_phase >= 0.85 and orb_phase <= 1):
            eclipse = fake_spec[0]
        elif (orb_phase > 0.2 and orb_phase < 0.85):
            eclipse = fake_spec[1]

        bg_exp = fits.open(init_back)[1].header['EXPOSURE']
        eclipse_exp = fits.open(eclipse)[1].header['EXPOSURE']
        #### now to build the mathpha command
        mathpha = 'mathpha'
        calculation = ''
        calculation += "('" + init_back + "'+'" + eclipse + "')"

        unit = 'R' #for rate ; use 'C' for counts
        outfile = "outfil='" + comb_spec_folder + "x" + backfile + "'"
        exposure = 'exposure=' + str(bg_exp + eclipse_exp)
        errmeth = 'errmeth=gaussian'
        properr = 'properr=yes'
        ncomments = 'ncomments=0'
        areascal = 'areascal=NULL'
        clobber = 'clobber=YES'

        mathpha_line = mathpha+' "'+calculation+ '" '+unit+' '+outfile+' '+exposure+' '+errmeth+' '+properr+' '+ncomments+' '+areascal+' '+clobber
        command_file.write(mathpha_line + '\n')

    command_file.close()

    return

    Given a timing model/ephemeris, figure out which orbital phase the events in a
    background spectrum/event file are in (defined by some centroid time), then
    write a mathpha command combining those files appropriately in rate space

    init_back_array - array of input background file
    fake_spec - array of files split by orbital phase
    T0 - reference time ; deepest point of eclipse
    Porb - orbital period in days
    
Given a timing model/ephemeris, figure out which orbital phase the events in a
background spectrum/event file are in (defined by some centroid time), then
write a mathpha command combining those files appropriately in rate space

array of input background file
fake_spec - array of files split by orbital phase
T0 - reference time ; deepest point of eclipse
Porb - orbital period in days
Given a timing model / ephemeris figure out which orbital phase the events in a background spectrum / event file are in ( defined by some centroid time ) then write a mathpha command combining those files appropriately in rate space array of input background file fake_spec - array of files split by orbital phase T0 - reference time ; deepest point of eclipse Porb - orbital period in days
def combine_back(init_back_array,fake_spec,T0,Porb):
    command_file = open(Lv0_dirs.NGC300_2020 + '3C50_X1_mathpha.go','w')
    for i in tqdm(range(len(init_back_array))):
        init_back = init_back_array[i]
        gti_no = init_back[-8:-4]
        init_cl = Lv0_dirs.NGC300_2020 + 'cl50/pha/cl50_' + gti_no + '.pha'
        backfile = str(pathlib.Path(init_back).name)
        comb_spec_folder = Lv0_dirs.NGC300_2020 + 'bg_cl50/xpha/'
        tstart = fits.open(init_cl)[1].header['TSTART']
        tstop = fits.open(init_cl)[1].header['TSTOP']
        centroid_t = fits.open(init_cl)[1].header['MJDREFI'] + fits.open(init_cl)[1].header['MJDREFF'] + ((tstart+tstop)/2)/86400
        orb_phase = (centroid_t-T0)%Porb/Porb
        if (orb_phase >= 0.0 and orb_phase <= 0.20) or (orb_phase >= 0.85 and orb_phase <= 1):
            eclipse = fake_spec[0]
        elif (orb_phase > 0.2 and orb_phase < 0.85):
            eclipse = fake_spec[1]
        bg_exp = fits.open(init_back)[1].header['EXPOSURE']
        eclipse_exp = fits.open(eclipse)[1].header['EXPOSURE']
        mathpha = 'mathpha'
        calculation = ''
        calculation += "('" + init_back + "'+'" + eclipse + "')"
        unit = 'R' 
        outfile = "outfil='" + comb_spec_folder + "x" + backfile + "'"
        exposure = 'exposure=' + str(bg_exp + eclipse_exp)
        errmeth = 'errmeth=gaussian'
        properr = 'properr=yes'
        ncomments = 'ncomments=0'
        areascal = 'areascal=NULL'
        clobber = 'clobber=YES'
        mathpha_line = mathpha+' "'+calculation+ '" '+unit+' '+outfile+' '+exposure+' '+errmeth+' '+properr+' '+ncomments+' '+areascal+' '+clobber
        command_file.write(mathpha_line + '\n')
    command_file.close()
    return
def combine_back ( init_back_array , fake_spec , T0 , Porb ) : command_file = open ( Lv0_dirs . NGC300_2020 + '3C50_X1_mathpha.go' , 'w' ) for i in tqdm ( range ( len ( init_back_array ) ) ) : init_back = init_back_array [ i ] gti_no = init_back [ - 8 : - 4 ] init_cl = Lv0_dirs . NGC300_2020 + 'cl50/pha/cl50_' + gti_no + '.pha' backfile = str ( pathlib . Path ( init_back ) . name ) comb_spec_folder = Lv0_dirs . NGC300_2020 + 'bg_cl50/xpha/' tstart = fits . open ( init_cl ) [ 1 ] . header [ 'TSTART' ] tstop = fits . open ( init_cl ) [ 1 ] . header [ 'TSTOP' ] centroid_t = fits . open ( init_cl ) [ 1 ] . header [ 'MJDREFI' ] + fits . open ( init_cl ) [ 1 ] . header [ 'MJDREFF' ] + ( ( tstart + tstop ) / 2 ) / 86400 orb_phase = ( centroid_t - T0 ) % Porb / Porb if ( orb_phase >= 0.0 and orb_phase <= 0.20 ) or ( orb_phase >= 0.85 and orb_phase <= 1 ) : eclipse = fake_spec [ 0 ] elif ( orb_phase > 0.2 and orb_phase < 0.85 ) : eclipse = fake_spec [ 1 ] bg_exp = fits . open ( init_back ) [ 1 ] . header [ 'EXPOSURE' ] eclipse_exp = fits . open ( eclipse ) [ 1 ] . header [ 'EXPOSURE' ] mathpha = 'mathpha' calculation = '' calculation += "('" + init_back + "'+'" + eclipse + "')" unit = 'R' outfile = "outfil='" + comb_spec_folder + "x" + backfile + "'" exposure = 'exposure=' + str ( bg_exp + eclipse_exp ) errmeth = 'errmeth=gaussian' properr = 'properr=yes' ncomments = 'ncomments=0' areascal = 'areascal=NULL' clobber = 'clobber=YES' mathpha_line = mathpha + ' "' + calculation + '" ' + unit + ' ' + outfile + ' ' + exposure + ' ' + errmeth + ' ' + properr + ' ' + ncomments + ' ' + areascal + ' ' + clobber command_file . write ( mathpha_line + '\n' ) command_file . close ( ) return
Given a timing model/ephemeris, figure out which orbital phase the events in a
background spectrum/event file are in (defined by some centroid time), then
write a mathpha command combining those files appropriately in rate space
Given a timing model / ephemeris figure out which orbital phase the events in a background spectrum / event file are in ( defined by some centroid time ) then write a mathpha command combining those files appropriately in rate space
"""
    Given a timing model/ephemeris, figure out which orbital phase the events in a
    background spectrum/event file are in (defined by some centroid time), then
    write a mathpha command combining those files appropriately in rate space

    init_back_array - array of input background file
    fake_spec - array of files split by orbital phase
    T0 - reference time ; deepest point of eclipse
    Porb - orbital period in days
    """ #first assuming the timing model, determine how much time (in d) has passed #### now to build the mathpha command #for rate ; use 'C' for counts
init_back_array
fake_spec
T0
Porb