コード例 #1
0
def time_conversion(atime):
    """
    convert time format from <yyyyddd.ddd> to second from 1998.1.1
    input:  time    --- time in <yyyyddd.ddd> format
    output: time    --- time in second from 1998.1.1
    """
    atime = str(atime)

    year = str(atime[0:4])
    yday = str(atime[4:7])

    fday = float('0' + atime[7:])

    val = 24 * fday
    hh = int(val)
    val = 60 * (val - hh)
    mm = int(val)
    ss = 60 * (val - mm)
    ss = int(ss)

    lhh = mcf.add_leading_zero(hh)
    lmm = mcf.add_leading_zero(mm)
    lss = mcf.add_leading_zero(ss)

    time = year + ':' + yday + ':' + lhh + ':' + lmm + ':' + lss

    time = Chandra.Time.DateTime(time).secs

    return time
コード例 #2
0
def set_collection_period(year, mon):
    """
    set a data collection period in the form of <yyyy>:<jjj>:00:00:00
    input:  year    --- year of the data collection starts
            mon     --- month of the data colleciton starts
    output: start   --- data collection starting time in <yyyy>:<jjj>:00:00:00
            stop    --- data collection stopping time in <yyyy>:<jjj>:00:00:00
    """
    #
    #--- set finishing date
    #
    syear = year
    smon = mon + 1
    if smon > 12:
        smon = 1
        syear += 1
#
#--- convert time format
#
    start = str(year) + ':' + mcf.add_leading_zero(mon) + ':01'
    start = time.strftime('%Y:%j:00:00:00', time.strptime(start, '%Y:%m:%d'))

    stop = str(syear) + ':' + mcf.add_leading_zero(smon) + ':01'
    stop = time.strftime('%Y:%j:00:00:00', time.strptime(stop, '%Y:%m:%d'))

    return [start, stop]
コード例 #3
0
ファイル: extract_line_stat.py プロジェクト: chandra-mta/MTA
def convert_date_format(sdate):
    """
    convert time format from <Mmm> <dd> <yyyy> <hh>:<mm><AM/PM> to <yyyy>:<ddd>:<hh>:<mm>:<ss>
    input   sdate   --- date in <Mmm> <dd> <yyy> <hh>:<mm><AM/PM>
    output  ltime   --- date in <yyyy>:<ddd>:<hh>:<mm>:<ss>
    """
    atemp = re.split('\s+', sdate)
    mon = mcf.change_month_format(atemp[0])
    mon = mcf.add_leading_zero(mon)
    day = atemp[1]
    day = mcf.add_leading_zero(day)
    year = atemp[2]

    tpart = atemp[3]
    mc = re.search('AM', tpart)
    if mc is not None:
        add = 0
        spl = 'AM'
    else:
        add = 12
        spl = 'PM'
    btemp = re.split(spl, tpart)
    ctemp = re.split(':', btemp[0])
    hr = str(int(ctemp[0]) + add)
    mm = ctemp[1]

    ltime = year + ':' + mon + ':' + day + ':' + hr + ':' + mm + ':00'
    ltime = time.strftime("%Y:%j:%H:%M:%S",
                          time.strptime(ltime, '%Y:%m:%d:%H:%M:%S'))

    return ltime
コード例 #4
0
def update_plt_html_date():
    """
    update html pages for plots; just replacing date
    no input, but get the list from plot_dir
    """
    [lyear, lmon, lday] = mcf.today_date()
    date = mcf.add_leading_zero(lmon) + '/'
    date = date + mcf.add_leading_zero(lday) + '/' + str(lyear)

    cmd = 'ls ' + plot_dir + '/*html>./ztemp'
    os.system(cmd)
    data = mcf.read_data_file('./ztemp', remove=1)

    for ent in data:
        hdat = mcf.read_data_file(ent)

        sline = ''
        for oline in hdat:
            m = re.search('Last Update', oline)
            if m is not None:
                sline = sline + 'Last Update: ' + date + '\n'
            else:
                sline = sline + oline + '\n'

        with open(ent, 'w') as fo:
            fo.write(sline)
