return read_cache(file_list(f), GWRecArray, nproc, None, *args, **kwargs) # set up keyword arguments reckwargs = { 'on_attributeerror': 'raise', 'get_as_columns': False } for key in reckwargs: if key in kwargs: reckwargs[key] = kwargs.pop(key) reckwargs['columns'] = kwargs.get('columns', None) # read from LIGO_LW return table_from_file(f, table_.tableName, *args, **kwargs).to_recarray(**reckwargs) return _read_ligolw, _read_recarray # register reader and auto-id for LIGO_LW for table in TableByName.itervalues(): tablename = strip(table.tableName) llwfunc, recfunc = read_table_factory(table) # register generic reader and table-specific reader for LIGO_LW registry.register_reader('ligolw', table, llwfunc) registry.register_reader(tablename, table, llwfunc) registry.register_identifier('ligolw', table, identify_ligolw) # register table-specific reader for GWRecArray registry.register_reader(tablename, GWRecArray, recfunc)
# This file is part of GWpy. # # GWpy is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # GWpy is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with GWpy. If not, see <http://www.gnu.org/licenses/>. """Read gravitational-wave data from a cache of files """ from astropy.io import registry from glue.ligolw.lsctables import TableByName from ...io.cache import (identify_cache, identify_cache_file, read_cache_factory) # register cache reading for all lsctables for table in TableByName.itervalues(): registry.register_reader('lcf', table, read_cache_factory(table)) registry.register_reader('cache', table, read_cache_factory(table)) registry.register_identifier('lcf', table, identify_cache_file) registry.register_identifier('cache', table, identify_cache)
# -- read ----------------------------------- return Table(read_ligolw_table(source, tablename=tablename, **read_kw), **convert_kw) # -- write -------------------------------------------------------------------- def write_table(table, target, tablename=None, **kwargs): """Write a `~astropy.table.Table` to file in LIGO_LW XML format """ if tablename is None: # try and get tablename from metadata tablename = table.meta.get('tablename', None) if tablename is None: # panic raise ValueError("please pass ``tablename=`` to specify the target " "LIGO_LW Table Name") return write_ligolw_tables(target, [table_to_ligolw(table, tablename)], **kwargs) # -- register ----------------------------------------------------------------- for table_ in TableByName.values(): # register conversion from LIGO_LW to astropy Table table_.__astropy_table__ = to_astropy_table for table_class in (Table, EventTable): registry.register_reader('ligolw', table_class, read_table) registry.register_writer('ligolw', table_class, write_table) registry.register_identifier('ligolw', table_class, is_ligolw)