Exemplo n.º 1
0
def find_too_ddt_poc_sub(obsid):
    """
    find poc from obsid by reading tables. 
    input:  obsid   --- obsid
    output: poc     --- poc

    """
    try:
        #
        #--- get the basic information about the observations and update the current data
        #
        monitor = []
        groupid = []
        sqlinfo = tdsql.get_target_info(obsid, monitor, groupid)
        grating = sqlinfo[4]
        prop_no = sqlinfo[10]
        target = sqlinfo[13]
        object = sqlinfo[14]

        poc = find_poc_from_propno_poc_list(grating, prop_no, target, object)
    except:
        #
        #--- if the database is not set up for the obsid, try to another method
        #
        poc = check_tooddt_prop_obsid_list(obsid)

    return poc
Exemplo n.º 2
0
def find_too_ddt_poc_sub(obsid):
    """
    find poc from obsid by reading tables. 
    input:  obsid   --- obsid
    output: poc     --- poc

    """
    try:
#
#--- get the basic information about the observations and update the current data
#
        monitor = []
        groupid = []
        sqlinfo = tdsql.get_target_info(obsid, monitor, groupid)
        grating = sqlinfo[4]
        prop_no = sqlinfo[10]
        target  = sqlinfo[13]
        object  = sqlinfo[14]

        poc = find_poc_from_propno_poc_list(grating, prop_no, target, object)
    except:
#
#--- if the database is not set up for the obsid, try to another method
#
        poc = check_tooddt_prop_obsid_list(obsid)

    return poc
def make_ddt_obs_list():
    """
    a create a table of proposal numbers and obsids related to them
    input:  none
    output: updated table of tooddt_prop_obsid_list
            prop_list   --- a list of propsal numbers
    """

    fo = open(outdir, 'a')

    [obsid_list, prop_list] = find_ddt_obsid_status()

    for prop_no in prop_list:

        olist = obsid_list[prop_no]
        if len(olist) > 0:
            olist2 = []
#
#--- just in a case, check the database to see whether there are more than listed in sot data
#
            for obsid in olist:
                olist2.append(obsid)
                monitor = []
                groupid = []
                sqlinfo = tdsql.get_target_info(obsid, monitor, groupid)
                olist2 = olist2 + monitor
                olist2 = olist2 + groupid
#
#--- clean out so that we won't have a duplicated information
#
            olist2.sort()
            olist3 = []
            prev = ''
            for ent in olist2:
                if ent == prev:
                    continue
                else:
                    olist3.append(str(ent))
                    prev = ent

            line = prop_no + '<>' + olist3[0] 
            for k in range(1, len(olist3)):
                line = line + ':' + olist3[k]
            line = line + '\n'
            fo.write(line)

    fo.close()

    return prop_list
Exemplo n.º 4
0
def make_ddt_obs_list():
    """
    a create a table of proposal numbers and obsids related to them
    input:  none
    output: updated table of tooddt_prop_obsid_list
            prop_list   --- a list of propsal numbers
    """

    fo = open(outdir, 'a')

    [obsid_list, prop_list] = find_ddt_obsid_status()

    for prop_no in prop_list:

        olist = obsid_list[prop_no]
        if len(olist) > 0:
            olist2 = []
            #
            #--- just in a case, check the database to see whether there are more than listed in sot data
            #
            for obsid in olist:
                olist2.append(obsid)
                monitor = []
                groupid = []
                sqlinfo = tdsql.get_target_info(obsid, monitor, groupid)
                olist2 = olist2 + monitor
                olist2 = olist2 + groupid
#
#--- clean out so that we won't have a duplicated information
#
            olist2.sort()
            olist3 = []
            prev = ''
            for ent in olist2:
                if ent == prev:
                    continue
                else:
                    olist3.append(str(ent))
                    prev = ent

            line = prop_no + '<>' + olist3[0]
            for k in range(1, len(olist3)):
                line = line + ':' + olist3[k]
            line = line + '\n'
            fo.write(line)

    fo.close()

    return prop_list
Exemplo n.º 5
0
def get_obs_status(obsid):
    """
    get a status of obsid
    input:  obsid   --- obsid   
    output: status  --- status. if it is not assigned, 'na' will be returned
    """
    try:
        monitor = []
        group = []
        sqlinfo = tdsql.get_target_info(obsid, monitor, group)
        status = sqlinfo[8]
    except:
        status = "na"

    return status
