예제 #1
0
def plot_data_with_matplotlib(spec):

    start_time = time.time()
    hitnum = int(s6fits.get_hits_over_file(spec.filename))
    end_time = time.time()
    print("get hit num time was %g seconds" % (end_time - start_time))

    snr = spec.s6hits[0].detected_power / spec.s6hits[0].mean_power
    x = np.array([snr])
    start_time = time.time()
    for i in range(1, hitnum - 1):
        snr = spec.s6hits[i].detected_power / spec.s6hits[i].mean_power
        x = np.append(x, snr)
        #print("SNR %f" % (snr))
        #print("det %s" % (spec.s6hits[i].detected_power))
    end_time = time.time()
    print("make snr array was %g seconds" % (end_time - start_time))

    #plt.plot(y,x,marker='.',)
    start_time = time.time()
    plt.hist(x, bins=1000)
    end_time = time.time()
    print("make plot was %g seconds" % (end_time - start_time))

    plt.xticks(np.arange(min(x), max(x) + 1, 10, dtype=int))

    start_time = time.time()
    plt.show()
    end_time = time.time()
    print("show plot was %g seconds" % (end_time - start_time))
예제 #2
0
def load_file(filename):
    spec = s6fits.s6dataspec_t()
    spec.filename = filename
    spec.sortby_rfreq = 0
    spec.sortby_time = 0
    spec.sortby_bors = 0
    #spec.sortby_ifreq = 0
    # Setting up this mode will remove all those hits which shows change of RF due to
    # smart frequency switching experiment. It only reads those hits which occur maximum number of time.
    spec.filterby_rf_center_mode = 1
    #Get hits from file
    s6fits.get_s6data(spec)

    hitnum = int(s6fits.get_hits_over_file(spec.filename))

    m_rfreq = []
    m_unix_time = []
    m_meanpower = []

    base_filename = ntpath.basename(spec.filename)

    start_time = spec.s6hits[0].unix_time
    #MARK for i in range(0,hitnum-1):
    for i in range(hitnum):
        if spec.s6hits[i].unix_time == start_time:
            m_rfreq.append(spec.s6hits[i].rfreq)
            m_unix_time.append(spec.s6hits[i].unix_time)
            m_meanpower.append(spec.s6hits[i].mean_power)
        else:
            break
    sort_rfreq_index = np.argsort(m_rfreq)
    sort_rfreq = np.array(m_rfreq)[sort_rfreq_index]
    sort_meanpower = np.array(m_meanpower)[sort_rfreq_index]

    return sort_meanpower, sort_rfreq, base_filename
예제 #3
0
def plot_data_with_matplotlib(spec):

    start_time = time.time()
    hitnum = int(s6fits.get_hits_over_file(spec.filename))
    end_time = time.time()
    print("get hit num time was %g seconds" % (end_time - start_time))

    m_ifreq = []  # new
    m_unix_time = []  # new
    m_meanpower = []  # new

    start_time = time.time()
    starttime = spec.s6hits[0].unix_time
    for i in range(0, hitnum - 1):
        if spec.s6hits[i].unix_time == starttime:
            m_ifreq.append(spec.s6hits[i].ifreq)
            m_meanpower.append(spec.s6hits[i].mean_power)
            m_unix_time.append(spec.s6hits[i].unix_time)
        else:
            break
    sort_ifreq_index = np.argsort(m_ifreq)
    sort_ifreq = np.array(m_ifreq)[sort_ifreq_index]
    sort_meanpower = np.array(m_meanpower)[sort_ifreq_index]

    #unique_unix_time, unique_index = np.unique(m_unix_time, return_index=True)
    #unique_ifreq = np.array(m_ifreq)[unique_index]
    #unique_meanpower = np.array(m_meanpower)[unique_index]
    #unique_ifreq_index = np.argsort(unique_ifreq)
    #sort_unique_ifreq = np.array(unique_ifreq)[unique_ifreq_index]
    #sort_unique_meanpower = np.array(unique_meanpower)[unique_ifreq_index]
    end_time = time.time()

    print("make snr array was %g seconds" % (end_time - start_time))

    #plt.plot(unix_time, ifreq,marker='.-',)
    start_time = time.time()
    #df.plot(kind='line',x="unix_time", y="ifreq")
    #plt.plot(unique_unix_time, unique_ifreq, '.-')
    plt.plot(sort_ifreq, sort_meanpower, '.-')
    plt.xlabel('ifreq')
    plt.ylabel('mean power')
    end_time = time.time()
    print("make plot was %g seconds" % (end_time - start_time))

    #	plt.xticks(np.arange(min(x), max(x)+1, 10, dtype=int))

    start_time = time.time()
    plt.show()
    end_time = time.time()
    print("show plot was %g seconds" % (end_time - start_time))
