def extractRadZoneInfo(year, month, type):

    "extract radiation zone information from MP data. input: year, month "

    if type == 'ENTRY':
        etype = 'RADENTRY'
    else:
        etype = 'RADEXIT'
#
#--- find the next month
#

    year2  = year
    month2 = month + 1

    if month2 == 13:
        year2 += 1
        month2 = 1

#
#--- extract this month and the next month radiation zone information
#

    name = str.upper(tcnv.changeMonthFormat(month)) + '*'
    if comp_test == 'test':
        line = 'cat ' + house_keeping + 'Test_prep/mp_data/*|grep ' + etype + ' >  ./zout'
    else:
#>        line = 'cat ' + ' /data/mpcrit1/mplogs/'+ str(year) + '/' +  name + '/ofls/*dot|grep ' + etype + '  >  /tmp/mta/zout'
        line = 'cat ' + ' /data/mpcrit1/mplogs/'+ str(year) + '/' +  name + '/ofls/*dot|grep ' + etype + ' >  ./zout'

    os.system(line)

    name = str.upper(tcnv.changeMonthFormat(month2)) + '*'
    if comp_test == 'test':
        line = 'cat ' + house_keeping + 'Test_prep/mp_data/' + str(year2) + '/' +  name + '/ofls/*dot|grep ' + etype + ' >>  ./zout'
    else:
#>        line = 'cat ' + ' /data/mpcrit1/mplogs/' + str(year2) + '/' +  name + '/ofls/*dot|grep ' + etype + '  >>  /tmp/mta/zout'
        line = 'cat ' + ' /data/mpcrit1/mplogs/' + str(year2) + '/' +  name + '/ofls/*dot|grep ' + etype + ' >>  ./zout'

    os.system(line)

#
#--- read the tmp files and clean up the the radiation zone entry / exit information
#