コード例 #5
0
ファイル: analyze_sim_data.py プロジェクト: chandra-mta/MTA
def convert_time_format(tline):
    """
    convert time formats from that in TL files
    input:  tline   --- time in TL format
    output: stime   --- seconds from 1998.1.1
            dom     --- day of mission
            atime   --- display time <yyyy><ddd><hh><mm><ss><ss>
    """

    atemp = re.split(':', tline)
    btemp = re.split('\s+', atemp[0])
    year = btemp[0]
    yday = mcf.add_leading_zero(btemp[1], 3)
    hh = mcf.add_leading_zero(btemp[2])
    mm = mcf.add_leading_zero(atemp[1])
    ctemp = re.split('\.', atemp[2])
    ss = mcf.add_leading_zero(ctemp[0])
    fsq = ctemp[1] + '0'
    #
    #--- chandra time
    #
    ltime = year + ':' + yday + ':' + hh + ':' + mm + ':' + ss + '.' + fsq
    stime = Chandra.Time.DateTime(ltime).secs
    #
    #--- display time
    #
    atime = year + yday + '.' + hh + mm + ss + fsq
    #
    #--- day of mission
    #
    dom = mcf.ydate_to_dom(year, yday)
    dom = dom + float(hh) / 24.0 + float(mm) / 1440.0 + float(ss) / 86400.0
    dom = dom + float(fsq) / 8640000.0

    return [stime, dom, atime]
コード例 #6
0
def update_main_html():
    """
    update main html page
    input: none but read a template from <house_keeping>
    output: <web_dir>/expousre.html
    """
    [tyear, mon, day] = mcf.today_date()
    today = mcf.change_month_format(mon)
    today = today + ' ' + mcf.add_leading_zero(day)
    today = today + ', ' + str(tyear)

    syear = tyear
    smon = mon - 1
    if smon < 1:
        smon = 12
        syear = tyear - 1

    lyear = str(syear)
    lmon = mcf.add_leading_zero(smon)
    line = lmon + '_' + lyear

    aline = mcf.change_month_format(smon) + ' ' + lyear

    ifile = house_keeping + 'template'
    with open(ifile, 'r') as f:
        data = f.read()

    data = data.replace('#ODATE#', line)
    data = data.replace('#DATE#', aline)
    data = data.replace('#TODAY#', today)

    ifile = web_dir + 'exposure.html'
    with open(ifile, 'w') as fo:
        fo.write(data)
コード例 #7
0
ファイル: pcadfilter.py プロジェクト: chandra-mta/MTA
def convert_time_format(line):
    """
    convert pcad time format to Chandra time: seconds from 1998.1.1
    input:  line    --- pcad time e.g.: 2019  42 14: 9:57.2
    output: ctime   --- chandra time
    """
    t = line.strip()
    year = t[0] + t[1] + t[2] + t[3]

    yday = int(t[5] + t[6] + t[7])
    yday = mcf.add_leading_zero(yday, 3)

    hh = int(t[9] + t[10])
    hh = mcf.add_leading_zero(hh)

    mm = int(t[12] + t[13])
    mm = mcf.add_leading_zero(mm)

    ss = int(t[15] + t[16])
    ss = mcf.add_leading_zero(ss)
    ss = ss + t[17] + t[
        18]  #---- adjust_dgit_len takes only int; so add the dicimal part

    stime = year + ':' + yday + ':' + hh + ':' + mm + ':' + ss

    ctime = Chandra.Time.DateTime(stime).secs

    return ctime
コード例 #8
0
def acis_sci_run_print_html(html_dir, pyear, pmonth, pday):
    """
    update three html pages according for the year (pyear)
    Input: html_dir --- web directory path
           pyear  --- the year you want to update the html pages
           pmonth --- current month
           pday   --- current month date
    Output: science_run.html
            science_run<year>.html
    """
    #
    #--- set substitution values
    #
    pyear = int(pyear)
    cpmon = mcf.add_leading_zero(int(float(pmonth)))
    cpday = mcf.add_leading_zero(int(float(pday)))
    update = str(pyear) + '-' + str(cpmon) + '-' + str(cpday)
    ydate = int(float(time.strftime("%j", time.strptime(update, '%Y-%m-%d'))))
    #
    #--- make a link table
    #
    ylist = ''
    j = 0
    for ryear in range(1999, pyear + 1):
        ylist = ylist + '<td><a href=' + http_dir + '/Year' + str(ryear)
        ylist = ylist + '/science_run' + str(ryear) + '.html>'
        ylist = ylist + '<strong>Year ' + str(
            ryear) + '</strong></a><br /><td />\n'
        #
        #--- every 6 years, break a row
        #
        if j == 5:
            j = 0
            ylist = ylist + '</tr><tr>\n'
        else:
            j += 1
