Example #1
0
def define_x_range(dlist, xunit=''):

    """
    set time plotting range
    Input:  dlist       --- list of data files (e.g., Data_2012_09)
    Output: start       --- starting time in either DOM or fractional year
            end         --- ending time in either DOM or fractional year
    """

    num = len(dlist)
    if num == 1:
        atemp  = re.split('Data_', dlist[0])
        btemp  = re.split('_',     atemp[1])
        year   = int(btemp[0])
        month  = int(btemp[1])
        nyear  = year
        nmonth = month + 1
        if nmonth > 12:
            nmonth = 1
            nyear += 1
    else:
        slist  = sorted(dlist)
        atemp  = re.split('Data_', slist[0])
        btemp  = re.split('_',     atemp[1])
        year   = int(btemp[0])
        month  = int(btemp[1])

        atemp  = re.split('Data_', slist[len(slist)-1])
        btemp  = re.split('_',     atemp[1])
        tyear  = int(btemp[0])
        tmonth = int(btemp[1])
        nyear  = tyear
        nmonth = tmonth + 1
        if nmonth > 12:
            nmonth = 1
            nyear += 1

    start  = tcnv.findDOM(year,  month,  1, 0, 0, 0)
    end    = tcnv.findDOM(nyear, nmonth, 1, 0, 0, 0)   
#
#--- if it is a long term, unit is in year
#
    if xunit == 'year':
        [syear, sydate] = tcnv.DOMtoYdate(start)
        chk = 4.0 * int(0.25 * syear)
        if chk == syear:
            base = 366
        else:
            base = 365
        start = syear + sydate/base
        [eyear, eydate] = tcnv.DOMtoYdate(end)
        chk = 4.0 * int(0.25 * eyear)
        if chk == eyear:
            base = 366
        else:
            base = 365
        end   = eyear + eydate/base

    return [start, end]
Example #2
0
def mv_old_file(dom):

    dom -= 30
    if dom > 0:
        [year, ydate] = tcnv.DOMtoYdate(dom)
        sydate = str(ydate)
        if ydate < 10:
            sydate = '00' + sydate
        elif ydate < 100:
            sydate = '0' + sydate

        atime = str(year) + ':' + sydate + ':00:00:00'
        stime = tcnv.axTimeMTA(atime)

        cmd = 'ls ' + house_keeping + '/Defect/CCD*/* > ' + zspace
        os.system(cmd)
        fs = open(zspace, 'r')
        ldata = [line.strip() for line in fs.readlines()]
        fs.close()
        mcf.rm_file(zspace)
        for ent in ldata:
            atemp = re.split('\/acis', ent)
            btemp = re.split('_', atemp[1])
            if int(btemp[0]) < stime:
                out = ent
                out = out.replace('Defect', 'Defect/Save')
                cmd = 'mv ' + ent + ' ' + out
                os.system(cmd)