#>    f = open('/tmp/mta/zout', 'r')
    f = open('./zout', 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

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

    outList = []
    for ent in data:
        line = cleanEntry(ent)
#        outList.list.append(line)
        outList.append(line)

    return outList
Пример #2
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
Пример #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 find_prev_date(cmon, lev):
    """
    find the last extreacted obsid date
    input:  cmon    --- current month
            lev     --- data level
    output: date    --- the date which to be used to start extracting data
    """

    afile = s_dir + lev + '/acis_obs'
#
#--- check whether file exist
#
    if os.path.isfile(afile):
        f     = open(afile, 'r')
        data  = [line.strip() for line in f.readlines()]
        f.close()
    
        if len(data) > 0:
            atemp = re.split('\s+', data[-1])
            mon   = atemp[-7]
#
#--- just in a case acis_obs is from the last month..
#
            dmon  = tcnv.changeMonthFormat(mon)
            if dmon == cmon:
                date  = atemp[-6]
            else:
                date  = '1'
        else:
            date = '1'
    else:
        date = "1"

    return date
Пример #5
0
def find_prev_date(cmon, lev):
    """
    find the last extreacted obsid date
    input:  cmon    --- current month
            lev     --- data level
    output: date    --- the date which to be used to start extracting data
    """

    afile = s_dir + lev + '/acis_obs'
    #
    #--- check whether file exist
    #
    if os.path.isfile(afile):
        f = open(afile, 'r')
        data = [line.strip() for line in f.readlines()]
        f.close()

        if len(data) > 0:
            atemp = re.split('\s+', data[-1])
            mon = atemp[-7]
            #
            #--- just in a case acis_obs is from the last month..
            #
            dmon = tcnv.changeMonthFormat(mon)
            if dmon == cmon:
                date = atemp[-6]
            else:
                date = '1'
        else:
            date = '1'
    else:
        date = "1"

    return date
Пример #6
0
def print_month_list():

    [year, mon, day, hours, min, sec, weekday, yday, dst] = tcnv.currentTime()

    line  = 'Sep99 41 71\n'
    begin = 71
    for iyear in range(1999, year+1):

        if tcnv.isLeapYear(iyear) == 1:
            month_list = month_list2
        else:
            month_list = month_list1

        lyear = str(iyear)
        syear = lyear[2] + lyear[3]
        for month in range(1, 13):
            if iyear == 1999 and  month < 10:
                continue
            if iyear == year and month > mon:
                break

            lmon = tcnv.changeMonthFormat(month)
            time = lmon + syear

            daynum = month_list[month-1]
            end    = daynum + begin
            
            line   = line + time + ' ' + str(begin) + ' ' + str(end) + '\n'
            begin  = end

    fo = open('/data/mta_www/mta_sim/Scripts/SIM_move/Outputs/months', 'w')
    fo.write(line)
    fo.close()
Пример #7
0
def past_data_entry(setno, mpos, mon, byear, text):
    """
    update the text for the given past month date
    input:  setno   --- indicator of which entry
            mpos    --- which step from the oldest month to indicate
                        the month
            byear   --- the last year
            text    --- the text which will be updated
    output: text    --- the text updated
    """
    chk = 0
    test = mon + mpos
    if test > 12:
        test -= 12
        if chk == 0:
            byear += 1

    ctest = str(test)
    if test < 10:
        ctest = '0' + ctest

    line = ctest + '_' + str(byear)

    mset = '#MSET' + str(setno) + '#'
    yset = '#YSET' + str(setno) + '#'
    myset = '#MYSET' + str(setno) + '#'

    text = text.replace(mset, tcnv.changeMonthFormat(test))
    text = text.replace(yset, str(byear))
    text = text.replace(myset, line)

    return text
Пример #8
0
def past_data_entry(setno, mpos, mon, byear, text):
    """
    update the text for the given past month date
    input:  setno   --- indicator of which entry
            mpos    --- which step from the oldest month to indicate
                        the month
            byear   --- the last year
            text    --- the text which will be updated
    output: text    --- the text updated
    """
    chk   = 0
    test  = mon + mpos
    if test > 12:
        test -= 12
        if chk == 0:
            byear += 1

    ctest = str(test)
    if test < 10:
        ctest = '0' + ctest

    line  = ctest + '_' + str(byear)

    mset  = '#MSET'  + str(setno) + '#'
    yset  = '#YSET'  + str(setno) + '#'
    myset = '#MYSET' + str(setno) + '#'

    text  = text.replace(mset,  tcnv.changeMonthFormat(test))
    text  = text.replace(yset,  str(byear))
    text  = text.replace(myset, line)

    return text
Пример #9
0
def update_html():

    """
    create/update error html page for a gvien machine and a user
    input: error_list_<cpu>_<user>, wheren cpu and user are found from the machine running this and account using.
    output: cron_error_<cpu>_<usr>.html in html_dir.
    """

#
#--- find the current time
#
    [year, mon, day, hours, min, sec, weekday, yday, dst] = tcnv.currentTime('Local')

    syear = str(year)
    smon  = str(mon)
    lmon = tcnv.changeMonthFormat(mon)

    if mon < 10:
        smon = '0' + smon
#
#--- set the file name and a hmtl page name
#
    file = error_log_dir + machine + '_' + user + '_' + smon + '_' + syear
    html = html_dir + 'cron_error_' + machine + '_' + user + '_' + smon + '_' + syear + '.html'
#
#--- start writing the html page
#
    out  = open(html, 'w')
    line = '<!DOCTYPE html>\n'
    line = line + '<html>\n'
    line = line + '<head>\n'
    line = line + '<title>Cron Error Log for ' + user.upper() + ' on ' +  machine.upper() + ': ' + lmon + ' ' + syear + '</title>\n'
    line = line + '<link rel="stylesheet" type="text/css" href="/mta/REPORTS/Template/mta_style_short.css" />\n'
    line = line + '</head>\n'
    line = line + '<body>\n'
    line = line + '<h3 style="padding-bottom: 10px"> Cron Error Log for ' + user.upper() + ' on ' +  machine.upper() + ': ' + lmon + ' ' + syear + '</h3>\n\n'
    line = line + '<hr />\n'
    line = line + '<pre style="padding-left: 5px;padding-bottom:10px">\n' 

    out.write(line)
#
#--- write the content of error_list
#
    f    = open(file, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    for ent in data:
        out.write(ent)
        out.write('\n')

    line = '</pre>\n'
    line = line + '<br /><hr /><br />\n'
    line = line + 'Back to <a href="https://cxc.cfa.harvard.edu/mta_days/mta_cron/cron_error_main.html">Top Page</a>\n'
    line = line + '\n</body>\n'
    line = line + '</html>\n'
    out.write(line)

    out.close()
Пример #10
0
def create_this_montcreate_this_month():
    """
    create ACA monthly script for the month
    input:  none, but read from ./Template
    outpu:  a file named .update_this_month
    """


    tlist = tcnv.currentTime()

    year  = str(tlist[0])
    syr   = year[2] + year[3]

    mon   = int(float(tlist[1]))
    smon  = str(tlist[1])
    if mon < 10:
        smon = '0' + smon
    lmon  = tcnv.changeMonthFormat(mon)
#
#--- format of: 2015_05
#
    yearmon = year + '_' + smon

#--- format of: MAY15
#
    umonyr  = lmon + syr
    umonyr  = umonyr.upper()
#
#--- format of: may15
#
    lmonyr  = umonyr.lower()


    file = dir_path + 'Template/update_temp'
    f    = open(file, 'r')
    data = f.read()
    f.close()

    data = data.replace('#YEAR_MON#', yearmon)
    data = data.replace('#UMONYR#',   umonyr)
    data = data.replace('#LMONYR#',   lmonyr)


    ofile = out_path + 'update_this_month'
    fo    = open(ofile, 'w')
    fo.write(data)
    fo.close()

    cmd = 'chmod 755 ' + ofile
    os.system(cmd)
#
#--- make output directory
#
    cmd = 'mkdir ' + out_path + '/' + umonyr
    os.system(cmd)
    cmd = 'mkdir ' + out_path + '/' + umonyr + '/Report'
    os.system(cmd)
    cmd = 'mkdir ' + out_path + '/' + umonyr + '/Data'
    os.system(cmd)
Пример #11
0
def add_to_log():

    """
    appending error logs extracted Logs location to a record file which will be used for html 
    no input, but it uses machine and user information to set up a file. 

    """
    tdate = current_time_from_machine()

    atemp = re.split('\s+|\t+', tdate)
    day   = atemp[0] 
    mon   = atemp[1]
    date  = atemp[2]
    if int(date) < 10:
        date = ' ' + date
    year  = atemp[5]

    tstamp= day + ' ' + mon + ' ' + date + ' ' + year       #---- this is the time format used for a log
#
#--- set a output file name
#
    dmon = tcnv.changeMonthFormat(mon)                      #--- chnage mon from letters to digit
    mon  = str(dmon)
    if dmon < 10:
        mon = '0' + mon
    
    file = error_log_dir + machine + '_' + user + '_' + mon + '_' + year
    f2   = open(file, 'a')

#
#--- append error logs to the error file
#
    dash   ='-----------------\n'
    border = '#############################################################################\n'

    f2.write('\n')
    f2.write(dash)
    f2.write(tstamp)
    f2.write('\n')
    f2.write(dash)

    f3  = open(tempout, 'r')
    data3 = [line for line in f3.readlines()]
    f3.close()

    for ent3 in data3:
        f2.write(ent3)
        f2.write('\n')

    f2.write('\n')
    f2.write(border)

    f2.close()
Пример #12
0
def find_time_interval(test='NO', month=4, year=2015):
    """
    create start and stop time and output directory name
    input:  test    --- if it is test, yes. default: 'NO'
            month   --- test month input. default: 4. it is ignored if not test.
            year    --- test year input.  default: 2015. it is ignored if not test.
    output: start   --- start time in the format of mm/01/yy (e.g. 03/01/15)
            stop    --- stop time
            dir     --- output directory name in the format of <Mon><yy> (e.g. Jan15)
    """

#
#--- for the case if you want to run the test, there is option...
#
    if test == 'NO':
#
#--- this function gives you the current time. year in the format of 2015, and month in 4
#
        [year, month, day, hours, min, sec, weekday, yday, dst] = tcnv.currentTime()
#
#--- we need start and stop times in the formats of 03/01/15, 04/01/15
#
    year_start = year
    year_end   = year

    this_month = str(month)
    if month < 10:
        this_month = '0' + this_month

    temp_month = month -1
    if temp_month < 1:
        temp_month = 12
        year_start -= 1
    last_month = str(temp_month)
    if temp_month < 10:
        last_month = '0' + last_month

    temp       = str(year_start)
    year_start = temp[2] + temp[3]

    temp       = str(year_end)
    year_end   = temp[2] + temp[3]

    start = last_month + '/01/' + year_start
    stop  = this_month + '/01/' + year_end
#
#--- create the output directory name (format example: Apr15)
#
    cmonth = tcnv.changeMonthFormat(temp_month)
    dir    = cmonth + year_start

    return (start, stop, dir)
Пример #13
0
def add_to_log():
    """
    appending error logs extracted Logs location to a record file which will be used for html 
    no input, but it uses machine and user information to set up a file. 

    """
    tdate = current_time_from_machine()

    atemp = re.split('\s+|\t+', tdate)
    day = atemp[0]
    mon = atemp[1]
    date = atemp[2]
    if int(date) < 10:
        date = ' ' + date
    year = atemp[5]

    tstamp = day + ' ' + mon + ' ' + date + ' ' + year  #---- this is the time format used for a log
    #
    #--- set a output file name
    #
    dmon = tcnv.changeMonthFormat(mon)  #--- chnage mon from letters to digit
    mon = str(dmon)
    if dmon < 10:
        mon = '0' + mon

    file = error_log_dir + machine + '_' + user + '_' + mon + '_' + year
    f2 = open(file, 'a')

    #
    #--- append error logs to the error file
    #
    dash = '-----------------\n'
    border = '#############################################################################\n'

    f2.write('\n')
    f2.write(dash)
    f2.write(tstamp)
    f2.write('\n')
    f2.write(dash)

    f3 = open(tempout, 'r')
    data3 = [line for line in f3.readlines()]
    f3.close()

    for ent3 in data3:
        f2.write(ent3)
        f2.write('\n')

    f2.write('\n')
    f2.write(border)

    f2.close()
Пример #14
0
def sdate_to_ldate_with_space(sdate):
    """
    change date in second from 1998.1.1 to MMM dd
    input:  stime   --- time in seconds from 1998.1.1
    output: ldate   --- date in form of MMM dd (e.g. Aug 19)
    """

    atemp = re.split('\/', sdate)
    mon   = int(float(atemp[0]))
    lmon  = tcnv.changeMonthFormat(mon)

    ldate = lmon + ' ' +  atemp[1]

    return ldate
Пример #15
0
def sdate_to_ldate_with_space(sdate):
    """
    change date in second from 1998.1.1 to MMM dd
    input:  stime   --- time in seconds from 1998.1.1
    output: ldate   --- date in form of MMM dd (e.g. Aug 19)
    """

    atemp = re.split('\/', sdate)
    mon   = int(float(atemp[0]))
    lmon  = tcnv.changeMonthFormat(mon)

    ldate = lmon + ' ' +  atemp[1]

    return ldate
def test_data_creation(lyear, lmonth):
    """
    check whether any data files are created
    input:  lyear   --- year of the data
            lmonth  --- month of the data
    output: True or False
    """

    lmonth = tcnv.changeMonthFormat(lmonth)
    lmonth = lmonth.upper()
    cmd = 'ls ' + data_dir + str(lyear) + str(lmonth) + '/*/*evt1* > ' + zspace
    os.system(cmd)
    data = hcf.read_file_data(zspace, remove=1)
    if len(data) > 0:
        return True
    else:
        return False
Пример #17
0
def create_display_data_table():
    """
    create a readable data table for html page
    Input: none, but read from <data_dir>/ccd<ccd>_<node>
    Output: <web_dir>/ccd<ccd>_<node>
    """

    for ccd in range(0, 10):
        for node in range(0, 4):
            file = 'ccd' + str(ccd) + '_' + str(node)
            infile = data_dir + file
            outfile = web_dir + 'Data/' + file

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

            fo = open(outfile, 'w')
            #
            #--- adding heading
            #
            line = "#\n#Date            Mn K alpha     Al K alpha     Ti K alpha       Slope   Sigma   Int     Sigma\n#\n"
            fo.write(line)
            for ent in data:
                atemp = re.split('\s+', ent)
                stime = int(atemp[0])
                #
                #--- converting the date into <mon> <year> form (e.g. May 2013)
                #
                ltime = tcnv.axTimeMTA(stime)
                btemp = re.split(':', ltime)
                year = btemp[0]
                [mon,
                 mdate] = tcnv.changeYdateToMonDate(int(year), int(btemp[1]))
                lmon = tcnv.changeMonthFormat(mon)
                line = lmon + ' ' + year
                for j in range(1, len(atemp)):
                    line = line + '\t' + atemp[j]

                line = line + '\n'
                fo.write(line)
            fo.close()
Пример #18
0
def create_display_data_table():

    """
    create a readable data table for html page
    Input: none, but read from <data_dir>/ccd<ccd>_<node>
    Output: <web_dir>/ccd<ccd>_<node>
    """

    for ccd in range(0, 10):
        for node in range(0, 4):
            file    = 'ccd' + str(ccd) + '_' +  str(node)
            infile  = data_dir + file
            outfile = web_dir + 'Data/' + file

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

            fo      = open(outfile, 'w')
#
#--- adding heading
#
            line    = "#\n#Date            Mn K alpha     Al K alpha     Ti K alpha       Slope   Sigma   Int     Sigma\n#\n"
            fo.write(line)
            for ent in data:
                atemp = re.split('\s+', ent)
                stime = int(atemp[0])
#
#--- converting the date into <mon> <year> form (e.g. May 2013)
#
                ltime = tcnv.axTimeMTA(stime)
                btemp = re.split(':', ltime)
                year  = btemp[0]
                [mon, mdate] = tcnv.changeYdateToMonDate(int(year), int(btemp[1]))
                lmon  = tcnv.changeMonthFormat(mon)
                line  = lmon + ' ' + year 
                for j in range(1, len(atemp)):
                    line = line + '\t' +  atemp[j]

                line = line + '\n'
                fo.write(line)
            fo.close()
Пример #19
0
def cleanup_sib_dir(lev, mon, year):
    """
    clean up the working directories
    input:  lev     --- data level
            mon     --- month of the data processed
            year    --- year of the data processd
    output: none
    """

    lmon = tcnv.changeMonthFormat(mon)
    lmon = lmon.lower()

    cmd = 'mv ' + s_dir + lev + '/Outdir/lres '
    cmd = cmd + s_dir + lev + '/Outdir/lres_' + lmon + str(year) + '_modified'
    os.system(cmd)

    cmd = 'rm -rf ' + s_dir + lev + '/Outdir/ctirm_dir'
    os.system(cmd)
    cmd = 'rm -rf ' + s_dir + lev + '/Outdir/filtered'
    os.system(cmd)
    cmd = 'rm -rf ' + s_dir + lev + '/Outdir/hres'
    os.system(cmd)
Пример #20
0
def cleanup_sib_dir(lev, mon, year):
    """
    clean up the working directories
    input:  lev     --- data level
            mon     --- month of the data processed
            year    --- year of the data processd
    output: none
    """

    lmon = tcnv.changeMonthFormat(mon)
    lmon = lmon.lower()

    cmd = 'mv ' + s_dir + lev + '/Outdir/lres ' 
    cmd = cmd   + s_dir + lev + '/Outdir/lres_' + lmon +str(year) + '_modified'
    os.system(cmd)

    cmd = 'rm -rf ' + s_dir + lev + '/Outdir/ctirm_dir'
    os.system(cmd)
    cmd = 'rm -rf ' + s_dir + lev + '/Outdir/filtered'
    os.system(cmd)
    cmd = 'rm -rf ' + s_dir + lev + '/Outdir/hres'
    os.system(cmd)
Пример #21
0
def dose_map_creation(year='', mon=''):
    """
    create acis and hrc dose maps
    input:  year    --- year; if it is "", the year of the last month will be used
            mon     --- month;if it is "", the month value of the last month is used
    output: /data/mta/www/mta_max_exp/Images/*.png,     e.g., ACSI_11_2016_i2.png
    """
    #
    #--- if year and month are not given, use the last month's month and year value
    #
    if year == '':
        #
        #--- find today's date
        #
        ltime = tcnv.currentTime()
        year = ltime[0]
        lyear = str(year)  #--- '2016'
        #
        #--- set the last month's month and year
        #
        mon = ltime[1] - 1

        if mon < 1:
            mon = 12
            year -= 1

    cmon = str(mon)
    if mon < 10:
        cmon = '0' + cmon  #--- e.g. 03 or 11

    lmon = tcnv.changeMonthFormat(mon)  #--- e.g. Mar or Nov

    lmonyr = lmon.lower() + lyear[2] + lyear[3]  #--- e.g. jan16
    lm_y = cmon + '_' + lyear  #--- e.g. 03_2016
    #
    #--- create clean acis and hrc exposure maps using ds9
    #
    run_exposure_maps(lyear, cmon)
Пример #22
0
def dose_map_creation(year='', mon=''):
    """
    create acis and hrc dose maps
    input:  year    --- year; if it is "", the year of the last month will be used
            mon     --- month;if it is "", the month value of the last month is used
    output: /data/mta/www/mta_max_exp/Images/*.png,     e.g., ACSI_11_2016_i2.png
    """
#
#--- if year and month are not given, use the last month's month and year value
#
    if year == '':
#
#--- find today's date
#
        ltime = tcnv.currentTime()
        year  = ltime[0]
        lyear = str(year)                           #--- '2016'
#
#--- set the last month's month and year
#
        mon   = ltime[1] -1    

        if mon < 1:
            mon   = 12
            year -= 1

    cmon   = str(mon)
    if mon < 10:
        cmon = '0' + cmon                           #--- e.g. 03 or 11

    lmon   = tcnv.changeMonthFormat(mon)            #--- e.g. Mar or Nov

    lmonyr = lmon.lower() + lyear[2] + lyear[3]     #--- e.g. jan16
    lm_y   = cmon + '_' + lyear                     #--- e.g. 03_2016
#
#--- create clean acis and hrc exposure maps using ds9
#
    run_exposure_maps(lyear, cmon)
Пример #23
0
def create_index(year, mon):
    """
    create index for the past report
    input:  year    --- year
            mon     --- month
    output: line    --- a text to be substituted
    """

    line = ''
    for xyear in range(year, 1999, -1):
        line = line + '<tr>\n<td>' + str(xyear) + '</td>'
        for xmonth in range(1, 13):
            if (xyear == year) and (xmonth >= mon):
                line = line + '<td>&#160</td>\n'
            else:
                stmon = tcnv.changeMonthFormat(xmonth)
                ltmon = stmon.upper()
                tyear = str(xyear)
                line = line + '<td><a href="/mta/REPORTS/MONTHLY/'
                line = line + tyear + ltmon + '/MONTHLY.html">' + stmon + '</a></td>\n'
        line = line + '</tr>\n\n'

    return line
Пример #24
0
def create_index(year, mon):
    """
    create index for the past report
    input:  year    --- year
            mon     --- month
    output: line    --- a text to be substituted
    """

    line = ''
    for xyear in range(year, 1999, -1):
        line = line + '<tr>\n<td>' + str(xyear) + '</td>'
        for xmonth in range(1, 13):
            if (xyear == year) and (xmonth >= mon):
                line = line + '<td>&#160</td>\n'
            else:
                stmon  = tcnv.changeMonthFormat(xmonth)
                ltmon  = stmon.upper()
                tyear  = str(xyear)
                line = line + '<td><a href="/mta/REPORTS/MONTHLY/' 
                line = line + tyear + ltmon + '/MONTHLY.html">' + stmon + '</a></td>\n'
        line = line + '</tr>\n\n'

    return line 
Пример #25
0
def add_html_page(ptype, plot_out,  yr, mo):

    """
    update/add html page to Plot directory
    Input:  ptype       --- indiecator of which html page to be updated
            plot_out    --- a directory where the html page is updated/created
            yr          --- a year of the file
            mo          --- a month of the file
    Output: either month.html or year.hmtl in an appropriate directory
    """

    current = tcnv.currentTime(format='Display')
    lmon    = ''

    if ptype == 'month':
        ofile  = plot_out + 'month.html'
        lmon   = tcnv.changeMonthFormat(int(mo))
        if level == 2:
            file = house_keeping + 'month2.html'
        else:
            file = house_keeping + 'month.html'

    elif ptype == 'year':
        ofile  = plot_out + 'year.html'
        if level == 2:
            file = house_keeping + 'year2.html'
        else:
            file = house_keeping + 'year.html'

    text = open(file, 'r').read()
    text = text.replace('#YEAR#',  yr)
    text = text.replace('#MONTH#', lmon)
    text = text.replace('#DATE#',  current)
    
    f     = open(ofile, 'w')
    f.write(text)
    f.close()
Пример #26
0
def print_main_html(ldate, this_year, this_month):

    """
    printing the main acis dose html page
    Input:  ldate      --- date of update
            this_year  --- current year in digit
            this_month --- current month in digit

    Output: <web_dir>/main_acis_dose_plot.html
    """
    line = '<!DOCTYPE html>\n'
    line = line + '<html>\n'
    line = line + '<head>\n'
    line = line + '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n'
    line = line + '<style  type="text/css">\n'
    line = line + 'table{text-align:center;margin-left:auto;margin-right:auto;border-style:solid;border-spacing:8px;border-width:2px;border-collapse:separate}\n'
    line = line + 'td{text-align:center;padding:8px}\n'
    line = line + '\n'
    line = line + 'a:link {color:#00CCFF;}\n'
    line = line + 'a:visited {color:yellow;}\n'
    line = line + '\n'
    line = line + 'span.nobr {white-space:nowrap;}\n'
    line = line + '</style>\n'
    line = line + '<title>ACIS Count Rate Plots </title>\n'
    line = line + '<script>\n'
    line = line + 'function MyWindowOpener(imgname) {\n'
    line = line + '    msgWindow=open("","displayname","toolbar=no,directories=no,menubar=no,location=no,scrollbars=no,status=no,width=732,height=560,resize=yes");\n'
    line = line + '    msgWindow.document.close();\n'
    line = line + '    msgWindow.document.write("<!DOCTYPE html>");\n'
    line = line + '    msgWindow.document.write("<html><head><title>Bias plot:   "+imgname+"</title></head>");\n'
    line = line + '    msgWindow.document.write("<<meta http-equiv=\'Content-Type\' content=\'text/html; charset=utf-8\' />");\n'
    line = line + '    msgWindow.document.write("<body style=\'background-color:white\'>");\n'
    line = line + '    msgWindow.document.write("<img src=\'./mta_days/mta_dose_count2/"+imgname+"\' style=\"width:692px;height:540px\"></body></html>");\n'
    line = line + '    msgWindow.focus();\n'
    line = line + '}\n'
    line = line + '</script>\n'





    line = line + '</head>\n'
    line = line + '<body style="color:#FFFFFF;background-color:#000000;">\n'

    line = line + '<h2 style="color:aqua;text-align:center">ACIS Dose Plots</h2>\n'
    line = line + '<h3 style="text-align:center">Last Update: ' + ldate + '</h3>\n'
    line = line + '<hr />\n'

#
#--- the links to long term plots
#
    line = line + '<h3>Long Term Trend Plots</h3>\n'
    line = line + '<p style="text-align:center">\n'
    line = line + '<a href="javascript:MyWindowOpener(\'./long_term_plot.png\')"><img src="./long_term_plot.png" style="text-align:center; width: 60%"></a>\n'
    line = line + '</p>\n'

    line = line + '<h3>Monthly Averaged Plots</h3>\n'
    line = line + '<p style="padding-bottom:20px">\n'

    line = line + '<a href=./month_avg_img.html>Imaging CCDs</a><br />\n'
    line = line + '<a href=./month_avg_spec.html>Front Side Spec CCDs</a><br />\n'
    line = line + '<a href=./month_avg_bi.html>Back Side Spec CCDs</a><br />\n'
    line = line + '</p>\n'
    line = line + '<p style="padding-top:20px;padding-bottom:20px"><b> Please Select A Period</b> </p>\n'
#
#--- table explanation
#
    line = line + '<p>\n'
    line = line + 'The following tabless list links to  plots of photon count rates  (counts/sec) for averages of 5min intervals against time (DOM).\n'
    line = line + 'They are simple photon counts for each CCD and not a back ground photon counts; \n'
    line = line + 'it means that no sources are removed from the computation.\n'
    line = line + '</p>\n'
    line = line + '\n'
#
#--- first table from year 2010 to current
#
    
    line = line + '<div style="padding-top:40px"></div>\n'
    line = line + '<table border=1>\n'
    line = line + '<tr>\n'
    line = line + '<th>Year</th>\n'

    for iyear in range(2010, this_year+1):
        line = line +  '<th><b>' + str(iyear) + '</b></th>\n'

    line = line +  '</tr>' + "\n"

    idiff = this_year - 2009

    for dmon in range(1, 13):

        cmon = tcnv.changeMonthFormat(dmon)
        cmon = cmon.upper()
        lmon = cmon.lower()

        line = line +  '<tr><th>' + cmon + '</th>'

        for ix in range(0, idiff):
            dyear     = 2010 + ix

            if ix < idiff -1:

                line = line +  '<td>';
                line = line +  '<a href=./'+ cmon + str(dyear) + '/acis_' + lmon + str(dyear) + '_dose_plot.html>'
                line = line +  cmon + ' ' +  str(dyear) + '</a></td>\n';

            elif ix >= idiff-1:

                if dmon > this_month:
                    line = line + '<td>---</td>\n'
                else:
                    line = line + '<td>'
                    line = line + '<a href=./' + cmon + str(dyear) + '/acis_'+ lmon + str(dyear) + '_dose_plot.html>'
                    line = line + cmon + str(dyear) + '</a></td>\n'

        line = line +  '</tr>\n'
        
    line = line +  '</table>\n'

    line = line + '<div style="padding-bottom:40px"> </div>\n'

#
#--- second table from year 2000 to 2009
#
    
    line = line + '<table border=1>\n'
    line = line + '<tr>\n'
    line = line + '<th>Year</th>\n'

    for iyear in range(2000, 2010):
        line = line +  '<th><b>' + str(iyear) + '</b></th>\n'

    line = line + '</tr>' + "\n"

    for dmon in range(1, 13):

        cmon = tcnv.changeMonthFormat(dmon)
        cmon = cmon.upper()
        lmon = cmon.lower()
        line = line +  '<tr><th>' + cmon + '</th>'

        for ix in range(0, 10):
            dyear     = 2000 + ix

            line = line +  '<td>';
            line = line +  '<a href=./'+ cmon + str(dyear) + '/acis_' + lmon + str(dyear) + '_dose_plot.html>'
            line = line +  cmon + ' ' + str(dyear) + '</a></td>\n';

        line = line +  '</tr>\n'
        
    line = line +  '</table>\n'
#
#--- links to monthly data files
#
    line = line + '<h3>Monthly Average Data</h3>\n'

    line = line + '<div style="padding-top:20px;padding-bottom:20px;text-align:left">\n'
    line = line + '<table border = 1><tr>\n'
    for ccd in range(0, 10):
       line = line + '<th>CCD ' + str(ccd) + '</th>'
    line = line + '</tr>\n'
    for ccd in range(0, 10):
        line = line + '<td><a href="monthly_avg_data_ccd' + str(ccd) + '.dat">Data</td>\n'

    line = line + '</tr></table>\n'
    line = line + '</div>\n'


    line = line + '<hr />\n'
    line = line + '<p style="padding-top:10px;padding-bottom:40px">\n'
    line = line + 'If you have any questions about this page, please contact <a href='
    line = line + '"mailto:[email protected]">[email protected]</a>.\n'
    line = line + '</p>'

	
    line = line + '</body>\n'
    line = line + '</html>\n'
#
#--- print the page
#
    file  = web_dir + '/main_acis_dose_plot.html'
    f     = open(file, 'w')
    f.write(line)
    f.close()
Пример #27
0
def create_weekly_report(date, year, debug = 0):
    """
    main script to set up the weekly report template for the week
    input:  date    --- date in the format of mmdd (e.g. 0910)
            year    --- year in the format of yyyy (e.g. 2015)
            debug   --- if it is other than 0, print out some output
    output: a direcotry containing templete (e.g. Sep10)
    """
#
#--- if the test is requested, create Test directory
#
    if debug != 0:
        os.system('mkdir /data/mta/Script/Weekly/Test/')
        odir = '/data/mta/Script/Weekly/Test/'
    else:
        odir = '/data/mta4/www/REPORTS/'

    oned  = 86400

    syear = str(year)                       #--- 4 digit year
    yrd2  = year[2] + year[3]               #--- 2 digit year
    year  = int(float(year))                #--- integer year
    
    date  = str(date)

    smon  = date[0] + date[1]               #--- two digit month
    mon   = int(float(smon))                #--- integer month
    lmon  = tcnv.changeMonthFormat(mon)     #--- month in letter (e.g.Mar)

    sday  = date[2] + date[3]               #--- two digit mday
    day   = int(float(sday))                #--- integer mday

    stop = tcnv.convertDateToCTime(year, mon, day, 0, 0, 0)

    day_n = stop - 7 * oned
#    tout  = tcnv.axTimeMTA(day_n)
#    ttemp = re.split(':', tout)
#    iru_start  = str(ttemp[0]) + '_' + str(ttemp[1])

    #day01 = stop - 6 * oned
    #day0  = stop - 7 * oned
    day01 = stop - 5 * oned
    day0  = stop - 6 * oned
    lday0 = stime_to_ddate(day0)
    sday0 = sdate_to_ldate(lday0)
    start = day0
    lday1 = stime_to_ddate(day01)

    tout  = tcnv.axTimeMTA(day0)
    ttemp = re.split(':', tout)
    iru_start  = str(ttemp[0]) + '_' + str(ttemp[1])
#
#---  year of the beginning of the period; could be different from that of the end
#
    byear      = ttemp[0]    

    lday0 = stime_to_ddate(day0)

    day1  = stop - 5 * oned
    lday1 = stime_to_ddate(day1)

    day2  = stop - 4 * oned
    lday2 = stime_to_ddate(day2)
    sday2 = sdate_to_ldate(lday2)

    day3  = stop - 3 * oned
    lday3 = stime_to_ddate(day3)

    day4  = stop - 2 * oned
    lday4 = stime_to_ddate(day4)
    sday4 = sdate_to_ldate(lday4)

    day5  = stop - 1 * oned
    lday5 = stime_to_ddate(day5)

    day6  = stop 
    lday6 = stime_to_ddate(day6)
    sday6 = sdate_to_ldate(lday6)

    #tout  = tcnv.axTimeMTA(day5)
    tout  = tcnv.axTimeMTA(day6)
    ttemp = re.split(':', tout)
    iru_stop    = '_' + str(ttemp[1])

    day7  = stop + 1 * oned
    lday7 = stime_to_ddate(day7)
#
#---- setting file name
#
    atemp = re.split('\/', lday6)
    file_date  = atemp[0] + atemp[1]
    file_date2 = atemp[0] + '/' + atemp[1]
    file_name  = file_date + '.html'
#
#--- title
#
    titledate     = lday0 + ' - ' + lday6

    ldate         = sdate_to_ldate(lday6)
    ldate_sp      = sdate_to_ldate_with_space(lday6)

#
#--- focal temp file name
#
    fptemp        = file_date + '_fptemp.gif'
    fpext_range   = str(start)+' '+  str(stop)
    fpstart       = str(start)
    fplsub        = '"'+ sday0 + '", "' + sday2  + '", "' +  sday4  + '", "' + sday6 + '"'
    fpdsub        = str(day0) + ', ' + str(day2) + ', ' + str(day4) + ', ' + str(day6)
#
#--- IRU span
#
    irudate       = iru_start + iru_stop
#
#--- telemetry idl command
#
    telmstart     = stime_to_ddate2(start)
    telmstop      = stime_to_ddate2(stop)
    telem_command = 'weekly_telem,' + telmstart + ',' + telmstop
#
#--- telemetry header line
#
    daylist = '|' + lday0 +'|' + lday1 + '|' + lday2 +'|' + lday3 +'|' + lday4 +'|' + lday5 +'|' + lday6  

#
#--- find trending dates/title
#
    tfile = tdir + 'trending_order'
    f    = open(tfile, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    data.reverse()
    chk = 0
    for ent in data:
        if ent == '\s+' or ent == '':
            continue 

        atemp = re.split(' : ', ent)
        adate = atemp[0].strip()
        aname = atemp[1].strip()
        if chk == 0:
            if adate == file_date2:
                title = aname
                chk   = 1
        else:
            if aname == title:
                last_trend_date = adate
                break
#
#--- index.html input
#
    s1 = sday0[0:3] + ' ' + sday0[3:5]
    s2 = sday6[0:3] + ' ' + sday6[3:5]
    index = '<td> <a href="./' + str(year) + '/' + file_date + '.html">' + s1 + ' - ' + s2 + '</a>'
#
#--- debugging output
#
    if debug != 0:
        print "file_name; "       + file_name 
        print "title date: "      + titledate
        print "ldate: "           + ldate
        print "fptemp: "          + fptemp
        print "fpext_range: "     + fpext_range
        print "fpstart: "         + fpstart
        print " fplsub: "         + fplsub
        print " fpdsub: "         + fpdsub
        print "irudate: "         + irudate
        print "telmstart: "       + telmstart
        print "telmstop: "        + telmstop
        print "telmcommand: "     + telem_command
        print "daylist: "         + daylist
        print "title: "           + title
        print "last_trend_date: " + last_trend_date
        print "index: "           + index
#
#--- create a work directory
#
    cmd = 'mkdir ' + wdir  + ldate
    os.system(cmd)
    outdir = wdir + ldate + '/'

    cmd = 'cp ' + tdir + 'get_ftemp_data.perl' + ' ' + outdir
    os.system(cmd)
    cmd = 'cp ' + tdir + 'subst3.perl'         + ' ' + outdir
    os.system(cmd)
    cmd = 'cp ' + tdir + 'test'                + ' ' + outdir
    os.system(cmd)

    cmd = 'mkdir ' + outdir + '/param'
    os.system(cmd)

#
#--- create instruction page
#
    tfile = tdir + 'instruction'
    f     = open(tfile, 'r')
    input = f.read()
    f.close()
    input = input.replace('#LDATE_S#', ldate_sp)
    input = input.replace('#LDATE#',   ldate)
    input = input.replace('#DDATE#',   file_date)
    input = input.replace('#YEAR#',    syear)
    input = input.replace('#DAYLIST#', daylist)
    input = input.replace('#TELM_CMD#',telem_command)
    input = input.replace('#INDEX#',    index)

    ofile = outdir  + ldate.lower()
    fo    = open(ofile, 'w')
    fo.write(input)
    fo.close()
#
#--- focal temp related files
#
    tfile = tdir + 'get_ftemp_wrap_script'
    f     = open(tfile, 'r')
    input = f.read()
    f.close()

    input = input.replace('#MANDD#',  ldate)
    ofile = outdir + 'get_ftemp_wrap_script'
    fo    = open(ofile, 'w')
    fo.write(input)
    fo.close()
    cmd = 'chmod 755 ' + outdir + 'get_ftemp_wrap_script'
    os.system(cmd)

    tfile = tdir + 'get_ftemp_main_script'
    f     = open(tfile, 'r')
    input = f.read()
    f.close()

    #input = input.replace('#START#',  str(start))
    #input = input.replace('#STOP#',   str(stop))
    input = input.replace('#START#',  str(start + 86400))
    input = input.replace('#STOP#',   str(stop + 86400))
    ofile = outdir + 'get_ftemp_main_script'
    fo    = open(ofile, 'w')
    fo.write(input)
    fo.close()

    cmd = 'chmod 755 ' + outdir + 'get_ftemp_main_script'
    os.system(cmd)

    tfile = tdir + 'plot_erad_time.pro'
    f     = open(tfile, 'r')
    input = f.read()
    f.close()

    input = input.replace('#START#',       str(start))
    input = input.replace('#SDATELIST#',   fpdsub)
    input = input.replace('#LDATELIST#',   fplsub)
    ofile = outdir + 'plot_erad_time.pro'
    fo    = open(ofile, 'w')
    fo.write(input)
    fo.close()

    cmd = 'cp -f ' + outdir + 'plot_erad_time.pro ./Focal/'
    os.system(cmd)
#
#--- this_week file
#
    tfile = tdir + 'this_week'
    f     = open(tfile, 'r')
    input = f.read()
    f.close()
    input = input.replace('#DDATE#',   file_date)
    input = input.replace('#IRUSPAN1#', irudate)
    input = input.replace('#IRUSPAN2#', irudate)
    input = input.replace('#TITLE#',    title)
    input = input.replace('#TITLEDATE#',titledate)

    atemp = last_trend_date
    atemp = atemp.replace('/', '')
    input = input.replace('#PREVREPORT#', atemp)

    atemp = re.split('/', last_trend_date)
    pmon  = int(float(atemp[0]))
    lmon  = tcnv.changeMonthFormat(pmon)
    line  = lmon + ' ' + atemp[1]
#
#--- the previous report could be from the last year
#
    ryear = syear
    if mon < pmon:
        ryear = year -1
        ryear = str(ryear)

    input = input.replace('#RYEAR#',      ryear)

    input = input.replace('#PREVDATE#',   line)

    atitle = str(title)
    atitle = atitle.replace(' ', '_')

    #file  = tdir + 'Headers/' + atitle
    #fs    = open(file, 'r')
    #trend = fs.read()
    #fs.close()
    #input = input.replace("#TREND#", trend)

    [temp1, temp2, temp3, temp4] = read_cti_values()
    input = input.replace('#ATEMP#',  temp1)
    input = input.replace('#ATEMP2#', temp2)
    input = input.replace('#DTEMP#',  temp3)
    input = input.replace('#DTEMP2#', temp4)

    [val, step] = read_sim()
    input = input.replace('#WMOVE#', val)
    input = input.replace('#WSTEP#', step)
#
#--- make photon and bad pixel output
#
    run_bad_pix_and_photon(outdir)
#
#--- run to get focal temp fits files
#
    tstop = stop + 86400
    [fcnt, fdata] = run_focal_temp_data(outdir, start, stop, fptemp)
    [fcnt, fdata] = run_focal_temp_data_new()

    input = input.replace('#TEMPPEAK#', str(fcnt))
    input = input.replace('#TEMPLIST#', fdata)
#
#--- bad pixel
#
    file  = outdir + 'bad_pix_list'
    fs    = open(file, 'r')
    bdata = fs.read()
    fs.close()
    input = input.replace('BAD_PIXEL_TABLE', bdata)
#
#--- photon
#
    file  = outdir + 'photons'
    fs    = open(file, 'r')
    pdata = fs.read()
    fs.close()
    input = input.replace('PHOTON_TABLE', pdata)
#
#--- telem data
#
    update_weekly_telem(year, byear, mon)

    tdata = run_telem_data(telem_command, daylist, outdir)
    input = input.replace('TELEM_TABLE', tdata)
#
#--- trend data
#
    trend = set_trend_data_input(str(date))
    input = input.replace('#TREND#', trend)
#
#--- write out the weekly report
#
    ofile = outdir + file_name
    fo    = open(ofile, 'w')
    fo.write(input)
    fo.close()
#
#--- clean up
#
    cmd = 'rm ./out ./out2'
    os.system(cmd)
#
#--- move files
#
    move_files(date, year, outdir, file_name, fptemp, odir)
#
#--- send out email to admin; notify the job complete
#
    send_email_to_admin(date, year)
Пример #28
0
def printHtml(indir,outdir,  hrc, date, year,month,mean_acc,std_acc,min_acc,min_apos,max_acc,max_apos, asig1, asig2, asig3,mean_dff,  \
                std_dff,min_dff,min_dpos,max_dff,max_dpos,dsig1, dsig2, dsig3):

    'create HTML page to display HRC historical data.'


    [tyear, mon, day, hours, min, sec, weekday, yday, dst] = tcnv.currentTime("Local")

    smon = str(mon)
    if mon < 10:
        smon = '0' + smon

    sday = str(day)
    if day < 10:
        sday = '0' + sday

    outdir = outdir + '/' + hrc + '.html'

    f = open(outdir, 'w')
#
#--- this is a html 5 document
#
    f.write('<!DOCTYPE html>\n')
    f.write('<html>\n')
    f.write('<head>\n')

    f.write("<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />\n")

    f.write("<style  type='text/css'>\n")
    f.write("table{text-align:center;margin-left:auto;margin-right:auto;border-style:solid;border-spacing:8px;border-width:2px;border-collapse:separate}\n")
    f.write("a:link {color:#00CCFF;}\n")
    f.write("a:visited {color:yellow;}\n")
    f.write("td{text-align:center;padding:8px}\n")
    f.write("</style>\n")


    if hrc == 'hrci':
        hname = 'HRC I'
        wname = 'HRCI'
    else:
        hname = 'HRC S'
        wname = 'HRCS'

    line = '<title>' + hname + ' History Data</title>\n'
    f.write(line)
    f.write("</head>\n")

    f.write('<body style="color:white;background-color:black">\n')
    line = '<h2 style="text-align:center">Data: ' + hname + '</h2>\n'
    f.write(line)

    f.write("<div style='padding-bottom:30px'>\n")
    f.write('<table border=1>\n')
    f.write('<tr><th>&#160;</th><th>&#160;</th><th colspan=11>Monlthy</th><th colspan=11>Cumulative</th></tr>\n')
    f.write('<tr style="color:yellow"><th>Year</th><th>Month</th>\n')
    f.write('<th>Mean</th><th>SD</th><th>Min</th><th>Min Position</th><th>Max</th><th>Max Position</th><th>68% Level</th><th>95% Level</th><th>99.7% Level</th><th>Data</th><th>Map</th>\n')
    f.write('<th>Mean</th><th>SD</th><th>Min</th><th>Min Position</th><th>Max</th><th>Max Position</th><th>68% Level</th><th>95% Level</th><th>99.7% Level</th><th>Data</th><th>Map</th></tr>\n')

    for i in range(0, len(date)):

        smonth = str(month[i])
        if month[i] < 10:
            smonth = '0' + smonth

        cmonth = tcnv.changeMonthFormat(month[i])        #---- converting digit to letters, i.e. 1 to Jan

#
#--- monthly HRC dose data
#

        if mean_dff[i] == 0 and std_dff[i] == 0:

            line = '<tr><td>%d</td><td>%d</td><td>NA</td><td>NA</td><td>NA</td><td>NA</td><td>NA</td><td>NA</td>\n' % (year[i], month[i])
            f.write(line)
            f.write('<td>No Data</td><td>No Image</td>\n')
        else:
            line = '<tr><td>%d</td><td>%d</td><td>%4.4f</td><td>%4.4f</td><td>%4.1f</td><td>%s</td><td>%4.1f</td><td>%s</td><td>%4.1f</td><td>%s</td><td>%4.1f</td>\n' \
                    % (year[i], month[i], mean_dff[i], std_dff[i], min_dff[i],min_dpos[i], max_dff[i], max_dpos[i],dsig1[i], dsig2[i], dsig3[i])
            f.write(line)

            fname = wname + '_' + smonth + '_' + str(year[i]) + '.fits.gz'
            line  = '<td><a href="https://cxc.cfa.harvard.edu/mta_days/mta_max_exp/Month_hrc/' + fname +'">fits</a></td>\n'
            f.write(line)
            fname = wname + '_' + smonth + '_' + str(year[i]) + '.png'
            line  = '<td><a href="https://cxc.cfa.harvard.edu/mta_days/mta_max_exp/Images/' + fname + '">map</a></td>\n'
            f.write(line)

#
#---- cumulative HRC dose data
#
        line = '<td>%4.4f</td><td>%4.4f</td><td>%4.1f</td><td>%s</td><td>%4.1f</td><td>%s</td><td>%4.1f</td><td>%s</td><td>%4.1f</td>\n' \
                    % (mean_acc[i], std_acc[i], min_acc[i], min_apos[i], max_acc[i], max_apos[i], asig1[i], asig2[i], asig3[i])

        f.write(line)
        fname = wname + '_08_1999_' + smonth + '_' + str(year[i]) + '.fits.gz'
        line  = '<td><a href="https://cxc.cfa.harvard.edu/mta_days/mta_max_exp/Cumulative_hrc/' + fname +'">fits</a></td>\n'
        f.write(line)
        fname = wname + '_08_1999_' + smonth + '_' + str(year[i]) + '.png'
        line  = '<td><a href="https://cxc.cfa.harvard.edu/mta_days/mta_max_exp/Images/' + fname + '">map</a></td>\n\n'
        f.write(line)

#
#--- put header every new year so that we can read data easier
#
        if month[i] % 12 == 0 and i != (len(date)-1):
            f.write('\n<tr style="color:yellow"><th>Year</th><th>Month</th><th>Mean</th><th>SD</th><th>Min</th><th>Min Position</th><th>Max</th><th>Max Position</th><th>68% Level</th><th>95% Level</th><th>99.7% Level</th><th>Data</th><th>Map</th>\n')
            f.write('<th>Mean</th><th>SD</th><th>Min</th><th>Min Position</th><th>Max</th><th>Max Position</th><th>68% Level</th><th>95% Level</th><th>99.7% Level</th><th>Data</th><th>Map</th></tr>\n\n')

    f.write('</table>\n\n')
    f.write("</div>\n")
    f.write('<hr />\n')

    line = '<p style="padding-top:10px;padding-bottom:10px"><strong style="font-size:105%;float:right">Last Update: ' + smon + '/' + sday + '/' + str(tyear) + '</strong></p>\n'
    f.write(line)

    line = '<p>If you have any questions about this page, contact <a href="mailto:[email protected]">[email protected].</a></p>\n'
    f.write(line)
    f.write('</body>\n')
    f.write('</html>\n')

    f.close()    
Пример #29
0
def find_time_interval_old(test='NO', month=4, year=2015):
    """
    ******THIS VERSION IS RETIRED !!! *********
    create start and stop time and output directory name
    input:  test    --- if it is test, yes. default: 'NO'
            month   --- test month input. default: 4. it is ignored if not test.
            year    --- test year input.  default: 2015. it is ignored if not test.
    output: start   --- start time in the format of mm/01/yy (e.g. 03/01/15)
            stop    --- stop time
            dir     --- output directory name in the format of <Mon><yy> (e.g. Jan15)
    """

    #
    #--- for the case if you want to run the test, there is option...
    #
    if test == 'NO':
        #
        #--- this function gives you the current time. year in the format of 2015, and month in 4
        #
        [year, month, day, hours, min, sec, weekday, yday,
         dst] = tcnv.currentTime()
#
#--- if the date is later 5th of the month, work on this month
#
    if day > 4:
        month += 1
        if month > 12:
            month = 1
            year += 1
#
#--- we need start and stop times in the formats of 03/01/15, 04/01/15
#
    year_start = year
    year_end = year

    this_month = str(month)
    if month < 10:
        this_month = '0' + this_month

    temp_month = month - 1
    if temp_month < 1:
        temp_month = 12
        year_start -= 1
    last_month = str(temp_month)
    if temp_month < 10:
        last_month = '0' + last_month

    #temp       = str(year_start)
    #year_start = temp[2] + temp[3]

    #temp       = str(year_end)
    #year_end   = temp[2] + temp[3]

#    start = last_month + '/01/' + year_start
#    stop  = this_month + '/01/' + year_end
    start = str(year_start) + '-' + last_month + '-01T00:00:00'
    stop = str(year_end) + '-' + this_month + '-01T00:00:00'
    #
    #--- create the output directory name (format example: Apr15)
    #
    cmonth = tcnv.changeMonthFormat(temp_month)
    temp = str(year_start)
    year_dir = temp[2] + temp[3]
    dir = cmonth + year_dir

    return (start, stop, dir)
def print_index_html():
    """
    create and/or update radiation related html page
    """
#
#--- find today's date
#
    [year, mon, day, hours, min, sec, weekday, yday, dst] = tcnv.currentTime()
#
#--- read header part and the first part of the index page
#
    line = open('./Template/index_top', 'r').read()
#
#--- start creating a link table
#
    line = line + '<table border=1 cellpadding=10 cellspacing=2>\n'
    line = line + '<tr>\n'
    line = line + '<td colspan=13>\n'
    line = line + '<table border=1 width=100%>\n'
    line = line + '<tr><th> <a href="all.html" style="font-size:120%">Mission since JAN2010</a></th></tr>\n'
    line = line + '</table>\n'
    line = line + '</td>\n'
    line = line + '</tr>\n'

    line = line + '<tr>'
    line = line + '<th>Year</th><th>Jan</th><th>Feb</th><th>Mar</th><th>Apr</th><th>May</th><th>Jun</th>\n'
    line = line + '<th>Jul</th><th>Aug</th><th>Sep</th><th>Oct</th><th>Nov</th><th>Dec</th>\n'
    line = line + '</tr>\n'
    for eyear in range(year, 1999, -1):
        line = line + '<tr>\n' 
        line = line + '<th>' + str(eyear) + '</th>\n'

        lyear    = str(eyear)
        syear    = lyear[2] + lyear[3]

        for emon in range(1, 13):
            lmon     = tcnv.changeMonthFormat(emon)
            monyear  = lmon.lower() + syear
            cmonyear = monyear.upper()

            if eyear == year and emon > mon:
                line = line +  '<td>' + cmonyear + '</td>\n'
            else:
                line = line + '<td><a href="./' + monyear + '.html">'+ cmonyear + '</a></td>\n'

        line = line + '</tr>\n\n'

    line  = line + '</table>\n'
#
#--- table finished. add a closing part
#
    line  = line + '<div style="padding-top: 15px"></div>\n'
    line  = line + '<hr />'
    line  = line + '<div style="padding-top: 15px"></div>\n'
    line  = line + '<p>This page is maintained by B. Spitzbart (<a href="*****@*****.**">[email protected]</a>).\n'
    line  = line + '</body</html>\n'
#
#--- now write out the page
#
    fo  = open('/data/mta4/www/DAILY/mta_rad/index.html', 'w')
    fo.write(line)
    fo.close()
Пример #31
0
def create_monthly(year='', mon=''):
    """
    create monthly report
    input:  year    --- year; if it is "", the year of the last month will be used
            mon     --- month;if it is "", the month value of the last month is used
    output: monthly report in /data/mta4/www/REPORTS/MONTLHY/<yyyy><MMM>/
    """
    #
    #--- if year and month are not given, use the last month's month and year value
    #
    if year == '':
        #
        #--- find today's date
        #
        ltime = tcnv.currentTime()
        year = ltime[0]
        lyear = str(year)  #--- '2016'
        #
        #--- set the last month's month and year
        #
        mon = ltime[1] - 1

        if mon < 1:
            mon = 12
            year -= 1
            lyear = str(year)  #--- '2016'

    cmon = str(mon)
    if mon < 10:
        cmon = '0' + cmon  #--- e.g. 03 or 11

    lmon = tcnv.changeMonthFormat(mon)  #--- e.g. Mar or Nov

    lmonyr = lmon.lower() + lyear[2] + lyear[3]  #--- e.g. jan16
    lm_y = cmon + '_' + lyear  #--- e.g. 03_2016
    #
    #--- set output directory
    #
    odir = '/data/mta4/www/REPORTS/MONTHLY/' + str(year) + lmon.upper()

    cmd = 'mkdir ' + odir
    os.system(cmd)

    odir = odir + '/'
    #
    #--- set month interval depending on leap year or not
    #
    if tcnv.isLeapYear(year) == 0:
        sdate = [
            '001', '032', '060', '091', '121', '152', '182', '213', '244',
            '274', '305', '335'
        ]
        edate = [
            '032', '060', '091', '121', '152', '182', '213', '244', '274',
            '305', '335', '001'
        ]
    else:
        sdate = [
            '001', '032', '061', '092', '122', '153', '183', '214', '245',
            '275', '306', '336'
        ]
        edate = [
            '032', '061', '092', '122', '153', '183', '214', '245', '275',
            '306', '336', '001'
        ]
#
#--- set start and stop time of the month in <yyyy>:<ddd>:00:00:00 format
#
    tstart = str(year) + ':' + sdate[mon - 1] + ':00:00:00'

    eyear = year
    if mon == 12:
        eyear = year + 1
    tstop = str(eyear) + ':' + edate[mon - 1] + ':00:00:00'
    #
    #--- create configulation plot
    #
    cmd = "cd /data/mta/Script/Month/Config/; create_config_plot.py " + tstart + ' ' + tstop
    os.system(cmd)
    #
    #--- create CTI plots
    #
    os.system(
        "cd /data/mta/Script/Month/CTI/;    monthly_report_cti_avg_plots.py")
    os.system(
        "cd /data/mta/Script/Month/CTI/;    monthly_report_cti_avg_plots_two_section.py"
    )
    #
    #--- create Focal Plane temperature plots
    #
    os.system("cd /data/mta/Script/Month/FOCAL/;  run_all_focal_scripts")
    #
    #--- create ACIS SIB plots
    #
    os.system("cd /data/mta/Script/Month/SIB/;    sib_monthly_report_plot.py")
    #
    #--- create SIM movement plots
    #
    os.system("cd /data/mta/Script/Month/SIM/;    create_monthly_sim_plots")
    #
    #--- copy the created plots to the report directory
    #
    cmd = "cp /data/mta/Script/Month/Config/rad_use_*.png " + odir
    os.system(cmd)
    cmd = "cp /data/mta/Script/Month/CTI/Plots/*png " + odir
    os.system(cmd)
    cmd = "cp -rf /data/mta/Script/Month/CTI/Data " + odir
    os.system(cmd)
    cmd = "cp /data/mta/Script/Month/FOCAL/*png " + odir
    os.system(cmd)
    cmd = "cp /data/mta/Script/Month/FOCAL/Plots/*png " + odir
    os.system(cmd)
    cmd = "cp /data/mta_www/mta_bad_pixel/Plots/hist_ccd_plot_front_side.png " + odir
    os.system(cmd)
    cmd = "cp /data/mta_www/mta_bad_pixel/Plots/hist_plot_ccd5.png " + odir
    os.system(cmd)
    cmd = "cp /data/mta/Script/Month/SIB/*png " + odir
    os.system(cmd)
    cmd = "cp /data/mta/www/mta_max_exp/Images/hrc_max_exp.gif " + odir
    os.system(cmd)
    cmd = "cp /data/mta_www/mta_grat/Focus/Plots/acis_hetg_streak_lrf_focus.png " + odir
    os.system(cmd)
    cmd = "cp /data/mta_www/mta_grat/Focus/Plots/acis_hetg_ax_lrf_focus.png " + odir
    os.system(cmd)
    cmd = "cp /data/mta/Script/Month/SIM/*.png " + odir
    os.system(cmd)
    cmd = "cp /data/mta4/www/DAILY/mta_rad/mon_per_diff_last_one_year.gif " + odir
    os.system(cmd)
    cmd = "cp /data/mta4/www/DAILY/mta_rad/rad_cnts_" + lmonyr + ".gif " + odir
    os.system(cmd)
    cmd = "cp /data/mta4/www/DAILY/mta_pcad/IRU/Plots_new/" + lyear + '/' + lmonyr + "_bias.png " + odir
    os.system(cmd)
    cmd = "cp /data/mta/www/mta_max_exp/Images/hrc_max_exp.gif " + odir
    os.system(cmd)
    #
    #--- move the plots to past plot saving directories
    #
    os.system(
        "mv -f /data/mta/Script/Month/Config/*.png /data/mta/Script/Month/Config/Plots/."
    )
    os.system(
        "mv -f /data/mta/Script/Month/FOCAL/Plots/*gif /data/mta/Script/Month/FOCAL/Plots/Past/."
    )
    os.system(
        "mv -f /data/mta/Script/Month/SIB/*png /data/mta/Script/Month/SIB/Plots/."
    )
    #
    #--- sun spot cycle download
    #
    cmd = 'wget -q -O' + odir + '/solar-cycle-sunspot-number.gif  http://services.swpc.noaa.gov/images/solar-cycle-sunspot-number.gif'
    os.system(cmd)
    #
    #--- now copy  month depend plot files and set the template file for the month
    #
    if mon == 1 or mon == 7:
        cmd = "cp /data/mta_www/mta_acis_sci_run/Corner_pix/Trend_Plots/I3cp.gif " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_acis_sci_run/Corner_pix/Trend_Plots/S3cp.gif " + odir
        os.system(cmd)

        cmd = "cp /data/mta_www/mta_bias_bkg/Plots/Overclock/ccd2.png " + odir + 'ccd2_oc.png'
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_bias_bkg/Plots/Sub/ccd2.png       " + odir + 'ccd2_sub.png'
        os.system(cmd)

        cmd = "cp /data/mta4/www/DAILY/mta_pcad/ACA/TOTAL/Report/MAG_I_AVG_2.png  " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_pcad/ACA/TOTAL/Report/MAG_I_AVG_6.png  " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_pcad/ACA/TOTAL/Report/MAG_I_AVG_7.png  " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_pcad/ACA/TOTAL/Report/MAG_I_AVG_11.png " + odir
        os.system(cmd)

        file = '/data/mta/Script/Month/Scripts/Templates/MONTHLY1.html'  #--- template file name

    elif mon == 2 or mon == 8:
        cmd = "cp /data/mta4/www/DAILY/mta_src/ACIS-I_d_tyear10_psf.gif " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_src/tot_all_xy.gif           " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_src/tot_all_d_rnd.gif        " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_src/tot_all_t_rnd.gif        " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_src/tot_all_d_ravg.gif       " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_src/tot_all_t_ravg.gif       " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_src/tot_all_d_snr.gif        " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_src/tot_all_t_snr.gif        " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_src/tot_all_rot.gif          " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_src/tot_all_t_rot.gif        " + odir
        os.system(cmd)

        cmd = "cp /data/mta_www/mta_aiming/Fig_save/acis_point_err.gif  " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_aiming/Fig_save/hrc_i_point_err.gif " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_aiming/Fig_save/hrc_s_point_err.gif " + odir
        os.system(cmd)

        cmd = "cp -r /data/mta4/www/DAILY/mta_src/Plots " + odir + 'HRMA_Plots'
        os.system(cmd)

        file = '/data/mta/Script/Month/Scripts/Templates/MONTHLY2.html'

    elif mon == 3 or mon == 9:
        cmd = "cp /data/mta_www/mta_acis_sci_run/Events_rej/CCD3_rej_cti.gif " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_acis_sci_run/Events_rej/CCD3_rej_obs.gif " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_acis_sci_run/Events_rej/CCD7_rej_cti.gif " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_acis_sci_run/Events_rej/CCD7_rej_obs.gif " + odir
        os.system(cmd)

        cmd = "cp /data/mta/www/mta_acis_gain/Plots/gain_plot_ccd3.png   " + odir
        os.system(cmd)
        cmd = "cp /data/mta/www/mta_acis_gain/Plots/offset_plot_ccd3.png " + odir
        os.system(cmd)
        cmd = "cp /data/mta/www/mta_acis_gain/Plots/gain_plot_ccd5.png   " + odir
        os.system(cmd)
        cmd = "cp /data/mta/www/mta_acis_gain/Plots/offset_plot_ccd5.png " + odir
        os.system(cmd)

        file = '/data/mta/Script/Month/Scripts/Templates/MONTHLY3.html'

    elif mon == 4 or mon == 10:
        #cmd = "cp /data/mta_www/mta_grat/EdE/heg_all.gif  " + odir
        #os.system(cmd)
        #cmd = "cp /data/mta_www/mta_grat/EdE/meg_all.gif  " + odir
        #os.system(cmd)
        #cmd = "cp /data/mta_www/mta_grat/EdE/leg_all.gif  " + odir
        #os.system(cmd)
        cmd = "cp /data/mta_www/mta_grat/EdE/*_2019.png " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_sim_twist/Plots/twist_plot.png " + odir
        os.system(cmd)

        file = '/data/mta/Script/Month/Scripts/Templates/MONTHLY4.html'

    elif mon == 5 or mon == 11:
        cmd = "cp /data/mta_www/mta_sib/Plots/Plot_long_term/full_plot_ccd3.png " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_sib/Plots/Plot_long_term/full_plot_ccd5.png " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_sib/Plots/Plot_long_term/full_plot_ccd7.png " + odir
        os.system(cmd)

        cmd = "cp /data/mta_www/mta_acis_hist/Html_pages/acis_hist_cccd3_high_pos.html   " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_acis_hist/Html_pages/acis_hist_cccd3_high_width.html " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_acis_hist/Html_pages/acis_hist_cccd3_high_cnt.html   " + odir
        os.system(cmd)

        file = '/data/mta/Script/Month/Scripts/Templates/MONTHLY5.html'

    elif mon == 6 or mon == 12:
        cmd = "cp /data/mta_www/mta_sim_twist/Plots/I-1.png   " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_sim_twist/Plots/S-2.png   " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_sim_twist/Plots/H-I-2.png " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_sim_twist/Plots/H-S-2.png " + odir
        os.system(cmd)

        file = '/data/mta/Script/Month/Scripts/Templates/MONTHLY6.html'
#
#--- create clean acis and hrc exposure maps using ds9
#
    run_exposure_maps(lyear, cmon)

    #--------------------------------------------------
    #--- read the template and substitute the contents
    #--------------------------------------------------

    fx = open(file, 'r')
    text = fx.read()
    fx.close()
    #
    #--- substitute values
    #
    fmonth_list = [
        'January', 'February', 'March', 'April', 'May', 'June', 'July',
        'August', 'September', 'October', 'November', 'December'
    ]

    fmon = fmonth_list[mon - 1]
    text = text.replace('#Month#', fmon)  #--- full month name e.g. May
    text = text.replace('#YEAR#', lyear)  #--- full year nane  e.g. 2016

    text = text.replace('#SMON#', lmon)  #--- short month, e.g. Jan
    text = text.replace('#LSMON#',
                        lmon.lower())  #--- short lower month, e.g. jan
    text = text.replace('#USMON#',
                        lmon.upper())  #--- short upper month, e.g. JAN

    line = 'rad_use_' + lmonyr + '.png'
    text = text.replace('#RADUSE#', line)  #--- e.g., rad_use_oct16.png

    line = cmon + '_' + lyear
    text = text.replace('#LMONYR#', line)  #--- mon_year e.g. 07_2016
    #
    #--- acis exposure tables
    #
    os.system(
        "cd /data/mta/Script/Exposure/Exc/; /data/mta/Script/Exposure/Scripts/ACIS_Scripts/acis_dose_monthly_report.py"
    )

    line = '/data/mta/Script/Exposure/Exc/monthly_diff_' + cmon + '_' + lyear
    f = open(line, 'r')
    dout = f.read()
    f.close()
    text = text.replace('#ACISMON#', dout)  #--- acis monthly dose

    line = '/data/mta/Script/Exposure/Exc/monthly_acc_' + cmon + '_' + lyear
    f = open(line, 'r')
    dout = f.read()
    f.close()
    text = text.replace('#ACISCMON#', dout)  #--- acis cumulative dose
    #
    #--- last 12 months exposure maps
    #
    byear = year - 1
    text = past_data_entry(1, 0, mon, byear, text)
    text = past_data_entry(2, 3, mon, byear, text)
    text = past_data_entry(3, 6, mon, byear, text)
    text = past_data_entry(4, 9, mon, byear, text)
    #
    #---- acis focal
    #
    fx = open('/data/mta/Script/Month/FOCAL/Plots/month_avg', 'r')
    data = [line.strip() for line in fx.readlines()]
    fx.close()

    atemp = re.split(':', data[0])
    btemp = re.split('\+\/\-', atemp[1])
    ft = round(float(btemp[0]), 2)
    ferr = round(float(btemp[1]), 2)

    text = text.replace('#FT#', str(ft))
    text = text.replace('#FERR#', str(ferr))

    atemp = re.split(':', data[1])
    btemp = re.split('\+\/\-', atemp[1])
    fw = round(float(btemp[0]), 2)
    werr = round(float(btemp[1]), 2)

    text = text.replace('#FW#', str(fw))
    text = text.replace('#WERR#', str(werr))

    line = 'erad_' + lmonyr + '.gif'  #--- erand_nov16.gif
    text = text.replace('#ERAND#', line)
    #
    #--- acis sib
    #
    yearmon = str(year) + '_' + cmon
    text = text.replace('#YEARMON#', yearmon)  #--- e.g. 2015_03
    #
    #--- hrc i monthly dose
    #
    line = hrc_monthly_report('HRCI', cmon, lmon, lyear)
    text = text.replace('#HRCIDOSE#', line)  #--- HRC I DIFF
    #
    #--- hrc cumulative
    #
    line = hrc_cumulative_report('HRCI', cmon, lmon, lyear)
    text = text.replace('#CHRCIDOSE#', line)  #--- HRC I Cumulative
    #
    #--- hrc s monthly dose
    #
    line = hrc_monthly_report('HRCS', cmon, lmon, lyear)
    text = text.replace('#HRCSDOSE#', line)  #--- HRC S DIFF
    #
    #--- hrc cumulative
    #
    line = hrc_cumulative_report('HRCS', cmon, lmon, lyear)
    text = text.replace('#CHRCSDOSE#', line)  #--- HRC S Cumulative
    #
    #--- IRU
    #
    text = text.replace("#SMONYR#", lmonyr)  #--- e.g., nov16
    #
    #--- envelope trending
    #
    line = get_envelope_trending(mon, odir)
    text = text.replace("#ENVTREND#", line)
    #
    #--- critical trends which are reported on Mar, Jun, Sep, and Dec
    #
    if mon in [3, 6, 9, 12]:
        text = run_critical_trend(text)
#
#--- Monthly Trend Reports
#
    text = run_month_trend(mon, text)
    #
    #--- last index
    #
    line = create_index(year, mon)
    text = text.replace('#YINDEX#', line)
    #
    #--- finally print out the report
    #
    ofile = odir + "MONTHLY.html"
    fo = open(ofile, 'w')
    fo.write(text)
    fo.close()
    #
    #--- chnage permission and owners
    #
    cmd = 'chmod 755 ' + odir + '/*'
    os.system(cmd)

    cmd = 'chgrp -R mtagroup ' + odir + '/*'
    os.system(cmd)
Пример #32
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]
Пример #33
0
def print_html(year, mon):
    """
    create and/or update radiation related html page
    """
    #
    #--- find today's date
    #
    if year == '':
        [year, mon, day, hours, min, sec, weekday, yday,
         dst] = tcnv.currentTime()
#
#--- find out the last month
#
#        cyear = year
#        lmon      = mon -1
#        if lmon < 1:
#            lmon  = 12
#            cyear = year -1

#
#--- for the case year and mon are given
#
    cyear = year
    lmon = mon
    #
    #--- choose a correct month list depending on whether this is the leap year
    #
    if tcnv.isLeapYear(cyear) == 1:
        mon_list = mon_list1
    else:
        mon_list = mon_list2

    last_day = mon_list[lmon - 1]
    #
    #--- convert the month from a numeric to letter
    #
    umon = tcnv.changeMonthFormat(lmon)
    smon = umon.lower()

    lmon_year = str(cyear)
    syear = lmon_year[2] + lmon_year[3]
    last_year = str(year - 1)
    syear2 = last_year[2] + last_year[3]
    monyear = smon + syear
    #
    #--- set output html page names
    #
    year_html = 'all' + syear + '.html'
    mon_html = monyear + '.html'
    rad_html = 'rad_time_' + monyear + '.html'
    #
    #--- read yearly html page template
    #
    data = open('./Template/yearly_template', 'r').read()

    data = data.replace('$#FYEAR#$', str(year))
    data = data.replace('$#SYEAR#$', syear)

    fo = open(year_html, 'w')
    fo.write(data)
    fo.close()
    #
    #--- read monthly html page template
    #
    data = open('./Template/monthly_template', 'r').read()

    data = data.replace('$#FYEAR#$', str(year))
    data = data.replace('$#UMON#$', umon)
    data = data.replace('$#MONYEAR#$', monyear)

    fo = open(mon_html, 'w')
    fo.write(data)
    fo.close()
    #
    #--- read rad_time html page template
    #
    data = open('./Template/rad_time_template', 'r').read()

    data = data.replace('$#LMONTH#$', fmon_list[mon - 2])
    data = data.replace('$#FYEAR#$', str(year))
    data = data.replace('$#MONYEAR#$', monyear)

    fo = open(rad_html, 'w')
    fo.write(data)
    fo.close()
Пример #34
0
def print_index_html():
    """
    create and/or update radiation related html page
    """
    #
    #--- find today's date
    #
    [year, mon, day, hours, min, sec, weekday, yday, dst] = tcnv.currentTime()
    #
    #--- read header part and the first part of the index page
    #
    line = open('./Template/index_top', 'r').read()
    #
    #--- start creating a link table
    #
    line = line + '<table border=1 cellpadding=10 cellspacing=2>\n'
    line = line + '<tr>\n'
    line = line + '<td colspan=13>\n'
    line = line + '<table border=1 width=100%>\n'
    line = line + '<tr><th> <a href="all.html" style="font-size:120%">Mission since JAN2010</a></th></tr>\n'
    line = line + '</table>\n'
    line = line + '</td>\n'
    line = line + '</tr>\n'

    line = line + '<tr>'
    line = line + '<th>Year</th><th>Jan</th><th>Feb</th><th>Mar</th><th>Apr</th><th>May</th><th>Jun</th>\n'
    line = line + '<th>Jul</th><th>Aug</th><th>Sep</th><th>Oct</th><th>Nov</th><th>Dec</th>\n'
    line = line + '</tr>\n'
    for eyear in range(year, 1999, -1):
        line = line + '<tr>\n'
        line = line + '<th>' + str(eyear) + '</th>\n'

        lyear = str(eyear)
        syear = lyear[2] + lyear[3]

        for emon in range(1, 13):
            lmon = tcnv.changeMonthFormat(emon)
            monyear = lmon.lower() + syear
            cmonyear = monyear.upper()

            if eyear == year and emon > mon:
                line = line + '<td>' + cmonyear + '</td>\n'
            else:
                line = line + '<td><a href="./' + monyear + '.html">' + cmonyear + '</a></td>\n'

        line = line + '</tr>\n\n'

    line = line + '</table>\n'
    #
    #--- table finished. add a closing part
    #
    line = line + '<div style="padding-top: 15px"></div>\n'
    line = line + '<hr />'
    line = line + '<div style="padding-top: 15px"></div>\n'
    line = line + '<p>This page is maintained by B. Spitzbart (<a href="*****@*****.**">[email protected]</a>).\n'
    line = line + '</body</html>\n'
    #
    #--- now write out the page
    #
    fo = open('/data/mta4/www/DAILY/mta_rad/index.html', 'w')
    fo.write(line)
    fo.close()
Пример #35
0
def print_month_html(mon_dir_name, ldate, this_year, this_month):

    """
    printing html page for each month
    Input:  mon_dir_name --- a directory in which the plots are kept
            ldate        --- date of update
            this_year    --- current year in digit
            this_month   --- current month in digit

    Output: <web_dir>/<mon_dir_name>/acis_<lmon><year>_dose_plot.html
    """
    cmon = tcnv.changeMonthFormat(this_month)
    cmon = cmon.upper()
    lmon = cmon.lower()

    line = '<!DOCTYPE html>\n'
    line = line + '<html>\n'
    line = line + '<head>\n'
    line = line + '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n'
    line = line + '<style  type="text/css">\n'
    line = line + 'table{text-align:center;margin-left:auto;margin-right:auto;border-style:solid;border-spacing:8px;border-width:2px;border-collapse:separate}\n'
    line = line + 'td{text-align:center;padding:8px}\n'
    line = line + '\n'
    line = line + 'a:link {color:#00CCFF;}\n'
    line = line + 'a:visited {color:yellow;}\n'
    line = line + '\n'
    line = line + 'span.nobr {white-space:nowrap;}\n'
    line = line + '</style>\n'
    line = line + '<title>ACIS Count Rate Plots </title>\n'
    line = line + '</head>\n'
    line = line + '<body style="color:#FFFFFF;background-color:#000000;">\n'

    line = line + '<h2 style="text-align:center;color:aqua">ACIS Count Rate Plot: ' + cmon + ', ' + str(this_year) + '</h2>\n'
    line = line + '<h3 style="text-align:center">Created on ' + ldate + '</h3>\n'
    line = line + '<hr />\n'
    line = line + '<p><b> Please Select CCD:</b> </p>\n'
    line = line + '<table  border=0 style="margin-left:auto;margin-right:auto">\n'
    line = line + '<tr><th style="font-size:110%">Plot</td><th style="font-size:110%">Data</td></tr>\n'

    for ccd in range(0, 10):
        line = line + '<tr><td><a href="./acis_dose_ccd' + str(ccd) + '.html">CCD ' + str(ccd) + ' Plot</a></td>' 
        line = line + '<td><a href="./ccd' + str(ccd) + '">CCD ' + str(ccd) + ' Data</a></td></tr>\n'

    line = line + '<td><a href="./acis_dose_ccd_5_7.html">CCDs 5 - 7 Plot</a></td><td>&#160</td></tr>\n'
    line = line + '<td><a href="./ephin_rate.html">Ephin Count Rate Plot</a></td><td><a href="./ephin_rate">Ephin Data</a></td></tr>\n'
    line = line + '</table>\n'


    line = line + '<p style="padding-top:15px;padding-bottom:15px">To check a dose map, please go to <a href=https://cxc.cfa.harvard.edu/mta/REPORTS/MONTHLY/'
    line = line +  str(this_year) + cmon +  '/MONTHLY.html>' + cmon + ' ' +  str(this_year) + ' Monthly Report</a>.</p>\n'

    line = line +  '<p>Back to <a href=../main_acis_dose_plot.html>Main Page</a>\n'
    line = line + '</body>\n</html>\n'

    cmon = tcnv.changeMonthFormat(this_month)
    cmon = cmon.upper()
    lmon = cmon.lower()

    name = web_dir + '/' + mon_dir_name + '/acis_' + lmon + str(this_year) + '_dose_plot.html'
    f    = open(name, 'w')
    f.write(line)
    f.close()
Пример #36
0
def create_monthly_focal_temp(year, month, eyear, emonth):
    """
    main script to create a monthly focal temp trend plots
    input:  year    --- start year in the format of yyyy (e.g. 2015)
            month   --- start month in the format of mm (e.g. 1 or 12)
            eyear   --- stopping year
            emonth  --- stopping month
    output: a direcotry containing templete (e.g. Sep10)
    """

    oned  = 86400

    syear = str(year)                       #--- 4 digit year
    yrd2  = syear[2] + syear[3]             #--- 2 digit year
    year  = int(float(year))                #--- integer year
    
    smon  = str(month)
    mon   = int(float(smon))                #--- integer month
    lmon  = tcnv.changeMonthFormat(mon)     #--- month in letter (e.g.Mar)

    sday  = '01'                            #--- two digit mday
    day   = 1                               #--- integer mday

    start = tcnv.convertDateToCTime(year, mon, day, 0, 0, 0)


    seyear = str(eyear)                     #--- 4 digit year
    eyrd2  = seyear[2] + seyear[3]          #--- 2 digit year
    eyear  = int(float(eyear))              #--- integer year
    
    semon  = str(emonth)
    emon   = int(float(semon))              #--- integer month
    lemon  = tcnv.changeMonthFormat(emon)   #--- month in letter (e.g.Mar)

    seday  = '01'                           #--- two digit mday
    eday   = 1                              #--- integer mday

    stop   = tcnv.convertDateToCTime(eyear, emon, eday, 0, 0, 0)
#
#--- set plot tick interval
#
    if mon == 2:
        dlist = [10, 20, 28]
        if tcnv.isLeapYear(year) == 1:
            dlist = [ 10, 20, 29]
    else:
        dlist  = [10, 20, 30]
    sdlist = [start]
    for ent in dlist:
        stime = tcnv.convertDateToCTime(year, mon, ent, 0, 0, 0)
        sdlist.append(stime)
#
#--- focal temp file name
#
    fptemp        = 'erad_' + lmon.lower() + yrd2 + '.gif'
    fpext_range   = str(start)+' '+  str(stop)
    fpstart       = str(start)
    fplsub        = '"' + lmon.lower() + '01","' + lmon.lower() + '10","' + lmon.lower() + '20","' + lmon.lower() + str(dlist[2]) + '"'
    fpdsub        = str(sdlist[0]) + ', ' + str(sdlist[1]) + ', ' + str(sdlist[2]) + ', ' + str(sdlist[3])

#
#--- copy command scripts and a couple of others needed
#
    cmd = 'cp -f  ' + tdir + 'get_ftemp_data.perl ' + wdir + '.'
    os.system(cmd)
    cmd = 'cp -f  ' + tdir + 'test ' + wdir + '.'
    os.system(cmd)
    cmd = 'cp -f  ' + tdir + 'run_temp  ' + wdir + '.'
    os.system(cmd)

    cmd = 'rm -rf param'
    os.system(cmd)
    cmd = 'mkdir param'
    os.system(cmd)
#
#--- create idl script
#
    tfile = tdir +  'plot_erad_time_month.pro'
    f     = open(tfile, 'r')
    input = f.read()
    f.close()

    input = input.replace('#START#',       str(start))
    input = input.replace('#SDATELIST#',   fpdsub)
    input = input.replace('#LDATELIST#',   fplsub)
    input = input.replace('#GIFNAME#',     fptemp)
    ofile =  wdir + 'plot_erad_time_month.pro'
    fo    = open(ofile, 'w')
    fo.write(input)
    fo.close()
#
#--- run the scripts
#
    run_focal_temp_data(start, stop) 
    cmd = 'mv ' + fptemp + ' ./Plots/.'
    os.system(cmd)
#
#--- clean up
#
    cmd = 'rm -rf param  get_ftemp_data.perl test run_temp plot_erad_time_month.pro out'
    os.system(cmd)
Пример #37
0
def create_monthly(year='', mon=''):
    """
    create monthly report
    input:  year    --- year; if it is "", the year of the last month will be used
            mon     --- month;if it is "", the month value of the last month is used
    output: monthly report in /data/mta4/www/REPORTS/MONTLHY/<yyyy><MMM>/
    """
#
#--- if year and month are not given, use the last month's month and year value
#
    if year == '':
#
#--- find today's date
#
        ltime = tcnv.currentTime()
        year  = ltime[0]
        lyear = str(year)                           #--- '2016'
#
#--- set the last month's month and year
#
        mon   = ltime[1] -1    

        if mon < 1:
            mon   = 12
            year -= 1
            lyear = str(year)                           #--- '2016'

    cmon   = str(mon)
    if mon < 10:
        cmon = '0' + cmon                           #--- e.g. 03 or 11

    lmon   = tcnv.changeMonthFormat(mon)            #--- e.g. Mar or Nov

    lmonyr = lmon.lower() + lyear[2] + lyear[3]     #--- e.g. jan16
    lm_y   = cmon + '_' + lyear                     #--- e.g. 03_2016
#
#--- set output directory
#
    odir  = '/data/mta4/www/REPORTS/MONTHLY/' + str(year) + lmon.upper()

    cmd = 'mkdir ' + odir
    os.system(cmd)

    odir  =  odir + '/'
#
#--- set month interval depending on leap year or not
#
    if tcnv.isLeapYear(year) == 0:
        sdate = ['001', '032', '060', '091', '121', '152', '182', '213', '244', '274', '305', '335']
        edate = ['032', '060', '091', '121', '152', '182', '213', '244', '274', '305', '335', '001']
    else:
        sdate = ['001', '032', '061', '092', '122', '153', '183', '214', '245', '275', '306', '336']
        edate = ['032', '061', '092', '122', '153', '183', '214', '245', '275', '306', '336', '001']
#
#--- set start and stop time of the month in <yyyy>:<ddd>:00:00:00 format
#
    tstart = str(year) + ':' + sdate[mon-1] + ':00:00:00' 

    eyear  = year
    if mon == 12:
        eyear = year + 1
    tstop  = str(eyear) + ':' + edate[mon-1] + ':00:00:00' 
#
#--- create configulation plot
#
    cmd = "cd /data/mta/Script/Month/Config/; create_config_plot.py " +  tstart + ' ' + tstop
    os.system(cmd)
#
#--- create CTI plots
#
    os.system("cd /data/mta/Script/Month/CTI/;    monthly_report_cti_avg_plots.py")
    os.system("cd /data/mta/Script/Month/CTI/;    monthly_report_cti_avg_plots_two_section.py")
#
#--- create Focal Plane temperature plots
#
    os.system("cd /data/mta/Script/Month/FOCAL/;  run_all_focal_scripts")
#
#--- create ACIS SIB plots
#
    os.system("cd /data/mta/Script/Month/SIB/;    sib_monthly_report_plot.py")
#
#--- create SIM movement plots
#
    os.system("cd /data/mta/Script/Month/SIM/;    create_monthly_sim_plots")
#
#--- copy the created plots to the report directory
#
    cmd = "cp /data/mta/Script/Month/Config/rad_use_*.png " + odir 
    os.system(cmd)
    cmd = "cp /data/mta/Script/Month/CTI/Plots/*png "       + odir 
    os.system(cmd)
    cmd = "cp -rf /data/mta/Script/Month/CTI/Data "         + odir 
    os.system(cmd)
    cmd = "cp /data/mta/Script/Month/FOCAL/Plots/*png "     + odir 
    os.system(cmd)
    cmd = "cp /data/mta/Script/Month/FOCAL/Plots/*gif "     + odir 
    os.system(cmd)
    cmd = "cp /data/mta_www/mta_bad_pixel/Plots/hist_ccd_plot_front_side.png " + odir 
    os.system(cmd)
    cmd = "cp /data/mta_www/mta_bad_pixel/Plots/hist_plot_ccd5.png " + odir 
    os.system(cmd)
    cmd = "cp /data/mta/Script/Month/SIB/*png "                      + odir 
    os.system(cmd)
    cmd = "cp /data/mta/www/mta_max_exp/Images/hrc_max_exp.gif "     + odir 
    os.system(cmd)
    cmd = "cp /data/mta_www/mta_grat/Focus/foc_acis_hetg.gif "       + odir 
    os.system(cmd)
    cmd = "cp /data/mta/Script/Month/SIM/*.png "                     + odir 
    os.system(cmd)
    cmd = "cp /data/mta4/www/DAILY/mta_rad/mon_per_diff_last_one_year.gif " + odir 
    os.system(cmd)
    cmd = "cp /data/mta4/www/DAILY/mta_rad/rad_cnts_" + lmonyr + ".gif "    + odir 
    os.system(cmd)
    cmd = "cp /data/mta4/www/DAILY/mta_pcad/IRU/Plots/" + lmonyr + "_1h_bias.gif " + odir 
    os.system(cmd)
    cmd = "cp /data/mta/www/mta_max_exp/Images/hrc_max_exp.gif "           + odir 
    os.system(cmd)
#
#--- move the plots to past plot saving directories
#
    os.system("mv -f /data/mta/Script/Month/Config/*.png /data/mta/Script/Month/Config/Plots/.")
    os.system("mv -f /data/mta/Script/Month/FOCAL/Plots/*gif /data/mta/Script/Month/FOCAL/Plots/Past/.")
    os.system("mv -f /data/mta/Script/Month/SIB/*png /data/mta/Script/Month/SIB/Plots/.")
#
#--- copy other plot files we need for the report
#
    cmd = "cp /data/mta4/www/DAILY/mta_pcad/IRU/Plots/" + lmonyr + "_1h_bias.gif " + odir
    os.system(cmd)
    cmd = 'cp /data/mta4/www/DAILY/mta_rad/rad_cnts_'   + lmonyr + ".gif "         + odir
    os.system(cmd)
#
#--- sun spot cycle download
#
    cmd = 'wget -q -O'+ odir + '/solar-cycle-sunspot-number.gif  http://services.swpc.noaa.gov/images/solar-cycle-sunspot-number.gif'
    os.system(cmd)
#
#--- now copy  month depend plot files and set the template file for the month
#
    if mon == 1 or mon == 7:
        cmd = "cp /data/mta_www/mta_acis_sci_run/Corner_pix/Trend_Plots/I3cp.gif " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_acis_sci_run/Corner_pix/Trend_Plots/S3cp.gif " + odir
        os.system(cmd)

        cmd = "cp /data/mta_www/mta_bias_bkg/Plots/Overclock/ccd2.png " + odir + 'ccd2_oc.png'
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_bias_bkg/Plots/Sub/ccd2.png       " + odir + 'ccd2_sub.png'
        os.system(cmd)

        cmd = "cp /data/mta4/www/DAILY/mta_pcad/ACA/TOTAL/Report/MAG_I_AVG_2.png  " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_pcad/ACA/TOTAL/Report/MAG_I_AVG_6.png  " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_pcad/ACA/TOTAL/Report/MAG_I_AVG_7.png  " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_pcad/ACA/TOTAL/Report/MAG_I_AVG_11.png " + odir
        os.system(cmd)

        file = '/data/mta/Script/Month/Scripts/Templates/MONTHLY1.html'             #--- template file name

    elif mon == 2 or mon == 8:
        cmd = "cp /data/mta4/www/DAILY/mta_src/ACIS-I_d_tyear10_psf.gif " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_src/tot_all_xy.gif           " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_src/tot_all_d_rnd.gif        " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_src/tot_all_t_rnd.gif        " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_src/tot_all_d_ravg.gif       " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_src/tot_all_t_ravg.gif       " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_src/tot_all_d_snr.gif        " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_src/tot_all_t_snr.gif        " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_src/tot_all_rot.gif          " + odir
        os.system(cmd)
        cmd = "cp /data/mta4/www/DAILY/mta_src/tot_all_t_rot.gif        " + odir
        os.system(cmd)

        cmd = "cp /data/mta_www/mta_aiming/Fig_save/acis_point_err.gif  " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_aiming/Fig_save/hrc_i_point_err.gif " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_aiming/Fig_save/hrc_s_point_err.gif " + odir
        os.system(cmd)

        file = '/data/mta/Script/Month/Scripts/Templates/MONTHLY2.html'

    elif mon == 3 or mon == 9:
        cmd = "cp /data/mta_www/mta_acis_sci_run/Events_rej/CCD3_rej_cti.gif " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_acis_sci_run/Events_rej/CCD3_rej_obs.gif " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_acis_sci_run/Events_rej/CCD7_rej_cti.gif " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_acis_sci_run/Events_rej/CCD7_rej_obs.gif " + odir
        os.system(cmd)

        cmd = "cp /data/mta/www/mta_acis_gain/Plots/gain_plot_ccd3.png   " + odir
        os.system(cmd)
        cmd = "cp /data/mta/www/mta_acis_gain/Plots/offset_plot_ccd3.png " + odir
        os.system(cmd)
        cmd = "cp /data/mta/www/mta_acis_gain/Plots/gain_plot_ccd5.png   " + odir
        os.system(cmd)
        cmd = "cp /data/mta/www/mta_acis_gain/Plots/offset_plot_ccd5.png " + odir
        os.system(cmd)

        file = '/data/mta/Script/Month/Scripts/Templates/MONTHLY3.html'

    elif mon == 4 or mon == 10:
        cmd = "cp /data/mta_www/mta_grat/EdE/heg_all.gif  " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_grat/EdE/meg_all.gif  " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_grat/EdE/leg_all.gif  " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_sim_twist/Plots/twist_plot.png " + odir
        os.system(cmd)

        file = '/data/mta/Script/Month/Scripts/Templates/MONTHLY4.html'

    elif mon == 5 or mon == 11:
        cmd = "cp /data/mta_www/mta_sib/Plots/Plot_long_term/full_plot_ccd3.png " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_sib/Plots/Plot_long_term/full_plot_ccd5.png " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_sib/Plots/Plot_long_term/full_plot_ccd7.png " + odir
        os.system(cmd)

        cmd = "cp /data/mta_www/mta_acis_hist/Html_pages/acis_hist_cccd3_high_pos.html   " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_acis_hist/Html_pages/acis_hist_cccd3_high_width.html " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_acis_hist/Html_pages/acis_hist_cccd3_high_cnt.html   " + odir
        os.system(cmd)

        file = '/data/mta/Script/Month/Scripts/Templates/MONTHLY5.html'

    elif mon == 6 or mon == 12:
        cmd = "cp /data/mta_www/mta_sim_twist/Plots/I-1.png   " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_sim_twist/Plots/S-2.png   " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_sim_twist/Plots/H-I-2.png " + odir
        os.system(cmd)
        cmd = "cp /data/mta_www/mta_sim_twist/Plots/H-S-2.png " + odir
        os.system(cmd)

        file = '/data/mta/Script/Month/Scripts/Templates/MONTHLY6.html'
#
#--- create clean acis and hrc exposure maps using ds9
#
    run_exposure_maps(lyear, cmon)

#--------------------------------------------------
#--- read the template and substitute the contents 
#--------------------------------------------------

    fx   = open(file, 'r')
    text = fx.read()
    fx.close()
#
#--- substitute values
#
    fmonth_list = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']

    fmon = fmonth_list[mon-1]             
    text = text.replace('#Month#', fmon)        #--- full month name e.g. May
    text = text.replace('#YEAR#',  lyear)       #--- full year nane  e.g. 2016

    text = text.replace('#SMON#', lmon)         #--- short month, e.g. Jan
    text = text.replace('#LSMON#', lmon.lower())#--- short lower month, e.g. jan

    line = 'rad_use_' + lmonyr + '.png'
    text = text.replace('#RADUSE#', line)       #--- e.g., rad_use_oct16.png

    line = cmon + '_' + lyear
    text = text.replace('#LMONYR#', line)       #--- mon_year e.g. 07_2016
#
#--- acis exposure tables
#
    os.system("cd /data/mta/Script/Exposure/Exc/; /data/mta/Script/Exposure/Scripts/ACIS_Scripts/acis_dose_monthly_report.py")

    line = '/data/mta/Script/Exposure/Exc/monthly_diff_' +  cmon + '_' + lyear
    f    = open(line, 'r')
    dout = f.read()
    f.close()
    text = text.replace('#ACISMON#', dout)       #--- acis monthly dose

    line = '/data/mta/Script/Exposure/Exc/monthly_acc_' +  cmon + '_' + lyear
    f    = open(line, 'r')
    dout = f.read()
    f.close()
    text = text.replace('#ACISCMON#', dout)     #--- acis cumulative dose
#
#--- last 12 months exposure maps
#
    byear = year -1
    text  = past_data_entry(1, 0, mon, byear, text)
    text  = past_data_entry(2, 3, mon, byear, text)
    text  = past_data_entry(3, 6, mon, byear, text)
    text  = past_data_entry(4, 9, mon, byear, text)
#
#---- acis focal
#
    fx    = open('/data/mta/Script/Month/FOCAL/Plots/month_avg', 'r')
    data  = [line.strip() for line in fx.readlines()]
    fx.close()

    atemp = re.split(':', data[0])
    btemp = re.split('\+\/\-', atemp[1])
    ft    = round(float(btemp[0]), 2)
    ferr  = round(float(btemp[1]), 2)

    text  = text.replace('#FT#',   str(ft))
    text  = text.replace('#FERR#', str(ferr))

    atemp = re.split(':', data[1])
    btemp = re.split('\+\/\-', atemp[1])
    fw    = round(float(btemp[0]), 2)
    werr  = round(float(btemp[1]), 2)

    text  = text.replace('#FW#',   str(fw))
    text  = text.replace('#WERR#', str(werr))

    line = 'erad_' + lmonyr + '.gif'                #--- erand_nov16.gif
    text = text.replace('#ERAND#', line)
#
#--- acis sib
#
    yearmon = str(year) +'_' + cmon
    text = text.replace('#YEARMON#', yearmon)       #--- e.g. 2015_03
#
#--- hrc i monthly dose
#
    line = hrc_monthly_report('HRCI', cmon, lmon,  lyear)    
    text = text.replace('#HRCIDOSE#', line)        #--- HRC I DIFF 
#
#--- hrc cumulative
#
    line = hrc_cumulative_report('HRCI', cmon, lmon,  lyear)
    text = text.replace('#CHRCIDOSE#', line)       #--- HRC I Cumulative
#
#--- hrc s monthly dose
#
    line = hrc_monthly_report('HRCS', cmon, lmon,  lyear)    
    text = text.replace('#HRCSDOSE#', line)        #--- HRC S DIFF 
#
#--- hrc cumulative
#
    line = hrc_cumulative_report('HRCS', cmon, lmon,  lyear)
    text = text.replace('#CHRCSDOSE#', line)       #--- HRC S Cumulative
#
#--- IRU
#
    text = text.replace("#SMONYR#", lmonyr)        #--- e.g., nov16
#
#--- envelope trending
#
    line = get_envelope_trending(mon, odir)
    text = text.replace("#ENVTREND#", line)
#
#--- critical trends which are reported on Mar, Jun, Sep, and Dec
#
    if mon in [3, 6, 9, 12]:
        text = run_critical_trend(text)
#
#--- Monthly Trend Reports
#
    text = run_month_trend(mon, text)
#
#--- last index
#
    line = create_index(year, mon)
    text = text.replace('#YINDEX#', line)
#
#--- finally print out the report
#
    ofile = odir + "MONTHLY.html"
    fo    = open(ofile, 'w')
    fo.write(text)
    fo.close()
#
#--- chnage permission and owners
#
    cmd = 'chmod 755 ' + odir + '/*'
    os.system(cmd)

    cmd = 'chgrp -R mtagroup ' + odir + '/*'
    os.system(cmd)
Пример #38
0
def update_main_html():
    """
    update the main cron error log html page 
    input: get from the list from indivisula html page, e.g., cron_error_rhodes_mta.html
    output: cron_error_main.html
    """

    #
    #--- create a list of file name (header)
    #

    #    file_list = []
    #    for cpu in cpu_list:
    #        for name in usr_list:
    #            filename = cpu + '_' + name
    #            file_list.append(filename)

    file_list = cpu_usr_list  #-- we may go back to above scheme in future, but this si fine for now

    #
    #--- find current time
    #
    [year, mon, day, hours, min, sec, weekday, yday,
     dst] = tcnv.currentTime('Local')

    syear = str(year)
    smon = str(mon)
    lmon = tcnv.changeMonthFormat(mon)

    if mon < 10:
        smon = '0' + smon

#
#--- start writing the html page
#
    html = html_dir + 'cron_error_main.html'

    out = open(html, 'w')
    line = '<!DOCTYPE html>\n'
    line = line + '<html>\n'
    line = line + '<head>\n'
    line = line + '<title>Cron Error Main page</title>\n'
    line = line + '<link rel="stylesheet" type="text/css" href="/mta/REPORTS/Template/mta_style_short.css" />\n'
    line = line + '</head>\n'
    line = line + '<body>\n'
    line = line + '<h2 style="padding-bottom: 10px"> Cron Error Log</h2>\n\n'
    line = line + '<pre style="padding-left: 5px;padding-bottom:10px">\n'
    line = line + '<hr />\n'
    line = line + '<table border=2 cellpadding = 5 cellspacing =5>\n'
    line = line + '<tr><th>Period</th>'
    out.write(line)

    for ent in file_list:
        atemp = re.split('_', ent)
        line = '<th>' + atemp[1] + ' on ' + atemp[0] + '</th>'
        out.write(line)

    out.write('</tr>\n')
    #
    #--- find the names of each html file (e.g. cron_error_rhodes_mta_06_2012.html)
    #
    templist = tempdir + 'zlist'
    cmd = 'ls ' + html_dir + '> ' + templist
    os.system(cmd)
    f = open(templist, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()
    cmd = 'rm ' + templist
    os.system(cmd)

    error_file_list = []

    for ent in data:
        m1 = re.search('.html', ent)
        m2 = re.search('cron_error_main.html', ent)
        if (m1 is not None) and (m2 is None):
            error_file_list.append(ent)

#
#--- start printing each row; column is ordered newest to oldeest
#
    year_list = range(2012, year + 1)
    year_list.reverse()
    month_list = range(1, 13)
    month_list.reverse()

    for dyear in year_list:
        for dmonth in month_list:
            if dyear == 2012 and dmonth < 6:  #---- this is the year/month the script was started
                break

            if (dyear < year) or (dyear == year and dmonth <= mon):

                lmon = tcnv.changeMonthFormat(
                    dmonth)  #--- convert month in digit to letters

                line = '<tr><th>' + lmon + ' ' + str(dyear) + '</th>'
                out.write(line)
                #
                #--- check which file (e.g. cron_error_rhodes_mta_06_2012.html) actually exists
                #
                for fent in file_list:
                    smon = str(dmonth)
                    if dmonth < 10:
                        smon = '0' + smon
                    fname = 'cron_error_' + fent + '_' + smon + '_' + str(
                        dyear) + '.html'
                    chk = 0
                    for comp in error_file_list:
                        if fname == comp:
                            chk = 1
                            break
                    if chk > 0:
                        #
                        #--- if exist, create a link
                        #
                        line = '<td style="color:red;text-align:center"><a href="' + fname + '">Error List</a></td>'
                    else:
                        line = '<td style="text-align:center">No Error</td>'
                    out.write(line)
                out.write('</tr>\n')

    out.write('</table>\n\n')

    out.write('<br /> <hr />\n')

    tdate = current_time_from_machine()

    line = '<pstyle="font-size:95%"><em>Last Update: ' + tdate + '</em><br />\n'
    line = line + 'If you have any questions about this page, contact <a href="mailto:[email protected]">[email protected]</a>.</p>\n'
    out.write(line)

    line = '\n</body>\n'
    line = line + '</html>\n'
    out.write(line)

    out.close()
Пример #39
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)
Пример #40
0
def plot_data(start, stop, mag_plot=1):
    """
    create a configulation display panel for a give time period
    input:  start   --- starting time in sec from 1998.1.1
            stop    --- stopping time in sec from 1998.1.1
    """

#
#---- set a few parameters
#
    if mag_plot == 0:
        pnum = 5
    else:
        pnum = 6

    mpl.rcParams['font.size'] = 11 
    mpl.rcParams['font.weight'] = 'strong' 
    props = font_manager.FontProperties(size=6)
    plt.subplots_adjust(hspace=0.05)
    plt.subplots_adjust(wspace=0.12)
#
#--- set a few others
#
    xpos  = stime_to_ydate(stop) + 0.1 
    ystep = 0.2
#
#--- read sim information
#
    [acis_i_start, acis_i_stop, acis_s_start, \
     acis_s_stop,  hrc_i_start, hrc_i_stop,   \
     hrc_s_start,  hrc_s_stop,  hetg_start,   \
     hetg_stop,    letg_start,  letg_stop,    \
     radmon_start, radmon_stop, fmt, time]  = erd.find_sim_position(start, stop)
#
#--- hetg /letg information plot
#
    start_set = [hetg_start, letg_start]
    stop_set  = [hetg_stop,  letg_stop]
    ax1 = plt.subplot(pnum, 1, 1)
    plot_strip_box(ax1,start, stop, start_set, stop_set, color1)

    plt.text(xpos, 0.8, "HETG", color=color1[0])
    plt.text(xpos, 0.6, "LETG", color=color1[1])
#
#--- acis /hrc information plot
#
    start_set = [acis_i_start, acis_s_start, hrc_i_start, hrc_s_start]
    stop_set  = [acis_i_stop,  acis_s_stop,  hrc_i_stop,  hrc_s_stop]
    ax2 = plt.subplot(pnum, 1, 2)
    plot_strip_box(ax2,start, stop, start_set, stop_set, color1)

    plt.text(xpos, 0.9, "ACIS I ", color=color1[0])
    plt.text(xpos, 0.7, "ACIS S ", color=color1[1])
    plt.text(xpos, 0.5, "HRC I ",  color=color1[2])
    plt.text(xpos, 0.3, "HRC S ",  color=color1[3])
#
#--- cti information plot
#
    [cti_start, cti_stop]               = erd.read_ccd_data(start, stop)
    start_set = [cti_start]
    stop_set  = [cti_stop]
    ax3 = plt.subplot(pnum, 1, 3)
    plot_strip_box(ax3, start, stop, start_set, stop_set, color1)
#
#--- altitude information plot
#
    [atime, alt, magx, magy, magz, crm]  = erd.read_orbit_data(start, stop)
    plot_line(ax3, start, stop, atime, alt)

    plt.text(xpos, 0.8, "CTI  ",     color=color1[0])
    plt.text(xpos, 0.7, "Check  ",     color=color1[0])
    plt.text(xpos, 0.4, "Altitude ", color="green")
#
#--- radmon information plot
#
    start_set = [radmon_start]
    stop_set  = [radmon_stop]
    ax4 = plt.subplot(pnum, 1, 4)
    plot_strip_box(ax4, start, stop, start_set, stop_set, color1)
#
#--- hrc sheild rate plot
#
    [htime, rate]                       = erd.read_hrc_data(start, stop)
    plot_line(ax4, start, stop, htime, rate)
#
#--- goes p3 rate plot
#
#    [gtime, p1, p2, p3]                 = erd.read_goes_data(start, stop)
#    plot_points(ax4, start, stop, gtime, p3, color='lime', pts=0.5,lw=0)

    plt.text(xpos, 0.8, "Radmon", color=color1[0])
    plt.text(xpos, 0.6, "HRC", color="green")
    plt.text(xpos, 0.5, "Shield", color="green")
    plt.text(xpos, 0.4, "Rate", color="green")
#    plt.text(xpos, 0.2, "GOES P3", color="green")
#
#--- magnetsphere plot
#
    if mag_plot != 0:
        [start_set, stop_set] = find_mag_region(start, stop)
        axm = plt.subplot(6, 1, 5)
        plot_strip_box(axm, start, stop, start_set, stop_set, color1)

#        plt.text(xpos, 0.9, "Solar",    color=color1[0])
#        plt.text(xpos, 0.8, "Wind",     color=color1[0])
        plt.text(xpos, 0.6, "Magneto-", color=color1[1])
        plt.text(xpos, 0.5, "sheath",   color=color1[1])
        plt.text(xpos, 0.3, "Magneto-", color=color1[2])
        plt.text(xpos, 0.2, "sphere",   color=color1[2])
#
#--- often the data are not available; so make a note on the plot
#
#        diff1 = stop - start
#        tlast = time[len(time)-1]
#        diff2 = tlast - start
#        ratio = diff2 / diff1
#        if ratio < 0.7:
#            xnote = 0.5 * (stop - tlast)
#            plt.text(xnote, 0.5, "No Data", color='maroon')
#
#--- FMT format information plot
#
    [start_set, stop_set] = find_fmt_region(start, stop, fmt, time)

    ax5 = plt.subplot(pnum, 1, pnum)
    plot_strip_box(ax5, start, stop, start_set, stop_set,color4)

    plt.text(xpos, 0.9, "FMT1", color=color4[0])
    plt.text(xpos, 0.7, "FMT2", color=color4[1])
    plt.text(xpos, 0.5, "FMT3", color=color4[2])
    plt.text(xpos, 0.3, "FMT4", color=color4[3])
    plt.text(xpos, 0.1, "FMT5", color=color4[4])
#
#--- plot x axis tick label only at the bottom ones
#
    if mag_plot == 0:
        ax_list = [ax1, ax2, ax3, ax4, ax5]
    else:
        ax_list = [ax1, ax2, ax3, ax4, ax5, axm]

    for ax in ax_list:
        for label in ax.get_yticklabels():
            label.set_visible(False)
        if ax != ax5:
            for label in ax.get_xticklabels():
                label.set_visible(False)
        else:
            pass
#
#--- x axis label
#
    mid   = int(0.5 * (start + stop))
    ltime = tcnv.axTimeMTA(mid)
    atemp = re.split(':', ltime)
    year  = int(atemp[0])
    ydate = int(atemp[1])
    [mon, day] = tcnv.changeYdateToMonDate(year,ydate)

    xlabel = "Time (DOY) " + str(atemp[0])
    ax5.set_xlabel(xlabel)

#
#--- set the size of the plotting area in inch (width: 10.0in, height 5.0in)
#   
    fig = matplotlib.pyplot.gcf()
    fig.set_size_inches(12.0, 10.0)
#
#--- save the plot in png format
#   
    syear = str(year)
    smon  = tcnv.changeMonthFormat(mon)
    smon  = smon.lower()
    outname = 'rad_use_' + smon + syear[2] + syear[3] + '.png'

    plt.savefig(outname, format='png', dpi=100)
    plt.close('all')
Пример #41
0
def update_weekly_run_file():
    """
    update idl script: update_plt_data.pro
    input:  none, but read from ./Template/update_plt_data_template
    outpu:  updated update_plt_data.pro
    """

#
#--- find today's date information (in local time)
#
    tlist = time.localtime()
    year  = tlist[0]
    mon   = tlist[1]
    day   = tlist[2]
    wday  = tlist[6]
    yday  = tlist[7]
#
#--- find the difference to Thursday. wday starts on Monday (0)
#--- that is the ending date
#
    diff = 3 - wday
    if diff != 0:
        yday += diff
        if yday < 1:
            year -= 1
            base = find_base(year)
            yday = base - yday
        else:
            base = find_base(year)
            if yday > base:
                year += 1
                yday = yday - base
#
#--- converting the year and ydate into the standard date output
#
    [mon, day] = find_mon_day_from_ydate(year, yday)
#
#--- find starting time; assume a week ago (Thursday)
#
    start = yday - 6
    if start < 1:
        syear = year -1
        base  = find_base(syear)
        syday = 365 - start
    else:
        syear = year
        syday = start

    [smon, sday] = find_mon_day_from_ydate(syear, syday)
#
#--- set dates in a few different format
#
    dsyday = str(syday)
    if syday < 10:
        dsyday = '00' + dsyday
    elif syday < 100:
        dsyday = '0'  + dsyday

    dyday = str(yday)
    if yday < 10:
        dyday = '00' + dyday
    elif yday < 100:
        dyday = '0'  + dyday

    period = str(syear) + '_' + str(dsyday) + '_' + str(dyday)

    begin = convert_date_format(syear, smon, sday)
    end   = convert_date_format(year,  mon,  day)
#
#--- month start/stop
#
    mstart = str(syear) + '-' + str(smon) + '-01'
    if smon == 12:
        mstop = str(syear+1) + '-01-01'
    else:
        nmon = smon + 1
        lnmon = str(nmon)
        if nmon < 10:
            lnmon = '0' + lnmon
        mstop = str(syear) + '-' + lnmon + '-01'
#
#--- set mmmyy (e.g., sep15)
#
    mon = tcnv.changeMonthFormat(smon)
    tmp = str(syear)
    monyr = mon.lower() + tmp[2] + tmp[3]
#
#-- read the template
#
    file  = s_dir + 'Template/update_plt_data_template'
    f     = open(file, 'r')
    data  = f.read()
    f.close()
#
#--- substitute the dates
#
    data  = data.replace("#PERIOD#", period)
    data  = data.replace("#WSTART#", begin)
    data  = data.replace("#WSTOP#",  end)
    data  = data.replace("#MONYR#",  monyr)
    data  = data.replace("#MSTART#", mstart)
    data  = data.replace("#MSTOP#",  mstop)
    data  = data.replace("#YEAR1#",  str(syear))
    data  = data.replace("#YEAR2#",  str(syear))
    data  = data.replace("#NYEAR#",  str(syear + 1))

    ofile = o_dir + 'update_plt_data.pro'
    fo    = open(ofile, 'w')
    fo.write(data)
    fo.close()
Пример #42
0
def printHtml(indir,outdir,  hrc, date, year,month,mean_acc,std_acc,min_acc,min_apos,max_acc,max_apos, asig1, asig2, asig3,mean_dff,  \
                std_dff,min_dff,min_dpos,max_dff,max_dpos,dsig1, dsig2, dsig3):

    'create HTML page to display HRC historical data.'

    [tyear, mon, day, hours, min, sec, weekday, yday,
     dst] = tcnv.currentTime("Local")

    smon = str(mon)
    if mon < 10:
        smon = '0' + smon

    sday = str(day)
    if day < 10:
        sday = '0' + sday

    outdir = outdir + '/' + hrc + '.html'

    f = open(outdir, 'w')
    #
    #--- this is a html 5 document
    #
    f.write('<!DOCTYPE html>\n')
    f.write('<html>\n')
    f.write('<head>\n')

    f.write(
        "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />\n"
    )

    f.write("<style  type='text/css'>\n")
    f.write(
        "table{text-align:center;margin-left:auto;margin-right:auto;border-style:solid;border-spacing:8px;border-width:2px;border-collapse:separate}\n"
    )
    f.write("a:link {color:#00CCFF;}\n")
    f.write("a:visited {color:yellow;}\n")
    f.write("td{text-align:center;padding:8px}\n")
    f.write("</style>\n")

    if hrc == 'hrci':
        hname = 'HRC I'
        wname = 'HRCI'
    else:
        hname = 'HRC S'
        wname = 'HRCS'

    line = '<title>' + hname + ' History Data</title>\n'
    f.write(line)
    f.write("</head>\n")

    f.write('<body style="color:white;background-color:black">\n')
    line = '<h2 style="text-align:center">Data: ' + hname + '</h2>\n'
    f.write(line)

    f.write("<div style='padding-bottom:30px'>\n")
    f.write('<table border=1>\n')
    f.write(
        '<tr><th>&#160;</th><th>&#160;</th><th colspan=11>Monlthy</th><th colspan=11>Cumulative</th></tr>\n'
    )
    f.write('<tr style="color:yellow"><th>Year</th><th>Month</th>\n')
    f.write(
        '<th>Mean</th><th>SD</th><th>Min</th><th>Min Position</th><th>Max</th><th>Max Position</th><th>68% Level</th><th>95% Level</th><th>99.7% Level</th><th>Data</th><th>Map</th>\n'
    )
    f.write(
        '<th>Mean</th><th>SD</th><th>Min</th><th>Min Position</th><th>Max</th><th>Max Position</th><th>68% Level</th><th>95% Level</th><th>99.7% Level</th><th>Data</th><th>Map</th></tr>\n'
    )

    for i in range(0, len(date)):

        smonth = str(month[i])
        if month[i] < 10:
            smonth = '0' + smonth

        cmonth = tcnv.changeMonthFormat(
            month[i])  #---- converting digit to letters, i.e. 1 to Jan

        #
        #--- monthly HRC dose data
        #

        if mean_dff[i] == 0 and std_dff[i] == 0:

            line = '<tr><td>%d</td><td>%d</td><td>NA</td><td>NA</td><td>NA</td><td>NA</td><td>NA</td><td>NA</td>\n' % (
                year[i], month[i])
            f.write(line)
            f.write('<td>No Data</td><td>No Image</td>\n')
        else:
            line = '<tr><td>%d</td><td>%d</td><td>%4.4f</td><td>%4.4f</td><td>%4.1f</td><td>%s</td><td>%4.1f</td><td>%s</td><td>%4.1f</td><td>%s</td><td>%4.1f</td>\n' \
                    % (year[i], month[i], mean_dff[i], std_dff[i], min_dff[i],min_dpos[i], max_dff[i], max_dpos[i],dsig1[i], dsig2[i], dsig3[i])
            f.write(line)

            fname = wname + '_' + smonth + '_' + str(year[i]) + '.fits.gz'
            line = '<td><a href="https://cxc.cfa.harvard.edu/mta_days/mta_max_exp/Month_hrc/' + fname + '">fits</a></td>\n'
            f.write(line)
            fname = wname + '_' + smonth + '_' + str(year[i]) + '.png'
            line = '<td><a href="https://cxc.cfa.harvard.edu/mta_days/mta_max_exp/Images/' + fname + '">map</a></td>\n'
            f.write(line)

#
#---- cumulative HRC dose data
#
        line = '<td>%4.4f</td><td>%4.4f</td><td>%4.1f</td><td>%s</td><td>%4.1f</td><td>%s</td><td>%4.1f</td><td>%s</td><td>%4.1f</td>\n' \
                    % (mean_acc[i], std_acc[i], min_acc[i], min_apos[i], max_acc[i], max_apos[i], asig1[i], asig2[i], asig3[i])

        f.write(line)
        fname = wname + '_08_1999_' + smonth + '_' + str(year[i]) + '.fits.gz'
        line = '<td><a href="https://cxc.cfa.harvard.edu/mta_days/mta_max_exp/Cumulative_hrc/' + fname + '">fits</a></td>\n'
        f.write(line)
        fname = wname + '_08_1999_' + smonth + '_' + str(year[i]) + '.png'
        line = '<td><a href="https://cxc.cfa.harvard.edu/mta_days/mta_max_exp/Images/' + fname + '">map</a></td>\n\n'
        f.write(line)

        #
        #--- put header every new year so that we can read data easier
        #
        if month[i] % 12 == 0 and i != (len(date) - 1):
            f.write(
                '\n<tr style="color:yellow"><th>Year</th><th>Month</th><th>Mean</th><th>SD</th><th>Min</th><th>Min Position</th><th>Max</th><th>Max Position</th><th>68% Level</th><th>95% Level</th><th>99.7% Level</th><th>Data</th><th>Map</th>\n'
            )
            f.write(
                '<th>Mean</th><th>SD</th><th>Min</th><th>Min Position</th><th>Max</th><th>Max Position</th><th>68% Level</th><th>95% Level</th><th>99.7% Level</th><th>Data</th><th>Map</th></tr>\n\n'
            )

    f.write('</table>\n\n')
    f.write("</div>\n")
    f.write('<hr />\n')

    line = '<p style="padding-top:10px;padding-bottom:10px"><strong style="font-size:105%;float:right">Last Update: ' + smon + '/' + sday + '/' + str(
        tyear) + '</strong></p>\n'
    f.write(line)

    line = '<p>If you have any questions about this page, contact <a href="mailto:[email protected]">[email protected].</a></p>\n'
    f.write(line)
    f.write('</body>\n')
    f.write('</html>\n')

    f.close()
Пример #43
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)
Пример #44
0
def print_html_page(comp_test, in_year=1, in_mon=1):
    """
    driving function to print all html pages for ACIS Dose Plots
    Input:  comp_test --- test indicator. if it is "test", it will run the test version
            in_year/in_mon --- if in_year and in_mon are given, the file is created for 
                               that year/month, otherwise, the files are created in the current year/month
    Output: html pages in <web_dir> and <web_dir>/<mon_dir_name>  (e.g. JAN2013)
    """

#
#---  find today's date and convert them appropriately
#
    if comp_test == 'test':
        bchk  = 0
        tday  = 13;
        umon  = 2;
        uyear = 2013;

        cmon  = tcnv.changeMonthFormat(umon)
        cmon  = cmon.upper()
        ldate = str(uyear) + '-' + str(umon) + '-' + str(tday)          #-- update date
    else:
#
#--- find today's date
#
        [uyear, umon, tday, hours, min, sec, weekday, yday, dst] = tcnv.currentTime()
#
#--- change month in digit into letters
#
        cmon  = tcnv.changeMonthFormat(umon)
        cmon  = cmon.upper()
        ldate = str(uyear) + '-' + str(umon) + '-' + str(tday)          #-- update date
#
#--- if year and month is given, create for that month. otherwise, create for this month
#
        bchk = 0
        if mcf.chkNumeric(in_year) and mcf.chkNumeric(in_mon):
            if in_year > 1900 and (in_mon >0 and in_mon < 13):
                bchk = 1
        if bchk > 0:
            uyear = in_year
            umon  = in_mon
            cmon  = tcnv.changeMonthFormat(umon)
            cmon  = cmon.upper()

    mon_dir_name = cmon + str(uyear);

#
#--- check whether this monnth web page already opens or not
#
    dname = web_dir + mon_dir_name
    chk   = mcf.chkFile(dname)

    if chk > 0:
        if bchk == 0:
#
#-- create only when it is working for the current month
#
            print_main_html(ldate, uyear, umon);

        print_month_html(mon_dir_name, ldate, uyear, umon);

        print_png_html(mon_dir_name, ldate, uyear, umon);
#
#--- change permission level and the owner of the files
#
        cmd = 'chgrp mtagroup ' + web_dir + '/* ' + web_dir + '/*/*'
        os.system(cmd)
        cmd = 'chmod 755 '+ web_dir + '/* ' + web_dir + '/*/*'
        os.system(cmd)
def print_run_rad():
    """
    create today's run_rad.pro idl script
    """
#
#--- find today's date
#
    [year, mon, day, hours, min, sec, weekday, yday, dst] = tcnv.currentTime()
#
#---if this is the first of the month, compute the last month
#
    if day < 2:
        subtract = 1
    else:
        subtract = 0
    cyear = year
    lmon      = mon - subtract
    if lmon < 1:
        lmon  = 12
        cyear = year -1
#
#--- choose a correct month list depending on whether this is the leap year
#
    if tcnv.isLeapYear(cyear) == 1:
        mon_list = mon_list1
    else:
        mon_list = mon_list2

    if lmon == 1:
        start_day = '001'
    else:
        sday = float(mon_list[lmon-2]) + 1
        start_day = str(sday)
        if sday < 10:
            start_day = '00' + start_day
        elif sday < 100:
            start_day = '0' + start_day

    last_day  = mon_list[lmon-1]
#
#--- convert the month from a numeric to letter
#
    smon      = tcnv.changeMonthFormat(lmon)
    smon      = smon.lower()
#
#--- set date format to the appropriate ones
#
    today     =  str(yday)
    if yday < 100:
        today = '0' + today
    elif today < 10:
        today = '00' + today

    day30     = yday - 30
    if day30 < 0:
        day30 = 366 + day30
        tday_year = str(year -1)
    else:
        tday_year =  str(year)

    if day30 < 10:
        day30 = '00' + str(day30)
    elif day30 < 100:
        day30 = '0' + str(day30)
    else:
        day30 = str(day30)


    lmon_year =  str(cyear)
    syear     =  lmon_year[2] + lmon_year[3]
    last_year =  str(year -1)
    syear2    =  last_year[2] + last_year[3]
    monyear   =  smon + syear
#
#--- now print out the run_rad.pro
#
    line = "x = mta_rad('" + tday_year + ":" + str(day30) +"')\n"
    line = line + "spawn, 'mv rad_cnts.gif rad_cnts_curr.gif'\n"
    line = line + "spawn, 'mv rad_use.gif rad_use_curr.gif'\n"
    line = line + "print, 'Done current'\n"
    line = line + "retall\n"
    
    line = line + "x = mta_rad('" + lmon_year + ":" + start_day + "','" + lmon_year + ":" + last_day + "')\n"
    line = line + "spawn, 'mv rad_cnts.gif rad_cnts_" + monyear + ".gif'\n"
    line = line + "spawn, 'mv rad_use.gif rad_use_"   + monyear + ".gif'\n"
    line = line + "spawn, 'mv eph_diff.gif eph_diff_" + monyear + ".gif'\n"
    line = line + "spawn, 'mv mon_diff.gif mon_diff_" + monyear + ".gif'\n"
    line = line + "spawn, 'mv per_diff.gif per_diff_" + monyear + ".gif'\n"
    line = line + "spawn, 'mv xper_diff.gif mon_per_diff_" + monyear + ".gif'\n"
    line = line + "print, 'Done " + monyear + "'\n"
    
    line = line + "x = mta_rad('" + last_year + ":001','" + lmon_year + ":001')\n"
    line = line + "spawn, 'mv rad_cnts.gif rad_cnts_" + syear2 + ".gif'\n"
    line = line + "spawn, 'mv rad_use.gif rad_use_"   + syear2 + ".gif'\n"
    line = line + "spawn, 'mv eph_diff.gif eph_diff_" + syear2 + ".gif'\n"
    line = line + "spawn, 'mv mon_diff.gif mon_diff_" + syear2 + ".gif'\n"
    line = line + "spawn, 'mv per_diff.gif per_diff_" + syear2 + ".gif'\n"
    line = line + "spawn, 'mv xper_diff.gif mon_per_diff_" + syear2 + ".gif'\n"
    line = line + "print, 'Done " + syear2 + "'\n"
    
    line = line + "x = mta_rad('" + last_year + ":" + today + "','" + lmon_year + ":" + today + "')\n"
    line = line + "spawn, 'mv rad_cnts.gif rad_cnts_last_one_year.gif'\n"
    line = line + "spawn, 'mv rad_use.gif rad_use_last_one_year.gif'\n"
    line = line + "spawn, 'mv eph_diff.gif eph_diff_last_one_year.gif'\n"
    line = line + "spawn, 'mv mon_diff.gif mon_diff_last_one_year.gif'\n"
    line = line + "spawn, 'mv per_diff.gif per_diff_last_one_year.gif'\n"
    line = line + "spawn, 'mv xper_diff.gif mon_per_diff_last_one_year.gif'\n"
    line = line + "print, 'Done Last One Year\n"
    
    line = line + "x = mta_rad()\n"
    line = line + "spawn, 'mv rad_cnts.gif rad_cnts_all.gif'\n"
    line = line + "spawn, 'mv rad_use.gif rad_use_all.gif'\n"
    line = line + "spawn, 'mv eph_diff.gif eph_diff_all.gif'\n"
    line = line + "spawn, 'mv mon_diff.gif mon_diff_all.gif'\n"
    line = line + "spawn, 'mv per_diff.gif per_diff_all.gif'\n"
    line = line + "print, 'Done all'\n"
    line = line + "retall\n"
    line = line + "exit\n"

#    fo   = open('test.pro', 'w')
    fo   = open('run_rad.pro', 'w')
    fo.write(line)
    fo.close()
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]
Пример #47
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)
Пример #48
0
def acis_dose_monthly_report(year='NA', month='NA'):
    """
     create monthly report tables 
     input: year and month, if they are not given, the latest stat will be used
    """

    #
    #--- if year and/or month is not given, find the latest year month entry
    #
    if year == 'NA' or month == 'NA':
        file = data_out + 'i_2_n_0_acc_out'
        f = open(file, 'r')
        data = [line.strip() for line in f.readlines()]
        f.close()

        line = data[len(data) - 1]
        atemp = re.split('\s+|\t+', line)
        year = int(atemp[0])
        month = int(atemp[1])

    syear = str(year)
    smon = str(month)
    if month < 10:
        smon = '0' + smon

    line = './monthly_diff_' + smon + '_' + syear
    f1 = open(line, 'w')

    line = './monthly_acc_' + smon + '_' + syear
    f2 = open(line, 'w')

    #
    #--- convert month in digit to month in letter
    #
    lmon = tcnv.changeMonthFormat(month)
    lmon = lmon.lower()
    #
    #--- find monthly stat
    #
    diff = mon_dir + 'ACIS_' + smon + '_' + syear + '.fits.gz'
    (mean, std, min, max) = getstat(diff)
    line = 'ACIS_' + lmon + syear[2] + syear[3] + ' 6004901       '
    f1.write(line)
    line = '%3.3f         %3.3f           %3.1f     %4d\n\n' % (mean, std, min,
                                                                max)
    f1.write(line)

    #
    #--- find cumulative stat
    #
    acc = cum_dir + 'ACIS_07_1999_' + smon + '_' + syear + '.fits.gz'
    (mean, std, min, max) = getstat(acc)
    line = 'ACIS_total   6004901       '
    f2.write(line)
    line = '%3.3f         %3.3f           %3.1f   %6d\n\n' % (mean, std, min,
                                                              max)
    f2.write(line)

    #
    #--- now print stat for each section
    #

    for inst in ('i', 's'):
        for ccd in (2, 3):
            f1.write('\n')
            f2.write('\n')
            for node in (0, 1, 2, 3):
                file1 = data_out + inst + '_' + str(ccd) + '_n_' + str(
                    node) + '_dff_out'
                file2 = data_out + inst + '_' + str(ccd) + '_n_' + str(
                    node) + '_acc_out'

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

                if year == 'NA' or month == 'NA':
                    line = data[len(data) - 1]
                    atemp = re.split('\s+|\t+', line)
                else:
                    for ent in data:
                        atemp = re.split('\s+|\t+', ent)
                        if int(atemp[0]) == year and int(atemp[1]) == month:
                            break

                line = inst.upper() + str(ccd) + ' node ' + str(
                    node) + '  262654\t'
                f1.write(line)
                line = '%3.6f\t%3.6f\t%3.1f\t%5.1f\n' % (float(
                    atemp[2]), float(atemp[3]), float(atemp[4]), float(
                        atemp[6]))
                f1.write(line)

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

                if year == 'NA' or month == 'NA':
                    line = data[len(data) - 1]
                    atemp = re.split('\s+|\t+', line)
                else:
                    for ent in data:
                        atemp = re.split('\s+|\t+', ent)
                        if int(atemp[0]) == year and int(atemp[1]) == month:
                            break

                line = inst.upper() + str(ccd) + ' node ' + str(
                    node) + '  262654\t'
                f2.write(line)
                line = '%3.6f\t%3.6f\t%3.1f\t%5.1f\n' % (float(
                    atemp[2]), float(atemp[3]), float(atemp[4]), float(
                        atemp[6]))
                f2.write(line)

    f1.close()
    f2.close()
