Lv1_ngc300_mathgrp_pha.py
def combine_back_scal(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.
    Unlike combine_back, this SCALES the spectra/GTIs in the ingress/egress sections
    based on the folded PN light curve!

    Remember that:
    025-080 -> off
    080-090 -> ingress
    090-010 -> on
    010-025 -> egress

    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_X1scale_mathpha.go','w')
    on_e = fake_spec[0]
    off_e = fake_spec[1]

    top = 0.022177
    bottom = 0.005351

    counter = 0
    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/xspha/' #x for 'extra', s for 'scale'

        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

        calculation = ''
        rate = orb_phase_rate(orb_phase)

        on_factor = round((top-rate)/(top-bottom),6)
        off_factor = round((rate-bottom)/(top-bottom),6)
        calculation += "('" + init_back + "'+" + str(off_factor) + "*'" + off_e + "'+" + str(on_factor) + "*'" + on_e + "')"

        bg_exp = fits.open(init_back)[1].header['EXPOSURE']
        eclipse_exp = 1e6 #1 Ms was used in the faked spectrum
        #### now to build the mathpha command
        mathpha = 'mathpha'

        unit = 'R' #for rate ; use 'C' for counts
        outfile = "outfil='" + comb_spec_folder + "xs" + 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()

    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.
    Unlike combine_back, this SCALES the spectra/GTIs in the ingress/egress sections
    based on the folded PN light curve!

    Remember that:
    025-080 -> off
    080-090 -> ingress
    090-010 -> on
    010-025 -> egress

    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.
Unlike combine_back, this SCALES the spectra/GTIs in the ingress/egress sections
based on the folded PN light curve!



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 . Unlike combine_back this SCALES the spectra / GTIs in the ingress / egress sections based on the folded PN light curve! 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_scal(init_back_array,fake_spec,T0,Porb):
    command_file = open(Lv0_dirs.NGC300_2020 + '3C50_X1scale_mathpha.go','w')
    on_e = fake_spec[0]
    off_e = fake_spec[1]
    top = 0.022177
    bottom = 0.005351
    counter = 0
    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/xspha/' 
        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
        calculation = ''
        rate = orb_phase_rate(orb_phase)
        on_factor = round((top-rate)/(top-bottom),6)
        off_factor = round((rate-bottom)/(top-bottom),6)
        calculation += "('" + init_back + "'+" + str(off_factor) + "*'" + off_e + "'+" + str(on_factor) + "*'" + on_e + "')"
        bg_exp = fits.open(init_back)[1].header['EXPOSURE']
        eclipse_exp = 1e6 
        mathpha = 'mathpha'
        unit = 'R' 
        outfile = "outfil='" + comb_spec_folder + "xs" + 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()
def combine_back_scal ( init_back_array , fake_spec , T0 , Porb ) : command_file = open ( Lv0_dirs . NGC300_2020 + '3C50_X1scale_mathpha.go' , 'w' ) on_e = fake_spec [ 0 ] off_e = fake_spec [ 1 ] top = 0.022177 bottom = 0.005351 counter = 0 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/xspha/' 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 calculation = '' rate = orb_phase_rate ( orb_phase ) on_factor = round ( ( top - rate ) / ( top - bottom ) , 6 ) off_factor = round ( ( rate - bottom ) / ( top - bottom ) , 6 ) calculation += "('" + init_back + "'+" + str ( off_factor ) + "*'" + off_e + "'+" + str ( on_factor ) + "*'" + on_e + "')" bg_exp = fits . open ( init_back ) [ 1 ] . header [ 'EXPOSURE' ] eclipse_exp = 1e6 mathpha = 'mathpha' unit = 'R' outfile = "outfil='" + comb_spec_folder + "xs" + 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 ( )
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.
    Unlike combine_back, this SCALES the spectra/GTIs in the ingress/egress sections
    based on the folded PN light curve!

    Remember that:
    025-080 -> off
    080-090 -> ingress
    090-010 -> on
    010-025 -> egress

    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
    """ #x for 'extra', s for 'scale' #first assuming the timing model, determine how much time (in d) has passed #1 Ms was used in the faked spectrum #### now to build the mathpha command #for rate ; use 'C' for counts
init_back_array
fake_spec
T0
Porb