DEPRECATED_Lv3_average_ps_segments.py
def binned_data(obsid,par_list,tbin_size):
    """
    Get binned (by tbin_size in s) data for a given ObsID - data was pre-processed
    by NICERsoft!

    obsid - Observation ID of the object of interest (10-digit str)
    par_list - A list of parameters we'd like to extract from the FITS file
    (e.g., from eventcl, PI_FAST, TIME, PI,)
    tbin_size - size of the time bin
    """
    if type(obsid) != str:
        raise TypeError("ObsID should be a string!")
    if type(par_list) != list and type(par_list) != np.ndarray:
        raise TypeError("par_list should either be a list or an array!")

    data_dict = Lv0_call_nicersoft_eventcl.get_eventcl(obsid,[True,'','','','',''],par_list)
    gtis = Lv0_call_nicersoft_eventcl.open_fits(obsid,[True,'','','','',''])[2].data

#    merged_data = fits.open('/Volumes/Samsung_T5/NICERsoft_outputs/trymerge/merged.evt')
#    data_dict = merged_data[1].data
#    gtis = merged_data[2].data

    times = data_dict['TIME']
#    times_MJDREFI = Lv0_call_nicersoft_eventcl.open_fits(obsid,[True,True,'','',30,200])[1].header['MJDREFI']
#    times_MJDREFF = Lv0_call_nicersoft_eventcl.open_fits(obsid,[True,True,'','',30,200])[1].header['MJDREFF']
#    times_MJD = times_MJDREFI + times_MJDREFF + times/86400 #to convert to MJD

#    starting_gti = np.array([gtis[0][0]])/86400 + times_MJDREFI + times_MJDREFF

    #demodulating!
#    times_demod = binary_psr.binary_psr("/Volumes/Samsung_T5/NICERsoft_outputs/J1231-1411.par").demodulate_TOAs(times_MJD)
#    starting_gti_demod = binary_psr.binary_psr("/Volumes/Samsung_T5/NICERsoft_outputs/J1231-1411.par").demodulate_TOAs(starting_gti)
#    times = (times_demod - times_MJDREFI - times_MJDREFF) * 86400
#    starting_gti = (starting_gti_demod - times_MJDREFI - times_MJDREFF) * 86400

#    truncated_times = times-starting_gti[0]
    truncated_times = times-gtis[0][0]
    counts = np.ones(len(times))

    startt = truncated_times[0]
    endt = truncated_times[-1]

    print('Binning started.')
    t_bins = np.arange(np.ceil((endt-startt)/tbin_size)+1)*tbin_size #getting an array of time values for the bins
    #summed_data, bin_edges, binnumber = stats.binned_statistic(truncated_times,counts,statistic='sum',bins=t_bins) #binning the counts in the data
    summed_data,edges = np.histogram(truncated_times,bins=t_bins)
    print('Binning finished.')

    return t_bins[:-1], summed_data

    Get binned (by tbin_size in s) data for a given ObsID - data was pre-processed
    by NICERsoft!

    obsid - Observation ID of the object of interest (10-digit str)
    par_list - A list of parameters we'd like to extract from the FITS file
    (e.g., from eventcl, PI_FAST, TIME, PI,)
    tbin_size - size of the time bin
    
Get binned (by tbin_size in s) data for a given ObsID - data was pre-processed
by NICERsoft!

Observation ID of the object of interest (10-digit str)
par_list - A list of parameters we'd like to extract from the FITS file

