def read_interrupt():
    """
    read the list of period, interruption start and end 
    input:  all_data    --- the list of period, interruption start and end
    output: [period, interrupt_start, interrupt_stop], but time is in seconds from 1998.1.1
    """
#
#--- read data
#
    file = house_keeping + '/all_data'
    f    = open(file, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()
    data.reverse()

    period          = []
    interrupt_start = []
    interrupt_stop  = []
#
#--- convert the date in yyyy:mm:hh:ss to seconds from 1998.1.1
#
    for ent in data:
        atemp = re.split('\s+', ent)
        btemp = re.split(':', atemp[1])
        start = tcnv.convertDateToTime2(int(btemp[0]), int(btemp[1]), int(btemp[2]), int(btemp[3]), int(btemp[4]), 0)
        btemp = re.split(':', atemp[2])
        stop  = tcnv.convertDateToTime2(int(btemp[0]), int(btemp[1]), int(btemp[2]), int(btemp[3]), int(btemp[4]), 0)
#
#--- save the list again
#
        period.append(atemp[0])
        interrupt_start.append(float(start))
        interrupt_stop.append(float(stop))

    return [period, interrupt_start, interrupt_stop]
Пример #2
0
def find_date_from_line(line):
    """
    find time from the data line 
    input:  line    --- data line. the line format must bei (for example):
                        2014 10 20  0120   56950   4800  9.10e-01  1.94e-01 ....
    output: dst     --- time in seconds from 1998.1.1
                        if the format does nto match, return -999
    """

    if line[0].isdigit():
        try:
            atemp = re.split('\s+', line)
            year  = int(float(atemp[0]))
            mon   = int(float(atemp[1]))
            day   = int(float(atemp[2]))
            hh    = atemp[3][0] + atemp[3][1]
            hh    = int(float(hh))
            mm    = atemp[3][2] + atemp[3][3]
            mm    = int(float(mm))
            dst   = tcnv.convertDateToTime2(year, mon, day, hours=hh , minutes=mm)
            return dst
        except:
            return -999
    else:
        return -999
Пример #3
0
def convert_date_to_sectime(odate):
    """
    convert time in <yyyy>-<mm>-<dd>T<hh>:<mm>:<ss> to seconds from 1998.1.1
    input:  odate   --- date in the format of <yyyy>-<mm>-<dd>T<hh>:<mm>:<ss>
    output: tsce    --- date in seconds from 1998.1.1
    """

    atemp = re.split('\s+', str(odate))
    mon = tcnv.changeMonthFormat(atemp[0])
    day = int(float(atemp[1]))
    year = int(float(atemp[2]))

    mc = re.search('AM', atemp[3])
    if mc is not None:
        time = atemp[3].replace('AM', '')
        btemp = re.split(':', time)
        hrs = int(float(btemp[0]))
        mins = int(float(btemp[1]))
    else:
        time = atemp[3].replace('PM', '')
        btemp = re.split(':', time)
        hrs = int(float(btemp[0])) + 12
        mins = int(float(btemp[1]))

    tsec = tcnv.convertDateToTime2(year, mon, day, hours=hrs, minutes=mins)

    return tsec
Пример #4
0
def convert_date_to_sectime(odate):
    """
    convert time in <yyyy>-<mm>-<dd>T<hh>:<mm>:<ss> to seconds from 1998.1.1
    input:  odate   --- date in the format of <yyyy>-<mm>-<dd>T<hh>:<mm>:<ss>
    output: tsce    --- date in seconds from 1998.1.1
    """

    atemp  = re.split('\s+', str(odate))
    mon    = tcnv.changeMonthFormat(atemp[0])
    day    = int(float(atemp[1]))
    year   = int(float(atemp[2]))

    mc     = re.search('AM', atemp[3])
    if mc is not None:
        time  = atemp[3].replace('AM','')    
        btemp = re.split(':', time)
        hrs   = int(float(btemp[0]))
        mins  = int(float(btemp[1]))
    else:
        time  = atemp[3].replace('PM','')
        btemp = re.split(':', time)
        hrs   = int(float(btemp[0])) + 12
        mins  = int(float(btemp[1]))

    tsec  = tcnv.convertDateToTime2(year, mon, day, hours=hrs, minutes=mins)

    return tsec
Пример #5
0
def make_data_list(year, mon, day, tail):
    """
    make a data list from the last entry date to the most current data
    input:  year    --- the year of the last entry
            mon     --- the month of the last entry
            day     --- the day of month of the last entry
            tail    --- the suffix of the data file 
    output  dlist   --- a list of data names
    """
#
#--- convert the date into seconds from 1998.1.1
#
    dst   = tcnv.convertDateToTime2(year, mon, day)
#
#--- find today's time
#
    today = tcnv.currentTime()
    cyear = today[0]
    cmon  = today[1]
    cday  = today[2]
    cdst  = tcnv.convertDateToTime2(cyear, cmon, cday)

    dlist = []
#
#--- check the current date is larger than the date indicated
#--- if so find how many days between and retrieve data for each day
#
    if cdst > dst:
        step = int(( cdst - dst)/86400)
        if step >= 1:
            head  = make_header(year, mon, day)
            name  = head + tail
            dlist.append(name)

        for i in range(2, step):
            sdate = int(cdst - 86400.0 * i)
            out   = tcnv.axTimeMTA(sdate)
            atemp = re.split(':', out)
            year  = int(atemp[0])
            ydate = int(atemp[1])

            [mon, day] = tcnv.changeYdateToMonDate(year, ydate)
            head  = make_header(year, mon, day)
            name  = head + tail
            dlist.append(name)

    return dlist
Пример #6
0
def read_interrupt():
    """
    read the list of period, interruption start and end 
    input:  all_data    --- the list of period, interruption start and end
    output: [period, interrupt_start, interrupt_stop], but time is in seconds from 1998.1.1
    """
    #
    #--- read data
    #
    #file = house_keeping + '/all_data'
    file = house_keeping + '/atemp'
    f = open(file, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()
    data.reverse()

    period = []
    interrupt_start = []
    interrupt_stop = []
    #
    #--- convert the date in yyyy:mm:hh:ss to seconds from 1998.1.1
    #
    for ent in data:
        atemp = re.split('\s+', ent)
        btemp = re.split(':', atemp[1])
        start = tcnv.convertDateToTime2(int(btemp[0]), int(btemp[1]),
                                        int(btemp[2]), int(btemp[3]),
                                        int(btemp[4]), 0)
        btemp = re.split(':', atemp[2])
        stop = tcnv.convertDateToTime2(int(btemp[0]), int(btemp[1]),
                                       int(btemp[2]), int(btemp[3]),
                                       int(btemp[4]), 0)
        #
        #--- save the list again
        #
        period.append(atemp[0])
        interrupt_start.append(float(start))
        interrupt_stop.append(float(stop))

    return [period, interrupt_start, interrupt_stop]
Пример #7
0
def create_adjusted_cti_tables(ccd_list, sub_dir, sub2_dir_list, out_dir):

    """
    create adjusted cti table: Data119, Data2000, Data7000, Data_cat-adjust
    Input:  ccd_list        --- a list of ccd #
            sub_dir         --- a name of sub directory which cti lists are read
            sub2_dir_list   --- a list of sub directories which adjusted cti tables are deposited
            out_dir         --- a directory name which adjucted cti will be deposited
                cti data are read from <data_dir>/<sub_dir>/<elm>_ccd<ccd #>
    Output: <data_dir>/<dir in sub2_dir_list>/<elm>_ccd<ccd#>
    """

    for elm in elm_list:

        for ccd in ccd_list:

            if (ccd == 5) or (ccd == 7):
                factor = 0.045              #--- these factors are given by C. Grant
            else:
                factor = 0.036
#
#--- read the main data set
#
            read_dir = data_dir + sub_dir + '/' + elm + '_ccd' + str(ccd)

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

            save1 = []
            save2 = []
            save3 = []
            save4 = []

            time3 = []
            time4 = []
            del_temp = []

            for ent in data:
#
#--- convert time format from 2013-10-05T17:35:58 to  year, stime and dom
#
                atemp       = re.split('\s+', ent)

                btemp   = re.split('T', atemp[0])
                ctemp   = re.split('-', btemp[0])
                year    = int(ctemp[0])
                tmon    = int(ctemp[1])
                tday    = int(ctemp[2])
                ctemp   = re.split(':', btemp[1])
                hrs     = int(ctemp[0])
                mins    = int(ctemp[1])
                secs    = int(ctemp[2])
                sectime = tcnv.convertDateToTime2(year, tmon, tday, hours=hrs, minutes=mins, seconds=secs)
                dom     = tcnv.stimeToDom(sectime)
                
                tspan       = int(atemp[12]) - int(atemp[11])
                temperature = float(atemp[7])
#
#--- use only data with the integration time longer than 1000 sec before 2003
#--- and only data with the integration time longer than 2000 sec after 2003
#
                if tspan < 1000:
                    pass
                if (tspan < 2000) and (year >= 2003):
                    pass
                else:
                    line = ent + '\n'
                    save3.append(line)
                    time3.append(dom)
#
#--- we need to adjust focal plane temperature between 9/16/2005 - 10/16/2005
#--- a reported temperature is about 1.3 warmer than a real focal temperature
#--- (from 12/1/05 email from C. Grant)
#
                    if (sectime >= 243215999) and (sectime <= 245894399):
                        temperature -= 1.3

#                    if temperature <= -119.7:
                    if temperature <= -119.5:

                        line = ent + '\n'
                        save1.append(line)

                        if tspan >= 7000:
                            save4.append(line)
                            time4.append(dom)
#
#--- correct temperature dependency with C. Grat factors
#
                    val = factor * (temperature + 119.87)

                    quad0 = select_grant_cti(atemp[1], val)
                    quad1 = select_grant_cti(atemp[2], val)
                    quad2 = select_grant_cti(atemp[3], val)
                    quad3 = select_grant_cti(atemp[4], val)

                    if (quad0 != 'na') and (quad1 != 'na') and (quad2 != 'na') and (quad3 != 'na'):
                        line = atemp[0] + '\t'
                        line = line + quad0    + '\t' + quad1    + '\t' + quad2    + '\t' + quad3    + '\t' 
                        line = line + atemp[5] + '\t' + atemp[6] + '\t' + atemp[7] + '\t' + atemp[8] + '\t'
                        line = line + atemp[9] + '\t' + atemp[10] + '\t' + atemp[11] + '\t' + atemp[12] + '\n'
                        save2.append(line)
#
#--- print out adjsted cti data table
#
            j = 0
            for sdir in sub2_dir_list:
                j += 1
                exec 'sdata = save%s' % (j)
                print_cti_results(sdir, elm, ccd, sdata)
#
#---- compute adjusted cti values and update tables
#
            compute_adjusted_cti(elm, ccd, time3, save3, time4, save4, out_dir)
Пример #8
0
def print_link_sub(shtml, efile):
    #
    #   input: shtml    --- a full html address of the page
    #          efile    --- a full physical address of the file
    #

    #
    #--- find the title of the html page it assumes that of between <title> tags
    #
    f = open(efile, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    note_save = []
    save_line = ''
    nchk = 0
    for line in data:
        mc = re.search('<title>', line)
        if mc is not None:
            atemp = re.split('<title>', line)
            btemp = re.split('<\\title>', atemp[1])
            title = btemp[0]
#
#--- find whether there is any "Note" in this page
#
        mc = re.search('<h3>Note</h3>', line)
        mc2 = re.search('<!--', line)
        if mc is not None:
            nchk = 1
        elif mc2 is not None:
            continue
        elif nchk == 1:
            mc = re.search('<p>', line)
            if mc is not None:
                nchk = 2
        elif nchk == 2:
            mc = re.search('<\/p>', line)
            if mc is not None:
                break
            note_save.append(line)

    save_line = save_line + "<li><a href='" + shtml + "'>" + title + "</a>"
    #
    #--- find the last updated date
    #
    atemp = re.split('\s+', time.ctime(os.path.getmtime(efile)))
    mtime = atemp[1] + ' ' + atemp[2] + ', ' + atemp[4]
    mon = tcnv.changeMonthFormat(atemp[1])
    day = int(float(atemp[2]))
    year = int(float(atemp[4]))
    stime = tcnv.convertDateToTime2(year, mon, day)

    save_line = save_line + "<span style='padding-left:20pxfont-size:90%'>(Last Update: " + mtime + ")</span></li>"
    #
    #----returning "Note"
    #
    note = ''
    if len(note_save) > 0:
        for ent in note_save:
            ent = ent.strip()
            test = ent.replace('\s|\t|\n', "")
            if ent != "None" and ent != "NONE" and ent != "NA" and ent != 'na' and ent != '':
                note = note + ' ' + ent

    return [save_line, note, stime]
def print_link_sub(shtml, efile):
#
#   input: shtml    --- a full html address of the page
#          efile    --- a full physical address of the file
#

#
#--- find the title of the html page it assumes that of between <title> tags
#
    f    = open(efile, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    note_save = []
    save_line = ''
    nchk      = 0
    for line in data:
        mc  = re.search('<title>', line)
        if mc is not None:
            atemp = re.split('<title>', line)
            btemp = re.split('<\\title>', atemp[1])
            title = btemp[0]
#
#--- find whether there is any "Note" in this page
#
        mc  = re.search('<h3>Note</h3>', line)
        mc2 = re.search('<!--', line)
        if mc is not None:
            nchk = 1
        elif mc2 is not None:
            continue
        elif nchk == 1:
            mc = re.search('<p>', line)
            if mc is not None:
                nchk = 2
        elif nchk == 2:
            mc = re.search('<\/p>', line)
            if mc is not None:
                break
            note_save.append(line)


    save_line = save_line +  "<li><a href='" + shtml + "'>" + title + "</a>"
#
#--- find the last updated date
#
    atemp = re.split('\s+', time.ctime(os.path.getmtime(efile)))
    mtime = atemp[1] + ' ' + atemp[2] + ', ' + atemp[4]
    mon   = tcnv.changeMonthFormat(atemp[1])
    day   = int(float(atemp[2]))
    year  = int(float(atemp[4]))
    stime = tcnv.convertDateToTime2(year, mon, day)

    save_line = save_line +  "<span style='padding-left:20pxfont-size:90%'>(Last Update: " + mtime + ")</span></li>"
#
#----returning "Note"
#
    note = ''
    if len(note_save) > 0:
        for ent in note_save:
            ent = ent.strip()
            test = ent.replace('\s|\t|\n',"")
            if ent != "None" and ent != "NONE" and ent != "NA" and ent !='na' and ent != '':
                note = note +  ' ' + ent

    return [save_line, note, stime]