Exemplo n.º 6
0
def get_obs_status(obsid):
    """
    get a status of obsid
    input:  obsid   --- obsid   
    output: status  --- status. if it is not assigned, 'na' will be returned
    """
    try:
        monitor = []
        group   = []
        sqlinfo = tdsql.get_target_info(obsid, monitor, group)
        status  = sqlinfo[8]
    except:
        status  = 'na'

    return status
Exemplo n.º 7
0
def remove_old_obs(list):
    """
    remved archived or cancelled observations and update obs date of the list
    input:  list    --- too_list or ddt_list
    outpu:  none, but update <list> 
    """

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

    fo = open(file, 'w')
    for ent in data:
        atemp = re.split('\s+', ent)

        try:
            monitor = []
            groupid = []
            sqlinfo = tdsql.get_target_info(atemp[2], monitor, groupid)
            status = sqlinfo[8]
            lts_lt_plan = sqlinfo[12]
            soe_st_sched_date = sqlinfo[11]

            if soe_st_sched_date is not None:
                date = soe_st_sched_date
            elif lts_lt_plan is not None:
                date = lts_lt_plan
            else:
                date = 'TBD'

        except:
            status = atemp[3]
            date = atemp[5]

        if (status == 'observed') or (status == 'unobserved'):
            line = atemp[0] + '\t' + atemp[1] + '\t' + atemp[2] + '\t'
            line = line + str(
                status) + '\t' + atemp[4] + '\t' + atemp[5] + '\t'
            line = line + str(date) + '\n'
            fo.write(line)

    fo.close()
Exemplo n.º 8
0
def remove_old_obs(list):
    """
    remved archived or cancelled observations and update obs date of the list
    input:  list    --- too_list or ddt_list
    outpu:  none, but update <list> 
    """

    file = too_dir + list
    f = open(file, "r")
    data = [line.strip() for line in f.readlines()]
    f.close()

    fo = open(file, "w")
    for ent in data:
        atemp = re.split("\s+", ent)

        try:
            monitor = []
            groupid = []
            sqlinfo = tdsql.get_target_info(atemp[2], monitor, groupid)
            status = sqlinfo[8]
            lts_lt_plan = sqlinfo[12]
            soe_st_sched_date = sqlinfo[11]

            if soe_st_sched_date is not None:
                date = soe_st_sched_date
            elif lts_lt_plan is not None:
                date = lts_lt_plan
            else:
                date = "TBD"

        except:
            status = atemp[3]
            date = atemp[5]

        if (status == "observed") or (status == "unobserved"):
            line = atemp[0] + "\t" + atemp[1] + "\t" + atemp[2] + "\t"
            line = line + str(status) + "\t" + atemp[4] + "\t" + atemp[5] + "\t"
            line = line + str(date) + "\n"
            fo.write(line)

    fo.close()
Exemplo n.º 9
0
def find_info(dfile):
    """
    find obsid and a observation time
    input:  dfile   --- original data file name
    output: obisd   --- obsid
            ltime   --- time in the format of <yyyy>:<ddd>:<hh>:<mm>:<ss
            stime   --- tine in second from 1998.1.1
    """
    #
    #--- find obsid
    #
    atemp = re.split('obsid_', dfile)
    btemp = re.split('_', atemp[1])
    obsid = btemp[0]

    monitor = []
    groupid = []
    #
    #--- get information about obsid
    #
    try:
        sqlinfo = tdsql.get_target_info(obsid, monitor, groupid)
    except:
        return 'na'
#
#--- 11th data is the date of the observation
#
    sdate = sqlinfo[11]
    #
    #--- convert the time into <yyyy>:<ddd>:<hh>:<mm>:<ss>
    #
    ltime = convert_date_format(sdate)
    #
    #--- convert time into seconds from 1998.1.1
    #
    stime = date = Chandra.Time.DateTime(ltime).secs

    return [obsid, ltime, stime]