#
#---- update the main html page
#
    template = house_keeping + 'science_run.html'
    outfile = html_dir + 'science_run.html'

    print_html_page(template, update, pyear, ylist, outfile)
    #
    #--- update sub directory html pages
    #
    ystop = pyear + 1
    for syear in range(1999, ystop):
        template = house_keeping + 'sub_year.html'
        outfile = html_dir + 'Year' + str(syear) + '/science_run' + str(
            syear) + '.html'

        if syear == pyear:
            ldate = update
        else:
            ldate = str(syear) + '-12-31'

        print_html_page(template, ldate, syear, ylist, outfile)
コード例 #9
0
ファイル: update_dea_rdb.py プロジェクト: chandra-mta/MTA
def convert_time_format(data):
    """
    convert time format from <ddd>:<seconds> to Chandra time
    we assume that the first entry of the list is the time 
    input:  data    --- a list of data
    output: save    --- a list of lists of data with converted time foramt
    """
    #
    #--- find today's year and ydate
    #
    out = time.strftime("%Y:%j", time.gmtime())
    atemp = re.split(':', out)
    year = int(float(atemp[0]))
    yday = int(float(atemp[1]))
    save = []
    for ent in data:
        atemp = re.split('\s+', ent)
        date = atemp[1]
        btemp = re.split(':', date)
        ydate = int(btemp[0])
        ytime = float(btemp[1])
        uyear = year
        #
        #--- if today's ydate is the first part of the year, it could be possible that
        #--- the date is from the last year; make sure tat the correspoinding year is a correct one.
        #
        if yday < 10:
            if ydate > 350:
                uyear = year - 1
        sydate = mcf.add_leading_zero(ydate, dlen=3)

        ytime /= 86400.0
        hp = ytime * 24
        hh = int(hp)
        lhh = mcf.add_leading_zero(hh)
        mp = (hp - hh) * 60
        mm = int(mp)
        lmm = mcf.add_leading_zero(mm)
        ss = int((mp - mm) * 60)
        lss = mcf.add_leading_zero(ss)

        stime = str(uyear) + ':' + str(sydate) + ':' + str(lhh) + ':' + str(
            lmm) + ':' + str(lss)

        try:
            ctime = Chandra.Time.DateTime(stime).secs
        except:
            continue

        out = ent.replace(date, str(ctime))
        save.append(out)

    return save
コード例 #10
0
ファイル: run_evt_script.py プロジェクト: chandra-mta/MTA_old
def run_evt_script(lev="Lev1"):
    """
    extract sib data from acis event  data
    input: lev  --- lev of the data to be processed; either "Lev1" or "Lev2"
    output: extracted data in Outdir/
    """
    #
    #--- find today's date information (in local time)
    #
    tlist = time.localtime()

    eyear = tlist[0]
    emon = tlist[1]
    eday = tlist[2]
    #
    #--- if today is before the 5th day of the month, complete the last month
    #
    if eday <= 4:
        eday = 1
        syear = eyear
        smon = emon - 1
        if smon < 1:
            syear -= 1
            smon = 12
    else:
        syear = eyear
        smon = emon