tbin_size - size of the time bin
Get binned ( by tbin_size in s ) data for a given ObsID - data was pre - processed by NICERsoft! Observation ID of the object of interest ( 10 - digit str ) par_list - A list of parameters we ' d like to extract from the FITS file tbin_size - size of the time bin
def binned_data(obsid,par_list,tbin_size):
    if type(obsid) != str:
        raise TypeError("ObsID should be a string!")
    if type(par_list) != list and type(par_list) != np.ndarray:
        raise TypeError("par_list should either be a list or an array!")
    data_dict = Lv0_call_nicersoft_eventcl.get_eventcl(obsid,[True,'','','','',''],par_list)
    gtis = Lv0_call_nicersoft_eventcl.open_fits(obsid,[True,'','','','',''])[2].data
    times = data_dict['TIME']
    truncated_times = times-gtis[0][0]
    counts = np.ones(len(times))
    startt = truncated_times[0]
    endt = truncated_times[-1]
    print('Binning started.')
    t_bins = np.arange(np.ceil((endt-startt)/tbin_size)+1)*tbin_size 
    summed_data,edges = np.histogram(truncated_times,bins=t_bins)
    print('Binning finished.')
    return t_bins[:-1], summed_data
def binned_data ( obsid , par_list , tbin_size ) : if type ( obsid ) != str : raise TypeError ( "ObsID should be a string!" ) if type ( par_list ) != list and type ( par_list ) != np . ndarray : raise TypeError ( "par_list should either be a list or an array!" ) data_dict = Lv0_call_nicersoft_eventcl . get_eventcl ( obsid , [ True , '' , '' , '' , '' , '' ] , par_list ) gtis = Lv0_call_nicersoft_eventcl . open_fits ( obsid , [ True , '' , '' , '' , '' , '' ] ) [ 2 ] . data times = data_dict [ 'TIME' ] truncated_times = times - gtis [ 0 ] [ 0 ] counts = np . ones ( len ( times ) ) startt = truncated_times [ 0 ] endt = truncated_times [ - 1 ] print ( 'Binning started.' ) t_bins = np . arange ( np . ceil ( ( endt - startt ) / tbin_size ) + 1 ) * tbin_size summed_data , edges = np . histogram ( truncated_times , bins = t_bins ) print ( 'Binning finished.' ) return t_bins [ : - 1 ] , summed_data
Get binned (by tbin_size in s) data for a given ObsID - data was pre-processed
by NICERsoft!
Get binned ( by tbin_size in s ) data for a given ObsID - data was pre - processed by NICERsoft!
"""
    Get binned (by tbin_size in s) data for a given ObsID - data was pre-processed
    by NICERsoft!

    obsid - Observation ID of the object of interest (10-digit str)
    par_list - A list of parameters we'd like to extract from the FITS file
    (e.g., from eventcl, PI_FAST, TIME, PI,)
    tbin_size - size of the time bin
    """ #    merged_data = fits.open('/Volumes/Samsung_T5/NICERsoft_outputs/trymerge/merged.evt') #    data_dict = merged_data[1].data #    gtis = merged_data[2].data #    times_MJDREFI = Lv0_call_nicersoft_eventcl.open_fits(obsid,[True,True,'','',30,200])[1].header['MJDREFI'] #    times_MJDREFF = Lv0_call_nicersoft_eventcl.open_fits(obsid,[True,True,'','',30,200])[1].header['MJDREFF'] #    times_MJD = times_MJDREFI + times_MJDREFF + times/86400 #to convert to MJD #    starting_gti = np.array([gtis[0][0]])/86400 + times_MJDREFI + times_MJDREFF #demodulating! #    times_demod = binary_psr.binary_psr("/Volumes/Samsung_T5/NICERsoft_outputs/J1231-1411.par").demodulate_TOAs(times_MJD) #    starting_gti_demod = binary_psr.binary_psr("/Volumes/Samsung_T5/NICERsoft_outputs/J1231-1411.par").demodulate_TOAs(starting_gti) #    times = (times_demod - times_MJDREFI - times_MJDREFF) * 86400 #    starting_gti = (starting_gti_demod - times_MJDREFI - times_MJDREFF) * 86400 #    truncated_times = times-starting_gti[0] #getting an array of time values for the bins #summed_data, bin_edges, binnumber = stats.binned_statistic(truncated_times,counts,statistic='sum',bins=t_bins) #binning the counts in the data
obsid
par_list
tbin_size