Exemple #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]
Exemple #2
0
def plot_dusk_result(diskName, duskName, nameList, pastData):

    #
    #--- find the disk capacity of the given disk
    #
    disk_capacity = diskCapacity(diskName)

    #
    #--- read the output from dusk
    #
    line = run_dir + duskName
    f = open(line, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()
    capacity = {}  #---- make a dictionary
    for ent in data:
        atemp = re.split('\s+|\t+', ent)
        try:
            val = 100.0 * float(atemp[0]) / disk_capacity
            val = round(val, 2)
            capacity[atemp[1]] = val
        except:
            pass
#
#--- today's date
#
    today = tcnv.currentTime('local')
    year = today[0]
    month = today[1]
    day = today[2]
    hours = today[3]
    minutes = today[4]
    seconds = today[5]
    #
    #--- convert to dom
    #
    dom = tcnv.findDOM(year, month, day, hours, minutes, seconds)
    dom = round(dom, 2)
    #
    #--- append the new data to the data table
    #
    f = open(pastData, 'a')
    f.write(str(dom))
    for dName in nameList:
        f.write(':')
        string = str(capacity[dName])
        f.write(string)
    f.write('\n')
    f.close()

    #
    #---- start plotting history data
    #
    try:
        plot_history_trend(diskName, duskName, nameList, pastData)
    except:
        pass
def plot_dusk_result(diskName, duskName, nameList, pastData):

#
#--- find the disk capacity of the given disk
#
    disk_capacity = diskCapacity(diskName)

#
#--- read the output from dusk
#
    line = run_dir + duskName
    f    = open(line, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()
    capacity = {}               #---- make a dictionary
    for ent in data:
        atemp = re.split('\s+|\t+', ent)
        try:
            val = 100.0 * float(atemp[0]) /disk_capacity
            val =  round(val, 2)
            capacity[atemp[1]] = val 
        except:
            pass
#
#--- today's date
#
    today   = tcnv.currentTime('local')
    year    = today[0]
    month   = today[1]
    day     = today[2]
    hours   = today[3]
    minutes = today[4]
    seconds = today[5]
#
#--- convert to dom
#
    dom   = tcnv.findDOM(year, month, day, hours, minutes,seconds)
    dom   = round(dom, 2)
#
#--- append the new data to the data table
#
    f   = open(pastData, 'a')
    f.write(str(dom))
    for dName in nameList:
        f.write(':')
        string = str(capacity[dName])
        f.write(string)
    f.write('\n')
    f.close()

#
#---- start plotting history data
#
    try:
        plot_history_trend(diskName, duskName, nameList, pastData)
    except:
        pass
Exemple #4
0
def convertTime(line):
    """
    extract time part from a data path (year, month, day) and covnert to DOM 
    Input:  line  --- fits file name (with a full data path)
                      example: /dsops/ap/sdp/cache/2013_05_26/acis/acisf485989498N001_5_bias0.fits
    Output: ctime --- file creation date in DOM
    """

    atemp = re.split('\/', line)
    btemp = re.split('_', atemp[5])
    year = int(btemp[0])
    month = int(btemp[1])
    day = int(btemp[2])

    ctime = tcnv.findDOM(year, month, day, 0, 0, 0)  #---- day of mission

    return ctime
def convertTime(line):

    """
    extract time part from a data path (year, month, day) and covnert to DOM 
    Input:  line  --- fits file name (with a full data path)
                      example: /dsops/ap/sdp/cache/2013_05_26/acis/acisf485989498N001_5_bias0.fits
    Output: ctime --- file creation date in DOM
    """

    atemp = re.split('\/', line)
    btemp = re.split('_', atemp[5])
    year  = int(btemp[0])
    month = int(btemp[1])
    day   = int(btemp[2])

    ctime = tcnv.findDOM(year, month, day, 0, 0, 0)             #---- day of mission

    return ctime
Exemple #6
0
def find_dom_from_mp_file(ent):
    """
    find dom date from the direoctry path name
    input:  ent --- full path to the file <mp_dir>/<date>/...
    output: dom --- day of mission
    """

    atemp = re.split(mp_dir, ent)
    btemp = atemp[1].replace('/', '')
    year = btemp[0] + btemp[1] + btemp[2] + btemp[3]
    month = btemp[4] + btemp[5]
    day = btemp[6] + btemp[7]
    year = int(float(year))
    month = int(float(month))
    day = int(float(day))

    ydate = tcnv.findYearDate(year, month, day)
    dom = tcnv.findDOM(year, ydate, 0, 0, 0)

    return dom
def cleanEntry(line):

    "Clean up Radiation zone Entry/Exist information suitable for use.  See extractRadZoneInfo "


    temp1 = re.split('\s+', str(line))
    temp2 = re.split('=',   temp1[0])
    ctime = temp2[1]
    dtime = re.split(':',   temp2[1])

    dom   = tcnv.findDOM(float(dtime[0]), float(dtime[1]), float(dtime[2]), float(dtime[3]), float(dtime[4]))   #--- get Day of Mission

    m = re.search('RADENTRY', line)
    if m is not None: 
        act = 'ENTRY'
    else:
        act = 'EXIT'

    line = act + '\t' + str(dom) + '\t' + str(ctime)

    return line
Exemple #8
0
def cleanEntry(line):

    "Clean up Radiation zone Entry/Exist information suitable for use.  See extractRadZoneInfo "

    temp1 = re.split('\s+', str(line))
    temp2 = re.split('=', temp1[0])
    ctime = temp2[1]
    dtime = re.split(':', temp2[1])

    dom = tcnv.findDOM(float(dtime[0]), float(dtime[1]), float(dtime[2]),
                       float(dtime[3]),
                       float(dtime[4]))  #--- get Day of Mission

    m = re.search('RADENTRY', line)
    if m is not None:
        act = 'ENTRY'
    else:
        act = 'EXIT'

    line = act + '\t' + str(dom) + '\t' + str(ctime)

    return line
def update_datatable(per0, per1, per2, per3, per4, per5, per6, per7, per8):
    """
    this function appends the newest data to the disk space data table
    Input: per0 ... per5: new measures for each disk. currently per3 is empty
    Output: <data_out>/disk_space_data (updated)
    """

    #
    #--- find out today's date in Local time frame
    #
    today = tcnv.currentTime('local')
    year = today[0]
    month = today[1]
    day = today[2]
    hours = today[3]
    minutes = today[4]
    seconds = today[5]
    #
    #--- convert to dom
    #
    dom = tcnv.findDOM(year, month, day, hours, minutes, seconds)
    dom = round(dom, 3)
    #
    #--- today's data
    #
    line = str(dom) + '\t' + str(per0) + '\t' + str(per1) + '\t' + str(
        per2) + '\t' + str(per4) + '\t' + str(per5) + '\t' + str(
            per6) + '\t' + str(per7) + '\t' + str(per8) + '\t'
    #
    #--- append to the data table
    #
    file = data_out + 'disk_space_data'
    f = open(file, 'a')
    f.write(line)
    f.write("\n")
    f.close()
Exemple #10
0
def sci_run_compute_gap(file):
    """
    for a given file name which contains a list, recompute the lost science time (excluding radiation zone) 
    input:  file    --- the file containing information, e.g.:
        20120313        2012:03:13:22:41        2012:03:14:13:57         53.3   auto" 
    output: file    --- updated file
    """
    #
    #--- if file is not given (if it is NA), ask the file input
    #
    test = exc_dir + file
    if not os.path.isfile(test):
        file = raw_input('Please put the intrrupt timing list: ')

    f = open(file, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()
    #
    #--- a starting date of the interruption in yyyy:mm:dd:hh:mm (e.g., 2006:03:20:10:30)
    #--- there could be multiple lines of date; in that is the case, the scripts add the rad zone list
    #--- to each date
    #

    update = []

    for ent in data:

        if not ent:  #--- if it is a blank line end the operation
            break

        etemp = re.split('\s+', ent)
        atemp = re.split(':', etemp[1])
        year = atemp[0]
        month = atemp[1]
        date = atemp[2]
        hour = atemp[3]
        mins = atemp[4]
        #
        #--- convert to dom/sec1998
        #
        ydate = tcnv.findYearDate(int(year), int(month), int(date))
        dom = tcnv.findDOM(int(year), int(ydate), int(hour), int(mins), 0)
        line = year + ':' + str(ydate) + ':' + hour + ':' + mins + ':00'
        csec = tcnv.axTimeMTA(line)
        #
        #--- end date
        #

        atemp = re.split(':', etemp[2])
        eyear = atemp[0]
        emonth = atemp[1]
        edate = atemp[2]
        ehour = atemp[3]
        emins = atemp[4]

        ydate = tcnv.findYearDate(int(eyear), int(emonth), int(edate))
        dom2 = tcnv.findDOM(int(eyear), int(ydate), int(ehour), int(emins), 0)
        line = eyear + ':' + str(ydate) + ':' + ehour + ':' + emins + ':00'
        csec2 = tcnv.axTimeMTA(line)
        #
        #--- date stamp for the list
        #
        list_date = str(year) + str(month) + str(date)

        #
        #--- read radiation zone information from "rad_zone_list" and add up the time overlap with
        #--- radiatio zones with the interruption time period
        #

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

        sum = 0
        for record in rlist:
            atemp = re.split('\s+', record)
            if list_date == atemp[0]:
                btemp = re.split(':', atemp[1])
                for period in btemp:

                    t1 = re.split('\(', period)
                    t2 = re.split('\)', t1[1])
                    t3 = re.split('\,', t2[0])
                    pstart = float(t3[0])
                    pend = float(t3[1])

                    if pstart >= dom and pstart < dom2:
                        if pend <= dom2:
                            diff = pend - pstart
                            sum += diff
                        else:
                            diff = dom2 - pstart
                            sum += diff
                    elif pstart < dom2 and pend > dom:
                        if pend <= dom2:
                            diff = pend - dom
                            sum += diff
                        else:
                            diff = dom2 - dom
                            sum += diff

                break

        sum *= 86400  #--- change unit from day to sec

        sciLost = (
            csec2 - csec - sum
        ) / 1000  #--- total science time lost excluding radiation zone passes

        line = etemp[0] + '\t' + etemp[1] + '\t' + etemp[
            2] + '\t' + "%.1f" % sciLost + '\t' + etemp[4]

        update.append(line)

    fo = open(file, 'w')
    for line in update:
        fo.write(line)
        fo.write('\n')
    fo.close()

    return update
Exemple #11
0
def update_new_obs_list():

    """
    update new_obs_lsit, too_list, ddt_list, and obs_in_30days
    no input but data are taken from sot_ocat.out.

    """
#
#--- set limit to the last 30  days
#
    [year, mon, day, hours, min, sec, weekday, yday, dst] = tcnv.currentTime('LOCAL')
    tdom = tcnv.findDOM(year, mon, day, 0, 0, 0)
    dom_limit = tdom - 30                      
    dom_limit = tdom - 100                      
    dom30days = tdom + 30                           #---- use to find observations will happen in 30 days
#
#--- read special obsid --- poc list
#
    line = too_dir + 'special_obsid_poc_list'
    f    = open(line, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    sp_obsid = []
    sp_user  = []
    for ent in data:
        atemp = re.split('\s+', ent)
        sp_obsid.append(atemp[0])
        sp_user.append(atemp[1])
#
#--- read database
#
    line = obs_ss + 'sot_ocat.out'
    f    = open(line, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    out_list = []
#
#--- read too_list and ddt_list
#
    line = too_dir + 'too_list'
    fo   = open(line, 'r')
    too  = [line.strip() for line in fo.readlines()]
    fo.close()
    too_dict = {}
    for ent in too:
        atemp = re.split('\s+', ent)
        too_dict[atemp[2]] = ent
    
    line = too_dir + 'ddt_list'
    fo   = open(line, 'r')
    ddt  = [line.strip() for line in fo.readlines()]
    fo.close()
    ddt_dict = {}
    for ent in ddt:
        atemp = re.split('\s+', ent)
        ddt_dict[atemp[2]] = ent
#
#--- open temporary writing files
#
    newf = temp_dir + 'new_obs_list'
    out1 = open(newf, 'w')
    obsf = temp_dir + 'obs_in_30days'
    out2 = open(obsf, 'w')
#
#--- start itelations
#
    for ent in data:
        atemp  = re.split('\^', ent)
        try:
            status = atemp[16].strip().lower()
            date   = atemp[13].strip()
        except:
            continue
#
#--- limit data re-checking to the last 30 days
#
        if str(date).lower() == 'null' or str(date).lower() == 'none':
            dom = 'NA'
        else:
            temp  = re.split('\s+', str(date))
            omon  = tcnv.changeMonthFormat(temp[0])
            oday  = int(temp[1])
            oyear = int(temp[2])
            dom   = tcnv.findDOM(oyear, omon, oday, 0, 0, 0)

        ochk = 0
        if str(date).lower() == 'null' or str(date).lower() == 'none':
            ochk = 1

        else:
            if dom > dom_limit:
                ochk = 1

        if ochk == 1  and (status == 'scheduled' or status == 'unobserved' or status == 'observed'):
            chk   = 0
            obsid = atemp[1].strip()
#
#--- check this obsid is listed on a special_obsid_poc_list
#
            sp_poc = 'na'
            for sval in range(0, len(sp_obsid)):
                if obsid == sp_obsid[sval]:
                    sp_poc = sp_user[sval]
                    break
#
#--- extract basic information
#
            monitor = []
            groupid = []
            try:
                (group_id, pre_id, pre_min_lead, pre_max_lead, grating, type, instrument, obs_ao_str, status, \
                seq_nbr, ocat_propid, soe_st_sched_date, lts_lt_plan,targname, object) = sql.get_target_info(int(obsid), monitor,groupid)
    
                if soe_st_sched_date is not None:
                    date = soe_st_sched_date
                    chk = 1
                elif lts_lt_plan is not None:
                    date = lts_lt_plan
                    chk  = 1
                else:
                    date = 'NA'
                    chk = 0
            except:
                date = 'NA'
                chk = 0
#
#--- check status change
#
            if status == 'scheduled' or status == 'unobserved' or status == 'observed':
#
#--- recompute with updated date
#
                if date == 'NA':
                    dom = 'NA'
                else:
                    temp  = re.split('\s+', str(date))
                    omon  = tcnv.changeMonthFormat(temp[0])
                    oday  = int(temp[1])
                    oyear = int(temp[2])
                    dom   = tcnv.findDOM(oyear, omon, oday, 0, 0, 0)
#
#--- if it is ddt or  too, add to the list anyway
#
                if type.lower() == 'ddt' or type.lower() == 'too':
                    chk = 1
                    if date == 'NA':
                        dom = tdom + 1000
#
#--- the observation is cleared all criteria;  prepare to print them out to files
#
                if chk == 1:
                    pchk = 1
                else:
                    pchk = 0
                    continue
    
                if sp_poc != 'na':
#
#-- for the case the obsid is given a specific poc
#
                    person = sp_poc

                elif type.lower() in ('ddt', 'too'):
                    test = pre_assigned_pos(object, grating)
                    if test != 0:
                        person = test
                    else:
#
#-- too/ddt case: assign poc
#
                        if date == 'NA':
                            person = 'TBD'
                            try:
                                [person, chk]  = tdfnc.find_too_ddt_poc(obsid)
                            except:
                                person = 'TBD'
                        else:
                            try:
                                [person, chk]  = tdfnc.find_too_ddt_poc(obsid)
                            except:
                                person = 'TBD'
#
#--- observed obsid but no poc name -- record mistake; so drop
#
                            if person  == 'TBD':
                                if status == 'observed':
                                    pchk = 0
                else:
#
#--- none too/ddt observations
#
                    person = tdfnc.match_usint_person(type,grating,int(seq_nbr),instrument, targname)
#
#--- print out to files
#
                if pchk == 1:
                    line  = type.lower() + '\t' + str(seq_nbr) + '\t' + obsid + '\t' + status  + '\t'   \
                            + person + '\t' + str(obs_ao_str) + '\t' + str(date) + '\n'
#
#--- if it is ddt or too observation, replace the line in ddt_list or too_list
#
                    if type.lower() == 'ddt':
                        try:
                            line = ddt_dict[obsid]
                            line = line + '\n'
                        except:
                            pass

                    if type.lower() == 'too':
                        try:
                            line = too_dict[obsid]
                            line = line + '\n'
                        except:
                            pass

                    out1.write(line)
    
                    if status != 'observed' and dom < dom30days:
                        out2.write(line)

    out1.close()
    out2.close()

    completeTask(temp_dir, too_dir, 'new_obs_list')
    completeTask(temp_dir, too_dir, 'obs_in_30days')

#
#---- create new_obs_list.txt
#
    ofile = too_dir + 'new_obs_list.txt'
    out   = open(ofile, 'w')
    out.write('Type    Seq #   ObsId   Status          TOO     AO      Observation Date\n')
    out.write('--------------------------------------------------------------------------\n\n')
    out.close()
    cmd = 'cat ' + too_dir + 'new_obs_list >> ' + ofile
    os.system(cmd)
def sci_run_add_to_rad_zone_list(file='NA'):

    'adding radiation zone list to rad_zone_list. input: file name containing: e.g. 20120313        2012:03:13:22:41        2012:03:14:13:57         53.3   auto'
    
#
#--- if file is not given (if it is NA), ask the file input
#

    if file == 'NA':
        file = raw_input('Please put the intrrupt timing list: ')

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

    for ent in data:

#
#--- a starting date of the interruption in yyyy:mm:dd:hh:mm (e.g., 2006:03:20:10:30)
#--- there could be multiple lines of date; in that is the case, the scripts add the rad zone list
#--- to each date
#

        etemp = re.split('\s+', ent)
    
        atemp = re.split(':', etemp[1])
        year  = atemp[0]
        month = atemp[1]
        date  = atemp[2]
        hour  = atemp[3]
        mins  = atemp[4]

#
#--- convert to dom/sec1998
#
        ydate = tcnv.findYearDate(int(year), int(month), int(date))
        dom   = tcnv.findDOM(int(year), int(ydate))
        line  = year + ':' + str(int(ydate)) + ':' + hour + ':' + mins + ':00'
        csec  = tcnv.axTimeMTA(line)

#
#--- end date
#

        atemp  = re.split(':', etemp[2])
        eyear  = atemp[0]
        emonth = atemp[1]
        edate  = atemp[2]
        ehour  = atemp[3]
        emins  = atemp[4]
 
        ydate = tcnv.findYearDate(int(eyear), int(emonth), int(edate))
        dom2  = tcnv.findDOM(int(eyear), int(ydate))
        line  = eyear + ':' + str(int(ydate)) + ':' + ehour + ':' + emins + ':00'
        csec2 = tcnv.axTimeMTA(line)

#
#--- date stamp for the list
#
        list_date = str(year) + str(month) + str(date)

#
#--- check radiation zones for 3 days before to 5 days after from the interruptiondate
#

        begin = dom - 3
        end   = dom2 + 5

#
#--- read radiation zone infornation
#

        infile = house_keeping + '/rad_zone_info'
        f      = open(infile, 'r')
        rdata  = [line.strip() for line in f.readlines()]
        f.close()
    
        status = []
        rdate  = []
        chk    = 0
        last_st= ''
        cnt    = 0
    
        for line in rdata:
            atemp = re.split('\s+', line)
    
            dtime = float(atemp[1])                 #--- dom of the entry or exit
    
            if chk  == 0 and atemp[0] == 'ENTRY' and dtime >= begin:
                status.append(atemp[0])
                rdate.append(dtime)
                chk += 1
                last_st = atemp[0]
                cnt += 1
            elif chk > 0 and dtime >= begin and dtime <= end:
                status.append(atemp[0])
                rdate.append(dtime)
                last_st = atemp[0]
                cnt += 1
            elif atemp[1] > end and last_st == 'EXIT':
                break
            elif atemp[1] > end and last_st == 'ENTRY':
                status.append(atemp[0])
                rdate.append(dtime)
                cnt += 1
                break
            
        f = open('./temp_zone', 'w')

#
#--- a format of the output is, e.g.: '20120313    (4614.2141112963,4614.67081268519):...'
#

        line = list_date + '\t'
        f.write(line)
    
        i = 0
        while i < cnt:
            line = '(' + str(rdate[i]) + ','
            f.write(line)
            i += 1
            if i < cnt-1:
                line = str(rdate[i]) + '):'
                f.write(line)
            else:
                line = str(rdate[i]) + ')\n'
                f.write(line)
            i += 1
    
        f.close()

#
#--- append the past rad zone list 
#

        oldFile = house_keeping + '/rad_zone_list~'
        crtFile = house_keeping + '/rad_zone_list'

#>        cmd = 'cat ' './temp_zone ' + crtFile + ' > /tmp/mta/temp_comb'
        cmd = 'cat '+ './temp_zone ' + crtFile +  ' > ./temp_comb'
        os.system(cmd)

#>        os.systm('rm /tmp/mta/temp_zone')
        os.system('rm ./temp_zone')

#
#--- save the old file and move the update file to rad_zone_list
#

        cmd     = 'chmod 775 ' + crtFile + ' ' +  oldFile
        os.system(cmd)
    
        cmd     = 'mv ' + crtFile + ' ' + oldFile
        os.system(cmd)
    
        cmd     = 'chmod 644 ' +  oldFile
        os.system(cmd)
    
#>        cmd     = 'mv  ' + '/tmp/mta/temp_comb ' + crtFile
        cmd     = 'mv  ' + './temp_comb ' + crtFile
        os.system(cmd)
Exemple #13
0
#
import convertTimeFormat       as tcnv
import mta_common_functions    as mcf
import bad_pix_common_function as bcf
#
#--- temp writing file name
#

rtail  = int(10000 * random.random())
zspace = '/tmp/zspace' + str(rtail)

#
#--- set a dimension for an array: set slightly larger than today's DOM.
#
[dyear, dmon, dday, dhours, dmin, dsec, dweekday, dyday, ddst] = tcnv.currentTime()
ddom = tcnv.findDOM(dyear, dmon, dday, dhours, dmin, dsec)
adim = int(ddom + 100)

#---------------------------------------------------------------------------------------------------
#--- plot_ccd_history: plotting warm pixel history                                               ---
#---------------------------------------------------------------------------------------------------

def plot_ccd_history():

    """
    plotting warm pixel history  
    Input: None but read from:
            <data_dir>/Disp_dir/ccd<ccd>_cnt
            <data_dir>/Disp_dir/bad_ccd<ccd>_cnt
            <data_dir>/Disp_dir/cum_ccd<ccd>_cnt
    Output: <plot_dir>hist_plot<ccd>.png
Exemple #14
0
def sci_run_add_to_rad_zone_list(file='NA'):

    'adding radiation zone list to rad_zone_list. input: file name containing: e.g. 20120313        2012:03:13:22:41        2012:03:14:13:57         53.3   auto'

    #
    #--- check whether the list alread exists; if it does, read which ones are already in the list
    #
    cmd = 'ls ' + house_keeping + '* > ./ztemp'
    os.system(cmd)
    #    f    = open('./ztemp', 'r')
    #    test = f.readlines()
    #    f.close()
    test = open('./ztemp').read()

    m1 = re.search('rad_zone_list', test)
    m2 = re.search('rad_zone_list~', test)

    eventList = []
    echk = 0
    if m1 is not None:
        line = house_keeping + 'rad_zone_list'
        f = open(line, 'r')
        data = [line.strip() for line in f.readlines()]
        f.close()

        for ent in data:
            atemp = re.split('\s+|\t+', ent)
            eventList.append(atemp[0])
            echk = 1

#
#--- if file is not given (if it is NA), ask the file input
#

    if file == 'NA':
        file = raw_input('Please put the intrrupt timing list: ')

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

    #
    #--- put the list in the reverse order
    #
    data.reverse()

    for ent in data:
        if not ent:
            break

#
#--- a starting date of the interruption in yyyy:mm:dd:hh:mm (e.g., 2006:03:20:10:30)
#--- there could be multiple lines of date; in that is the case, the scripts add the rad zone list
#--- to each date
#

        etemp = re.split('\s+', ent)
        echk = 0
        for comp in eventList:
            if comp == etemp[0]:
                echk = 1
                break

        if echk == 0:

            atemp = re.split(':', etemp[1])
            year = atemp[0]
            month = atemp[1]
            date = atemp[2]
            hour = atemp[3]
            mins = atemp[4]

            #
            #--- convert to dom/sec1998
            #
            ydate = tcnv.findYearDate(int(year), int(month), int(date))
            dom = tcnv.findDOM(int(year), int(ydate))
            line = year + ':' + str(
                int(ydate)) + ':' + hour + ':' + mins + ':00'
            csec = tcnv.axTimeMTA(line)

            #
            #--- end date
            #

            atemp = re.split(':', etemp[2])
            eyear = atemp[0]
            emonth = atemp[1]
            edate = atemp[2]
            ehour = atemp[3]
            emins = atemp[4]

            ydate = tcnv.findYearDate(int(eyear), int(emonth), int(edate))
            line = eyear + ':' + str(
                int(ydate)) + ':' + ehour + ':' + emins + ':00'
            csec2 = tcnv.axTimeMTA(line)

            #
            #--- date stamp for the list
            #
            list_date = str(year) + str(month) + str(date)

            #
            #--- check radiation zones for 3 days before to 5 days after from the interruptiondate
            #--- if the interruption lasted longer than 5 days, extend the range 7 more days
            #

            begin = dom - 3
            end = dom + 5

            diff = csec2 - csec
            if diff > 432000:
                end += 7

#
#--- read radiation zone infornation
#

            infile = house_keeping + '/rad_zone_info'
            f = open(infile, 'r')
            rdata = [line.strip() for line in f.readlines()]
            f.close()

            status = []
            rdate = []
            chk = 0
            last_st = ''
            cnt = 0

            for line in rdata:
                atemp = re.split('\s+', line)

                dtime = float(atemp[1])  #--- dom of the entry or exit

                if chk == 0 and atemp[0] == 'ENTRY' and dtime >= begin:
                    status.append(atemp[0])
                    rdate.append(dtime)
                    chk += 1
                    last_st = atemp[0]
                    cnt += 1
                elif chk > 0 and dtime >= begin and dtime <= end:
                    status.append(atemp[0])
                    rdate.append(dtime)
                    last_st = atemp[0]
                    cnt += 1
                elif atemp[1] > end and last_st == 'EXIT':
                    break
                elif atemp[1] > end and last_st == 'ENTRY':
                    status.append(atemp[0])
                    rdate.append(dtime)
                    cnt += 1
                    break

            f = open('./temp_zone', 'w')

            #
            #--- a format of the output is, e.g.: '20120313    (4614.2141112963,4614.67081268519):...'
            #

            line = list_date + '\t'
            f.write(line)

            upper = cnt - 1
            i = 0
            while i < cnt:
                line = '(' + str(rdate[i]) + ','
                f.write(line)
                i += 1
                if i < upper:
                    line = str(rdate[i]) + '):'
                    f.write(line)
                else:
                    line = str(rdate[i]) + ')\n'
                    f.write(line)
                i += 1

            f.close()

            #
            #--- append the past rad zone list
            #

            oldFile = house_keeping + '/rad_zone_list~'
            crtFile = house_keeping + '/rad_zone_list'

            if m1 is not None:
                cmd = 'cat ' + './temp_zone ' + crtFile + ' > ./temp_comb'
                os.system(cmd)

            else:
                os.system('mv .temp_zone ./temp_comb')

            os.system('rm ./temp_zone')

            #
            #--- save the old file and move the update file to rad_zone_list
            #

            if m2 is not None:
                cmd = 'chmod 775 ' + crtFile + ' ' + oldFile
                os.system(cmd)

            if m1 is not None:
                cmd = 'mv ' + crtFile + ' ' + oldFile
                os.system(cmd)

                cmd = 'chmod 644 ' + oldFile
                os.system(cmd)

            cmd = 'mv  ' + './temp_comb ' + crtFile
            os.system(cmd)
Exemple #15
0
def check_obs_status(obsid):
    """
    check obsid is eligible to be added to the curren list. 
    input: obsid. if it is either 'scheduled', 'unobserved', or 'observed' status and if it is obsverd
    less than 30 day ago, it is eliible. 
    """
    #
    #--- set limit to the last 30  days
    #
    [year, mon, day, hours, min, sec, weekday, yday,
     dst] = tcnv.currentTime('LOCAL')
    tdom = tcnv.findDOM(year, mon, day, 0, 0, 0)
    dom_limit = tdom - 30

    #
    #--- extract basic information
    #
    monitor = []
    groupid = []
    try:
        (group_id, pre_id, pre_min_lead, pre_max_lead, grating, type, instrument, obs_ao_str, status, \
        seq_nbr, ocat_propid, soe_st_sched_date, lts_lt_plan,targname) = sql.get_target_info(int(obsid), monitor,groupid)

        if soe_st_sched_date is not None:
            date = soe_st_sched_date
            chk = 1
        elif lts_lt_plan is not None:
            date = lts_lt_plan
            chk = 1
        else:
            date = 'NA'
            chk = 0
    except:
        date = 'NA'
        chk = 0
#
#--- check status change
#
    if chk == 1:
        if status == 'scheduled' or status == 'unobserved' or status == 'observed':
            #
            #--- recompute with updated date
            #
            if date == 'NA':
                dom = 'NA'
            else:
                temp = re.split('\s+', str(date))
                omon = tcnv.changeMonthFormat(temp[0])
                oday = int(temp[1])
                oyear = int(temp[2])
                dom = tcnv.findDOM(oyear, omon, oday, 0, 0, 0)

            if dom > dom_limst:
                chk = 1
            else:
                chk = 0

        else:
            chk = 0

    return chk
def update_new_obs_list():

    """
    update new_obs_lsit, too_list, ddt_list, and obs_in_30days
    no input but data are taken from sot_ocat.out.

    """
#
#--- set limit to the last 30  days
#
    [year, mon, day, hours, min, sec, weekday, yday, dst] = tcnv.currentTime('LOCAL')
    tdom = tcnv.findDOM(year, mon, day, 0, 0, 0)
    dom_limit = tdom - 30                      
    dom_limit = tdom - 100                      
    dom30days = tdom + 30                           #---- use to find observations will happen in 30 days
#
#--- read special obsid --- poc list
#
    line = too_dir + 'special_obsid_poc_list'
    f    = open(line, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    sp_obsid = []
    sp_user  = []
    for ent in data:
        atemp = re.split('\s+', ent)
        sp_obsid.append(atemp[0])
        sp_user.append(atemp[1])
#
#--- read database
#
    line = obs_ss + 'sot_ocat.out'
    f    = open(line, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    out_list = []
#
#--- read too_list and ddt_list
#
    line = too_dir + 'too_list'
    fo   = open(line, 'r')
    too  = [line.strip() for line in fo.readlines()]
    fo.close()
    too_dict = {}
    for ent in too:
        atemp = re.split('\s+', ent)
        too_dict[atemp[2]] = ent
    
    line = too_dir + 'ddt_list'
    fo   = open(line, 'r')
    ddt  = [line.strip() for line in fo.readlines()]
    fo.close()
    ddt_dict = {}
    for ent in ddt:
        atemp = re.split('\s+', ent)
        ddt_dict[atemp[2]] = ent
#
#--- open temporary writing files
#
    newf = temp_dir + 'new_obs_list'
    out1 = open(newf, 'w')
    obsf = temp_dir + 'obs_in_30days'
    out2 = open(obsf, 'w')
#
#--- start itelations
#
    for ent in data:
        atemp  = re.split('\^', ent)
        try:
            status = atemp[16].strip().lower()
            date   = atemp[13].strip()
        except:
            continue
#
#--- limit data re-checking to the last 30 days
#
        if str(date).lower() == 'null' or str(date).lower() == 'none':
            dom = 'NA'
        else:
            temp  = re.split('\s+', str(date))
            omon  = tcnv.changeMonthFormat(temp[0])
            oday  = int(temp[1])
            oyear = int(temp[2])
            dom   = tcnv.findDOM(oyear, omon, oday, 0, 0, 0)

        ochk = 0
        if str(date).lower() == 'null' or str(date).lower() == 'none':
            ochk = 1

        else:
            if dom > dom_limit:
                ochk = 1

        if ochk == 1  and (status == 'scheduled' or status == 'unobserved' or status == 'observed'):
            chk   = 0
            obsid = atemp[1].strip()
#
#--- check this obsid is listed on a special_obsid_poc_list
#
            sp_poc = 'na'
            for sval in range(0, len(sp_obsid)):
                if obsid == sp_obsid[sval]:
                    sp_poc = sp_user[sval]
                    break
#
#--- extract basic information
#
            monitor = []
            groupid = []
            try:
                (group_id, pre_id, pre_min_lead, pre_max_lead, grating, type, instrument, obs_ao_str, status, \
                seq_nbr, ocat_propid, soe_st_sched_date, lts_lt_plan,targname, object) = sql.get_target_info(int(obsid), monitor,groupid)
    
                if soe_st_sched_date is not None:
                    date = soe_st_sched_date
                    chk = 1
                elif lts_lt_plan is not None:
                    date = lts_lt_plan
                    chk  = 1
                else:
                    date = 'NA'
                    chk = 0
            except:
                date = 'NA'
                chk = 0
#
#--- check status change
#
            if status == 'scheduled' or status == 'unobserved' or status == 'observed':
#
#--- recompute with updated date
#
                if date == 'NA':
                    dom = 'NA'
                else:
                    temp  = re.split('\s+', str(date))
                    omon  = tcnv.changeMonthFormat(temp[0])
                    oday  = int(temp[1])
                    oyear = int(temp[2])
                    dom   = tcnv.findDOM(oyear, omon, oday, 0, 0, 0)
#
#--- if it is ddt or  too, add to the list anyway
#
                if type.lower() == 'ddt' or type.lower() == 'too':
                    chk = 1
                    if date == 'NA':
                        dom = tdom + 1000
#
#--- the observation is cleared all criteria;  prepare to print them out to files
#
                if chk == 1:
                    pchk = 1
                else:
                    pchk = 0
                    continue
    
                if sp_poc != 'na':
#
#-- for the case the obsid is given a specific poc
#
                    person = sp_poc

                elif type.lower() == 'ddt' or type.lower() == 'too':
#
#-- too/ddt case: assign poc
#
                    if date == 'NA':
                        person = 'TBD'
                    else:
                        try:
                            [person, chk]  = tdfnc.find_too_ddt_poc(obsid)
                        except:
                            person = 'TBD'
#
#--- observed obsid but no poc name -- record mistake; so drop
#
                        if person  == 'TBD':
                            if status == 'observed':
                                pchk = 0
                else:
#
#--- none too/ddt observations
#
                    person = tdfnc.match_usint_person(type,grating,int(seq_nbr),instrument, targname)
#
#--- print out to files
#
                if pchk == 1:
                    line  = type.lower() + '\t' + str(seq_nbr) + '\t' + obsid + '\t' + status  + '\t'   \
                            + person + '\t' + str(obs_ao_str) + '\t' + str(date) + '\n'
#
#--- if it is ddt or too observation, replace the line in ddt_list or too_list
#
                    if type.lower() == 'ddt':
                        try:
                            line = ddt_dict[obsid]
                            line = line + '\n'
                        except:
                            pass

                    if type.lower() == 'too':
                        try:
                            line = too_dict[obsid]
                            line = line + '\n'
                        except:
                            pass

                    out1.write(line)
    
                    if status != 'observed' and dom < dom30days:
                        out2.write(line)

    out1.close()
    out2.close()

    completeTask(temp_dir, too_dir, 'new_obs_list')
    completeTask(temp_dir, too_dir, 'obs_in_30days')

#
#---- create new_obs_list.txt
#
    ofile = too_dir + 'new_obs_list.txt'
    out   = open(ofile, 'w')
    out.write('Type    Seq #   ObsId   Status          TOO     AO      Observation Date\n')
    out.write('--------------------------------------------------------------------------\n\n')
    out.close()
    cmd = 'cat ' + too_dir + 'new_obs_list >> ' + ofile
    os.system(cmd)
def sci_run_compute_gap(file = 'NA'):

    'for a given file name which contains a list like: "20120313        2012:03:13:22:41        2012:03:14:13:57         53.3   auto", recompute the lost science time (excluding radiation zone) '

#
#--- if file is not given (if it is NA), ask the file input
#

    if file == 'NA':
        file = raw_input('Please put the intrrupt timing list: ')

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

#
#--- a starting date of the interruption in yyyy:mm:dd:hh:mm (e.g., 2006:03:20:10:30)
#--- there could be multiple lines of date; in that is the case, the scripts add the rad zone list
#--- to each date
#

    update = []

    for ent in data:

        if not ent:                         #--- if it is a blank line end the operation
            break

        etemp = re.split('\s+', ent)
        atemp = re.split(':', etemp[1])
        year  = atemp[0]
        month = atemp[1]
        date  = atemp[2]
        hour  = atemp[3]
        mins  = atemp[4]

#
#--- convert to dom/sec1998
#
        ydate = tcnv.findYearDate(int(year), int(month), int(date))              #--- a function from convertTimeFormat
        dom   = tcnv.findDOM(int(year), int(ydate), int(hour), int(mins), 0)     #--- a function from convertTimeFormat
        line  = year + ':' + str(ydate) + ':' + hour + ':' + mins + ':00'
        csec  = tcnv.axTimeMTA(line)                                             #--- a function from convertTimeFormat

#
#--- end date
#

        atemp  = re.split(':', etemp[2])
        eyear  = atemp[0]
        emonth = atemp[1]
        edate  = atemp[2]
        ehour  = atemp[3]
        emins  = atemp[4]

        ydate = tcnv.findYearDate(int(eyear), int(emonth), int(edate))
        dom2  = tcnv.findDOM(int(eyear), int(ydate), int(ehour), int(emins), 0)
        line  = eyear + ':' + str(ydate) + ':' + ehour + ':' + emins + ':00'
        csec2 = tcnv.axTimeMTA(line)
    
#
#--- date stamp for the list
#
        list_date = str(year) + str(month) + str(date)

#
#--- read radiation zone information from "rad_zone_list" and add up the time overlap with 
#--- radiatio zones with the interruption time period
#

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

        sum = 0
        for record in rlist:
            atemp = re.split('\s+', record)
            if list_date == atemp[0]:
                btemp = re.split(':', atemp[1])

                for period in btemp:

                    t1 = re.split('\(', period)
                    t2 = re.split('\)', t1[1])
                    t3 = re.split('\,', t2[0])
                    pstart = float(t3[0])
                    pend   = float(t3[1])

                    if pstart >= dom and  pstart < dom2:
                        if pend <= dom2:
                            diff = pend - pstart
                            sum += diff
                        else:
                            diff = dom2 - pstart
                            sum += diff
                    elif pstart < dom2 and pend > dom:
                        if pend <= dom2:
                            diff = pend - dom
                            sum += diff
                        else:
                            diff = dom2 - dom
                            sum += diff

                break
                
        sum *= 86400                            #--- change unit from day to sec

        sciLost = (csec2 - csec - sum) / 1000   #--- total science time lost excluding radiation zone passes

        line = etemp[0] + '\t' + etemp[1] + '\t' + etemp[2] + '\t' + "%.1f" %  sciLost  + '\t' + etemp[4]

        update.append(line)
#
#--- update the file 
#

    oldfile = file + '~'
    cmd = 'mv ' + file + ' ' + oldfile
    os.system(cmd)
    f = open(file, 'w')
    for ent in update:
        f.write(ent)
        f.write('\n')

    f.close()
def sci_run_add_to_rad_zone_list(file='NA'):

    'adding radiation zone list to rad_zone_list. input: file name containing: e.g. 20120313        2012:03:13:22:41        2012:03:14:13:57         53.3   auto'
    
#
#--- check whether the list alread exists; if it does, read which ones are already in the list
#
    cmd = 'ls ' + house_keeping + '* > ./ztemp'
    os.system(cmd)
#    f    = open('./ztemp', 'r')
#    test = f.readlines()
#    f.close()
    test = open('./ztemp').read()
 
    m1   = re.search('rad_zone_list',  test)
    m2   = re.search('rad_zone_list~', test)

    eventList = []
    echk      = 0
    if m1 is not None:
        line = house_keeping + 'rad_zone_list'
        f    = open(line, 'r')
        data = [line.strip() for line in f.readlines()]
        f.close()

        for ent in data:
            atemp = re.split('\s+|\t+', ent)
            eventList.append(atemp[0])
            echk = 1


#
#--- if file is not given (if it is NA), ask the file input
#

    if file == 'NA':
        file = raw_input('Please put the intrrupt timing list: ')

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

#
#--- put the list in the reverse order
#
    data.reverse()

    for ent in data:
        if not ent:
            break

#
#--- a starting date of the interruption in yyyy:mm:dd:hh:mm (e.g., 2006:03:20:10:30)
#--- there could be multiple lines of date; in that is the case, the scripts add the rad zone list
#--- to each date
#

        etemp = re.split('\s+', ent)
        echk = 0
        for comp in eventList:
           if comp == etemp[0]:
               echk = 1
               break

        if echk == 0:
    
            atemp = re.split(':', etemp[1])
            year  = atemp[0]
            month = atemp[1]
            date  = atemp[2]
            hour  = atemp[3]
            mins  = atemp[4]

#
#--- convert to dom/sec1998
#
            ydate = tcnv.findYearDate(int(year), int(month), int(date))
            dom   = tcnv.findDOM(int(year), int(ydate))
            line  = year + ':' + str(int(ydate)) + ':' + hour + ':' + mins + ':00'
            csec  = tcnv.axTimeMTA(line)

#
#--- end date
#

            atemp  = re.split(':', etemp[2])
            eyear  = atemp[0]
            emonth = atemp[1]
            edate  = atemp[2]
            ehour  = atemp[3]
            emins  = atemp[4]
     
            ydate = tcnv.findYearDate(int(eyear), int(emonth), int(edate))
            line  = eyear + ':' + str(int(ydate)) + ':' + ehour + ':' + emins + ':00'
            csec2 = tcnv.axTimeMTA(line)

#
#--- date stamp for the list
#
            list_date = str(year) + str(month) + str(date)

#
#--- check radiation zones for 3 days before to 5 days after from the interruptiondate
#--- if the interruption lasted longer than 5 days, extend the range 7 more days
#

            begin = dom - 3
            end   = dom + 5

            diff = csec2 - csec
            if diff > 432000:
                end += 7

#
#--- read radiation zone infornation
#

            infile = house_keeping + '/rad_zone_info'
            f      = open(infile, 'r')
            rdata  = [line.strip() for line in f.readlines()]
            f.close()
        
            status = []
            rdate  = []
            chk    = 0
            last_st= ''
            cnt    = 0
        
            for line in rdata:
                atemp = re.split('\s+', line)
        
                dtime = float(atemp[1])                 #--- dom of the entry or exit
        
                if chk  == 0 and atemp[0] == 'ENTRY' and dtime >= begin:
                    status.append(atemp[0])
                    rdate.append(dtime)
                    chk += 1
                    last_st = atemp[0]
                    cnt += 1
                elif chk > 0 and dtime >= begin and dtime <= end:
                    status.append(atemp[0])
                    rdate.append(dtime)
                    last_st = atemp[0]
                    cnt += 1
                elif atemp[1] > end and last_st == 'EXIT':
                    break
                elif atemp[1] > end and last_st == 'ENTRY':
                    status.append(atemp[0])
                    rdate.append(dtime)
                    cnt += 1
                    break
            
            f = open('./temp_zone', 'w')

#
#--- a format of the output is, e.g.: '20120313    (4614.2141112963,4614.67081268519):...'
#

            line = list_date + '\t'
            f.write(line)
        
            upper = cnt -1
            i = 0;
            while i < cnt:
                line = '(' + str(rdate[i]) + ','
                f.write(line)
                i += 1
                if i < upper:
                    line = str(rdate[i]) + '):'
                    f.write(line)
                else:
                    line = str(rdate[i]) + ')\n'
                    f.write(line)
                i += 1
        
            f.close()

#
#--- append the past rad zone list 
#

            oldFile = house_keeping + '/rad_zone_list~'
            crtFile = house_keeping + '/rad_zone_list'
    
            if m1 is not None:
                cmd = 'cat '+ './temp_zone ' + crtFile +  ' > ./temp_comb'
                os.system(cmd)
    
            else:
                os.system('mv .temp_zone ./temp_comb')

            os.system('rm ./temp_zone')

#
#--- save the old file and move the update file to rad_zone_list
#

            if m2 is not None:
                cmd     = 'chmod 775 ' + crtFile + ' ' +  oldFile
                os.system(cmd)
        
            if m1 is not None:
                cmd     = 'mv ' + crtFile + ' ' + oldFile
                os.system(cmd)
        
                cmd     = 'chmod 644 ' +  oldFile
                os.system(cmd)
        
            cmd     = 'mv  ' + './temp_comb ' + crtFile
            os.system(cmd)
def sci_run_add_to_rad_zone_list(file='NA'):

    'adding radiation zone list to rad_zone_list. input: file name containing: e.g. 20120313        2012:03:13:22:41        2012:03:14:13:57         53.3   auto'

    #
    #--- if file is not given (if it is NA), ask the file input
    #

    if file == 'NA':
        file = raw_input('Please put the intrrupt timing list: ')

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

    for ent in data:

        #
        #--- a starting date of the interruption in yyyy:mm:dd:hh:mm (e.g., 2006:03:20:10:30)
        #--- there could be multiple lines of date; in that is the case, the scripts add the rad zone list
        #--- to each date
        #

        etemp = re.split('\s+', ent)

        atemp = re.split(':', etemp[1])
        year = atemp[0]
        month = atemp[1]
        date = atemp[2]
        hour = atemp[3]
        mins = atemp[4]

        #
        #--- convert to dom/sec1998
        #
        ydate = tcnv.findYearDate(int(year), int(month), int(date))
        dom = tcnv.findDOM(int(year), int(ydate))
        line = year + ':' + str(int(ydate)) + ':' + hour + ':' + mins + ':00'
        csec = tcnv.axTimeMTA(line)

        #
        #--- end date
        #

        atemp = re.split(':', etemp[2])
        eyear = atemp[0]
        emonth = atemp[1]
        edate = atemp[2]
        ehour = atemp[3]
        emins = atemp[4]

        ydate = tcnv.findYearDate(int(eyear), int(emonth), int(edate))
        dom2 = tcnv.findDOM(int(eyear), int(ydate))
        line = eyear + ':' + str(
            int(ydate)) + ':' + ehour + ':' + emins + ':00'
        csec2 = tcnv.axTimeMTA(line)

        #
        #--- date stamp for the list
        #
        list_date = str(year) + str(month) + str(date)

        #
        #--- check radiation zones for 3 days before to 5 days after from the interruptiondate
        #

        begin = dom - 3
        end = dom2 + 5

        #
        #--- read radiation zone infornation
        #

        infile = house_keeping + '/rad_zone_info'
        f = open(infile, 'r')
        rdata = [line.strip() for line in f.readlines()]
        f.close()

        status = []
        rdate = []
        chk = 0
        last_st = ''
        cnt = 0

        for line in rdata:
            atemp = re.split('\s+', line)

            dtime = float(atemp[1])  #--- dom of the entry or exit

            if chk == 0 and atemp[0] == 'ENTRY' and dtime >= begin:
                status.append(atemp[0])
                rdate.append(dtime)
                chk += 1
                last_st = atemp[0]
                cnt += 1
            elif chk > 0 and dtime >= begin and dtime <= end:
                status.append(atemp[0])
                rdate.append(dtime)
                last_st = atemp[0]
                cnt += 1
            elif atemp[1] > end and last_st == 'EXIT':
                break
            elif atemp[1] > end and last_st == 'ENTRY':
                status.append(atemp[0])
                rdate.append(dtime)
                cnt += 1
                break

        f = open('./temp_zone', 'w')

        #
        #--- a format of the output is, e.g.: '20120313    (4614.2141112963,4614.67081268519):...'
        #

        line = list_date + '\t'
        f.write(line)

        i = 0
        while i < cnt:
            line = '(' + str(rdate[i]) + ','
            f.write(line)
            i += 1
            if i < cnt - 1:
                line = str(rdate[i]) + '):'
                f.write(line)
            else:
                line = str(rdate[i]) + ')\n'
                f.write(line)
            i += 1

        f.close()

        #
        #--- append the past rad zone list
        #

        oldFile = house_keeping + '/rad_zone_list~'
        crtFile = house_keeping + '/rad_zone_list'

        #>        cmd = 'cat ' './temp_zone ' + crtFile + ' > /tmp/mta/temp_comb'
        cmd = 'cat ' + './temp_zone ' + crtFile + ' > ./temp_comb'
        os.system(cmd)

        #>        os.systm('rm /tmp/mta/temp_zone')
        os.system('rm ./temp_zone')

        #
        #--- save the old file and move the update file to rad_zone_list
        #

        cmd = 'chmod 775 ' + crtFile + ' ' + oldFile
        os.system(cmd)

        cmd = 'mv ' + crtFile + ' ' + oldFile
        os.system(cmd)

        cmd = 'chmod 644 ' + oldFile
        os.system(cmd)

        #>        cmd     = 'mv  ' + '/tmp/mta/temp_comb ' + crtFile
        cmd = 'mv  ' + './temp_comb ' + crtFile
        os.system(cmd)
Exemple #20
0
def check_obs_status(obsid):

    """
    check obsid is eligible to be added to the curren list. 
    input: obsid. if it is either 'scheduled', 'unobserved', or 'observed' status and if it is obsverd
    less than 30 day ago, it is eliible. 
    """
#
#--- set limit to the last 30  days
#
    [year, mon, day, hours, min, sec, weekday, yday, dst] = tcnv.currentTime('LOCAL')
    tdom = tcnv.findDOM(year, mon, day, 0, 0, 0)
    dom_limit = tdom - 30

#
#--- extract basic information
#
    monitor = []
    groupid = []
    try:
        (group_id, pre_id, pre_min_lead, pre_max_lead, grating, type, instrument, obs_ao_str, status, \
        seq_nbr, ocat_propid, soe_st_sched_date, lts_lt_plan,targname) = sql.get_target_info(int(obsid), monitor,groupid)

        if soe_st_sched_date is not None:
            date = soe_st_sched_date
            chk = 1
        elif lts_lt_plan is not None:
            date = lts_lt_plan
            chk  = 1
        else:
            date = 'NA'
            chk = 0
    except:
        date = 'NA'
        chk = 0
#
#--- check status change
#
    if chk  == 1:
        if status == 'scheduled' or status == 'unobserved' or status == 'observed':
#
#--- recompute with updated date
#
            if date == 'NA':
                dom = 'NA'
            else:
                temp  = re.split('\s+', str(date))
                omon  = tcnv.changeMonthFormat(temp[0])
                oday  = int(temp[1])
                oyear = int(temp[2])
                dom   = tcnv.findDOM(oyear, omon, oday, 0, 0, 0)
    
            if dom  > dom_limst:
                chk = 1
            else:
                chk = 0
    
        else:
            chk = 0

    return chk
Exemple #21
0
def update_ddt_too():
    """
    update new_obs_lsit, too_list, ddt_list, and obs_in_30days
    no input but data are taken from sot_ocat.out.

    """
    #
    #--- set limit to the last 60 days
    #
    [year, mon, day, hours, min, sec, weekday, yday,
     dst] = tcnv.currentTime('LOCAL')
    tdom = tcnv.findDOM(year, mon, day, 0, 0, 0)
    dom_limit = tdom - 60
    #
    #--- read special obsid --- poc list
    #
    line = too_dir + 'special_obsid_poc_list'
    f = open(line, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    sp_obsid = []
    sp_user = []
    for ent in data:
        atemp = re.split('\s+', ent)
        sp_obsid.append(atemp[0])
        sp_user.append(atemp[1])

#
#--- read too_list and ddt_list and make obsid <---> poc dictionary
#
    poc_dict = {}
    cddt = []
    ctoo = []

    line = too_dir + 'ddt_list'
    fo = open(line, 'r')
    ddt = [line.strip() for line in fo.readlines()]
    fo.close()

    for ent in ddt:
        atemp = re.split('\s+', ent)
        obsid = atemp[2].strip()
        poc_dict[obsid] = atemp[4]
        cddt.append(obsid)

    line = too_dir + 'too_list'
    fo = open(line, 'r')
    too = [line.strip() for line in fo.readlines()]
    fo.close()

    for ent in too:
        atemp = re.split('\s+', ent)
        obsid = atemp[2].strip()
        poc_dict[obsid] = atemp[4]
        ctoo.append(obsid)

#
#--- read database
#
    line = obs_ss + 'sot_ocat.out'
    f = open(line, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()
    #
    #--- start itelations
    #
    fo1 = open('tmp_ddt_list', 'w')
    fo2 = open('tmp_too_list', 'w')
    new_ddt = []
    new_too = []
    for ent in data:
        atemp = re.split('\^', ent)

        try:
            type = atemp[14].strip().lower()
            if type != 'too' and type != 'ddt':
                continue

            obsid = atemp[1].strip()
            seq_no = atemp[3].strip()
            date = atemp[15].strip()
            status = atemp[16].strip().lower()
            ao = atemp[21].strip()
        except:
            continue
#
#--- convert date to dom
#
        if str(date).lower() == 'null' or str(date).lower() == 'none':
            dom = 'NA'
        else:
            temp = re.split('\s+', str(date))
            omon = tcnv.changeMonthFormat(temp[0])
            oday = int(temp[1])
            oyear = int(temp[2])
            dom = tcnv.findDOM(oyear, omon, oday, 0, 0, 0)

        if status == 'scheduled' or status == 'unobserved' or status == 'observed':

            if status == 'observed':
                if dom == 'NA':
                    continue
                elif dom < dom_limit:
                    continue
            else:
                if dom == 'NA':
                    continue
#
#--- find poc of the observation
#
            try:
                #
                #--- check this obsid is already assigned poc
                #
                person = poc_dict[obsid]
            except:
                #
                #--- check this obsid is listed on a special_obsid_poc_list
                #
                sp_poc = 'na'
                person = 'TBD'
                for sval in range(0, len(sp_obsid)):
                    if obsid == sp_obsid[sval]:
                        sp_poc = sp_user[sval]
                        break

                    if sp_poc != 'na':
                        #
                        #-- for the case the obsid is given a specific poc
                        #
                        person = sp_poc
                    else:
                        #
                        #--- it is new; so assigned today's poc
                        #
                        try:
                            [person, chk] = tdfnc.find_too_ddt_poc(obsid)
                        except:
                            person = 'TBD'

            line = str(type) + '\t'
            line = line + str(seq_no) + '\t'
            line = line + str(obsid) + '\t'
            line = line + str(status) + '\t'
            line = line + str(person) + '\t'
            line = line + str(ao) + '\t'
            line = line + str(date) + '\n'

            if type == 'ddt':
                fo1.write(line)
                new_ddt.append(obsid)
            else:
                fo2.write(line)
                new_too.append(obsid)

    fo1.close()
    fo2.close()
    #
    #--- check new one has any entries, if so replace the current one
    #
    #    if len(new_ddt) > 0:
    #        cmd = 'mv ' + too_dir + 'ddt_list ' + too_dir  + 'ddt_list~'
    #        os.system(cmd)
    #        cmd = 'mv tmp_ddt_list ' + too_dir + 'ddt_list'
    #        os.system(cmd)
    #        nddt = check_new_entry(cddt, new_ddt)
    #    else:
    #        cmd = 'rm tmp_ddt_list'
    #        os.system(cmd)

    if len(new_too) > 0:
        #        cmd = 'mv '+ too_dir + 'too_list ' + too_dir + 'too_list~'
        #        os.system(cmd)
        #        cmd = 'mv tmp_too_list ' + too_dir + 'too_list'
        #        os.system(cmd)
        ntoo = check_new_entry(ctoo, new_too)
#    else:
#        cmd = 'rm tmp_too_list'
#        os.system(cmd)
#
#-- if there are new entries, send notification email
#
#if len(nddt) > 0 or len(ntoo) > 0:
    if len(ntoo) > 0:
        line = 'Possible new entry\n'
        #if len(nddt) > 0:
        #    for obsid in nddt:
        #        line = line + 'ddt: ' + str(obsid) + '\n'
        if len(ntoo) > 0:
            for obsid in ntoo:
                line = line + 'too: ' + str(obsid) + '\n'

        print "I AM HERE: " + str(line)
Exemple #22
0
def update_ddt_too():
    """
    update new_obs_lsit, too_list, ddt_list, and obs_in_30days
    no input but data are taken from sot_ocat.out.

    """
    #
    #--- set limit to the last 60 days
    #
    [year, mon, day, hours, min, sec, weekday, yday,
     dst] = tcnv.currentTime('LOCAL')
    tdom = tcnv.findDOM(year, mon, day, 0, 0, 0)
    dom_limit = tdom - 60

    #
    #--- read too_list and ddt_list and make obsid <---> poc dictionary
    #
    poc_dict = {}
    cddt = []
    ctoo = []

    line = too_dir + 'ddt_list'
    fo = open(line, 'r')
    ddt = [line.strip() for line in fo.readlines()]
    fo.close()

    for ent in ddt:
        atemp = re.split('\s+', ent)
        obsid = atemp[2].strip()
        #
        #--- if the poc is 'TBD', skip!
        #
        if atemp[4] != 'TBD':
            poc_dict[obsid] = atemp[4]

        cddt.append(obsid)

    line = too_dir + 'too_list'
    fo = open(line, 'r')
    too = [line.strip() for line in fo.readlines()]
    fo.close()

    for ent in too:
        atemp = re.split('\s+', ent)
        obsid = atemp[2].strip()

        if atemp[4] != 'TBD':
            poc_dict[obsid] = atemp[4]

        ctoo.append(obsid)
#
#--- poc list from the prop numbers<---> poc relation
#
    [obsid_list, poc_list] = make_obsid_poc_list()
    for k in range(0, len(obsid_list)):
        poc_dict[obsid_list[k]] = poc_list[k]
#
#--- read special obsid --- poc list
#
    line = too_dir + 'special_obsid_poc_list'
    f = open(line, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    for ent in data:
        atemp = re.split('\s+', ent)
        poc_dict[atemp[0]] = atemp[1]
#
#--- read database
#
    line = obs_ss + 'sot_ocat.out'
    f = open(line, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()
    #
    #--- start itelations
    #
    fo1 = open('tmp_ddt_list', 'w')
    fo2 = open('tmp_too_list', 'w')
    new_ddt = []
    new_too = []
    for ent in data:
        atemp = re.split('\^', ent)

        try:
            type = atemp[14].strip().lower()
            if type != 'too' and type != 'ddt':
                continue

            obsid = atemp[1].strip()
            seq_no = atemp[3].strip()
            date = atemp[13].strip()
            if date == 'NULL':
                date = atemp[15].strip()
            status = atemp[16].strip().lower()
            ao = atemp[21].strip()
        except:
            continue
#
#--- convert date to dom
#
        if str(date).lower() == 'null' or str(date).lower() == 'none':
            dom = 'NA'
        else:
            temp = re.split('\s+', str(date))
            omon = tcnv.changeMonthFormat(temp[0])
            oday = int(temp[1])
            oyear = int(temp[2])
            dom = tcnv.findDOM(oyear, omon, oday, 0, 0, 0)

        if status == 'scheduled' or status == 'unobserved' or status == 'observed':

            if status == 'observed':
                if dom == 'NA':
                    continue
                elif dom < dom_limit:
                    continue
            else:
                if dom == 'NA':
                    continue
#
#--- find poc of the observation
#
            try:
                #
                #--- check this obsid is already assigned poc
                #
                person = poc_dict[obsid]
                if person == '':
                    person = 'TBD'
            except:
                person = 'TBD'
#
#--- it is new; so assigned today's poc
#
            if person == 'TBD':
                try:
                    person = find_person_in_charge()
                except:
                    pass

            line = str(type) + '\t'
            line = line + str(seq_no) + '\t'
            line = line + str(obsid) + '\t'
            line = line + str(status) + '\t'
            line = line + str(person) + '\t'
            line = line + str(ao) + '\t'
            line = line + str(date) + '\n'

            if type == 'ddt':
                fo1.write(line)
                new_ddt.append(obsid)
            else:
                fo2.write(line)
                new_too.append(obsid)

    fo1.close()
    fo2.close()
    #
    #--- check new one has any entries, if so replace the current one
    #
    if len(new_ddt) > 0:
        cmd = 'mv ' + too_dir + 'ddt_list ' + too_dir + 'ddt_list~'
        os.system(cmd)
        cmd = 'mv tmp_ddt_list ' + too_dir + 'ddt_list'
        os.system(cmd)
        nddt = check_new_entry(cddt, new_ddt)
    else:
        cmd = 'rm tmp_ddt_list'
        os.system(cmd)
        nddt = []

    if len(new_too) > 0:
        cmd = 'mv ' + too_dir + 'too_list ' + too_dir + 'too_list~'
        os.system(cmd)
        cmd = 'mv tmp_too_list ' + too_dir + 'too_list'
        os.system(cmd)
        ntoo = check_new_entry(ctoo, new_too)
    else:
        cmd = 'rm tmp_too_list'
        os.system(cmd)
        ntoo = []
#
#-- if there are new entries, send notification email
#
    if len(nddt) > 0 or len(ntoo) > 0:
        line = 'Possible new entry\n'
        if len(nddt) > 0:
            for obsid in nddt:
                line = line + 'ddt: ' + str(obsid) + '\n'
        if len(ntoo) > 0:
            for obsid in ntoo:
                line = line + 'too: ' + str(obsid) + '\n'

        out = temp_dir + 'mail'
        fo = open(out, 'w')
        fo.write(line)
        fo.close()

        cmd = 'cat ' + out + ' | mailx -s"Subject: New ddt/too observation" [email protected]'
        os.system(cmd)

        cmd = 'rm ' + out
        os.system(cmd)
def acis_sci_run_print_html(html_dir, pyear, pmonth, pday, pchk):
    """
    update three html pages according for the year (pyear)
    Input: html_dir --- web directory path
           pyear  --- the year you want to update the html pages
           pmonth --- current month
           pday   --- current month date
           pchk   --- if it is "yes", it will also update the main html, otherwise, just update subs
    Output: science_run.html
            science_long_term.html
            science_run<year>.html

    """
    pyear = int(pyear)

    update = str(pyear) + '-' + str(pmonth) + '-' + str(pday)
    dom = int(tcnv.findDOM(pyear, pmonth, pday, 0, 0, 0))
    ydate = tcnv.findYearDate(pyear, pmonth, pday)
    #
    #---- update the main html page
    #
    if pchk == 'yes':
        ylist = ''
        j = 0
        for ryear in range(1999, pyear + 1):
            ylist = ylist + '<td><a href=' + http_dir + '/Year' + str(
                ryear) + '/science_run' + str(ryear) + '.html>'
            ylist = ylist + '<strong>Year ' + str(
                ryear) + '</strong></a><br /><td />\n'
            if j == 5:
                j = 0
                ylist = ylist + '</tr><tr>\n'
            else:
                j += 1

        line = house_keeping + 'science_run.html'
        f = open(line, 'r')
        hfile = f.read()
        f.close()
        temp = hfile.replace('#UPDATE#', update)
        temp1 = temp.replace('#DOY#', str(ydate))
        temp2 = temp1.replace('#DOM#', str(dom))
        temp3 = temp2.replace('#YEAR#', str(pyear))
        temp4 = temp3.replace('#YLIST#', str(ylist))

        line = html_dir + 'science_run.html'
        f = open(line, 'w')
        f.write(temp4)
        f.close()

#
#--- update this year's sub directory html page
#

    line = house_keeping + 'sub_year.html'
    f = open(line, 'r')
    hfile = f.read()
    f.close()
    temp = hfile.replace('#UPDATE#', update)
    temp1 = temp.replace('#DOY#', str(ydate))
    temp2 = temp1.replace('#DOM#', str(dom))
    temp3 = temp2.replace('#YEAR#', str(pyear))

    line = html_dir + 'Year' + str(pyear) + '/science_run' + str(
        pyear) + '.html'
    f = open(line, 'w')
    f.write(temp3)
    f.close()
    #
    #--- update long term html page
    #
    line = house_keeping + 'science_long_term.html'
    f = open(line, 'r')
    hfile = f.read()
    f.close()
    temp = hfile.replace('#UPDATE#', update)
    temp1 = temp.replace('#DOY#', str(ydate))
    temp2 = temp1.replace('#DOM#', str(dom))

    line = html_dir + 'Long_term/science_long_term.html'
    f = open(line, 'w')
    f.write(temp2)
    f.close()
def update_ddt_too():

    """
    update new_obs_lsit, too_list, ddt_list, and obs_in_30days
    no input but data are taken from sot_ocat.out.

    """
#
#--- set limit to the last 60 days
#
    [year, mon, day, hours, min, sec, weekday, yday, dst] = tcnv.currentTime('LOCAL')
    tdom = tcnv.findDOM(year, mon, day, 0, 0, 0)
    dom_limit = tdom - 60                      

#
#--- read too_list and ddt_list and make obsid <---> poc dictionary
#
    poc_dict = {}
    cddt     = []
    ctoo     = []

    line = too_dir + 'ddt_list'
    fo   = open(line, 'r')
    ddt  = [line.strip() for line in fo.readlines()]
    fo.close()

    for ent in ddt:
        atemp = re.split('\s+', ent)
        obsid = atemp[2].strip()
#
#--- if the poc is 'TBD', skip!
#
        if atemp[4] != 'TBD':
            poc_dict[obsid] = atemp[4] 

        cddt.append(obsid)

    line = too_dir + 'too_list'
    fo   = open(line, 'r')
    too  = [line.strip() for line in fo.readlines()]
    fo.close()

    for ent in too:
        atemp = re.split('\s+', ent)
        obsid = atemp[2].strip()

        if atemp[4] != 'TBD':
             poc_dict[obsid] = atemp[4] 

        ctoo.append(obsid)
#
#--- poc list from the prop numbers<---> poc relation
#
    [obsid_list, poc_list] = make_obsid_poc_list()
    for k in range(0, len(obsid_list)):
        poc_dict[obsid_list[k]] = poc_list[k]
#
#--- read special obsid --- poc list
#
    line = too_dir + 'special_obsid_poc_list'
    f    = open(line, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    for ent in data:
        atemp = re.split('\s+', ent)
        poc_dict[atemp[0]] = atemp[1]
#
#--- read database
#
    line = obs_ss + 'sot_ocat.out'
    f    = open(line, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()
#
#--- start itelations
#
    fo1     = open('tmp_ddt_list', 'w')
    fo2     = open('tmp_too_list', 'w')
    new_ddt = []
    new_too = []
    for ent in data:
        atemp  = re.split('\^', ent)

        try:
            type   = atemp[14].strip().lower()
            if type != 'too' and type != 'ddt':
                continue

            obsid  = atemp[1].strip()
            seq_no = atemp[3].strip()
            date   = atemp[13].strip()
            if date == 'NULL':
                date   = atemp[15].strip()
            status = atemp[16].strip().lower()
            ao     = atemp[21].strip()
        except:
            continue
#
#--- convert date to dom
#
        if str(date).lower() == 'null' or str(date).lower() == 'none':
            dom = 'NA'
        else:
            temp  = re.split('\s+', str(date))
            omon  = tcnv.changeMonthFormat(temp[0])
            oday  = int(temp[1])
            oyear = int(temp[2])
            dom   = tcnv.findDOM(oyear, omon, oday, 0, 0, 0)

        if status == 'scheduled' or status == 'unobserved' or status == 'observed':

            if status == 'observed':
                if dom == 'NA':
                    continue
                elif dom < dom_limit:
                    continue
            else:
                if dom == 'NA':
                    continue
#
#--- find poc of the observation
#
            try:
#
#--- check this obsid is already assigned poc
#
                person = poc_dict[obsid]
                if person == '':
                    person = 'TBD'
            except:
                person = 'TBD'
#
#--- it is new; so assigned today's poc
#
            if person == 'TBD':
                try:
                    person = find_person_in_charge()
                except:
                    pass

            line = str(type) + '\t'
            line = line + str(seq_no) + '\t'
            line = line + str(obsid)  + '\t'
            line = line + str(status) + '\t'
            line = line + str(person) + '\t'
            line = line + str(ao)     + '\t'
            line = line + str(date)   + '\n'

            if type == 'ddt':
                fo1.write(line)
                new_ddt.append(obsid)
            else:
                fo2.write(line)
                new_too.append(obsid)

    fo1.close()
    fo2.close()
#
#--- check new one has any entries, if so replace the current one
#
    if len(new_ddt) > 0:
        cmd = 'mv ' + too_dir + 'ddt_list ' + too_dir  + 'ddt_list~'
        os.system(cmd)
        cmd = 'mv tmp_ddt_list ' + too_dir + 'ddt_list'
        os.system(cmd)
        nddt = check_new_entry(cddt, new_ddt)
    else:
        cmd = 'rm tmp_ddt_list'
        os.system(cmd)
        nddt = []

    if len(new_too) > 0:
        cmd = 'mv '+ too_dir + 'too_list ' + too_dir + 'too_list~'
        os.system(cmd)
        cmd = 'mv tmp_too_list ' + too_dir + 'too_list'
        os.system(cmd)
        ntoo = check_new_entry(ctoo, new_too)
    else:
        cmd = 'rm tmp_too_list'
        os.system(cmd)
        ntoo = []
#
#-- if there are new entries, send notification email
#
    if len(nddt) > 0 or len(ntoo) > 0:
        line = 'Possible new entry\n'
        if len(nddt) > 0:
            for obsid in nddt:
                line = line + 'ddt: ' + str(obsid) + '\n'
        if len(ntoo) > 0:
            for obsid in ntoo:
                line = line + 'too: ' + str(obsid) + '\n'

        out = temp_dir + 'mail'
        fo  = open(out, 'w')
        fo.write(line)
        fo.close()

        cmd = 'cat ' + out + ' | mailx -s"Subject: New ddt/too observation" [email protected]'
        os.system(cmd)

        cmd = 'rm ' + out
        os.system(cmd)
def acis_sci_run_print_html(html_dir, pyear, pmonth, pday,  pchk):
    """
    update three html pages according for the year (pyear)
    Input: html_dir --- web directory path
           pyear  --- the year you want to update the html pages
           pmonth --- current month
           pday   --- current month date
           pchk   --- if it is "yes", it will also update the main html, otherwise, just update subs
    Output: science_run.html
            science_long_term.html
            science_run<year>.html

    """
    pyear = int(pyear)

    update = str(pyear) + '-' + str(pmonth) + '-' + str(pday)
    dom    = int(tcnv.findDOM(pyear, pmonth, pday, 0, 0, 0))
    ydate  = tcnv.findYearDate(pyear, pmonth, pday)
#
#---- update the main html page
#
    if pchk == 'yes':
        ylist = ''
        j    = 0
        for ryear in range(1999, pyear+1):
            ylist = ylist + '<td><a href=' + http_dir + '/Year' + str(ryear) + '/science_run' + str(ryear) + '.html>'
            ylist = ylist + '<strong>Year ' + str(ryear) + '</strong></a><br /><td />\n'
            if j == 5:
                j = 0
                ylist = ylist + '</tr><tr>\n'
            else:
                j += 1
    
    
        line  = house_keeping + 'science_run.html'
        f     = open(line, 'r')
        hfile = f.read()
        f.close()
        temp  = hfile.replace('#UPDATE#', update)
        temp1 = temp.replace('#DOY#',     str(ydate))
        temp2 = temp1.replace('#DOM#',    str(dom))
        temp3 = temp2.replace('#YEAR#',   str(pyear))
        temp4 = temp3.replace('#YLIST#',  str(ylist))
    
        line = html_dir + 'science_run.html'
        f    = open(line, 'w')
        f.write(temp4)
        f.close()

#
#--- update this year's sub directory html page
#

    line  = house_keeping + 'sub_year.html'
    f     = open(line, 'r')
    hfile = f.read()
    f.close()
    temp  = hfile.replace('#UPDATE#', update)
    temp1 = temp.replace('#DOY#',     str(ydate))
    temp2 = temp1.replace('#DOM#',    str(dom))
    temp3 = temp2.replace('#YEAR#',   str(pyear))

    line = html_dir + 'Year' + str(pyear) + '/science_run' + str(pyear) + '.html'
    f    = open(line, 'w')
    f.write(temp3)
    f.close()
#
#--- update long term html page
#
    line  = house_keeping + 'science_long_term.html'
    f     = open(line, 'r')
    hfile = f.read()
    f.close()
    temp  = hfile.replace('#UPDATE#', update)
    temp1 = temp.replace('#DOY#',     str(ydate))
    temp2 = temp1.replace('#DOM#',    str(dom))

    line = html_dir + 'Long_term/science_long_term.html'
    f    = open(line, 'w')
    f.write(temp2)
    f.close()