Пример #49
0
def update_main_html():

    """
    update the main cron error log html page 
    input: get from the list from indivisula html page, e.g., cron_error_rhodes_mta.html
    output: cron_error_main.html
    """

#
#--- create a list of file name (header)
#

#    file_list = []
#    for cpu in cpu_list:
#        for name in usr_list:
#            filename = cpu + '_' + name
#            file_list.append(filename)

    file_list = cpu_usr_list                    #-- we may go back to above scheme in future, but this si fine for now

#
#--- find current time
#
    [year, mon, day, hours, min, sec, weekday, yday, dst] = tcnv.currentTime('Local')

    syear = str(year)
    smon  = str(mon)
    lmon = tcnv.changeMonthFormat(mon)

    if mon < 10:
        smon = '0' + smon

#
#--- start writing the html page
#
    html = html_dir +  'cron_error_main.html'

    out  = open(html, 'w')
    line = '<!DOCTYPE html>\n'
    line = line + '<html>\n'
    line = line + '<head>\n'
    line = line + '<title>Cron Error Main page</title>\n'
    line = line + '<link rel="stylesheet" type="text/css" href="/mta/REPORTS/Template/mta_style_short.css" />\n'
    line = line + '</head>\n'
    line = line + '<body>\n'
    line = line + '<h2 style="padding-bottom: 10px"> Cron Error Log</h2>\n\n'
    line = line + '<pre style="padding-left: 5px;padding-bottom:10px">\n' 
    line = line + '<hr />\n'
    line = line + '<table border=2 cellpadding = 5 cellspacing =5>\n'
    line = line + '<tr><th>Period</th>'
    out.write(line)

    for ent in file_list:
        atemp = re.split('_', ent)
        line = '<th>' + atemp[1] + ' on ' + atemp[0]  + '</th>'
        out.write(line)

    out.write('</tr>\n')