Example #3
0
def read_rad_zone_data(start, stop):
    """
    extract radiation zone information for a given time span
    input:  start       --- starting time
            stop        --- stopping time
            data are read from /data/mta/Script/Interrupt/house_keeping/rad_zone_info
    output: rad_start   --- a list of radiation zone starting time
            rad_stop    --- a list of radiation zone stopping time
    """

    f = open('/data/mta/Script/Interrupt/house_keeping/rad_zone_info', 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    rad_start = []
    rad_stop = []
    rad_in = 0

    for ent in data:
        atemp = re.split('\s+', ent)
        try:
            val = float(atemp[1])  #---- check time is in digit (dom)
        except:
            continue

        [year, ydate] = tcnv.DOMtoYdate(float(atemp[1]))
        #
        #--- convert time to sec from 1998.1.1
        #
        day_part = int(ydate)
        rest = ydate - day_part
        hour = int(24 * rest)
        rest = 24 * rest - hour
        minutes = int(60 * rest)

        ltime = str(year) + ':' + str(day_part) + ':' + str(hour) + ':' + str(
            minutes) + ':00'
        stime = tcnv.axTimeMTA(ltime)

        if stime >= start and stime < stop:
            if atemp[0] == 'ENTRY' and rad_in == 0:
                rad_start.append(stime)
                rad_in = 1
            elif atemp[0] == 'EXIT' and rad_in == 1:
                rad_stop.append(stime)
                rad_in = 0
        elif stime >= stop:
            break
        else:
            continue

    if len(rad_stop) < len(rad_start):
        rad_stop.append(stop)

    return [rad_start, rad_stop]
Example #4
0
def get_rad_zone(period):
    """
    read rad_zone_list
    input:  period  --- the period name of the interruption
    output: rad_zone    --- a list of lists of radiation zone start time and stop time
    """

    file = house_keeping + 'rad_zone_list'
    f = open(file, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    rad_zone = ''
    for ent in data:
        atemp = re.split('\s+', ent)
        if atemp[0] == period:
            rad_zone = atemp[1]
            break

    if rad_zone == '':
        return [0, 0]
    else:
        #
        #--- if there are values, convert them into ydate (no year part kept)
        #
        start_list = []
        stop_list = []
        atemp = re.split(':', rad_zone)
        for line in atemp:
            atemp = re.split('\(', line)
            btemp = re.split('\)', atemp[1])
            ent = re.split('\,', btemp[0])
            temp = tcnv.DOMtoYdate(float(ent[0]))
            start_list.append(temp[1])

            temp = tcnv.DOMtoYdate(float(ent[1]))
            stop_list.append(temp[1])

        rad_zone = [start_list, stop_list]

    return rad_zone
Example #5
0
def readRadZone(event):

    "read radiation zone data from 'rad_zone_list. Format: 20120313    (4614.2141112963,4614.67081268519):(4616.8308428125,4617.31948864583):.."

    file = house_keeping + 'rad_zone_list'

    f = open(file, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    radZone = []

    for ent in data:
        atemp = re.split('\s+|\t+', ent)
        if atemp[0] == event:
            btemp = re.split(':', atemp[1])
            for line in btemp:
                ctemp = re.split('\(', line)
                dtemp = re.split('\)', ctemp[1])
                etemp = re.split('\,', dtemp[0])

                (year1, ydate1) = tcnv.DOMtoYdate(
                    float(etemp[0])
                )  #--- function from convertTimeFormat.py: change dom to ydate
                (year2, ydate2) = tcnv.DOMtoYdate(float(etemp[1]))
                if year1 == year2:
                    line = str(ydate1) + ':' + str(ydate2)
                    radZone.append(line)
                else:
                    chk = 4.0 * int(0.25 * year1)
                    if chk == year1:
                        base = 366
                    else:
                        base = 365

                    temp = ydate2 + base
                    line = str(ydate1) + ':' + str(temp)
                    radZone.append(line)

    return radZone
Example #6
0
def read_data(file):
    """
    read data from a given file
    Input:  file    --- input file name
    Output: date_list   --- a list of date
            ede_list    --- a list of ede value
            error_list  --- a list of computed ede error
    """

    f = open(file, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    date_list = []
    ede_list = []
    error_list = []
    for ent in data:
        atemp = re.split('\s+', ent)
        if mcf.chkNumeric(atemp[0]) == False:
            continue

        fwhm = float(atemp[2])
        ferr = float(atemp[3])
        ede = float(atemp[4])
        dom = float(atemp[10])
        (year, ydate) = tcnv.DOMtoYdate(dom)
        if tcnv.isLeapYear(year) == 1:
            base = 366
        else:
            base = 365
        fyear = year + ydate / base
        date_list.append(fyear)
        ede_list.append(ede)
        #
        #--- the error of EdE is computed using FWHM and its error value
        #
        error = math.sqrt(ede * ede * ((ferr * ferr) / (fwhm * fwhm)))

        error_list.append(error)

    return [date_list, ede_list, error_list]