def return_empty_sngl(nones=False): """ Function to create a SnglInspiral object where all columns are populated but all are set to values that test False (ie. strings to '', floats/ints to 0, ...). This avoids errors when you try to create a table containing columns you don't care about, but which still need populating. NOTE: This will also produce a process_id and event_id with 0 values. For most applications these should be set to their correct values. Parameters ---------- nones : bool (False) If True, just set all columns to None. Returns -------- lsctables.SnglInspiral The "empty" SnglInspiral object. """ sngl = lsctables.SnglInspiral() cols = lsctables.SnglInspiralTable.validcolumns for entry in cols: col_name = Column.ColumnName(entry) value = None if nones else default_null_value(col_name, cols[entry]) setattr(sngl, col_name, value) return sngl
def startColumn(self, parent, attrs, __orig_startColumn=ContentHandler.startColumn): """Convert types in <Column> elements from ilwdchar to int. Notes ----- This method is adapted from :func:`ligo.lw.utils.ilwd.strip_ilwdchar`. """ result = __orig_startColumn(self, parent, attrs) # If this is an ilwdchar column, then create a function to convert its # rows' values for use in the startStream method below. if result.Type in IDTypes: old_type = ToPyType[result.Type] def converter(old_value): return ROWID_PYTYPE(str(old_type(old_value)).split(":")[-1]) remapped[(id(parent), result.Name)] = converter result.Type = ROWID_TYPE # If this is an ilwdchar column, then normalize the column name. if parent.Name in TableByName: validcolumns = TableByName[parent.Name].validcolumns if result.Name not in validcolumns: stripped_column_to_valid_column = { Column.ColumnName(name): name for name in validcolumns} if result.Name in stripped_column_to_valid_column: result.setAttribute( 'Name', stripped_column_to_valid_column[result.Name]) return result
def return_search_summary(start_time=0, end_time=0, nevents=0, ifos=None): """ Function to create a SearchSummary object where all columns are populated but all are set to values that test False (ie. strings to '', floats/ints to 0, ...). This avoids errors when you try to create a table containing columns you don't care about, but which still need populating. NOTE: This will also produce a process_id with 0 values. For most applications these should be set to their correct values. It then populates columns if given them as options. Returns -------- lsctables.SeachSummary The "empty" SearchSummary object. """ if ifos is None: ifos = [] # create an empty search summary search_summary = lsctables.SearchSummary() cols = lsctables.SearchSummaryTable.validcolumns for entry in cols: col_name = Column.ColumnName(entry) value = default_null_value(col_name, cols[entry]) setattr(search_summary, col_name, value) # fill in columns if ifos: search_summary.instruments = ifos if nevents: search_summary.nevents = nevents if start_time and end_time: search_summary.in_start_time = int(start_time) search_summary.in_start_time_ns = int(start_time % 1 * 1e9) search_summary.in_end_time = int(end_time) search_summary.in_end_time_ns = int(end_time % 1 * 1e9) search_summary.out_start_time = int(start_time) search_summary.out_start_time_ns = int(start_time % 1 * 1e9) search_summary.out_end_time = int(end_time) search_summary.out_end_time_ns = int(end_time % 1 * 1e9) return search_summary
from glue.ligolw import lsctables from ligo.lw.lsctables import TableByName as ligo_lw_TableByName from ligo.lw.param import Param as ligo_lw_Param from ligo.lw.table import Column as ligo_lw_Column # # dictionary mapping lsctables table class to dictionary mapping column # name to ilwd:char class. we only consider tables that are named in both # glue.ligolw.lsctables and ligo.lw.lsctables, assuming we won't be # converting documents that contain tables that have been removed from the # latter. # ilwdchar_tables = dict( (tblname, dict((ligo_lw_Column.ColumnName(colname), None) for colname, coltype in tblcls.validcolumns.items() if coltype == u"ilwd:char")) for tblname, tblcls in lsctables.TableByName.items() if tblname in ligo_lw_TableByName and u"ilwd:char" in tblcls.validcolumns.values()) destrip_column = dict( (key, dict(value)) for key, value in ilwdchar_tables.items()) for tblname, colnamemap in destrip_column.items(): for colname in list(colnamemap): colnamemap[colname], = ( destripped for destripped in ligo_lw_TableByName[tblname].validcolumns if ligo_lw_Column.ColumnName(destripped) == colname)