#
#--- find the last date of the previous data analyzed
#
    sday = find_prev_date(smon, lev)
    #
    #--- now convert the date format
    #
    lemon = mcf.add_leading_zero(emon)
    leday = mcf.add_leading_zero(eday)
    stop = str(eyear) + '-' + lemon + '-' + leday + 'T00:00:00'

    lsmon = mcf.add_leading_zero(smon)
    lsday = mcf.add_leading_zero(sday)
    start = str(syear) + '-' + lsmon + '-' + lsday + 'T00:00:00'
    #
    #--- extract obsid list for the period
    #
    xxx = 999
    if xxx == 999:
        #try:
        scf.find_observation(start, stop, lev=lev)
        #
        #---  run the main script
        #
        process_evt(lev)
コード例 #11
0
def convert_to_julian_date(year, mon, day):
    """
    convert calender date to julian date
    input:  year    --- year
            mon     --- month
            day     --- day
    output: jd      --- julian date
    """
    line = str(year) + ':' + str(mcf.add_leading_zero(mon))
    line = line + ':' + str(mcf.add_leading_zero(day))
    dt = datetime.datetime.strptime(line, '%Y:%m:%d')
    jd = julian.to_jd(dt + datetime.timedelta(hours=12), fmt='jd')

    return jd
コード例 #12
0
def set_date(year, mon):
    """
    set the data for the last month
    input:  year    --- year; optional
            mon     --- mon; optional
    output: begni   --- starting date in <yyyy>:<ddd>:<hh>:<mm>:<ss>
            end     --- stopping date in <yyyy>:<ddd>:<hh>:<mm>:<ss>
            syear   --- year of the starting time
            smon    --- month of the starting time
            eyear   --- year of the ending time
            emon    --- month of the ending time
    """
    #
    #--- if the year/month are not give, find today's date information (in local time)
    #
    if year == '':
        tlist = time.localtime()
        #
        #--- set data time interval to the 1st of the last month to the 1st of this month
        #
        eyear = tlist[0]
        emon = tlist[1]
    else:
        eyear = year
        emon = mon + 1
        if emon > 12:
            emon = 1
            eyear += 1

    tline = str(eyear) + ' ' + str(emon) + ' 1'
    tlist = time.strptime(tline, "%Y %m %d")
    eyday = tlist[7]

    lyday = mcf.add_leading_zero(eyday, 3)
    end = str(eyear) + ':' + str(lyday) + ':00:00:00'

    syear = eyear
    smon = emon - 1
    if smon < 1:
        syear -= 1
        smon = 12

    tline = str(syear) + ' ' + str(smon) + ' 1'
    tlist = time.strptime(tline, "%Y %m %d")
    syday = tlist[7]

    lyday = mcf.add_leading_zero(syday, 3)
    begin = str(syear) + ':' + str(lyday) + ':00:00:00'

    return [begin, end, syear, smon, eyear, emon]
コード例 #13
0
def get_ctime(year, month, day):
    """
    convert year month day into Chandra time
    input:  year    --- year
            month   --- month
            day     --- day of month
    output: limt    --- time in seconds from 19981.1.
    """
    ltime = str(year) + ':' + mcf.add_leading_zero(
        month) + ':' + mcf.add_leading_zero(day)
    ltime = time.strftime('%Y:%j:00:00:00', time.strptime(ltime, '%Y:%m:%d'))
    ltime = int(Chandra.Time.DateTime(ltime).secs)

    return ltime
コード例 #14
0
ファイル: update_stat_table.py プロジェクト: chandra-mta/MTA
def convert_mday_to_stime(year, month, mday):
    """
    convert year, month, mday into Chandra time
    input:  year    --- year
            month   --- month   
            mday    --- day of the monty
    output: ltime   --- time in seconds from 19981.1
    """
    ltime = str(year) + ':' + mcf.add_leading_zero(
        month) + ':' + mcf.add_leading_zero(mday)
    ltime = time.strftime('%Y:%j:00:00:00', time.strptime(ltime, '%Y:%m:%d'))
    ltime = int(Chandra.Time.DateTime(ltime).secs)

    return ltime