Exemplo n.º 10
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)
Exemplo n.º 11
0
def update_list(list_name, newList):
    """
    update list for a given obsid list.
    input: list_name (e.g., too_list, ddt_list), newList: a list of new obsids

    """
    #
    #--- save the old file
    #

    old = list_name + '~'
    cmd = 'cp ' + too_dir + list_name + ' ' + too_dir + old
    os.system(cmd)

    #
    #--- open an appropriate list (too_list or ddt_list, but can be new_obs_list)
    #

    line = too_dir + list_name
    f = open(line, 'a')

    emailList = []
    new_obsid_list = []
    new_person_list = []

    for obsid in newList:
        monitor = []
        group = []
        #
        #--- read basic information about the observation
        #
        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) = tdsql.get_target_info(obsid, monitor, group)
            chk = 1
        except:
            chk = 0

#
#--- if there are information available, procceed
#
        if chk > 0:
            #
            #--- if it is too or ddt, it gives poc, otherwise 'TBD'
            #
            if list_name == 'too_list' or list_name == 'ddt_list':
                [poc, cnew] = find_too_ddt_poc(obsid)
                update_propno_poc_list(ocat_propid, poc)
            else:
                #
                #--- if this is not ddt or too, check whether obsid is already in new_obs_list, and have assigned poc
                #--- if not, find who is the charge for the observation
                #
                poc = find_current_poc(obsid)
                if poc == 'TBD':
                    poc = find_person_in_charge(targname, grating, object)
#
#--- set observation date; probably soe_st_sched_date, but if not lts_lt_plan
#
            if str(soe_st_sched_date).lower() != 'null' and str(
                    soe_st_sched_date).lower() != 'none':
                date = soe_st_sched_date
            else:
                date = lts_lt_plan

#
#--- append the new observation to the list
#
            line = type.lower() + '\t' + str(seq_nbr) + '\t' + str(
                obsid) + '\t' + status + '\t' + poc + '\t' + str(
                    obs_ao_str) + '\t' + str(date) + '\n'
            f.write(line)
            emailList.append(line)
            new_obsid_list.append(obsid)
            new_person_list.append(poc)

    f.close()
    #
    #--- notify the update by email
    #
    atemp = re.split('_', list_name)
    send_email(atemp[0], emailList, temp_dir)