예제 #4
0
def plot_data_with_gnuplot(spec):

    #flen = float(s6fits.get_time_over_file(spec.filename))
    hitnum = int(s6fits.get_hits_over_file(spec.filename))

    base_filename = ntpath.basename(spec.filename)
    data_filename = base_filename + ".mp_data"
    plot_filename = base_filename + ".mp.png"

    m_unix_time = []
    m_meanpower = []
    time_value = []
    j = 0
    meanpower = 0
    start_time = long(spec.s6hits[0].unix_time)
    start_time = int(spec.s6hits[0].unix_time)
    for i in range(0, hitnum - 1):
        if spec.s6hits[i].unix_time != start_time:
            m_unix_time.append(start_time)
            m_meanpower.append(math.log(meanpower / j))
            start_time = spec.s6hits[i].unix_time
            j = 0
            meanpower = 0
        meanpower += spec.s6hits[i].mean_power
        j += 1

    m_unix_time = np.array(m_unix_time)
    plot_time = np.arange(len(m_unix_time))
    sort_meanpower = np.array(m_meanpower)
    data_f = open(data_filename, 'w')
    for x in range(0, len(m_unix_time) - 1):
        #print >> data_f, sort_meanpower[x], m_unix_time[x]
        print >> data_f, sort_meanpower[x], plot_time[x]
    data_f.close()

    cmd = 'set term png; set out "%s";                \
				set title "%s"; unset key;                \
		   		set xl "time/s"; set yl "Mean Power/log"; \
				plot "%s" using 2:1 with line;'              \
       % (plot_filename, base_filename, data_filename)
    cmd_f = open("baseband_gnuplot_cmds", 'w')
    print >> cmd_f, cmd
    cmd_f.close()

    os.system('gnuplot baseband_gnuplot_cmds')
    os.remove("baseband_gnuplot_cmds")
    os.remove(data_filename)
예제 #5
0
def plot_data_with_gnuplot(spec):
    ##hitrec = spec.s6hits
    ##s6fits.print_hits_table(spec.s6hits)
    #spechdr = spec.s6hitsheaders

    #print spec.total_missedpk
    #print spec.rf_center_mode,spec.filter_rf_center_mode,spec.cfitsio_error
    os.system('gnuplot pow_gnuplot_cmds')

    flen = float(s6fits.get_time_over_file(spec.filename))
    hitnum = int(s6fits.get_hits_over_file(spec.filename))

    base_filename = ntpath.basename(spec.filename)
    data_filename = base_filename + ".pow_data"
    plot_filename = base_filename + ".pow.png"

    histo = [0] * 100
    data_f = open(data_filename, 'w')
    for i in range(1, hitnum - 1):
        snr = spec.s6hits[i].detected_power / spec.s6hits[i].mean_power
        print >> data_f, snr

    # see http://psy.swansea.ac.uk/staff/carter/gnuplot/gnuplot_frequency.htm
    cmd = 'set term png; set out "%s";                						\
			set boxwidth 0.05 absolute ; set style fill solid 1.0 noborder; \
			set title "%s"; unset key; set logscale x;     					\
		   	set xl "SNR"; set yl "number of hits"; 							\
																			\
			bin_width  = 0.1; bin_number(x) = floor(x/bin_width); 			\
			rounded(x) = bin_width * ( bin_number(x) + 0.5 );				\
																			\
			plot "%s" using (rounded($1)):(1) smooth frequency with boxes;'    \
      % (plot_filename, base_filename, data_filename)
    cmd_f = open("pow_gnuplot_cmds", 'w')
    print >> cmd_f, cmd
    cmd_f.close()

    os.system('gnuplot pow_gnuplot_cmds')

    os.remove("pow_gnuplot_cmds")
    os.remove(data_filename)

    print flen, hitnum
