Esempio n. 1
0
def extract_data_under_condition(hdata, select_list):
    """
    extract specified data from the hrc hk data set
    input:  hdata       --- hrc hk data processed by extrct_hrchk_data
            select_list --- a list contains lists of [<column name>, <condition>]
                            used to select data
    output: hdata       --- selected data
    """
    #
    #--- the list select_list contains lists of [<name>, <condition>]
    #
    for ent in select_list:
        name = ent[0]
        mc = re.search(':', ent[1])
        #
        #-- numerical range case; need start and stop range
        #
        if mc is not None:
            atemp = re.split(':', ent[1])
            cstart = int(float(atemp[0]))
            cstop = int(float(atemp[1]))

            hdata = hcf.select_data_with_condition(hdata, name, '>=', cstart)
            hdata = hcf.select_data_with_condition(hdata, name, '<=', cstop)
#
#--- single condition case
#
        else:
            cond = ent[1]
            hdata = hcf.select_data_with_condition(hdata, name, '==', cond)

#
#--- check whether any data left in the datatable
#
        try:
            test = hdata.field('time')
            if len(test) == 0:
                return ''
        except:
            return ''
#
#--- check one more last time whether any data left in the datatable
#
    try:
        test = hdata.field(0)
    except:
        test = []

    if len(list(test)) > 0:
        return hdata
    else:
        return ''
Esempio n. 2
0
def find_scint(tstart, tstop):
    """
    find integrated EPHIN flux
    input: tstart   --- starting time in seconds from 1998.1.1
           tstop    --- stopping time in seconds from 1998.1.1
    output; avg     --- average of ephin flux
            std     --- standard deviation of flux
    """
    #
    #--- extract ephin data
    #
    hcf.run_arc5gl('retrieve', tstart, tstop, dataset='flight',detector='ephin',\
                    level=1,filetype='ephrates')
    #
    #--- create extracted fits file list
    #
    ldir = exc_dir + 'Temp_dir/'
    flist = hcf.get_file_list(ldir, 'lc1.fits.gz')
    #
    #--- combine all fits files into one
    #
    hcf.combine_fits_files(flist, 'ztemp.fits', azip=0)
    [cols, tbdata] = hcf.read_fits_file('ztemp.fits')
    #
    #--- limit data to between tstart and tstop
    #
    tbdata = hcf.select_data_with_condition(tbdata, 'time', ">=", tstart)
    tbdata = hcf.select_data_with_condition(tbdata, 'time', "<=", tstop)
    #
    #--- compute the basic stat
    #
    [avg, med, std, vmin, vmax, vcnt] = get_basic_stat(tbdata['scint'])

    cmd = 'rm ztemp.fits' + '*'
    os.system(cmd)

    if hcf.check_file_in_dir(ldir):
        cmd = 'rm  ' + ldir + '*'
        os.system(cmd)

    return [avg, std]
Esempio n. 3
0
def get_time_period_engineer_data(time_list, hrc_type, start, stop):
    """
    extract time period in which hrc engireer data gives  2pre<a/b>ds=hrc type
    input:  time_list   --- a list of lists of starting and stoppping time
                            from previous condition
            hrc_type    --- hrc type either IMG or SPEC
            start       --- start time of the entire period
            stop        --- stop time of the entire period
    output: rlist       --- a list of lists of starting and stoppping time
    """
    #
    #--- HRC Side changed from side A to side B on Aug 24, 2020.
    #
    if stop < 714614394:
        msid = '2PREADS'
    else:
        msid = '2PREBDS'
#
#--- extract hrc engineer fits files
#
    fits_list = extract_fits_files(time_list,
                                   'hrc',
                                   '0',
                                   'hrc2eng',
                                   subdetector='eng')
    #
    #--- extract data needed
    #
    dout = hcf.combine_and_select_data(fits_list, ['time', msid])
    try:
        chk = float(dout[0][0])
        if chk > 1000:
            pass
        else:
            return [[], []]
    except:
        return [[], []]
#
#--- select time with 2pre<a/b>ds == hrc_type (either hrc i or hrc s coditino)
#
    odata = hcf.select_data_with_condition(dout, msid, '==', hrc_type)
    #
    #--- get lists of start and stop time periods
    #
    tlist = list(odata.field('TIME'))
    rlist = find_time_span(tlist, start, stop)
    #
    #--- remove indivisual fits files
    #
    for ent in fits_list:
        mcf.rm_file(ent)

    return rlist
Esempio n. 4
0
def find_evt_stat(efits, chip_id=''):
    """
    find count rate, pha postion from hrc evt 1 file
    input   efits   --- hrc evt1 fits file name
            chip_id     --- chip_id for hrc_s_125 and hrc_s_90; default: 0
    output: date_obs    --- date of observation
            tstart      --- starting time in seconds from 1998.1.1
            tstop       --- stopping time in seconds from 1998.1.1
            avg         --- average of pha
            med         --- mediam of pha
            std         --- standard deviation of pha
            duration    --- duration of the evt1 data
            tcnt        --- the number of entries
            cnt_p_sec   --- counts per second
    """
    #
    #--- read values from header
    #
    date_obs = hcf.read_header_value(efits, 'date-obs')
    tstart = hcf.read_header_value(efits, 'tstart')
    tstop = hcf.read_header_value(efits, 'tstop')
    #
    #--- read data
    #
    [cols, tbdata] = hcf.read_fits_file(efits)
    #
    #--- if chip_id is given, select out the data for the chip_id
    #
    if chip_id != '':
        tbdata = hcf.select_data_with_condition(tbdata, 'chip_id', '==',
                                                chip_id)