Exemplo n.º 12
0
def update_monitor_list(new_ddt_too_list, new_ddt_too_person, tempdir='NA'):
    """
    update monitor_too_ddt. input: lists of: new_ddt_too_list and new_ddt_too_person (obsid list and poc list)

    """
    #
    #--- read the current monitor_too_ddt list
    #
    line = too_dir + 'monitor_too_ddt'
    f = open(line, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    #
    #--- three information we need; obsid, who is poc, and proposal id which is same for all obsids in the same monitor/group
    #
    added_obsid = []
    added_person = []
    added_propid = []

    for ent in data:
        atemp = re.split('\s+|\t+', ent)
        obsid = int(atemp[0].strip())
        #
        #--- get the basic information about the observations and update the current data
        #
        monitor = []
        groupid = []
        sqlinfo = tdsql.get_target_info(obsid, monitor, groupid)
        try:
            chk = 1
            #            (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)

            status = sqlinfo[8]
            ocat_propid = sqlinfo[10]

            if status == 'observed' or status == 'scheduled' or status == 'unobserved':
                line = str(obsid) + '\t' + atemp[1] + '\t' + str(ocat_propid)
                added_obsid.append(obsid)
                added_person.append(atemp[1])
                added_propid.append(ocat_propid)
        except:
            pass

#
#--- now check the new obsids are totally new or one of group/monintor members
#
    for i in range(0, len(new_ddt_too_list)):

        nobsid = int(new_ddt_too_list[i])
        chk = 0
        for comp in added_obsid:
            if comp == nobsid:
                chk = 1

        if chk == 0:
            monitor = []
            groupid = []
            try:
                chk = 1
                (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) = tdsql.get_target_info(nobsid, monitor,groupid)

                if len(monitor) > 0:
                    for ment in monitor:
                        added_obsid.append(int(ment))
                        added_person.append(new_ddt_too_person[i])
                        added_propid.append(int(ocat_propid))

                if len(group) > 0:
                    for gent in group:
                        added_obsid.append(int(gent))
                        added_person.append(new_ddt_too_person[i])
                        added_propid.append(int(ocat_propid))

            except:
                pass

#
#--- make a list with neede information
#
    if len(added_obsid) > 0:
        updated_list = []
        for i in range(0, len(added_obsid)):
            line = str(added_obsid[i]) + '\t' + added_person[i] + '\t' + str(
                added_propid[i])
            updated_list.append(line)

        updated_list.sort()
        #
        #--- save the old list
        #
        cmd = 'mv ' + too_dir + 'monitor_too_ddt ' + too_dir + 'monitor_too_ddt~'
        os.system(cmd)

        line = too_dir + 'monitor_too_ddt'
        out = open(line, 'w')
        for ent in updated_list:
            out.write(ent)
            out.write('\n')

        out.close()
        #
        #--- check whether there are any new entries
        #

        new_file = too_dir + 'monitor_too_ddt'
        old_file = too_dir + 'monitor_too_ddt~'
        newentry = find_new_entry(new_file, old_file)
        if len(newentry) > 0:

            if tempdir == 'NA':
                tempdir = './'

            tempfile = tempdir + 'ztemp'

            f = open(tempfile, 'w')
            line = 'Following obsids are added to monitor_too_ddt list. Please check whether they are correct.\n\n'
            f.write(line)

            for ent in newentry:
                line = ent + '\n'
                f.write(line)

            f.close()

            cmd = 'cat ' + tempfile + ' | mailx -s"Subject: New Monitor Entry" [email protected]'
            os.system(cmd)
Exemplo n.º 13
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() == 'ddt' or type.lower() == 'too':
#
#-- too/ddt case: assign poc
#
                    if date == 'NA':
                        person = 'TBD'
                    else:
                        try:
                            [person, chk]  = tdfnc.find_too_ddt_poc(obsid)
                        except:
                            person = 'TBD'
#
#--- observed obsid but no poc name -- record mistake; so drop
#
                        if person  == 'TBD':
                            if status == 'observed':
                                pchk = 0
                else:
#
#--- none too/ddt observations
#
                    person = tdfnc.match_usint_person(type,grating,int(seq_nbr),instrument, targname)
#
#--- print out to files
#
                if pchk == 1:
                    line  = type.lower() + '\t' + str(seq_nbr) + '\t' + obsid + '\t' + status  + '\t'   \
                            + person + '\t' + str(obs_ao_str) + '\t' + str(date) + '\n'
#
#--- if it is ddt or too observation, replace the line in ddt_list or too_list
#
                    if type.lower() == 'ddt':
                        try:
                            line = ddt_dict[obsid]
                            line = line + '\n'
                        except:
                            pass

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

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

    out1.close()
    out2.close()

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

#
#---- create new_obs_list.txt
#
    ofile = too_dir + 'new_obs_list.txt'
    out   = open(ofile, 'w')
    out.write('Type    Seq #   ObsId   Status          TOO     AO      Observation Date\n')
    out.write('--------------------------------------------------------------------------\n\n')
    out.close()
    cmd = 'cat ' + too_dir + 'new_obs_list >> ' + ofile
    os.system(cmd)
Exemplo n.º 14
0
def update_list(list_name, newList):

    """
    update list for a given obsid list.
    input: list_name (e.g., too_list, ddt_list), newList: a list of new obsids

    """
#
#--- save the old file
#

    old = list_name + '~'
    cmd = 'cp ' + too_dir + list_name + ' '+ too_dir + old
    os.system(cmd)

#
#--- open an appropriate list (too_list or ddt_list, but can be new_obs_list)
#

    line = too_dir + list_name
    f    = open(line, 'a')

    emailList       = []
    new_obsid_list  = []
    new_person_list = []

    for obsid in newList:
        monitor = []
        group   = []
#
#--- read basic information about the observation
#
        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) = tdsql.get_target_info(obsid, monitor, group)
            chk = 1
        except:
            chk = 0

#
#--- if there are information available, procceed
#
        if chk > 0:
#
#--- if it is too or ddt, it gives poc, otherwise 'TBD'
#
            if list_name == 'too_list' or list_name == 'ddt_list':
                [poc, cnew] = find_too_ddt_poc(obsid)
                update_propno_poc_list(ocat_propid, poc)
            else:
#
#--- if this is not ddt or too, check whether obsid is already in new_obs_list, and have assigned poc
#--- if not, find who is the charge for the observation
#
                poc = find_current_poc(obsid)
                if poc == 'TBD':
                    poc = find_person_in_charge(targname, grating, object)
#
#--- set observation date; probably soe_st_sched_date, but if not lts_lt_plan 
#
            if str(soe_st_sched_date).lower() != 'null' and str(soe_st_sched_date).lower() != 'none':
                date = soe_st_sched_date
            else:
                date = lts_lt_plan