コード例 #15
0
def acis_dose_conv_to_png(indir, outdir, year, month):
    """
    prepare to convet fits files into png images, 
    input:  indir   --- directory where input fits file located
            outdir  --- directory where png files will be moved
            year    --- year
            month   --- month
    output: outfile --- <outdir>/ACIS*_<smon>_<syear>.png
    """
    scale = 'sqrt'
    #color   = 'rainbow'
    color = 'sls'

    syear = str(year)
    smon = mcf.add_leading_zero(month)
    hname = 'ACIS*' + smon + '_' + syear + '*.fits*'

    for ifile in os.listdir(indir):

        if fnmatch.fnmatch(ifile, hname):
            file_p = indir + ifile

            btemp = re.split('\.fits', ifile)
            out = btemp[0]
            outfile = outdir + out + '.png'

            expf.convert_fits_to_img(file_p, scale, color, outfile, chk=1)
        else:
            pass
コード例 #16
0
def hrc_dose_extract_stat_data_month(year, month):
    """
    compute HRC statistics: 
    input   year    --- year
            month   --- month
    output: <data_dir>/hrc<inst>_<acc/dff>_out
    """
    year = int(year)
    month = int(month)

    syear = str(year)
    smonth = mcf.add_leading_zero(month)
    #
    #--- center exposure map stat
    #
    ifile = cum_hrc_dir + '/HRCS_08_1999_' + smonth + '_' + syear + '.fits.gz'
    out = data_out + '/hrcs_acc_out'
    comp_stat(ifile, year, month, out)

    ifile = mon_hrc_dir + '/HRCS_' + smonth + '_' + syear + '.fits.gz'
    out = data_out + '/hrcs_dff_out'
    comp_stat(ifile, year, month, out)

    ifile = cum_hrc_dir + '/HRCI_08_1999_' + smonth + '_' + syear + '.fits.gz'
    out = data_out + '/hrci_acc_out'
    comp_stat(ifile, year, month, out)

    ifile = mon_hrc_dir + '/HRCI_' + smonth + '_' + syear + '.fits.gz'
    out = data_out + '/hrci_dff_out'
    comp_stat(ifile, year, month, out)
コード例 #17
0
ファイル: acis_compute_stat.py プロジェクト: chandra-mta/MTA
def run_comp_stat(year, month, head, sec, area):
    """
    set up the input and run comp_stat to write out the stat results
    input:  year    --- year
            month   --- month
            head    --- indicator of which ccd (e.g., 'i_2', 's_3)
            sec     --- a list of section of ccd
            area    --- a list of area of ccd to be extracted (e.g., '[1:256,1:1020]')
    output: updated <data_dir>/<ccd#>_<node#>_<diff/acc>_out
    """
    #
    #--- set input file names
    #
    tail = head.replace('_', '')
    syear = str(year)
    smon = mcf.add_leading_zero(month)

    name1 = cum_acis_dir + 'ACIS_07_1999_' + smon + '_' + syear + '_' + tail + '.fits.gz'
    name2 = mon_acis_dir + 'ACIS_' + smon + '_' + syear + '_' + tail + '.fits.gz'

    for k in range(0, 4):
        #
        #--- cummulative stat
        #
        line = name1 + area[k]
        out = head + '_n_' + str(sec[k]) + '_acc_out'
        comp_stat(line, year, month, out)
        #
        #--- this month's stat
        #
        line = name2 + area[k]
        out = head + '_n_' + str(sec[k]) + '_dff_out'
        comp_stat(line, year, month, out)
コード例 #18
0
def find_start_and_stop_time():
    """
    find start and stop time (set for the last month)
    """
    out = time.strftime("%Y:%m", time.gmtime())
    [lyear, lmon] = re.split(':', out)
    tstop = lyear + ':' + lmon + ':01'
    tstop = mcf.convert_date_format(tstop,
                                    ifmt='%Y:%m:%d',
                                    ofmt='%Y:%j:00:00:00')

    year = int(float(lyear))
    mon = int(float(lmon))
    pyear = year
    pmon = mon - 1
    if pmon < 1:
        pmon = 12
        pyear -= 1

    tstart = str(pyear) + ':' + mcf.add_leading_zero(pmon) + ':01'
    tstart = mcf.convert_date_format(tstart,
                                     ifmt='%Y:%m:%d',
                                     ofmt='%Y:%j:00:00:00')

    return [tstart, tstop]