#
#--- find the names of each html file (e.g. cron_error_rhodes_mta_06_2012.html)
#
    templist = tempdir + 'zlist'
    cmd = 'ls ' + html_dir + '> ' + templist
    os.system(cmd)
    f    = open(templist, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()
    cmd = 'rm ' + templist
    os.system(cmd)

    error_file_list = []

    for ent in data:
        m1 = re.search('.html', ent)
        m2 = re.search('cron_error_main.html', ent)
        if (m1 is not None) and (m2 is None):
            error_file_list.append(ent)

#
#--- start printing each row; column is ordered newest to oldeest
#
    year_list = range(2012, year + 1)
    year_list.reverse()
    month_list = range(1,13)
    month_list.reverse()

    for dyear in year_list:
        for dmonth in month_list:
            if dyear == 2012 and dmonth < 6:                    #---- this is the year/month the script was started
                break

            if (dyear < year) or (dyear == year  and dmonth <=  mon):

                lmon = tcnv.changeMonthFormat(dmonth)           #--- convert month in digit to letters

                line = '<tr><th>' + lmon + ' ' + str(dyear) + '</th>'
                out.write(line)
#
#--- check which file (e.g. cron_error_rhodes_mta_06_2012.html) actually exists
#
                for fent in file_list:
                    smon  = str(dmonth)
                    if dmonth < 10:
                        smon = '0' + smon
                    fname = 'cron_error_' + fent + '_' + smon + '_' + str(dyear) + '.html'
                    chk = 0
                    for comp in error_file_list:
                        if fname == comp:
                            chk = 1
                            break
                    if chk > 0:
#
#--- if exist, create a link
#
                        line = '<td style="color:red;text-align:center"><a href="' + fname + '">Error List</a></td>'
                    else:
                        line = '<td style="text-align:center">No Error</td>'
                    out.write(line)
                out.write('</tr>\n')

    out.write('</table>\n\n')

    out.write('<br /> <hr />\n')

    tdate = current_time_from_machine()

    line = '<pstyle="font-size:95%"><em>Last Update: ' + tdate + '</em><br />\n'
    line = line + 'If you have any questions about this page, contact <a href="mailto:[email protected]">[email protected]</a>.</p>\n'
    out.write(line)

    line = '\n</body>\n'
    line = line + '</html>\n'
    out.write(line)

    out.close()
Пример #50
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)
def run_hrc_stowed_background_monthly_update(lyear='', lmonth=''):
    """
    run monthly update for the hrc stowed background data
    input:  lyear, lmonth   --- the year and month of the data to be processed
                                if they are not given, the last month of year and year will be used
    output: newly proccessed data: <data_dir>/<yyyy><mmm>/*
            if it is jan or jul, cummulative maps for the year (and the entire period) are created
    """
    #
    #--- clean up exc dir
    #
    cmd = 'rm -rf ' + exc_dir + 'Temp_dir/* 2> /dev/null'
    os.system(cmd)

    cmd = 'rm -rf ' + exc_dir + 'param 2> /dev/null'
    os.system(cmd)

    cmd = 'mkdir ' + exc_dir + 'param 2> /dev/null'
    os.system(cmd)
    #
    #--- if date (year/month) to be processed is not given, find the last month's year, month
    #
    if lyear == '':
        ctime = time.gmtime()  #--- today's date information
        lyear = ctime.tm_year
        lmonth = ctime.tm_mon - 1

        if lmonth < 1:
            lyear -= 1
            lmonth = 12