#
#--- append the new observation to the list
#
            line = type.lower() + '\t' + str(seq_nbr) + '\t' + str(obsid) + '\t' + status + '\t' + poc + '\t' + str(obs_ao_str) +  '\t' + str(date) + '\n'
            f.write(line)
            emailList.append(line)
            new_obsid_list.append(obsid)
            new_person_list.append(poc)

    f.close()
#
#--- notify the update by email
#
    atemp = re.split('_', list_name)
    send_email(atemp[0], emailList, temp_dir)
Exemplo n.º 15
0
def update_monitor_list(new_ddt_too_list, new_ddt_too_person, tempdir='NA'):

    """
    update monitor_too_ddt. input: lists of: new_ddt_too_list and new_ddt_too_person (obsid list and poc list)

    """
#
#--- read the current monitor_too_ddt list
#
    line = too_dir + 'monitor_too_ddt'
    f    = open(line, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

#
#--- three information we need; obsid, who is poc, and proposal id which is same for all obsids in the same monitor/group
#
    added_obsid  = []
    added_person = []
    added_propid = []

    for ent in data:
        atemp = re.split('\s+|\t+', ent)
        obsid = int(atemp[0].strip())
#
#--- get the basic information about the observations and update the current data
#
        monitor = []
        groupid = []
        sqlinfo = tdsql.get_target_info(obsid, monitor, groupid)
        try:
            chk = 1
#            (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)

            status = sqlinfo[8]
            ocat_propid = sqlinfo[10]

            if status == 'observed' or status == 'scheduled' or status == 'unobserved':
                line = str(obsid) + '\t' + atemp[1] + '\t' + str(ocat_propid)
                added_obsid.append(obsid)
                added_person.append(atemp[1])
                added_propid.append(ocat_propid)
        except:
            pass

#
#--- now check the new obsids are totally new or one of group/monintor members
#
    for i in range(0, len(new_ddt_too_list)):

        nobsid = int(new_ddt_too_list[i])
        chk = 0
        for comp in added_obsid:
            if comp == nobsid:
                chk = 1

        if chk == 0:
            monitor = []
            groupid = []
            try:
                chk = 1
                (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) = tdsql.get_target_info(nobsid, monitor,groupid)

                if len(monitor) > 0:
                    for ment in monitor:
                        added_obsid.append(int(ment))
                        added_person.append(new_ddt_too_person[i])
                        added_propid.append(int(ocat_propid))

                if len(group) > 0:
                    for gent in group:
                        added_obsid.append(int(gent))
                        added_person.append(new_ddt_too_person[i])
                        added_propid.append(int(ocat_propid))

            except:
                pass

#
#--- make a list with neede information
#
    if len(added_obsid) > 0:
        updated_list = []
        for i in range(0, len(added_obsid)):
            line = str(added_obsid[i]) + '\t' + added_person[i] + '\t' + str(added_propid[i])
            updated_list.append(line)

        updated_list.sort()
#
#--- save the old list
#
        cmd = 'mv ' + too_dir + 'monitor_too_ddt ' + too_dir + 'monitor_too_ddt~'
        os.system(cmd)
    
        line = too_dir + 'monitor_too_ddt'
        out = open(line, 'w')
        for ent in updated_list:
            out.write(ent)
            out.write('\n')
    
        out.close()
#
#--- check whether there are any new entries
#

        new_file = too_dir + 'monitor_too_ddt'
        old_file = too_dir + 'monitor_too_ddt~'
        newentry = find_new_entry(new_file, old_file)
        if len(newentry) > 0:

            if tempdir == 'NA':
                tempdir = './'
        
            tempfile = tempdir + 'ztemp'
        
            f = open(tempfile, 'w')
            line = 'Following obsids are added to monitor_too_ddt list. Please check whether they are correct.\n\n'
            f.write(line)

            for ent in newentry:
                line = ent + '\n'
                f.write(line)

            f.close()

            cmd = 'cat ' + tempfile + ' | mailx -s"Subject: New Monitor Entry" [email protected]'
            os.system(cmd)
Exemplo n.º 16
0
def find_poc(prop_no, obsid):
    """
    find a poc for given proposal id and/or obsid
    input:  prop_no --- proposal id 
            obsid   --- obsid
            it also needs access to:
                sybase
                /data/mta4/CUS/www/Usint/ocat/Info_save/too_contact_info/propno_poc_list
                /data/mta4/CUS/www/Usint/ocat/Info_save/too_contact_info/special_obsid_poc_list
    output: poc     --- poc
    """
#
#--- find basic information from sybase
#
    (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), [],[])