コード例 #19
0
def update_main_html():
    """
    update the top html page --- changes are just updated date
    input:  none, but read from <house_keeping>/exp_template
    output: <web_dir>/exposure.html
    """
    today = time.strftime('%m:%d:%Y', time.gmtime())
    atemp = re.split(':', today)
    tyear = int(float(atemp[2]))
    mon = int(float(atemp[0]))
    day = int(float(atemp[1]))
    #
    #--- display date
    #
    cmon = mcf.change_month_format(mon)
    today = cmon + ' ' + mcf.add_leading_zero(day) + ', ' + str(tyear)
    #
    #--- link date for the most recent plots
    #
    [lyear, lmon] = find_last_entry_data()

    smon = float(lmon)
    if smon < 10:
        lmon = '0' + lmon
    line = lmon + '_' + lyear

    data = read_template('main_page')
    data = data.replace('#LATEST#', line)
    data = data.replace('#UPDATE#', today)

    ofile = web_dir + 'hrc_exposure_map.html'
    with open(ofile, 'w') as fo:
        fo.write(data)
コード例 #20
0
def correct_naming(obsid, inst):
    """
    check secondary and analysis directories and correct wrongly named fits and par file
    input:  obsid   --- obsid   
            inst    --- instrument. either "i" or "s"
    """
    cobsid = str(int(float(obsid)))
    if len(cobsid) == 5:
        return

    lobsid = mcf.add_leading_zero(obsid, 5)

    for sdir in ['secondary', 'analysis']:

        cmd = 'ls /data/hrc/' + inst + '/' + lobsid + '/' + sdir + '/hrcf* >' + zspace
        os.system(cmd)

        data = mcf.read_data_file(zspace, remove=1)
        for ent in data:
            atemp = re.split('\/', ent)
            fname = atemp[-1]
            mc = re.search(lobsid, fname)
            if mc is not None:
                continue
            else:
                atemp = re.split('hrcf', fname)
                btemp = re.split('_', atemp[1])
                sobs = btemp[0]
                new = fname.replace(sobs, lobsid)
                full = '/data/hrc/' + inst + '/' + lobsid + '/' + sdir + '/' + new

                cmd = 'mv ' + ent + ' ' + full
                os.system(cmd)
コード例 #21
0
def ede_temperature_plots(ifile):
    """
    plot OBA/HRMA temperature - EdE relations
    input:  ifile   --- a file name of data
    output: *_plot.png/*_low_res_plot.png --- two plots; one is in 200dpi and another in 40dpi
    """
    #
    #--- read data
    #
    [xdata, xdata2, ydata, yerror] = read_ede_data(ifile)
    #
    #--- set y plotting range
    #
    [ymin, ymax] = set_min_max(ydata)
    ymax = 2100
    #
    #--- plot OBA data
    #
    for oob in range(1, 63):
        msid = 'oobthr' + mcf.add_leading_zero(oob)
        #
        #--- set label, output file name...
        #
        label = create_label(ifile)
        outdir = web_dir + 'OBA/Plots/'
        outname = set_out_name(outdir, msid, ifile)
        #
        #--- find a corresponding temperature
        #
        try:
            [temperature, ydata_c,
             yerror_c] = get_temp_data(msid, xdata2, ydata, yerror)
            #
            #--- plot data
            #
            plot_data(temperature, ydata_c, yerror_c, ymin, ymax, msid, label,
                      outname)
        except:
            cmd = 'cp ' + house_keeping + 'no_data.png ' + outname
            os.system(cmd)

#
#--- plot HRMA data
#
    for rt in range(556, 581):
        msid = '4rt' + str(rt) + 't'

        try:
            [temperature, ydata_c,
             yerror_c] = get_temp_data(msid, xdata2, ydata, yerror)
        except:
            continue

        label = create_label(ifile)
        outdir = web_dir + 'HRMA/Plots/'
        outname = set_out_name(outdir, msid, ifile)
        plot_data(temperature, ydata_c, yerror_c, ymin, ymax, msid, label,
                  outname)