#
#--- find stat of pha
#
    [avg, med, std, vmin, vmax, vcnt] = get_basic_stat(tbdata['pha'])
    #
    #--- find time related quantities
    #
    time = tbdata['time']
    [tavg, tmed, tstd, tmin, tmax, tcnt] = get_basic_stat(tbdata['time'])
    #
    #--- compute duration etc
    #
    duration = tmax - tmin
    if duration > 0:
        cnt_p_sec = tcnt / duration
    else:
        cnt_p_sec = 0

    return [date_obs, tstart, tstop, avg, med, std, duration, tcnt, cnt_p_sec]
Esempio n. 5
0
def create_data_period(start, stop, dlist, colname='', lgc='', val=''):
    """
    create a pair of time lists which indicate when tscpos is in positive side
    input:  start       --- starting time in mm/dd/yy,hh:mm:ss or seconds from 1998.1.1
            stop        --- stopping time in mm/dd/yy,hh:mm:ss or seconds from 1998.1.1
            dlist       --- a list of fits file names
            colname     --- if given, the following two must be given. default: ''
            lgc         --- logical indicator such as "<=", "==". not effective unless colname is given
            val         --- value of the condition. not effective unless colname is given
    output: start_list  --- a list of starting time in format of seconds from 1998.1.1
            stop_list   --- a list of stopping tine in format of seconds from 1998.1.1
            
    """
    #
    #--- check time format
    #
    if (not isinstance(start, float)) and (not isinstance(start, int)):
        start = hcf.convertto1998sec(start)
        stop = hcf.convertto1998sec(stop)

    time_list = []
    chk = 0
    for fits in dlist:
        #
        #--- extract time and tscpos information from fits file
        #
        [cols_in, hdata] = hcf.read_fits_file(fits)
        #
        #--- if an extra condition is given, run the next
        #
        if colname != '':
            hdata = hcf.select_data_with_condition(hdata, colname, lgc, val)
        else:
            pass

        tlist = list(hdata.field('TIME'))

        if chk == 0:
            time_list = tlist
            chk = 1
        else:
            time_list = time_list + tlist
#
#--- create two lists: starting time and ending time
#
    time_list = sort_and_clean(time_list)

    t_lists = find_time_span(time_list, start, stop)

    return t_lists
Esempio n. 6
0
def get_time_period_engineer_data(time_list, hrc_type, start, stop):
    """
    extract time period in which hrc engireer data gives  2preads=hrc type
    input:  time_list   --- a list of lists of starting and stoppping time
                            from previous condition
            hrc_type    --- hrc type either IMG or SPEC
            start       --- start time of the entire period
            stop        --- stop time of the entire period
    output: rlist       --- a list of lists of starting and stoppping time
    """
#
#--- extract hrc engineer fits files
#
    fits_list = extract_fits_files(time_list, 'hrc', '0', 'hrc2eng', subdetector='eng')
#
#--- extract data needed
#
    dout = hcf.combine_and_select_data(fits_list, ['time','2PREADS'])
    if dout == NULL:
        return [[], []]
#
#--- select time with 2preads == hrc_type (either hrc i or hrc s coditino)
#
    odata = hcf.select_data_with_condition(dout ,'2PREADS', '==', hrc_type)
#
#--- get lists of start and stop time periods
#
    tlist = list(odata.field('TIME'))
    rlist = find_time_span(tlist, start, stop) 
#
#--- remove indivisual fits files
#
    for ent in fits_list:
        mcf.rm_file(ent)

    return rlist
Esempio n. 7
0
def find_antico_rate(ss_file, tstart, tstop):
    """
    find a ratio of valid/total of anti-co data
    input:  ss_file --- science fits file name
            tstart  --- starting time in seconds from 1998.1.1
            tstop   --- stopping tine in seconds from 1998.1.1
    output: tstat   --- statistics of tlevart column
            vstat   --- statistics of vlevart column
            sstat   --- statistics of shevart column
            astat   --- statistics of antico values
            see get_basic_stat for output (a list of statistics)
    """
    [cols, tbdata] = hcf.read_fits_file(ss_file)

    tbdata = hcf.select_data_with_condition(tbdata, 'time', ">=", tstart)
    tbdata = hcf.select_data_with_condition(tbdata, 'time', "<=", tstop)
    #
    #--- remove outlyers; the first several entries are not reliable
    #
    tbdata = hcf.select_data_with_condition(tbdata, 'tlevart', ">", 0)
    tbdata = hcf.select_data_with_condition(tbdata, 'tlevart', "<", 500)
    tbdata = hcf.select_data_with_condition(tbdata, 'vlevart', ">", 0)
    tbdata = hcf.select_data_with_condition(tbdata, 'vlevart', "<", 300)

    tlevart = tbdata['tlevart']
    vlevart = tbdata['vlevart']
    shevart = tbdata['shevart']
    #
    #--- compute antico values
    #
    antico = vlevart / tlevart  #--- array / array gives array
    #
    #--- compute basic statistics for each column
    #
    tstat = get_basic_stat(tlevart)
    vstat = get_basic_stat(vlevart)
    sstat = get_basic_stat(shevart)
    astat = get_basic_stat(antico)
    #
    #--- output are in a list: [avg, med, std, min, max, cnt]
    #
    return [tstat, vstat, sstat, astat]