Lv1_ngc300_binning.py
def binned_text(bin_size):
    """
    Given the MJDs, binned counts, and associated uncertainties, put them into a text file

    No arguments because I'll put all the bands in here
    """
    E_bins_low = np.array([20-1,30-1,40-1,100-1,200-1,400-1,40-1,1300-1])
    E_bins_high = np.array([30-1,40-1,100-1,200-1,400-1,1200-1,1200-1,1501-1])

    bgsub_files = sorted(glob.glob(Lv0_dirs.NGC300_2020 + 'spectra_' + bin_size + '/58*_' + bgsub_type + '*_cl50.pha'))

    output_text = open(Lv0_dirs.NGC300_2020 + 'n300_ulx.' + bgsub_type + '_cl50_g2020norm_' + str(binsize_s).zfill(2) + 'd.fffphot','w')
    output_text_err = open(Lv0_dirs.NGC300_2020 + 'n300_ulx.' + bgsub_type + '_cl50_g2020err_norm_' + str(binsize_s).zfill(2) + 'd.fffphot','w')

    for i in tqdm(range(len(bgsub_files))): #for each averaged spectrum
        mjd = str(pathlib.Path(bgsub_files[i]).name)[:5]
        files_in_interval = filenames[(time>=float(mjd))&(time<float(mjd)+binsize_s)]

        if bgsub_type == 'bgsub':
            filtered_files = [Lv0_dirs.NGC300_2020 + 'bgsub_cl50/pha/' + files_in_interval[a] for a in range(len(files_in_interval))]
        elif bgsub_type == 'xbgsub':
            filtered_files = [Lv0_dirs.NGC300_2020 + 'bgsub_cl50/xpha/' + files_in_interval[a] for a in range(len(files_in_interval))]
        elif bgsub_type == 'xsbgsub':
            filtered_files = [Lv0_dirs.NGC300_2020 + 'bgsub_cl50/xspha/' + files_in_interval[a] for a in range(len(files_in_interval))]

        rates_all = []
        errs_all = []
        for j in range(len(E_bins_low)): #for each energy band
            rates_all.append(sum(fits.open(bgsub_files[i])[1].data['RATE'][E_bins_low[j]:E_bins_high[j]]))
            errs = fits.open(bgsub_files[i])[1].data['STAT_ERR'][E_bins_low[j]:E_bins_high[j]]
            errs_all.append( np.sqrt(np.mean(errs**2) * len(errs)))

        rate_1 = mjd #for the MJD
        rate_2 = '' #for the count rates in each band
        rate_3 = '' #for the list of files that goes into each bin
        for j in range(len(rates_all)):
            rate_2 += str(round(rates_all[j],4)) + ' '
        for j in range(len(filtered_files)):
            if j != len(filtered_files)-1:
                rate_3 += filtered_files[j] + ','
            else:
                rate_3 += filtered_files[j]
        output_text.write(rate_1 + ' ' + rate_2 + rate_3 + '\n')

        errs_1 = mjd #for the MJD
        errs_2 = '' #for the count rates in each band
        errs_3 = '' #for the list of files that goes into each bin
        for j in range(len(errs_all)):
            errs_2 += str(round(errs_all[j],4)) + ' '
        for j in range(len(filtered_files)):
            if j != len(filtered_files)-1:
                errs_3 += filtered_files[j] + ','
            else:
                errs_3 += filtered_files[j]
        output_text_err.write(errs_1 + ' ' + errs_2 + errs_3 + '\n')

    output_text.close()
    output_text_err.close()

    Given the MJDs, binned counts, and associated uncertainties, put them into a text file

    No arguments because I'll put all the bands in here
    
Given the MJDs, binned counts, and associated uncertainties, put them into a text file
No arguments because I'll put all the bands in here
Given the MJDs binned counts and associated uncertainties put them into a text file No arguments because I ' ll put all the bands in here
def binned_text(bin_size):
    E_bins_low = np.array([20-1,30-1,40-1,100-1,200-1,400-1,40-1,1300-1])
    E_bins_high = np.array([30-1,40-1,100-1,200-1,400-1,1200-1,1200-1,1501-1])
    bgsub_files = sorted(glob.glob(Lv0_dirs.NGC300_2020 + 'spectra_' + bin_size + '/58*_' + bgsub_type + '*_cl50.pha'))
    output_text = open(Lv0_dirs.NGC300_2020 + 'n300_ulx.' + bgsub_type + '_cl50_g2020norm_' + str(binsize_s).zfill(2) + 'd.fffphot','w')
    output_text_err = open(Lv0_dirs.NGC300_2020 + 'n300_ulx.' + bgsub_type + '_cl50_g2020err_norm_' + str(binsize_s).zfill(2) + 'd.fffphot','w')
    for i in tqdm(range(len(bgsub_files))): 
        mjd = str(pathlib.Path(bgsub_files[i]).name)[:5]
        files_in_interval = filenames[(time>=float(mjd))&(time<float(mjd)+binsize_s)]
        if bgsub_type == 'bgsub':
            filtered_files = [Lv0_dirs.NGC300_2020 + 'bgsub_cl50/pha/' + files_in_interval[a] for a in range(len(files_in_interval))]
        elif bgsub_type == 'xbgsub':
            filtered_files = [Lv0_dirs.NGC300_2020 + 'bgsub_cl50/xpha/' + files_in_interval[a] for a in range(len(files_in_interval))]
        elif bgsub_type == 'xsbgsub':
            filtered_files = [Lv0_dirs.NGC300_2020 + 'bgsub_cl50/xspha/' + files_in_interval[a] for a in range(len(files_in_interval))]
        rates_all = []
        errs_all = []
        for j in range(len(E_bins_low)): 
            rates_all.append(sum(fits.open(bgsub_files[i])[1].data['RATE'][E_bins_low[j]:E_bins_high[j]]))
            errs = fits.open(bgsub_files[i])[1].data['STAT_ERR'][E_bins_low[j]:E_bins_high[j]]
            errs_all.append( np.sqrt(np.mean(errs**2) * len(errs)))
        rate_1 = mjd 
        rate_2 = '' 
        rate_3 = '' 
        for j in range(len(rates_all)):
            rate_2 += str(round(rates_all[j],4)) + ' '
        for j in range(len(filtered_files)):
            if j != len(filtered_files)-1:
                rate_3 += filtered_files[j] + ','
            else:
                rate_3 += filtered_files[j]
        output_text.write(rate_1 + ' ' + rate_2 + rate_3 + '\n')
        errs_1 = mjd 
        errs_2 = '' 
        errs_3 = '' 
        for j in range(len(errs_all)):
            errs_2 += str(round(errs_all[j],4)) + ' '
        for j in range(len(filtered_files)):
            if j != len(filtered_files)-1:
                errs_3 += filtered_files[j] + ','
            else:
                errs_3 += filtered_files[j]
        output_text_err.write(errs_1 + ' ' + errs_2 + errs_3 + '\n')
    output_text.close()
    output_text_err.close()