コード例 #22
0
def find_un_processed_data(inst):
    """
    find hrc obsids which need to be reprocessed
    input: inst     --- insturment indicator "i" or "s"
    output: uhrc    --- a list of obsids of either hrc i or hrc s
    """
    #
    #--- extract all hrc obsid listed in database
    #
    infile = '/data/mta4/obs_ss/sot_ocat.out'
    data = mcf.read_data_file(infile)

    h_list = []
    h_dict = {}
    for ent in data:
        atemp = re.split('\^', ent)
        if inst == 'i':
            mc = re.search('HRC-I', atemp[12])
        else:
            mc = re.search('HRC-S', atemp[12])

        if mc is not None:
            atemp = re.split('\^\s+', ent)
            atemp[0].strip()
            try:
                val = int(float(atemp[1]))
            except:
                continue
            h_list.append(val)
            h_dict[val] = check_status(ent)

        else:
            continue

    uhrc = clean_the_list(h_list, h_dict, inst)
    #
    #--- calibration data starting 61* or 62* obsids
    #
    clist = find_hrc_calib_obsid(inst)
    #
    #--- combine them before return
    #
    uhrc = uhrc + clist
    #
    #--- check whether the data is already processed: check 5 digit directory
    #
    clean = []
    cdir = '/data/hrc/' + str(inst) + '/'
    for obsid in uhrc:
        chk = mcf.add_leading_zero(obsid, 5)
        chk = cdir + chk
        if os.path.isdir(chk):
            pass
        else:
            clean.append(obsid)

    return clean
コード例 #23
0
def convertto1998sec(year, yday):
    """
    convert time format from mm/dd/yy,hh:mm:ss to seconds from 1998.1.1
    input:  ftime      --- time in mm/dd/yy,hh:mm:ss or yyyy-mm-dd,hh:mm:ss
    output  stime      --- time in seconds from 1998.1.1
    """
    ftime   = str(year) + ':' + mcf.add_leading_zero(yday, 3) + ':00:00:00'
    sec1998 = Chandra.Time.DateTime(ftime).secs

    return sec1998
コード例 #24
0
def get_obsdate():
    """
    read sot database and make a list of obsids and its observation dates
    Input:  none, but read data from <sot_direcotry>
    Output: obs_dict ---    a dictionary of obsid <--> starting date
    """
#
#--- read sot data
#
    data = mcf.read_data_file(sot_directory)

    obsid_list = []
    start_date = []
    index_date = []
    obs_dict   = {}
    for ent in data:
        temp = re.split('\^', ent)
        obsid = temp[1]
#
#--- check the data are valid
#
        try:
            atemp = re.split('\s+', temp[13])
            mon   = mcf.change_month_format(atemp[0])
            date  = atemp[1]
            year  = atemp[2][2] + atemp[2][3]
        except:
            continue
#
#--- starting date in form of 05/23/14
#
        lmon  = mcf.add_leading_zero(mon)
        ldate = mcf.add_leading_zero(date)

        dline = lmon + '/' + ldate + '/' + year

        try:
            obs_dict[int(obsid)] = dline
        except:
            pass

    return obs_dict
コード例 #25
0
def start_stop_period(year, yday):
    """
    convert year and yday to the mm/dd/yy, 00:00:00 format
    input:  year    --- year
            yday    --- yday
    output: [start, stop]   --- in the format of mm/dd/yy, 00:00:00 
    """
    today = str(year) + ':' + mcf.add_leading_zero(yday, 3)
    start = today + ':00:00:00'
    stop  = today + ':23:59:59'

    return [start, stop]
コード例 #26
0
def correct_pacd_path(obsid, inst):
    """
    correcting pcad.lst data path to a full path
    input:  obsid   --- obsid
            inst    --- instrument either 'i' or 's'
    output: corrected pcad.lst file
    """
    lobsid = mcf.add_leading_zero(obsid, 5)

    cmd = 'ls /data/hrc/' + inst + '/' + lobsid + '/primary/pcad.lst > ' + zspace
    os.system(cmd)
    data = mcf.read_data_file(zspace, remove=1)

    for ifile in data:
        out = mcf.read_data_file(ifile)
        aline = ''
        for line in out:
            atemp = re.split('\/', line)
            if len(atemp) > 2:
                obsid = atemp[4]
                nform = mcf.add_leading_zero(obsid, 5)
                if obsid != nform:
                    test = line
                    line = line.replace(obsid, nform)

                    aline = aline + line + '\n'
            else:
                atemp = re.split('\/', ifile)
                obsid = atemp[4]
                ipath = '/data/hrc/' + inst + '/' + mcf.add_leading_zero(
                    obsid, 5) + '/primary/'
                line = ipath + line + '\n'
                aline = aline + line

        if aline == '':
            continue

        with open(ifile, 'w') as fo:
            fo.write(aline)