#
#--- check whether the data was already processed; if not, run the process
#
    smonth = tcnv.changeMonthFormat(lmonth)
    cdir = data_dir + str(lyear) + smonth.upper()

    smail = 0
    if not os.path.isdir(cdir):
        try:
            hsb.hrc_stowed_background(lyear, lmonth, lyear, lmonth)
            #
            #--- if the processed month is june or december, update maps and html pages
            #
            if (lmonth == 12) or (lmonth == 6):
                #
                #--- update total event number tables
                #
                get_yearly_evt_count()

                chif.yearly_cummulative_image(lyear)
                hpm.plot_hrc_map(lyear)
                hpm.plot_hrc_map('total')  #---- creating cumulative maps
                hpm.plot_hrc_map(
                    'total',
                    1)  #---- creating cumulative histogram for the front page
                hpr.plot_hrc_trend_data()  #---- creating trending plots
                uhhp.create_html_pages(lyear)  #---- updating all html pages
                create_cumulative_image()

            if test_data_creation(lyear, lmonth):
                smail = 1
            else:
                smail = 3
        except:
            smail = 2
    else:
        smail = 0
#
#--- remove the temp file if it is still around
#
    cmd = 'rm /tmp/zspace*hrc* 2> /dev/null'
    os.system(cmd)

    cmd = 'rm -rf ' + exc_dir + 'Temp_dir/* 2> /dev/null'
    os.system(cmd)
    #
    #--- sending mail
    #
    if smail == 1:
        message = 'hrc stowed proccess ran normally for the period: ' + str(
            lyear) + ' : ' + str(lmonth) + '\n'
        header = '"Subject: HRC Stowed Data Process Complated"'

    elif smail == 2:
        message = 'hrc stowed proccess ran into problems with the data for the period: ' + str(
            lyear) + ' : ' + str(lmonth) + '\n'
        header = '"Subject: HRC Stowed Data Process Failed"'

    elif smail == 3:
        message = 'hrc stowed proccess did not find any data for the period: ' + str(
            lyear) + ' : ' + str(lmonth) + '\n'
        header = '"Subject: HRC Stowed Data Process: No Data Found"'

    if smail > 0:
        send_email(message, header)
