コード例 #1
0
def read_data(file):
    """
    read data and convert time in the fractional year
    input:  file    --- file name
    output: time    --- time in fractional year
            val     --- corner pix centroid mean 
            mid     --- id of the data point. 0: faint, 1: afaint, 2: vfaint
    """

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

    time = []
    val  = []
    mid  = []
    for ent in data:
        atemp = re.split('\s+', ent)
#
#--- convert time in fractional year
#
        ytime = tcnv.sectoFracYear(float(atemp[0]))
        time.append(ytime)
        try:
            val.append(float(atemp[2]))
            if atemp[5] == 'AFAINT':
                mid.append(1)
            elif atemp[5] == 'VFAINT':
                mid.append(2)
            else:
                mid.append(0)
        except:
            pass

    return [time, val, mid]
コード例 #2
0
ファイル: hrc_gain_trend_plot.py プロジェクト: tisobe/MTA_old
def hrc_gain_trend_plot():
    """
    create time trend of Gaussian profiles fit on HRC PHA data. It also create trend along radial distnace for each year
    Input:  none but the data is read from <house_keeping>/fitting_results
    Outut:  time trend plots in <plot_dir> / hrc_i_time_trend.png hrc_s_time_trend.png
            radial_distance plots            hrc_i_radial_dist_year<year>.png
    """

    file = house_keeping + 'fitting_results'
    f = open(file, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()
    #
    #--- set a few things such as labeling
    #
    yMinSets = [0, 0, 20]
    yMaxSets = [250, 250, 100]
    yname = 'PHA'
    entLabels = ["PHA Median", "PHA Voigt Peak Position", "PHA FWHM"]
    #
    #--- time trend plots
    #
    xmin = 1999
    ctemp = tcnv.currentTime()  #--- finding this year
    xmax = end_year = int(ctemp[0]) + 1
    xname = 'Time (Year)'
    #
    #--- HRC I
    #
    time_i = []
    dist_i = []
    med_i = []
    center_i = []
    width_i = []

    time_s = []
    dist_s = []
    med_s = []
    center_s = []
    width_s = []

    for ent in data:
        if ent[0] == '#':  #--- avoid comments
            continue

        atemp = re.split('\t+', ent)
        #
        #--- if the width is < 1 or amp is smaller than 5, probably it did not find a correct source position
        #
        if float(atemp[12]) < 1:
            continue
        if float(atemp[11]) < 5:
            continue

        fyear = tcnv.sectoFracYear(float(atemp[2]))
        if atemp[3] == 'HRC-I':
            time_i.append(fyear)
            dist_i.append(float(atemp[8]))
            med_i.append(float(atemp[9]))
            center_i.append(float(atemp[10]))
            width_i.append(float(atemp[12]))
        else:
            time_s.append(fyear)
            dist_s.append(float(atemp[8]))
            med_s.append(float(atemp[9]))
            center_s.append(float(atemp[10]))
            width_s.append(float(atemp[12]))

    xSets = [time_i, time_i, time_i]
    ySets = [med_i, center_i, width_i]
    dist = dist_indexing(dist_i)

    plotPanel(xmin, xmax, yMinSets, yMaxSets, xSets, ySets, dist, xname, yname,
              entLabels)
    cmd = 'mv out.png ' + web_dir + 'Trend_plots/hrc_i_time_trend.png'
    os.system(cmd)
    #
    #--- HRC S
    #
    xSets = [time_s, time_s, time_s]
    ySets = [med_s, center_s, width_s]
    dist = dist_indexing(dist_s)

    plotPanel(xmin, xmax, yMinSets, yMaxSets, xSets, ySets, dist, xname, yname,
              entLabels)
    cmd = 'mv out.png ' + web_dir + 'Trend_plots/hrc_s_time_trend.png'
    os.system(cmd)

    #
    #--- trend along radial distance
    #
    xmin = 0
    xmax = 16
    xname = 'Radial Distance(Arcsec)'
    #
    #--- HRC I
    #
    for pyear in range(1999, end_year):
        dist = []
        med = []
        center = []
        width = []
        mark = []
        pend = pyear + 1
        for j in range(0, len(time_i)):
            if (time_i[j] >= pyear) and (time_i[j] < pend):
                dist.append(dist_i[j])
                med.append(med_i[j])
                center.append(center_i[j])
                width.append(width_i[j])

        xSets = [dist, dist, dist]
        ySets = [med, center, width]
        plotPanel(xmin,
                  xmax,
                  yMinSets,
                  yMaxSets,
                  xSets,
                  ySets,
                  mark,
                  xname,
                  yname,
                  entLabels,
                  extraNote=pyear)

        outname = web_dir + '/Trend_plots/hrc_i_radial_dist_year' + str(
            pyear) + '.png'
        cmd = 'mv out.png ' + outname
        os.system(cmd)
#
#--- HRC S
#
    for pyear in range(1999, end_year):
        dist = []
        med = []
        center = []
        width = []
        mark = []
        pend = pyear + 1
        for j in range(0, len(time_s)):
            if (time_s[j] >= pyear) and (time_s[j] < pend):
                dist.append(dist_s[j])
                med.append(med_s[j])
                center.append(center_s[j])
                width.append(width_s[j])

        xSets = [dist, dist, dist]
        ySets = [med, center, width]
        plotPanel(xmin,
                  xmax,
                  yMinSets,
                  yMaxSets,
                  xSets,
                  ySets,
                  mark,
                  xname,
                  yname,
                  entLabels,
                  extraNote=pyear)

        outname = web_dir + '/Trend_plots/hrc_s_radial_dist_year' + str(
            pyear) + '.png'
        cmd = 'mv out.png ' + outname
        os.system(cmd)
コード例 #3
0
def create_sim_temp_plots(start, stop):
    """
    control function to run sim temperature trending plots etc
    input:  start   --- starting year
            stop    --- stopping year
                if they are the same, it will cerate the plot for the year
                else, it will create the entire range (from 1999 to current)
    output: plots in <web_dir>/Plots/
                sim_temp_<year>.png
                sim)translation_<year>.png
    """
#
#--- check whether to create  full range or indivisual year plots
#
    if stop - start > 1:
        fname = web_dir + 'Plots/sim_temp_fullrange.png'
        oname = web_dir + 'Plots/sim_translation_fullrange.png'
        pname = web_dir + 'Plots/pitchangle_fullrange.png'
        title = str(start) + ' - ' + str(stop-1)
        yind  = 0
    else:
        fname = web_dir + 'Plots/sim_temp_' + str(start) + '.png'
        oname = web_dir + 'Plots/sim_translation_' + str(start) + '.png'
        pname = web_dir + 'Plots/pitchangle_' + str(start) + '.png'
        title = 'Year: ' + str(start)
        yind  = 1
        if tcnv.isLeapYear(start) == 1:
            base = 366
        else:
            base = 365
#
#--- read sim temperature data file
#
    file = data_dir + 'tsc_temps.txt'
    f    = open(file, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    x     = []
    ts    = []
    te    = []
    delta = []
    steps = []

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

        try:
            time  = convert_to_fyear(atemp[0])
            if time < start:
                continue
            if time > stop:
                break
            if yind == 1:
                time = (time - start) * base

            t1    = float(atemp[2])
            t2    = float(atemp[3])
            t3    = t2 - t1
            t4    = float(atemp[5])

            if t1 > 60 or t1 < -40:
                continue
            if t2 > 60 or t2 < -40:
                continue
            x.append(time)          #--- time in year or yday
            ts.append(t1)           #--- sim temperature at the beginning
            te.append(t2)           #--- sim temperature at the ending
            delta.append(t3)        #--- the sim temperature difference 
            steps.append(t4)        #--- the number of steps
        except:
            continue

#
#--- run moving average
#
    mvstep = 30 
    [mxs, mys] = smooth_data(x, ts, mvstep)
    if len(mxs) == 0:
        skip = 1
    else:
        skip = 0

    [mxe, mye] = smooth_data(x, te, mvstep)
    if len(mxe) == 0:
        skip = 1
    else:
        skip = 0

#
#--- read pitch angle data
#
    file = '/data/mta/DataSeeker/data/repository/orb_angle.rdb'
    f    = open(file, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    stime = []
    angle = []

    m      = 0
    for ent in data[2:]:
        atemp = re.split('\s+', ent)
        try:
            time  = tcnv.sectoFracYear(float(atemp[0]))
            if time < start:
                continue
            if time > stop:
                break

            if yind == 1:
                time = (time - start) * base
#
#--- just take the data every 20 mins or so (data is taken every 300 sec)
#
            if m % 4 == 0:
                stime.append(time)
                angle.append(float(atemp[1]))
            m += 1
        except:
            continue
#
#--- if yind == 0, full range, otherwise, year plot
#
    if yind == 0:
        xmin = start
        xmax = stop 
        tdff = 1.0e-5
    else:
        xmin = 1
        xmax = base
        tdff = 3.5e-3
#
#--- match delta and angle --- not used
#
##    angle2 = []
##    js = 0
##    for k in range(0, len(x)):
##        angle2.append(0)
##        for j in range(js, len(stime)):
##            if x[k] < stime[j]:
##                angle2[k] = angle[j]
##                break;
##            else:
##                if j >= len(stime) -1:
##                    angle2[k] = angle[-1]
##                    break;
##                if x[k] >= stime[j] and x[k] <= stime[j+1]:
##                    angle2[k] = angle[j]
##                    js = j
##                    break
##                else:
##                    continue


#
#--- plot time tred of sim temperature
#
    plot_sim_temp_data(xmin, xmax, x, ts, te, mxs, mys, mxe, mye, delta, stime, angle, fname, yind, title, skip)
#
#--- plot translation step - delta sim temperature
#
    plot_step_delta(steps, delta, oname, title)
コード例 #4
0
def hrc_gain_trend_plot():

    """
    create time trend of Gaussian profiles fit on HRC PHA data. It also create trend along 
    radial distnace for each year
    input:  none but the data is read from <house_keeping>/fitting_results
    outut:  time trend plots in <plot_dir> / hrc_i_time_trend.png hrc_s_time_trend.png
            radial_distance plots            hrc_i_radial_dist_year<year>.png
    """
#
#--- time trend plots
#
    xmin  = 1999
    ctemp = tcnv.currentTime()          #--- finding this year
    end_year =  int(ctemp[0]) + 1       #--- set end of this year
    xmax  = end_year
    xname = 'Time (Year)'
#
#--- read voigt profile fitting to the pha distribution of each data from the table.
#
    ifile = data_dir + 'fitting_results'
    f    = open(ifile, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    obsid_i  = []
    time_i   = []
    dist_i   = []
    med_i    = []
    center_i = []
    width_i  = []
    
    obsid_s  = []
    time_s   = []
    dist_s   = []
    med_s    = []
    center_s = []
    width_s  = []
    
    for ent in data:
        if ent[0] == '#':           #--- avoid comments
            continue

        atemp = re.split('\t+', ent)
#
#--- if the width is < 1 or amp is smaller than 5, probably it did not find a correct source position
#
        if float(atemp[12]) < 1:
            continue
        if float(atemp[11]) < 5:
            continue
#
#--- separate the data to hrc i and hrc s
#
        fyear = tcnv.sectoFracYear(float(atemp[2]))
        if atemp[3] == 'HRC-I':
            obsid_i.append(atemp[0])
            time_i.append(fyear)
            dist_i.append(float(atemp[8]))
            med_i.append(float(atemp[9]))
            center_i.append(float(atemp[10]))
            width_i.append(float(atemp[12]))
        else:
            obsid_s.append(atemp[0])
            time_s.append(fyear)
            dist_s.append(float(atemp[8]))
            med_s.append(float(atemp[9]))
            center_s.append(float(atemp[10]))
            width_s.append(float(atemp[12]))
#
#--- create an interactive plot for HRC I
#

    xSets    = [time_i, time_i, time_i]
    ySets    = [med_i, center_i, width_i]
    dist     = dist_indexing(dist_i)

    intlabel = crate_label_html(obsid_i, dist_i)
    [fig_hi, fit1_hi, fit2_hi] = plotPanel(xmin, xmax, yMinSets, yMaxSets, \
                        xSets, ySets, dist,  xname, yname,  entLabels, intlabel=intlabel, inst = 'hrc_i')
#
#--- create an interactive plot for HRC S
#
    xSets    = [time_s, time_s, time_s]
    ySets    = [med_s, center_s, width_s]
    dist     = dist_indexing(dist_s)

    intlabel = crate_label_html(obsid_s,  dist_s)
    [fig_hs, fit1_hs, fit2_hs] =  plotPanel(xmin, xmax, yMinSets, yMaxSets, \
                        xSets, ySets, dist,  xname, yname,  entLabels, intlabel=intlabel, inst='hrc_s')
#
#---- update the main html page
#
    update_html_page(fig_hi, fig_hs, fit1_hi, fit2_hi, fit1_hs, fit2_hs, time_i)
#
#---- create radiao html pages
#
    create_radial_html_page(time_i, obsid_i, dist_i, med_i, center_i, width_i, end_year, inst='i')
    create_radial_html_page(time_s, obsid_s, dist_s, med_s, center_s, width_s, end_year, inst='s')
#
#--- create energy gain fitting result table page
#
    gain_fitting_table()
コード例 #5
0
ファイル: hrc_plotting_routines.py プロジェクト: tisobe/HRC
def plot_dead_time_trend():
    """ 
    update hrc_i_115_dtf_plot.png plot file
    input:  none, but read from hrc_i_115_stat_results
    output: <plot dir>/hrc_i_115_dtf_plot.png
    """
    #
    #--- read data
    #
    dfile = data_dir + 'Stats/hrc_i_115_stat_results'
    f = open(dfile, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    time = []
    cnt_rate = []
    v_rate = []
    dtf = []
    #
    #--- computer dead time correciton fuctor
    #
    for ent in data:
        atemp = re.split('\s+', ent)
        date = tcnv.sectoFracYear(float(atemp[1]))
        a_rate = float(atemp[5]) / float(atemp[13])

        time.append(date)
        cnt_rate.append(float(atemp[5]))
        v_rate.append(float(atemp[13]))
        dtf.append(a_rate)

#
#--- setting a plotting surface
#
    prep_plot()
    mpl.rcParams['font.size'] = 11
    props = font_manager.FontProperties(size=11)
    psize = 8
    tfsize = 12
    #
    #--- start plotting
    #
    xmin = 1999
    xmax = int(max(time)) + 1
    #
    #--- Count Rate per Sec
    #
    a1 = plt.subplot(311)
    ymin = 3.45
    ymax = 3.55
    title = 'Count Rate per Sec'
    plt.axis([xmin, xmax, ymin, ymax])
    plt.plot(time, cnt_rate, color='blue', lw=0, marker='+', markersize=psize)
    plt.text(2000, 3.538, title, size=tfsize, weight='bold')
    #
    #--- Valid Count Rate per Sec
    #
    a2 = plt.subplot(312)
    ymin = 0
    ymax = 200
    title = 'Valid Count Rate per Sec'
    plt.axis([xmin, xmax, ymin, ymax])
    plt.plot(time, v_rate, color='blue', lw=0, marker='+', markersize=psize)
    plt.text(2000, 160, title, size=tfsize, weight='bold')
    #
    #--- Dead Time Correction Fator
    #
    a3 = plt.subplot(313)
    ymin = 0
    ymax = 0.1
    title = 'Dead Time Correctin Factor'
    plt.axis([xmin, xmax, ymin, ymax])
    plt.plot(time, dtf, color='blue', lw=0, marker='+', markersize=psize)
    plt.text(2000, 0.02, title, size=tfsize, weight='bold')
    #
    #--- add x ticks label only on the panels of the last row
    #
    plt.setp(a1.get_xticklabels(), visible=False)
    plt.setp(a2.get_xticklabels(), visible=False)

    a3.set_xlabel("Time (Year)", size=11)
    #
    #--- save the plot in file
    #
    outname = 'hrc_i_115_dtf_plot.png'
    outname = plot_dir + outname
    create_plot_file(outname)
コード例 #6
0
ファイル: hrc_plotting_routines.py プロジェクト: tisobe/HRC
def read_stat_data(infile):
    """
    read a stat data file and return a list of lists of data
    input:  infile    --- input file name (with a full path)
    output:  0: time            --- time in year date
             1: tstart          --- start time in seconds from 1998.1.1
             2: tstop           --- stop time in seconds from 1998.1.1
             3: duration        --- duration in seconds
             4: total_count     --- total counts
             5: count_per_sec   --- counts per seonds
             6: pha_mean        --- pha mean
             7: pha_median      --- pha median
             8: pha_sigma       --- pha sigma
             9: t_mean          --- total count rate mean
            10: t_median        --- total count rate median
            11: t_sigma         --- total count rate sigma
            12: v_mean          --- valid count rate mean
            13: v_median        --- valid count rate median
            14: v_sigma         --- valid count rate sigma
            15: s_mean          --- shield count rate mean
            16: s_median        --- shield count rate median
            17: s_sigma         --- shield count rate sigma
            18: anti_co_mean    --- anti conicidnece rate mean
            19: anti_co_median  --- anti conicidnece rate median
            20: anti_co_sigma   --- anti conicidnece rate sigma
            21: s2hvst          --- s2hvst value
            22: s2hvlv          --- s2jvlv valie
            23: scint           --- scint 
            24: scint_std       --- scint sigma
    """

    data = hcf.read_file_data(infile)

    date = []
    tstart = []
    tstop = []
    duration = []
    total_count = []
    count_per_sec = []
    pha_mean = []
    pha_median = []
    pha_sigma = []
    t_mean = []
    t_median = []
    t_sigma = []
    v_mean = []
    v_median = []
    v_sigma = []
    s_mean = []
    s_median = []
    s_sigma = []
    anti_co_mean = []
    anti_co_median = []
    anti_co_sigma = []
    s2hvst = []
    s2hvlv = []
    scint = []
    scint_std = []
    time = []

    for ent in data:
        aval = re.split('\s+', ent)
        aval3 = float(aval[3])
        #
        #--- if the observation interval is shorter than 900 sec, drop the data set.
        #--- these data set are not accurate enough.
        #
        if aval3 < 900:
            continue
        else:

            try:
                date.append(aval[0])
                start = float(aval[1])
                tstart.append(start)
                tstop.append(float(aval[2]))
                duration.append(aval3)
                total_count.append(float(aval[4]))
                count_per_sec.append(float(aval[5]))
                pha_mean.append(float(aval[6]))
                pha_median.append(float(aval[7]))
                pha_sigma.append(float(aval[8]))
                t_mean.append(float(aval[9]))
                t_median.append(float(aval[10]))
                t_sigma.append(float(aval[11]))
                v_mean.append(float(aval[12]))
                v_median.append(float(aval[13]))
                v_sigma.append(float(aval[14]))
                #
                #--- changing a plotting range for an easy view
                #
                s_mean.append(0.001 * float(aval[15]))
                s_median.append(0.001 * float(aval[16]))
                s_sigma.append(0.001 * float(aval[17]))

                anti_co_mean.append(float(aval[18]))
                anti_co_median.append(float(aval[19]))
                anti_co_sigma.append(float(aval[20]))

                s2hvst.append(int(float(aval[21])))
                s2hvlv.append(int(float(aval[22]) + 0.5))

                scint.append(float(aval[23]))
                scint_std.append(float(aval[24]))

                tval = tcnv.sectoFracYear(start)
                time.append(tval)
            except:
                continue

    return [time, tstart, tstop, duration, total_count, count_per_sec, \
            pha_mean,  pha_median, pha_sigma,  \
            t_mean, t_median, t_sigma, \
            v_mean, v_median, v_sigma, \
            s_mean, s_median, s_sigma, \
            anti_co_mean, anti_co_median, anti_co_sigma, \
            s2hvst, s2hvlv, scint, scint_std]
コード例 #7
0
def hrc_gain_trend_plot():
    """
    create time trend of Gaussian profiles fit on HRC PHA data. It also create trend along 
    radial distnace for each year
    input:  none but the data is read from <house_keeping>/fitting_results
    outut:  time trend plots in <plot_dir> / hrc_i_time_trend.png hrc_s_time_trend.png
            radial_distance plots            hrc_i_radial_dist_year<year>.png
    """
    #
    #--- time trend plots
    #
    xmin = 1999
    ctemp = tcnv.currentTime()  #--- finding this year
    end_year = int(ctemp[0]) + 1  #--- set end of this year
    xmax = end_year
    xname = 'Time (Year)'
    #
    #--- read voigt profile fitting to the pha distribution of each data from the table.
    #
    ifile = data_dir + 'fitting_results'
    f = open(ifile, 'r')
    data = [line.strip() for line in f.readlines()]
    f.close()

    obsid_i = []
    time_i = []
    dist_i = []
    med_i = []
    center_i = []
    width_i = []

    obsid_s = []
    time_s = []
    dist_s = []
    med_s = []
    center_s = []
    width_s = []

    for ent in data:
        if ent[0] == '#':  #--- avoid comments
            continue

        atemp = re.split('\t+', ent)
        #
        #--- if the width is < 1 or amp is smaller than 5, probably it did not find a correct source position
        #
        if float(atemp[12]) < 1:
            continue
        if float(atemp[11]) < 5:
            continue
#
#--- separate the data to hrc i and hrc s
#
        fyear = tcnv.sectoFracYear(float(atemp[2]))
        if atemp[3] == 'HRC-I':
            obsid_i.append(atemp[0])
            time_i.append(fyear)
            dist_i.append(float(atemp[8]))
            med_i.append(float(atemp[9]))
            center_i.append(float(atemp[10]))
            width_i.append(float(atemp[12]))
        else:
            obsid_s.append(atemp[0])
            time_s.append(fyear)
            dist_s.append(float(atemp[8]))
            med_s.append(float(atemp[9]))
            center_s.append(float(atemp[10]))
            width_s.append(float(atemp[12]))
#
#--- create an interactive plot for HRC I
#

    xSets = [time_i, time_i, time_i]
    ySets = [med_i, center_i, width_i]
    dist = dist_indexing(dist_i)

    intlabel = crate_label_html(obsid_i, dist_i)
    [fig_hi, fit1_hi, fit2_hi] = plotPanel(xmin, xmax, yMinSets, yMaxSets, \
                        xSets, ySets, dist,  xname, yname,  entLabels, intlabel=intlabel, inst = 'hrc_i')
    #
    #--- create an interactive plot for HRC S
    #
    xSets = [time_s, time_s, time_s]
    ySets = [med_s, center_s, width_s]
    dist = dist_indexing(dist_s)

    intlabel = crate_label_html(obsid_s, dist_s)
    [fig_hs, fit1_hs, fit2_hs] =  plotPanel(xmin, xmax, yMinSets, yMaxSets, \
                        xSets, ySets, dist,  xname, yname,  entLabels, intlabel=intlabel, inst='hrc_s')
    #
    #---- update the main html page
    #
    update_html_page(fig_hi, fig_hs, fit1_hi, fit2_hi, fit1_hs, fit2_hs,
                     time_i)
    #
    #---- create radiao html pages
    #
    create_radial_html_page(time_i,
                            obsid_i,
                            dist_i,
                            med_i,
                            center_i,
                            width_i,
                            end_year,
                            inst='i')
    create_radial_html_page(time_s,
                            obsid_s,
                            dist_s,
                            med_s,
                            center_s,
                            width_s,
                            end_year,
                            inst='s')
    #
    #--- create energy gain fitting result table page
    #
    gain_fitting_table()