예제 #6
0
def plot_data_with_gnuplot(spec):

    #flen = float(s6fits.get_time_over_file(spec.filename))
    hitnum = int(s6fits.get_hits_over_file(spec.filename))

    base_filename = ntpath.basename(spec.filename)
    data_filename = base_filename + ".bb_data"
    plot_filename = base_filename + ".bb.png"

    m_ifreq = []
    m_unix_time = []
    m_meanpower = []

    start_time = spec.s6hits[0].unix_time
    for i in range(0, hitnum - 1):
        if spec.s6hits[i].unix_time == start_time:
            m_ifreq.append(spec.s6hits[i].ifreq)
            m_unix_time.append(spec.s6hits[i].unix_time)
            m_meanpower.append(spec.s6hits[i].mean_power)
        else:
            break

    sort_ifreq_index = np.argsort(m_ifreq)
    sort_ifreq = np.array(m_ifreq)[sort_ifreq_index]
    sort_meanpower = np.array(m_meanpower)[sort_ifreq_index]

    data_f = open(data_filename, 'w')
    for x in range(0, len(m_ifreq) - 1):
        print >> data_f, sort_meanpower[x], sort_ifreq[x]
    data_f.close()

    cmd = 'set term png; set out "%s";                \
			set title "%s"; unset key;                \
		   	set xl "ifreq"; set yl "Mean Power"; \
			plot "%s" using 2:1 with line;'              \
      % (plot_filename, base_filename, data_filename)
    cmd_f = open("baseband_gnuplot_cmds", 'w')
    print >> cmd_f, cmd
    cmd_f.close()

    os.system('gnuplot baseband_gnuplot_cmds')
    os.remove("baseband_gnuplot_cmds")
    os.remove(data_filename)
def plot_data_with_matplotlib(spec):

    start_time = time.time()
    hitnum = int(s6fits.get_hits_over_file(spec.filename))
    end_time = time.time()
    print("get hit num time was %g seconds" % (end_time - start_time))

    start_time = time.time()
    z = np.dtype(spec.s6hits[0])
    z.names
    end_time = time.time()
    print("make freq array one line was %g seconds" % (end_time - start_time))

    hit_start_time = spec.s6hits[0].unix_time
    #print("start time %s" % (hit_start_time))
    x = np.array([spec.s6hits[0].unix_time - hit_start_time])
    start_time = time.time()
    for i in range(1, hitnum - 1):
        x = np.append(x, [spec.s6hits[i].unix_time - hit_start_time])
        #print("time %s x %s" % (spec.s6hits[i].unix_time, x))
    end_time = time.time()
    print("make time array was %g seconds" % (end_time - start_time))

    start_time = time.time()
    y = np.array([spec.s6hits[0].ifreq])
    for i in range(1, hitnum - 1):
        y = np.append(y, [spec.s6hits[i].ifreq])
        #print("ifreq %s" % (spec.s6hits[i].ifreq))
    end_time = time.time()
    print("make freq array was %g seconds" % (end_time - start_time))

    #plt.plot(y,x,marker='.',)
    start_time = time.time()
    plt.scatter(y, x, s=.1)
    end_time = time.time()
    print("make plot was %g seconds" % (end_time - start_time))

    start_time = time.time()
    plt.show()
    end_time = time.time()
    print("show plot was %g seconds" % (end_time - start_time))

    print flen, hitnum
def plot_data_with_gnuplot(spec):
    ##hitrec = spec.s6hits
    ##s6fits.print_hits_table(spec.s6hits)
    #spechdr = spec.s6hitsheaders

    #print spec.total_missedpk
    #print spec.rf_center_mode,spec.filter_rf_center_mode,spec.cfitsio_error

    #print spec.s6hits[0].unix_time, spec.s6hits[1].unix_time

    flen = float(s6fits.get_time_over_file(spec.filename))
    hitnum = int(s6fits.get_hits_over_file(spec.filename))

    base_filename = ntpath.basename(spec.filename)
    data_filename = base_filename + ".wf_data"
    plot_filename = base_filename + ".wf.png"

    data_f = open(data_filename, 'w')
    start_time = spec.s6hits[0].unix_time
    start_jtime = spec.s6hits[0].julian_date
    for x in range(0, hitnum - 1):
        #print >> data_f, spec.s6hits[x].unix_time - start_time, spec.s6hits[x].ifreq
        print >> data_f, int((spec.s6hits[x].julian_date - start_jtime) *
                             86400), spec.s6hits[x].rfreq
    data_f.close()

    cmd = 'set term png; set out "%s";                \
			set title "%s"; unset key;                \
		   	set xl "Freq (MHz)"; set yl "Time (Sec)"; \
			plot "%s" using 2:1 with dots;'              \
      % (plot_filename, base_filename, data_filename)
    cmd_f = open("wf_gnuplot_cmds", 'w')
    print >> cmd_f, cmd
    cmd_f.close()

    os.system('gnuplot wf_gnuplot_cmds')

    os.remove("wf_gnuplot_cmds")
    os.remove(data_filename)

    print flen, hitnum