def get_experiment_type(xmldoc, time_slide_dict): """ Determine the which experiment type(s) the coincident triggers in this file belong to. It uses information from the inspiral files stored in the process params table to decide if the triggers come from playground time or are from an injection run. If the time_slide_dict has more than one entry, then the triggers are from a slide run. """ # get the param column of the process_params table process_params_tbl = lsctables.ProcessParamsTable.get_table(xmldoc) pp_value = set(process_params_tbl.getColumnByName("value")) pp_param = set(process_params_tbl.getColumnByName("param")) zero_lag_dict = dict([ dict_entry for dict_entry in time_slide_dict.items() if not any(dict_entry[1].values()) ]) # determine experiment type(s) datatypes = ['all_data', 'exclude_play', 'playground'] usertags = set(['FULL_DATA', 'PLAYGROUND']) if len(zero_lag_dict): if ('--injection-file' in pp_param) and not (pp_value & usertags): datatypes = ['simulation'] elif 'PLAYGROUND' in pp_value: datatypes = ['playground'] if len(time_slide_dict) > len(zero_lag_dict): datatypes += ['slide'] return datatypes
def populate_experiment_summ_table( xmldoc, experiment_id, time_slide_dict, veto_def_name, verbose = False ): """ Populate the experiment_summ_table using an experiment_id, a veto_def_name, and a list of time_slide ids. @xmldoc: xmldoc to get/write table to @experiment_id: experiment_id to be added to the table. @veto_def_name: veto_def_name to be added to the table. @time_slide_dict: time_slide table as dictionary; used to set time_slide_id column and figure out whether or not is zero-lag. Can either be the result of lsctables.time_slide_table.as_dict or any dictionary having same format. """ if verbose: print >> sys.stderr, "\tPopulating the Experiment Summary table..." # find the experiment_summary table or create one if needed try: expr_summ_table = table.get_table(xmldoc, lsctables.ExperimentSummaryTable.tableName) except ValueError: expr_summ_table = xmldoc.childNodes[0].appendChild(lsctables.New(lsctables.ExperimentSummaryTable)) # populate the experiment_summary table datatypes = get_experiment_type(xmldoc, time_slide_dict) for type in datatypes: for slide_id in time_slide_dict: if type == "slide" and not any( time_slide_dict[slide_id].values() ): continue if type != "slide" and any( time_slide_dict[slide_id].values() ): continue expr_summ_table.write_experiment_summ( experiment_id, slide_id, veto_def_name, type, sim_proc_id = None ) if type != "slide": break
def populate_experiment_summ_table(xmldoc, experiment_id, time_slide_dict, veto_def_name, verbose=False): """ Populate the experiment_summ_table using an experiment_id, a veto_def_name, and a list of time_slide ids. @xmldoc: xmldoc to get/write table to @experiment_id: experiment_id to be added to the table. @veto_def_name: veto_def_name to be added to the table. @time_slide_dict: time_slide table as dictionary; used to set time_slide_id column and figure out whether or not is zero-lag. Can either be the result of lsctables.time_slide_table.as_dict or any dictionary having same format. """ if verbose: print >> sys.stderr, "\tPopulating the Experiment Summary table..." # find the experiment_summary table or create one if needed try: expr_summ_table = table.get_table( xmldoc, lsctables.ExperimentSummaryTable.tableName) except ValueError: expr_summ_table = xmldoc.childNodes[0].appendChild( lsctables.New(lsctables.ExperimentSummaryTable)) # populate the experiment_summary table datatypes = get_experiment_type(xmldoc, time_slide_dict) for type in datatypes: for slide_id in time_slide_dict: if type == "slide" and not any(time_slide_dict[slide_id].values()): continue if type != "slide" and any(time_slide_dict[slide_id].values()): continue expr_summ_table.write_experiment_summ(experiment_id, slide_id, veto_def_name, type, sim_proc_id=None) if type != "slide": break
def populate_experiment_map(xmldoc, veto_def_name, verbose=False): from glue.pipeline import s2play as is_in_playground # # find the experiment_map table or create one if needed # if verbose: print >> sys.stderr, "\tMapping coinc events to experiment_summary table..." try: expr_map_table = lsctables.ExperimentMapTable.get_table(xmldoc) except ValueError: expr_map_table = xmldoc.childNodes[0].appendChild( lsctables.New(lsctables.ExperimentMapTable)) # # find the coinc_event table # coinc_event_table = lsctables.CoincTable.get_table(xmldoc) # # Index the coinc_inspiral table as a dictionary # coinc_index = dict( (row.coinc_event_id, row) for row in lsctables.CoincInspiralTable.get_table(xmldoc)) # # Get the time_slide_table as dict # time_slide_dict = lsctables.TimeSlideTable.get_table(xmldoc).as_dict() # # find the experiment & experiment summary tables # expr_table = lsctables.ExperimentTable.get_table(xmldoc) expr_summ_table = lsctables.ExperimentSummaryTable.get_table(xmldoc) # # determine what experiment datatypes are in this file # datatypes = get_experiment_type(xmldoc, time_slide_dict) # # cycle through the coincs in the coinc_inspiral table # for coinc in coinc_event_table: # # get the experiment and experiment_summ_id for this coinc # for expr in expr_table: if expr.instruments == coinc.instruments: expr_id = expr.experiment_id in_playground = is_in_playground( coinc_index[coinc.coinc_event_id].end_time) for type in datatypes: # make sure that all_data triggers also get mapped to the right # all_data sub-type: exclude_play or playground if in_playground & (type == "exclude_play"): continue elif (not in_playground) & (type == "playground"): continue # if doing zerolag and slides together, make sure the triggers are mapped correctly elif type == "slide" and not any( time_slide_dict[coinc.time_slide_id].values()): continue elif type != "slide" and any( time_slide_dict[coinc.time_slide_id].values()): continue else: # map the coinc to an experiment expr_map = lsctables.ExperimentMap() expr_map.coinc_event_id = coinc.coinc_event_id expr_map.experiment_summ_id = expr_summ_table.get_expr_summ_id( expr_id, coinc.time_slide_id, veto_def_name, type, sim_proc_id=None) if not expr_map.experiment_summ_id: raise ValueError, "%s experiment_summ_id could not be found with %s" \ %( type, ','.join([ str(expr_id), str(coinc.time_slide_id), veto_def_name ])) # map the experiment expr_map_table.append(expr_map) # Increment number of events in nevents column by 1 expr_summ_table.add_nevents(expr_map.experiment_summ_id, 1)
def populate_experiment_map(xmldoc, veto_def_name, verbose = False): from glue.pipeline import s2play as is_in_playground # # find the experiment_map table or create one if needed # if verbose: print >> sys.stderr, "\tMapping coinc events to experiment_summary table..." try: expr_map_table = table.get_table(xmldoc, lsctables.ExperimentMapTable.tableName) except ValueError: expr_map_table = xmldoc.childNodes[0].appendChild(lsctables.New(lsctables.ExperimentMapTable)) # # find the coinc_event table # coinc_event_table = table.get_table(xmldoc, lsctables.CoincTable.tableName) # # Index the coinc_inspiral table as a dictionary # coinc_index = dict((row.coinc_event_id, row) for row in table.get_table(xmldoc, lsctables.CoincInspiralTable.tableName)) # # Get the time_slide_table as dict # time_slide_dict = table.get_table(xmldoc, lsctables.TimeSlideTable.tableName).as_dict() # # find the experiment & experiment summary tables # expr_table = table.get_table(xmldoc, lsctables.ExperimentTable.tableName) expr_summ_table = table.get_table(xmldoc, lsctables.ExperimentSummaryTable.tableName) # # determine what experiment datatypes are in this file # datatypes = get_experiment_type(xmldoc, time_slide_dict) # # cycle through the coincs in the coinc_inspiral table # for coinc in coinc_event_table: # # get the experiment and experiment_summ_id for this coinc # for expr in expr_table: if expr.instruments == coinc.instruments: expr_id = expr.experiment_id in_playground = is_in_playground( coinc_index[coinc.coinc_event_id].end_time ) for type in datatypes: # make sure that all_data triggers also get mapped to the right # all_data sub-type: exclude_play or playground if in_playground & (type == "exclude_play"): continue elif (not in_playground) & (type == "playground"): continue # if doing zerolag and slides together, make sure the triggers are mapped correctly elif type == "slide" and not any( time_slide_dict[coinc.time_slide_id].values() ): continue elif type != "slide" and any( time_slide_dict[coinc.time_slide_id].values() ): continue else: # map the coinc to an experiment expr_map = lsctables.ExperimentMap() expr_map.coinc_event_id = coinc.coinc_event_id expr_map.experiment_summ_id = expr_summ_table.get_expr_summ_id( expr_id, coinc.time_slide_id, veto_def_name, type, sim_proc_id = None ) if not expr_map.experiment_summ_id: raise ValueError, "%s experiment_summ_id could not be found with %s" \ %( type, ','.join([ str(expr_id), str(coinc.time_slide_id), veto_def_name ])) # map the experiment expr_map_table.append(expr_map) # Increment number of events in nevents column by 1 expr_summ_table.add_nevents( expr_map.experiment_summ_id, 1 )
def get_experiment_type(xmldoc, time_slide_dict): """ Determine the which experiment type(s) the coincident triggers in this file belong to. It uses information from the inspiral files stored in the process params table to decide if the triggers come from playground time or are from an injection run. If the time_slide_dict has more than one entry, then the triggers are from a slide run. """ # get the param column of the process_params table process_params_tbl = lsctables.table.get_table(xmldoc, lsctables.ProcessParamsTable.tableName) pp_value = set(process_params_tbl.getColumnByName("value")) pp_param = set(process_params_tbl.getColumnByName("param")) zero_lag_dict = dict([dict_entry for dict_entry in time_slide_dict.items() if not any( dict_entry[1].values() )]) # determine experiment type(s) datatypes = ['all_data', 'exclude_play', 'playground'] usertags = set(['FULL_DATA','PLAYGROUND']) if len(zero_lag_dict): if ('--injection-file' in pp_param) and not (pp_value & usertags): datatypes = ['simulation'] elif 'PLAYGROUND' in pp_value: datatypes = ['playground'] if len(time_slide_dict) > len(zero_lag_dict): datatypes += ['slide'] return datatypes