#
#--- check only unobserved or scheduled observations
#
    if (status != 'unobserved') and (status != 'scheduled') :
        return 'na'
#
#--- check too and ddt cases
#
    f    = open('/data/mta4/CUS/www/Usint/ocat/Info_save/too_contact_info/propno_poc_list', 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    tooddt = {}
    for ent in data:
        atemp = re.split('<>', ent)
        tooddt[atemp[0]] = atemp[1]
#
#--- if it is too or ddt but poc is not assigned, return 'TBD'
#
    try:
        poc = tooddt[prop_no]
        return poc
    except:
        if type == 'too' or type == 'ddt':
            poc = 'TBD'
            return poc
#
#--- check none-standard poc assignment
# 
    f    = open('/data/mta4/CUS/www/Usint/ocat/Info_save/too_contact_info/special_obsid_poc_list', 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()
#
#--- find proposal # based of ocat_propid
#
    cmd      = 'select prop_num from prop_info  where ocat_propid= ' + str(ocat_propid)
    out      = sql.readSQL(cmd, 'axafocat')
    prop_num = out['prop_num']

    special_assignment = {}
    prev = ''
    for ent in data:
        atemp  = re.split('\s+', ent)
        poc    = atemp[2]
        propno = atemp[3]
        if propno != prev:
            special_assignment[propno] = poc
            prev = propno
        else:
            continue

    try:
        poc = special_assignment[prop_num]
    except:
#
#--- give back the standard poc
#
        poc = tdfnc.match_usint_person(type, grating, int(seq_nbr), instrument, targname)

    return poc
Exemplo n.º 17
0
def read_ddt_too_from_email(tooList, ddtList):
    """
    extreact TOO/DDT obsid from cus email achive. no input, but need tooList, ddtList.
    """

    #
    #--- read email archive
    #
    f = open('/arc/cus/mail_archive', 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    #
    #--- find certain signatures for TOO/DDT observation approved email, and extract their obsids
    #

    tooSet = []
    ddtSet = []
    tchk = 0
    dchk = 0
    for ent in data:

        m1 = re.search('Obsid', ent)

        if m1 is not None:
            m2 = re.search('Seq', ent)
            m5 = re.search('Prop', ent)

            if m2 is not None:

                #                m3 = re.search('is a TOO which has recently', ent)
                #                m4 = re.search('is a DDT which has recently', ent)
                m3 = re.search('is a TOO', ent)
                m4 = re.search('is a DDT', ent)

                if m3 is not None:
                    obsid = getObsid(ent)
                    tooSet.append(obsid)
                    tchk += 1

                elif m4 is not None:
                    obsid = getObsid(ent)
                    ddtSet.append(obsid)
                    dchk += 1

            elif m5 is not None:

                m6 = re.search('is a TOO', ent)
                m7 = re.search('is a DDT', ent)

                if m6 is not None:
                    obsid = getObsid(ent)
                    tooSet.append(obsid)
                    tchk += 1

                elif m7 is not None:
                    obsid = getObsid(ent)
                    ddtSet.append(obsid)
                    dchk += 1

#
#---- remove duplicated entries
#

    tlen = 0
    dlen = 0
    if tchk > 0:
        tempList = tdfnc.removeDuplicate(tooSet, sorted='yes')
        tlen = len(tempList)
        if tlen > 0:
            for ent in tempList:
                monitor = []
                group = []
                sqlinfo = tdsql.get_target_info(ent, monitor, group)
                status = sqlinfo[8]
                if status == 'unobserved':
                    tooList.append(ent)

    if dchk > 0:
        tempList = tdfnc.removeDuplicate(ddtSet, sorted='yes')
        dlen = len(tempList)
        if dlen > 0:
            for ent in tempList:
                monitor = []
                group = []
                sqlinfo = tdsql.get_target_info(ent, monitor, group)
                status = sqlinfo[8]
                if status == 'unobserved':
                    ddtList.append(ent)

    return tlen + dlen