コード例 #27
0
def convert_time_format(itime):
    """
    convert tl file time format to yyyddd.hhmmss
    example: 2019  10 18:38:28.5 ---> 2019010.183828
    input:  time in tl time format
    output: time in yyyyddd.hhmmss
    """
    itime = itime.strip()
    year = itime[0] + itime[1] + itime[2] + itime[3]
    ydate = itime[5] + itime[6] + itime[7]
    hh = itime[9] + itime[10]
    mm = itime[12] + itime[13]
    ss = itime[15] + itime[16]

    ydate = mcf.add_leading_zero(ydate, 3)
    hh = mcf.add_leading_zero(hh)
    mm = mcf.add_leading_zero(mm)
    ss = mcf.add_leading_zero(ss)

    date = year + ydate + '.' + hh + mm + ss + '00'

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

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

    line = str(year) + ':' + mcf.add_leading_zero(
        month) + ':' + mcf.add_leading_zero(day)
    ydate = int(time.strftime('%j', time.strptime(line, '%Y:%m:%d')))
    dom = mcf.ydate_to_dom(year, ydate)

    return dom
コード例 #29
0
def convert_to_ctime(year, mon, day, hh, mm, ss):
    """
    convert time in Chandra time
    input:  year    --- year
            mon     --- month
            day     --- mday
            hh      --- houris
            mm      --- minutes
            ss      --- seconds
    output: ctime   --- chandra time; seconds from 1998.1.1
    """

    ctime = str(year) + ':' + mcf.add_leading_zero(
        mon) + ':' + mcf.add_leading_zero(day)
    ctime = ctime + ':' + mcf.add_leading_zero(
        hh) + ':' + mcf.add_leading_zero(mm)
    ctime = ctime + ':' + mcf.add_leading_zero(ss)

    ctime = time.strftime('%Y:%j:%H:%M:%S',
                          time.strptime(ctime, '%Y:%m:%d:%H:%M:%S'))
    ctime = Chandra.Time.DateTime(ctime).secs

    return ctime
コード例 #30
0
ファイル: plot_sim_avg_step.py プロジェクト: chandra-mta/MTA
def set_month_interval(this_year, this_mon):
    """
    create month interval list
    input:  this_year   --- this year in yyyy format
            this_mon    --- this month in mm format
    otput:  a list of lists of: [starting time], [ending time], [mid time of the month in second from 1998.1.1]]
    """

    start     = []
    stop      = []
    mid       = []
    for year in range(1999, this_year + 1):
        for mon in range(1, 13):
            if (year == 19999) and (mon < 8):
                continue
            elif (year == this_year) and (mon >= this_mon):
                break

            btime = str(year)  + ':' + mcf.add_leading_zero(mon)  + ':01:00:00:00'
            btime = time.strftime('%Y:%j:%H:%M:%S', time.strptime(btime, '%Y:%m:%d:%H:%M:%S'))
            nmon  = mon + 1
            nyear = year
            if nmon > 12:
                nmon   = 1
                nyear += 1
            etime = str(nyear) + ':' + mcf.add_leading_zero(nmon) + ':01:00:00:00'
            etime = time.strftime('%Y:%j:%H:%M:%S', time.strptime(etime, '%Y:%m:%d:%H:%M:%S'))

            begin = int(Chandra.Time.DateTime(btime).secs)
            end   = int(Chandra.Time.DateTime(etime).secs)
            avg   = int(0.5 * (begin + end))

            start.append(begin)
            stop.append(end)
            mid.append(avg)

    return [start, stop, mid]