ogle = synthetic_data.CadenceFromSurvey( database_location='../db/ogle_cadences.db') cadence_dict = {'hip': hip, 'ogle': ogle} period = 25 number_points = 4000 ## make a curve number_tfe = 60 power = 10 tfe = np.ndarray(number_tfe * 3).reshape((number_tfe, 3)) tfe[:, 0] = np.linspace(.01, .99, number_tfe) tfe[:, 1] = np.abs(tfe[:, 0]) - pow(tfe[:, 0], power) print tfe ## examine noisification for i in range(1): tfe2 = cadence_noisify_smoothed( tfe, ['ogle', 'first', number_points, period, cadence_dict]) print tfe2 visualize.plot_curve(tfe2, period=period) if 0: randoms = np.random.normal(size=(10, 3)) randoms_out = cadence_noisify(randoms, [5, 'first', 6]) print randoms_out print randoms if 0: noisification_dict = get_noisification_dict() print noisification_dict
(times[:, np.newaxis], fluxes[:, np.newaxis], errors[:, np.newaxis])) return tfe ## light curve now in aRRLyraeFund.curve_this aRRLyraeFund = synthetic_data.RRLyraeFund() aRRLyraeFund.generateCurve() ## put cadence in aCadence filename = "../data/OGLEIII/classical-cepheid/OGLE-LMC-CEP-2233.dat" aCadence = synthetic_data.CadenceFromTFE() aCadence.generate_cadence(fname=filename) ## check that this worked tfe = ComputeTfe(aRRLyraeFund, aCadence) visualize.plot_curve(tfe, period=aRRLyraeFund.period_this) ## parameters for entering tfes into database source_class = "rr lyrae" survey = "full" points_per_curve = len(aCadence.error_this) period = aRRLyraeFund.period_this curve_info = [ points_per_curve, source_class, 0, 0, 0, 0, None, survey, 0, period ] curve_info_names = [ "number_points", "classification", "c1", "e1", "c2", "e2", "raw_xml", "survey", "xml_filename", "true_period" ] ## generate light curve using full cadence
# make a nice view of the features table sql_cmd = """CREATE VIEW IF NOT EXISTS sources_short AS SELECT source_id,original_source_id,classification,noisification,noise_args,true_period FROM sources""" cursor.execute(sql_cmd) # set up the survey and # create two curves and visualize them aSurvey = synthetic_data.surveySetup() aCadence = synthetic_data.CadenceFromVOSource() aSurvey.aCadence = aCadence aSurvey.generateCurve() tfe = np.column_stack((aSurvey.times[:,np.newaxis], aSurvey.fluxes[:,np.newaxis], aSurvey.errors[:,np.newaxis])) visualize.plot_curve(tfe,period= (2*aSurvey.period_this)) # generate training data, add to db survey='normal' for i in range(1000): aSurvey.generateCurve() tfe = np.column_stack((aSurvey.times[:,np.newaxis],aSurvey.fluxes[:,np.newaxis],aSurvey.errors[:,np.newaxis])) points_per_curve = len(aSurvey.times) source_class = aSurvey.class_name period = aSurvey.period_this curve_info = [points_per_curve,source_class,0,0,0,0,None,survey,0,period] curve_info_names = ["number_points","classification","c1","e1","c2","e2","raw_xml","survey","xml_filename","true_period"] print source_class
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) tfe = create_database.get_measurements(db_info[which][0],cursor) visualize.plot_curve(tfe,1/db_info[which][4],classification=db_info[which][2],survey=db_info[which][3],show_plot=False,save_figure=True,save_figure_name='original_plot.pdf') tfe = create_database.get_measurements(db_info[which][0],cursor,table='measurements_smoothed') visualize.plot_curve(tfe,1/db_info[which][4],classification=db_info[which][2],survey=db_info[which][3],show_plot=False,save_figure=True,save_figure_name='smoothed_plot.pdf') ###### ###### ADD ENTRIES IN SOURCES FOR NOISIFIED VERSIONS ###### reload(create_database) sql_cmd = """DELETE from sources WHERE source_id != original_source_id""" cursor.execute(sql_cmd)
## light curve now in aRRLyraeFund.curve_this aRRLyraeFund = synthetic_data.RRLyraeFund() aRRLyraeFund.generateCurve() ## put cadence in aCadence filename = "../data/OGLEIII/classical-cepheid/OGLE-LMC-CEP-2233.dat" aCadence = synthetic_data.CadenceFromTFE() aCadence.generate_cadence(fname=filename) ## check that this worked tfe = ComputeTfe(aRRLyraeFund,aCadence) visualize.plot_curve(tfe,period=aRRLyraeFund.period_this) ## parameters for entering tfes into database source_class = "rr lyrae" survey = "full" points_per_curve = len(aCadence.error_this) period = aRRLyraeFund.period_this curve_info = [points_per_curve,source_class,0,0,0,0,None,survey,0,period] curve_info_names = ["number_points","classification","c1","e1","c2","e2","raw_xml","survey","xml_filename","true_period"]
cursor.execute(sql_cmd) # make a nice view of the features table sql_cmd = """CREATE VIEW IF NOT EXISTS sources_short AS SELECT source_id,original_source_id,classification,noisification,noise_args,true_period FROM sources""" cursor.execute(sql_cmd) # set up the survey and # create two curves and visualize them aSurvey = synthetic_data.surveySetup() aCadence = synthetic_data.CadenceFromVOSource() aSurvey.aCadence = aCadence aSurvey.generateCurve() tfe = np.column_stack( (aSurvey.times[:, np.newaxis], aSurvey.fluxes[:, np.newaxis], aSurvey.errors[:, np.newaxis])) visualize.plot_curve(tfe, period=(2 * aSurvey.period_this)) # generate training data, add to db survey = 'normal' for i in range(1000): aSurvey.generateCurve() tfe = np.column_stack( (aSurvey.times[:, np.newaxis], aSurvey.fluxes[:, np.newaxis], aSurvey.errors[:, np.newaxis])) points_per_curve = len(aSurvey.times) source_class = aSurvey.class_name period = aSurvey.period_this curve_info = [ points_per_curve, source_class, 0, 0, 0, 0, None, survey, 0, period ] curve_info_names = [
## get the cadences hip = synthetic_data.CadenceFromSurvey(database_location='../db/hipparcos_cadences.db') ogle = synthetic_data.CadenceFromSurvey(database_location='../db/ogle_cadences.db') cadence_dict = {'hip':hip,'ogle':ogle} period = 25 number_points = 4000 ## make a curve number_tfe = 60 power = 10 tfe = np.ndarray(number_tfe*3).reshape((number_tfe,3)) tfe[:,0] = np.linspace(.01,.99,number_tfe) tfe[:,1] = np.abs(tfe[:,0]) - pow(tfe[:,0],power) print tfe ## examine noisification for i in range(1): tfe2 = cadence_noisify_smoothed(tfe,['ogle','first',number_points,period,cadence_dict]) print tfe2 visualize.plot_curve(tfe2,period=period) if 0: randoms = np.random.normal(size=(10,3)) randoms_out = cadence_noisify(randoms,[5,'first',6]) print randoms_out print randoms if 0: noisification_dict = get_noisification_dict() print noisification_dict
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) tfe = create_database.get_measurements(db_info[which][0], cursor) visualize.plot_curve(tfe, 1 / db_info[which][4], classification=db_info[which][2], survey=db_info[which][3], show_plot=False, save_figure=True, save_figure_name='original_plot.pdf') tfe = create_database.get_measurements(db_info[which][0], cursor, table='measurements_smoothed') visualize.plot_curve(tfe, 1 / db_info[which][4], classification=db_info[which][2], survey=db_info[which][3], show_plot=False, save_figure=True, save_figure_name='smoothed_plot.pdf')
print aCadence.unique_source_ids.size aCadence.generate_cadence() print aCadence.cadence_this print aCadence.error_this if 0: aSurvey = surveySetup(aCadence=CadenceFromSurvey()) aSurvey.generateCurve() print "class is: " + aSurvey.class_name tfe = np.column_stack( (aSurvey.times[:, np.newaxis], aSurvey.fluxes[:, np.newaxis], aSurvey.errors[:, np.newaxis])) print "the period is:" print aSurvey.period_this visualize.plot_curve(tfe, freq=(1 / (2 * aSurvey.period_this)), classification=aSurvey.class_name) if 0: aRRLyraeFund = RRLyraeFund() aRRLyraeFund.generateCurve() print "RR Lyrae Fundamental Mode Period:" print aRRLyraeFund.period_this aJittered = jittered() cadence = aJittered() fluxes = aRRLyraeFund.curve_this(cadence) tfe = np.column_stack((cadence[:, np.newaxis], fluxes[:, np.newaxis], np.empty(fluxes.size)[:np.newaxis])) visualize.plot_curve(tfe, freq=(1 / (2 * aRRLyraeFund.period_this))) if 0:
print aCadence.unique_source_ids print aCadence.unique_source_ids.size aCadence.generate_cadence() print aCadence.cadence_this print aCadence.error_this if 0: aSurvey = surveySetup(aCadence = CadenceFromSurvey()) aSurvey.generateCurve() print "class is: " + aSurvey.class_name tfe = np.column_stack((aSurvey.times[:,np.newaxis],aSurvey.fluxes[:,np.newaxis],aSurvey.errors[:,np.newaxis])) print "the period is:" print aSurvey.period_this visualize.plot_curve(tfe, freq=(1 / (2*aSurvey.period_this)), classification= aSurvey.class_name) if 0: aRRLyraeFund = RRLyraeFund() aRRLyraeFund.generateCurve() print "RR Lyrae Fundamental Mode Period:" print aRRLyraeFund.period_this aJittered = jittered() cadence = aJittered() fluxes = aRRLyraeFund.curve_this(cadence) tfe = np.column_stack((cadence[:,np.newaxis],fluxes[:,np.newaxis], np.empty(fluxes.size)[:np.newaxis])) visualize.plot_curve(tfe,freq= (1 / (2*aRRLyraeFund.period_this)))
# make a nice view of the features table sql_cmd = """CREATE VIEW IF NOT EXISTS features_short AS SELECT source_id,freq1_harmonics_freq_0,std,max,weighted_average FROM features""" cursor.execute(sql_cmd) # make a nice view of the features table sql_cmd = """CREATE VIEW IF NOT EXISTS sources_short AS SELECT source_id,original_source_id,classification,noisification,noise_args,true_period FROM sources""" cursor.execute(sql_cmd) # set up the survey and # create two curves and visualize them aSurvey = synthetic_data.surveySetup() aSurvey.generateCurve() tfe = np.column_stack((aSurvey.times[:,np.newaxis], aSurvey.fluxes[:,np.newaxis], aSurvey.errors[:,np.newaxis])) visualize.plot_curve(tfe,period=aSurvey.period_this) # generate training data, add to db survey='train' for i in range(500): aSurvey.generateCurve() tfe = np.column_stack((aSurvey.times[:,np.newaxis],aSurvey.fluxes[:,np.newaxis],aSurvey.errors[:,np.newaxis])) points_per_curve = len(aSurvey.times) source_class = aSurvey.class_name period = aSurvey.period_this curve_info = [points_per_curve,source_class,0,0,0,0,None,survey,0,period] curve_info_names = ["number_points","classification","c1","e1","c2","e2","raw_xml","survey","xml_filename","true_period"]
aBetaLyrae = synthetic_data.Eclipsing(dip_ratio=scipy.stats.uniform(loc=.5, scale=.5), fraction_flat=scipy.stats.uniform( loc=0, scale=.5)) class_names = [ 'Classical Cepheid', 'Mira', 'RR Lyrae Fundamental', 'Beta Persei', 'Beta Lyrae' ] classes = [aClassicalCepheid, aMira, aRRLyraeFund, aBetaPersei, aBetaLyrae] priors = np.array([.2, .2, .2, .2, .2]) aSurvey = synthetic_data.Survey(class_names, classes, priors, aCadence) aSurvey.generateCurve() tfe = np.column_stack( (aSurvey.times[:, np.newaxis], aSurvey.fluxes[:, np.newaxis], aSurvey.errors[:, np.newaxis])) visualize.plot_curve(tfe, period=(2 * aSurvey.period_this)) # generate training data, add to db survey = 'synthetic_train' for i in range(500): aSurvey.generateCurve() tfe = np.column_stack( (aSurvey.times[:, np.newaxis], aSurvey.fluxes[:, np.newaxis], aSurvey.errors[:, np.newaxis])) points_per_curve = len(aSurvey.times) source_class = aSurvey.class_name period = aSurvey.period_this curve_info = [ points_per_curve, source_class, 0, 0, 0, 0, None, survey, 0, period ] curve_info_names = [
aBetaPersei = synthetic_data.Eclipsing( dip_ratio=scipy.stats.uniform(loc=.2,scale=.8), fraction_flat=scipy.stats.uniform(loc=.2,scale=.6)) aBetaLyrae = synthetic_data.Eclipsing( dip_ratio=scipy.stats.uniform(loc=.5,scale=.5), fraction_flat=scipy.stats.uniform(loc=0,scale=.5)) class_names = ['Classical Cepheid','Mira','RR Lyrae Fundamental', 'Beta Persei','Beta Lyrae'] classes = [aClassicalCepheid,aMira,aRRLyraeFund,aBetaPersei,aBetaLyrae] priors = np.array([.2,.2,.2,.2,.2]) aSurvey = synthetic_data.Survey(class_names,classes,priors,aCadence) aSurvey.generateCurve() tfe = np.column_stack((aSurvey.times[:,np.newaxis], aSurvey.fluxes[:,np.newaxis], aSurvey.errors[:,np.newaxis])) visualize.plot_curve(tfe,period= (2*aSurvey.period_this)) # generate training data, add to db survey='synthetic_train' for i in range(500): aSurvey.generateCurve() tfe = np.column_stack((aSurvey.times[:,np.newaxis],aSurvey.fluxes[:,np.newaxis],aSurvey.errors[:,np.newaxis])) points_per_curve = len(aSurvey.times) source_class = aSurvey.class_name period = aSurvey.period_this curve_info = [points_per_curve,source_class,0,0,0,0,None,survey,0,period] curve_info_names = ["number_points","classification","c1","e1","c2","e2","raw_xml","survey","xml_filename","true_period"] print source_class