Esempio n. 1
0
    def test_combine_evt1_files(self):

        #
        #--- make a list of all evt1 file of the year
        #
        year = 2000
        hdir = 'hrc_i_115'
        e_list = get_evt1_list(year, hdir)
        if len(e_list) == 0:
            print("Something wrong in getting files")
#
#--- combined all evt1 files of the year
#
        oname = 'test_combined_evt1.fits'
        hcf.combine_fits_files(e_list, oname)

        tstart = hcf.read_header_value(oname, 'tstart')
        tstop = hcf.read_header_value(oname, 'tstop')

        tstart = int(float(tstart))
        tstop = int(float(tstop))

        self.assertEquals(tstart, 65961070)
        self.assertEquals(tstop, 93190294)

        mcf.rm_files(oname)
Esempio n. 2
0
def extract_data_and_combine(time_list,
                             detector,
                             level,
                             filetype,
                             name,
                             fcol_line=''):
    """
    extract fits files in the time span(s) and combine all of them to one fits file
    input:  time_list   --- a list of lists [[start_time>],[<stop_time>]]
            detector    --- detector name (e.g. hrc)
            level       --- level (e.g. 0, 1)
            filetype    --- file type (e.g. hrcss, hrchk)
            name        --- name of the resulted combined fits file
    output: name        --- resulted fits file
    """
    #
    #--- extreact files
    #
    fits_list = extract_fits_files(time_list, detector, level, filetype)
    #
    #--- combine fits file to one
    #
    hcf.combine_fits_files(fits_list, name, azip=0, fcol_line=fcol_line)
    #
    #--- remove indivisual fits files
    #
    for ent in fits_list:
        mcf.rm_file(ent)
Esempio n. 3
0
def combine_short_exposure_files(evt1_list):
    """
    combine evt1 files if the time difference between two fits files is less than < 180 sec
    output: combined fits files if they meet the condition
    """
    #
    #--- check whether the file exists
    #
    if len(evt1_list) < 2:
        return evt1_list

    else:
        #
        #-- find the first evt1 file start and stop time
        #
        out_list = []
        prev = evt1_list[0]
        [pstart, pstop] = find_start_and_end(prev)

        for i in range(1, len(evt1_list)):
            #
            #--- check the next evt1 file and check whether the time span is less than 180 sec
            #--- if so, combine them
            #
            [nstart, nstop] = find_start_and_end(evt1_list[i])

            if (nstart - pstop) < 180:
                hcf.combine_fits_files([prev, evt1_list[i]], prev)
                #
                #--- remove the added evt1 file
                #
                cmd = 'rm ' + evt1_list[i]
                os.system(cmd)
            else:
                out_list.append(prev)

                prev = evt1_list[i]
                pstart = nstart
                pstop = nstop

        out_list.append(prev)

        return out_list
Esempio n. 4
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. 5
0
def create_image_file(hdir, year,  oname, lev1, lev2, instmap, sbin,\
                      factor, lev1_opt, lev2_opt, sec=''):
    """
    create lev1 and lev2 image files from evt1 file
    input:  hdir    --- instrument name, e,g hrc_i_125
            year    --- the year that the data is processed
            oname   --- evt1 fits file name
            lev1    --- lev1 output fits file name
            lev2    --- lev2 output fits file name
            instmap --- the name of instrument map
            sbin    --- binning size (usually 128 or 256)
            factor  --- normalization factor
            lev2_opt--- option to be used to compute lev2 image file
    output: lev1, lev2, and instmap fits files
    """
    #
    #--- make a list of all evt1 file of the year
    #
    e_list = get_evt1_list(year, hdir)
    if len(e_list) == 0:
        return NULL
#
#--- combined all evt1 files of the year
#
    if (sec == '') or (sec == 1):
        hcf.combine_fits_files(e_list, oname, azip=0)
#
#--- lev 1 image
#
    create_binned_image(oname,
                        'temp_img.fits',
                        xsize=sbin,
                        ysize=sbin,
                        opt1=lev1_opt,
                        opt2='image')
    os.system('cp temp_img.fits comb_temp_img.fits')
    #
    #--- normalized by factor
    #
    img_calc('temp_img.fits', outfile=lev1, factor=factor)
    #
    #--- lev 2 image: bit corrected image
    #
    create_binned_image(oname,
                        'temp_img.fits',
                        xsize=sbin,
                        ysize=sbin,
                        opt1=lev2_opt,
                        opt2='image')
    #
    #---  for the case of hrc i
    #
    if hdir == 'hrc_i_115':
        #
        #--- compute a instrument map
        #
        create_inst_map(oname, instmap)
        #
        #--- normalized with the instrument map
        #
        img_calc('temp_img.fits',
                 instmap,
                 outfile='temp_norm_img.fits',
                 method='div')
        #
        #--- normalized by the factor
        #
        img_calc('temp_norm_img.fits', outfile=lev2, factor=factor)
#
#--- for the case of hrc s
#
    else:
        img_calc('temp_img.fits', outfile=lev2, factor=factor)
#
#--- clean up!
#
    cmd = 'rm ' + exc_dir + '*.fits'
    os.system(cmd)