def binned_text ( bin_size ) : E_bins_low = np . array ( [ 20 - 1 , 30 - 1 , 40 - 1 , 100 - 1 , 200 - 1 , 400 - 1 , 40 - 1 , 1300 - 1 ] ) E_bins_high = np . array ( [ 30 - 1 , 40 - 1 , 100 - 1 , 200 - 1 , 400 - 1 , 1200 - 1 , 1200 - 1 , 1501 - 1 ] ) bgsub_files = sorted ( glob . glob ( Lv0_dirs . NGC300_2020 + 'spectra_' + bin_size + '/58*_' + bgsub_type + '*_cl50.pha' ) ) output_text = open ( Lv0_dirs . NGC300_2020 + 'n300_ulx.' + bgsub_type + '_cl50_g2020norm_' + str ( binsize_s ) . zfill ( 2 ) + 'd.fffphot' , 'w' ) output_text_err = open ( Lv0_dirs . NGC300_2020 + 'n300_ulx.' + bgsub_type + '_cl50_g2020err_norm_' + str ( binsize_s ) . zfill ( 2 ) + 'd.fffphot' , 'w' ) for i in tqdm ( range ( len ( bgsub_files ) ) ) : mjd = str ( pathlib . Path ( bgsub_files [ i ] ) . name ) [ : 5 ] files_in_interval = filenames [ ( time >= float ( mjd ) ) & ( time < float ( mjd ) + binsize_s ) ] if bgsub_type == 'bgsub' : filtered_files = [ Lv0_dirs . NGC300_2020 + 'bgsub_cl50/pha/' + files_in_interval [ a ] for a in range ( len ( files_in_interval ) ) ] elif bgsub_type == 'xbgsub' : filtered_files = [ Lv0_dirs . NGC300_2020 + 'bgsub_cl50/xpha/' + files_in_interval [ a ] for a in range ( len ( files_in_interval ) ) ] elif bgsub_type == 'xsbgsub' : filtered_files = [ Lv0_dirs . NGC300_2020 + 'bgsub_cl50/xspha/' + files_in_interval [ a ] for a in range ( len ( files_in_interval ) ) ] rates_all = [ ] errs_all = [ ] for j in range ( len ( E_bins_low ) ) : rates_all . append ( sum ( fits . open ( bgsub_files [ i ] ) [ 1 ] . data [ 'RATE' ] [ E_bins_low [ j ] : E_bins_high [ j ] ] ) ) errs = fits . open ( bgsub_files [ i ] ) [ 1 ] . data [ 'STAT_ERR' ] [ E_bins_low [ j ] : E_bins_high [ j ] ] errs_all . append ( np . sqrt ( np . mean ( errs ** 2 ) * len ( errs ) ) ) rate_1 = mjd rate_2 = '' rate_3 = '' for j in range ( len ( rates_all ) ) : rate_2 += str ( round ( rates_all [ j ] , 4 ) ) + ' ' for j in range ( len ( filtered_files ) ) : if j != len ( filtered_files ) - 1 : rate_3 += filtered_files [ j ] + ',' else : rate_3 += filtered_files [ j ] output_text . write ( rate_1 + ' ' + rate_2 + rate_3 + '\n' ) errs_1 = mjd errs_2 = '' errs_3 = '' for j in range ( len ( errs_all ) ) : errs_2 += str ( round ( errs_all [ j ] , 4 ) ) + ' ' for j in range ( len ( filtered_files ) ) : if j != len ( filtered_files ) - 1 : errs_3 += filtered_files [ j ] + ',' else : errs_3 += filtered_files [ j ] output_text_err . write ( errs_1 + ' ' + errs_2 + errs_3 + '\n' ) output_text . close ( ) output_text_err . close ( )
Given the MJDs, binned counts, and associated uncertainties, put them into a text file
No arguments because I'll put all the bands in here
Given the MJDs binned counts and associated uncertainties put them into a text file No arguments because I ' ll put all the bands in here
"""
    Given the MJDs, binned counts, and associated uncertainties, put them into a text file

    No arguments because I'll put all the bands in here
    """ #for each averaged spectrum #for each energy band #for the MJD #for the count rates in each band #for the list of files that goes into each bin #for the MJD #for the count rates in each band #for the list of files that goes into each bin
bin_size