Пример #52
0
def update_html():
    """
    create/update error html page for a gvien machine and a user
    input: error_list_<cpu>_<user>, wheren cpu and user are found from the machine running this and account using.
    output: cron_error_<cpu>_<usr>.html in html_dir.
    """

    #
    #--- find the current time
    #
    [year, mon, day, hours, min, sec, weekday, yday,
     dst] = tcnv.currentTime('Local')

    syear = str(year)
    smon = str(mon)
    lmon = tcnv.changeMonthFormat(mon)

    if mon < 10:
        smon = '0' + smon
#
#--- set the file name and a hmtl page name
#
    file = error_log_dir + machine + '_' + user + '_' + smon + '_' + syear
    html = html_dir + 'cron_error_' + machine + '_' + user + '_' + smon + '_' + syear + '.html'
    #
    #--- start writing the html page
    #
    out = open(html, 'w')
    line = '<!DOCTYPE html>\n'
    line = line + '<html>\n'
    line = line + '<head>\n'
    line = line + '<title>Cron Error Log for ' + user.upper(
    ) + ' on ' + machine.upper() + ': ' + lmon + ' ' + syear + '</title>\n'
    line = line + '<link rel="stylesheet" type="text/css" href="/mta/REPORTS/Template/mta_style_short.css" />\n'
    line = line + '</head>\n'
    line = line + '<body>\n'
    line = line + '<h3 style="padding-bottom: 10px"> Cron Error Log for ' + user.upper(
    ) + ' on ' + machine.upper() + ': ' + lmon + ' ' + syear + '</h3>\n\n'
    line = line + '<hr />\n'
    line = line + '<pre style="padding-left: 5px;padding-bottom:10px">\n'

    out.write(line)
    #
    #--- write the content of error_list
    #
    f = open(file, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    for ent in data:
        out.write(ent)
        out.write('\n')

    line = '</pre>\n'
    line = line + '<br /><hr /><br />\n'
    line = line + 'Back to <a href="https://cxc.cfa.harvard.edu/mta_days/mta_cron/cron_error_main.html">Top Page</a>\n'
    line = line + '\n</body>\n'
    line = line + '</html>\n'
    out.write(line)

    out.close()
Пример #53
0
def find_obs_date(obsid):
    """
    find the observation date for a given obsid.

    """
    #
    #---checking the current user
    #
    user = getpass.getuser()
    user = user.strip()

    if user == 'mta':
        cmd = 'lynx -source http://acis.mit.edu/cgi-bin/get-obsid?id=' + str(
            obsid) + ' > ' + mtemp_dir + 'ztemp'
    elif user == 'cus':
        cmd = 'lynx -source http://acis.mit.edu/cgi-bin/get-obsid?id=' + str(
            obsid) + ' > ' + ctemp_dir + 'ztemp'
    else:
        print "the user is not mta or cus. Exiting"
        eixt(1)

    os.system(cmd)

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

    cmd = 'rm ' + mtemp_dir + 'ztemp'
    os.system(cmd)

    chk = 0
    for ent in data:
        if chk == 1:
            atemp = re.split('\<tt\>', ent)
            btemp = re.split('\<', atemp[1])
            date = btemp[0]
            chk += 1
            break
        else:
            m = re.search('Start Date:', ent)
            if m is not None:
                chk = 1

    atemp = re.split('\s+|\t+', date)
    btemp = re.split('-', atemp[0])

    mon = tcnv.changeMonthFormat(int(
        btemp[1]))  #--- convert digit month to letter month

    #
    #--- change time format from 24 hr to 12 hr system
    #
    ctemp = re.split(':', atemp[1])
    part = 'AM'
    time = int(ctemp[0])
    if time >= 12:
        time -= 12
        part = 'PM'

    stime = str(time)
    if time < 10:
        stime = '0' + stime

    stime = stime + ':' + ctemp[1] + part
    date = mon + ' ' + btemp[2] + ' ' + btemp[0] + ' ' + stime

    return date
def print_html(year, mon):
    """
    create and/or update radiation related html page
    """
#
#--- find today's date
#
    if year == '':
        [year, mon, day, hours, min, sec, weekday, yday, dst] = tcnv.currentTime()
#
#--- find out the last month
#
#        cyear = year
#        lmon      = mon -1
#        if lmon < 1:
#            lmon  = 12
#            cyear = year -1

#
#--- for the case year and mon are given
#
    cyear = year
    lmon  = mon
#
#--- choose a correct month list depending on whether this is the leap year
#
    if tcnv.isLeapYear(cyear) == 1:
        mon_list = mon_list1
    else:
        mon_list = mon_list2

    last_day  = mon_list[lmon-1]
#
#--- convert the month from a numeric to letter
#
    umon      = tcnv.changeMonthFormat(lmon)
    smon      = umon.lower()

    lmon_year =  str(cyear)
    syear     =  lmon_year[2] + lmon_year[3]
    last_year =  str(year -1)
    syear2    =  last_year[2] + last_year[3]
    monyear   =  smon + syear
#
#--- set output html page names
#
    year_html = 'all' + syear + '.html'
    mon_html  = monyear + '.html'
    rad_html  = 'rad_time_' + monyear + '.html'
#
#--- read yearly html page template
#
    data = open('./Template/yearly_template', 'r').read()

    data = data.replace('$#FYEAR#$', str(year))
    data = data.replace('$#SYEAR#$', syear)

    fo   = open(year_html, 'w')
    fo.write(data)
    fo.close()
#
#--- read monthly html page template
#
    data = open('./Template/monthly_template', 'r').read()

    data = data.replace('$#FYEAR#$', str(year))
    data = data.replace('$#UMON#$',umon )
    data = data.replace('$#MONYEAR#$', monyear)

    fo   = open(mon_html, 'w')
    fo.write(data)
    fo.close()
#
#--- read rad_time html page template
#
    data = open('./Template/rad_time_template', 'r').read()

    data = data.replace('$#LMONTH#$', fmon_list[mon-2])
    data = data.replace('$#FYEAR#$', str(year))
    data = data.replace('$#MONYEAR#$', monyear)

    fo   = open(rad_html, 'w')
    fo.write(data)
    fo.close()
Пример #55
0
def create_weekly_report(date, year, debug = 0):
    """
    main script to set up the weekly report template for the week
    input:  date    --- date in the format of mmdd (e.g. 0910)
            year    --- year in the format of yyyy (e.g. 2015)
            debug   --- if it is other than 0, print out some output
    output: a direcotry containing templete (e.g. Sep10)
    """
#
#--- if the test is requested, create Test directory
#
    if debug != 0:
        os.system('mkdir /data/mta/Script/Weekly/Test/')
        odir = '/data/mta/Script/Weekly/Test/'
    else:
        odir = '/data/mta4/www/REPORTS/'

    oned  = 86400

    syear = str(year)                       #--- 4 digit year
    yrd2  = year[2] + year[3]               #--- 2 digit year
    year  = int(float(year))                #--- integer year
    
    date  = str(date)

    smon  = date[0] + date[1]               #--- two digit month
    mon   = int(float(smon))                #--- integer month
    lmon  = tcnv.changeMonthFormat(mon)     #--- month in letter (e.g.Mar)

    sday  = date[2] + date[3]               #--- two digit mday
    day   = int(float(sday))                #--- integer mday

    stop = tcnv.convertDateToCTime(year, mon, day, 0, 0, 0)

    day_n = stop - 7 * oned
#    tout  = tcnv.axTimeMTA(day_n)
#    ttemp = re.split(':', tout)
#    iru_start  = str(ttemp[0]) + '_' + str(ttemp[1])

    #day01 = stop - 6 * oned
    #day0  = stop - 7 * oned
    day01 = stop - 5 * oned
    day0  = stop - 6 * oned
    lday0 = stime_to_ddate(day0)
    sday0 = sdate_to_ldate(lday0)
    start = day0
    lday1 = stime_to_ddate(day01)

    tout  = tcnv.axTimeMTA(day0)
    ttemp = re.split(':', tout)
    iru_start  = str(ttemp[0]) + '_' + str(ttemp[1])
#
#---  year of the beginning of the period; could be different from that of the end
#
    byear      = ttemp[0]    

    lday0 = stime_to_ddate(day0)

    day1  = stop - 5 * oned
    lday1 = stime_to_ddate(day1)

    day2  = stop - 4 * oned
    lday2 = stime_to_ddate(day2)
    sday2 = sdate_to_ldate(lday2)

    day3  = stop - 3 * oned
    lday3 = stime_to_ddate(day3)

    day4  = stop - 2 * oned
    lday4 = stime_to_ddate(day4)
    sday4 = sdate_to_ldate(lday4)

    day5  = stop - 1 * oned
    lday5 = stime_to_ddate(day5)

    day6  = stop 
    lday6 = stime_to_ddate(day6)
    sday6 = sdate_to_ldate(lday6)

    #tout  = tcnv.axTimeMTA(day5)
    tout  = tcnv.axTimeMTA(day6)
    ttemp = re.split(':', tout)
    iru_stop    = '_' + str(ttemp[1])

    day7  = stop + 1 * oned
    lday7 = stime_to_ddate(day7)
#
#---- setting file name
#
    atemp = re.split('\/', lday6)
    file_date  = atemp[0] + atemp[1]
    file_date2 = atemp[0] + '/' + atemp[1]
    file_name  = file_date + '.html'
#
#--- title
#
    titledate     = lday0 + ' - ' + lday6

    ldate         = sdate_to_ldate(lday6)
    ldate_sp      = sdate_to_ldate_with_space(lday6)

#
#--- focal temp file name
#
    fptemp        = file_date + '_fptemp.png'
    fpext_range   = str(start)+' '+  str(stop)
    fpstart       = str(start)
    fplsub        = '"'+ sday0 + '", "' + sday2  + '", "' +  sday4  + '", "' + sday6 + '"'
    fpdsub        = str(day0) + ', ' + str(day2) + ', ' + str(day4) + ', ' + str(day6)
#
#--- IRU span
#
    irudate       = iru_start + iru_stop
    irudate       = str(syear) + '/' +  iru_start + iru_stop        #--- Jul 27, 2018
#
#--- telemetry idl command
#
    telmstart     = stime_to_ddate2(start)
    telmstop      = stime_to_ddate2(stop)
    telem_command = 'weekly_telem,' + telmstart + ',' + telmstop
#
#--- telemetry header line
#
    daylist = '|' + lday0 +'|' + lday1 + '|' + lday2 +'|' + lday3 +'|' + lday4 +'|' + lday5 +'|' + lday6  

#
#--- find trending dates/title
#
    tfile = tdir + 'trending_order'
    f    = open(tfile, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    data.reverse()
    chk = 0
    for ent in data:
        if ent == '\s+' or ent == '':
            continue 

        atemp = re.split(' : ', ent)
        adate = atemp[0].strip()
        aname = atemp[1].strip()
        file_date2.strip()
        if chk == 0:
            if str(adate) == str(file_date2):
                title = aname
                chk   = 1
        else:
            if aname == title:
                last_trend_date = adate
                break
#
#--- index.html input
#
    s1 = sday0[0:3] + ' ' + sday0[3:5]
    s2 = sday6[0:3] + ' ' + sday6[3:5]
    index = '<td> <a href="./' + str(year) + '/' + file_date + '.html">' + s1 + ' - ' + s2 + '</a>'
#
#--- debugging output
#
    if debug != 0:
        print "file_name; "       + file_name 
        print "title date: "      + titledate
        print "ldate: "           + ldate
        print "fptemp: "          + fptemp
        print "fpext_range: "     + fpext_range
        print "fpstart: "         + fpstart
        print " fplsub: "         + fplsub
        print " fpdsub: "         + fpdsub
        print "irudate: "         + irudate
        print "telmstart: "       + telmstart
        print "telmstop: "        + telmstop
        print "telmcommand: "     + telem_command
        print "daylist: "         + daylist
        print "title: "           + title
        print "last_trend_date: " + last_trend_date
        print "index: "           + index
#
#--- create a work directory
#
    cmd = 'mkdir ' + wdir  + ldate
    os.system(cmd)
    outdir = wdir + ldate + '/'

    cmd = 'cp ' + tdir + 'get_ftemp_data.perl' + ' ' + outdir
    os.system(cmd)
    cmd = 'cp ' + tdir + 'subst3.perl'         + ' ' + outdir
    os.system(cmd)
    cmd = 'cp ' + tdir + 'test'                + ' ' + outdir
    os.system(cmd)

    cmd = 'mkdir ' + outdir + '/param'
    os.system(cmd)

#
#--- create instruction page
#
    tfile = tdir + 'instruction'
    f     = open(tfile, 'r')
    input = f.read()
    f.close()
    input = input.replace('#LDATE_S#', ldate_sp)
    input = input.replace('#LDATE#',   ldate)
    input = input.replace('#DDATE#',   file_date)
    input = input.replace('#YEAR#',    syear)
    input = input.replace('#DAYLIST#', daylist)
    input = input.replace('#TELM_CMD#',telem_command)
    input = input.replace('#INDEX#',    index)

    ofile = outdir  + ldate.lower()
    fo    = open(ofile, 'w')
    fo.write(input)
    fo.close()
#
#--- focal temp related files
#
#    tfile = tdir + 'get_ftemp_wrap_script'
#    f     = open(tfile, 'r')
#    input = f.read()
#    f.close()
#
#    input = input.replace('#MANDD#',  ldate)
#    ofile = outdir + 'get_ftemp_wrap_script'
#    fo    = open(ofile, 'w')
#    fo.write(input)
#    fo.close()
#    cmd = 'chmod 755 ' + outdir + 'get_ftemp_wrap_script'
#    os.system(cmd)
#
#    tfile = tdir + 'get_ftemp_main_script'
#    f     = open(tfile, 'r')
#    input = f.read()
#    f.close()
#
#    #input = input.replace('#START#',  str(start))
#    #input = input.replace('#STOP#',   str(stop))
#    input = input.replace('#START#',  str(start + 86400))
#    input = input.replace('#STOP#',   str(stop + 86400))
#    ofile = outdir + 'get_ftemp_main_script'
#    fo    = open(ofile, 'w')
#    fo.write(input)
#    fo.close()
#
#    cmd = 'chmod 755 ' + outdir + 'get_ftemp_main_script'
#    os.system(cmd)
#
#    tfile = tdir + 'plot_erad_time.pro'
#    f     = open(tfile, 'r')
#    input = f.read()
#    f.close()
#
#    input = input.replace('#START#',       str(start))
#    input = input.replace('#SDATELIST#',   fpdsub)
#    input = input.replace('#LDATELIST#',   fplsub)
#    ofile = outdir + 'plot_erad_time.pro'
#    fo    = open(ofile, 'w')
#    fo.write(input)
#    fo.close()
#
#    cmd = 'cp -f ' + outdir + 'plot_erad_time.pro ./Focal/'
#    os.system(cmd)
#
#--- this_week file
#
    tfile = tdir + 'this_week'
    f     = open(tfile, 'r')
    input = f.read()
    f.close()
    input = input.replace('#DDATE#',   file_date)
    input = input.replace('#IRUSPAN1#', irudate)
    input = input.replace('#IRUSPAN2#', irudate)
    input = input.replace('#TITLE#',    title)
    input = input.replace('#TITLEDATE#',titledate)

    atemp = last_trend_date
    atemp = atemp.replace('/', '')
    input = input.replace('#PREVREPORT#', atemp)

    atemp = re.split('/', last_trend_date)
    pmon  = int(float(atemp[0]))
    lmon  = tcnv.changeMonthFormat(pmon)
    line  = lmon + ' ' + atemp[1]
#
#--- the previous report could be from the last year
#
    ryear = syear
    if mon < pmon:
        ryear = year -1
        ryear = str(ryear)

    input = input.replace('#RYEAR#',      ryear)

    input = input.replace('#PREVDATE#',   line)

    atitle = str(title)
    atitle = atitle.replace(' ', '_')

    #file  = tdir + 'Headers/' + atitle
    #fs    = open(file, 'r')
    #trend = fs.read()
    #fs.close()
    #input = input.replace("#TREND#", trend)

    [temp1, temp2, temp3, temp4, ftemp5, ftemp6, ftemp7, ftemp8] = read_cti_values()
    input = input.replace('#ATEMP#',  temp3)
    input = input.replace('#ATEMP2#', temp4)
    input = input.replace('#DTEMP#',  temp7)
    input = input.replace('#DTEMP2#', temp8)

    [val, step] = read_sim()
    input = input.replace('#WMOVE#', val)
    input = input.replace('#WSTEP#', step)
#
#--- make photon and bad pixel output
#
    run_bad_pix_and_photon(outdir)
#
#--- run to get focal temp fits files
#
    tstop = stop + 86400
    #[fcnt, fdata] = run_focal_temp_data(outdir, start, stop, fptemp)
    [fcnt, fdata] = run_focal_temp_data_new(fptemp, outdir)

    input = input.replace('#TEMPPEAK#', str(fcnt))
    input = input.replace('#TEMPLIST#', fdata)
#
#--- bad pixel
#
    file  = outdir + 'bad_pix_list'
    fs    = open(file, 'r')
    bdata = fs.read()
    fs.close()
    input = input.replace('BAD_PIXEL_TABLE', bdata)
#
#--- photon
#
    file  = outdir + 'photons'
    fs    = open(file, 'r')
    pdata = fs.read()
    fs.close()
    input = input.replace('PHOTON_TABLE', pdata)
#
#--- telem data
#
    update_weekly_telem(year, byear, mon)

    tdata = run_telem_data(telem_command, daylist, outdir)
    input = input.replace('TELEM_TABLE', tdata)
#
#--- trend data
#
    trend = set_trend_data_input(str(date))
    input = input.replace('#TREND#', trend)
#
#--- write out the weekly report
#
    ofile = outdir + file_name
    fo    = open(ofile, 'w')
    fo.write(input)
    fo.close()
#
#--- clean up
#
    cmd = 'rm ./out ./out2'
    os.system(cmd)
#
#--- move files
#
    move_files(date, year, outdir, file_name, fptemp, odir)
#
#--- send out email to admin; notify the job complete
#
    send_email_to_admin(date, year)
Пример #56
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