Exemple #1
0
def plot_curve(tfe,period=0,plot_folded=True,
               plot_unfolded=True,smooth_folded=True,
               classification='Unknown Class',
               survey='Unknown Survey',
               show_plot=True,
               save_figure=False,
               save_figure_name='figure.pdf'):

    ## check to make sure arguments are consistent
    if period == 0 and plot_folded == True:
        print "Need a period to fold on. Add period as an argument to the function call."
        return
    if not plot_folded and not plot_unfolded:
        print "No plots requested!"
        return

    ## don't want to overwrite plots
    plt.close()

    ## make title and phase times
    title = classification + ' from ' + survey

    ## both folded and unfolded
    if plot_unfolded and plot_folded:
        plt.figure(1)
        plt.subplot(211)
        plt.title(title)
        plt.plot(tfe[:,0],tfe[:,1],'r.')
        plt.xlabel("Time")
        plt.ylabel("Flux")
        ## smooth on 
        plt.subplot(212)
        smo = smoothers.supersmooth(tfe,period)
        plt.plot(tfe[:,0],smo,tfe[:,0],tfe[:,1],'x')
        plt.xlabel("Phased using period: " + repr(period))
        plt.ylabel("Flux")
        ## smooth on estimated period
        ## plt.subplot(213)
        ## smo = smoothers.supersmooth(tfe,1/2)
        ## plt.plot(tfe[:,0],smo,'o',tfe[:,0],tfe[:,1],'x')

    ## only unfolded plot
    if plot_unfolded and not plot_folded:
        plt.plot(tfe[:,0],tfe[:,1],'r.')
        plt.title(title)
        plt.xlabel("Time")
        plt.ylabel("Flux")

    ## only folded plot
    if not plot_unfolded and plot_folded:
        plt.plot(folded,tfe[:,1],'r.')
        plt.title(title)
        plt.ylabel("Flux")
        plt.xlabel("Phase")

    ## either save figure or show figure
    if save_figure:
        plt.savefig(save_figure_name)
    if show_plot:
        plt.show()
Exemple #2
0


######### STORE SMOOTHED CURVES
## smooth curves and store smoothed values in measurements_smoothed
cursor.execute(sql_cmd)
connection.commit()
sql_cmd = """SELECT S.source_id, true_period, classification, survey, freq1_harmonics_freq_0 FROM sources AS S JOIN features AS F ON S.source_id=F.source_id"""
cursor.execute(sql_cmd)
db_info = cursor.fetchall()
for i in db_info:
    print i

for i in db_info:
    tfe = create_database.get_measurements(i[0],cursor)
    smo = smoothers.supersmooth(tfe,1/i[4])
    tfe[:,1] = smo
    tfe[:,2] = 1
    create_database.insert_measurements(cursor,i[0],tfe,table='measurements_smoothed')	

connection.commit()






########### VISUALIZE SMOOTHED CURVES ###########
## does this work out okay?
## run several times and use evince to view both at once
which = np.random.randint(low=0,high=len(db_info))
Exemple #3
0
                                    delete_existing=True)
connection.commit()

######### STORE SMOOTHED CURVES
## smooth curves and store smoothed values in measurements_smoothed
cursor.execute(sql_cmd)
connection.commit()
sql_cmd = """SELECT S.source_id, true_period, classification, survey, freq1_harmonics_freq_0 FROM sources AS S JOIN features AS F ON S.source_id=F.source_id"""
cursor.execute(sql_cmd)
db_info = cursor.fetchall()
for i in db_info:
    print i

for i in db_info:
    tfe = create_database.get_measurements(i[0], cursor)
    smo = smoothers.supersmooth(tfe, 1 / i[4])
    tfe[:, 1] = smo
    tfe[:, 2] = 1
    create_database.insert_measurements(cursor,
                                        i[0],
                                        tfe,
                                        table='measurements_smoothed')

connection.commit()

########### VISUALIZE SMOOTHED CURVES ###########
## does this work out okay?
## run several times and use evince to view both at once
which = np.random.randint(low=0, high=len(db_info))
reload(visualize)
Exemple #4
0
def compute_residuals(tfe,period):
    smo = smoothers.supersmooth(tfe,period,normalize_times=False)
    tfe[:,1] = np.mean(tfe[:,1]) + tfe[:,1] - smo
Exemple #5
0
def compute_residuals(tfe, period):
    smo = smoothers.supersmooth(tfe, period, normalize_times=False)
    tfe[:, 1] = np.mean(tfe[:, 1]) + tfe[:, 1] - smo


sql_cmd = """SELECT S.source_id, survey, freq1_harmonics_freq_0, classification, xml_filename FROM sources AS S JOIN features AS F ON S.source_id=F.source_id WHERE classification = 'rr'"""
cursor.execute(sql_cmd)
db_info = cursor.fetchall()
for i in db_info:
    print i


curve_info_names = ["classification","survey","original_source_id","number_points","xml_filename"]

for i in db_info:
    tfe = create_database.get_measurements(i[0],cursor)
    period = 1 / i[2]
    smo = smoothers.supersmooth(tfe,period,normalize_times=False)
    tfe_smoothed = np.concatenate((tfe[:,0].reshape((tfe[:,0].size,1)),
                                   smo.reshape(smo.size,1),
                                   tfe[:,2].reshape((tfe[:,2].size,1))),
                                  axis=1)
    residuals = np.mean(tfe[:,1]) + tfe[:,1] - smo
    tfe_residual = np.concatenate((tfe[:,0].reshape((tfe[:,0].size,1)),
                                   residuals.reshape(residuals.size,1),
                                   tfe[:,2].reshape((tfe[:,2].size,1))),
                                  axis=1)
    curve_info = ['smoothed',i[1],i[0],tfe.shape[0],i[4]]
    create_database.enter_record(curve_info,
                                 curve_info_names,
                                 tfe_smoothed,
                                 cursor=cursor)	
    curve_info[0] = 'residual'