Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try:
getattr(row, 'set_%s' % colname)(datum)
except AttributeError:
setattr(row, colname, datum)
return row
return row_from_ascii
# register generic ASCII parsing for all tables
for table in TableByName.values():
# register whitespace-delimited ASCII
register_reader(
'ascii', table, table_from_ascii_factory(
table, 'ascii', row_from_ascii_factory(table, None)))
register_identifier('ascii', table, identify_factory('txt', 'txt.gz'))
# register csv
register_reader(
'csv', table, table_from_ascii_factory(
table, 'csv', row_from_ascii_factory(table, ','), delimiter=','))
register_identifier('csv', table, identify_factory('csv', 'csv.gz'))
__author__ = 'Duncan Macleod '
def table_from_omicron(source, *args, **kwargs):
"""Read an `EventTable` from an Omicron ROOT file
This function just redirects to the format='root' reader with appropriate
defaults.
"""
if not args: # only default treename if args not given
kwargs.setdefault('treename', 'triggers')
return EventTable.read(source, *args, format='root', **kwargs)
registry.register_reader('root.omicron', EventTable, table_from_omicron)
except (UnicodeDecodeError, struct.error):
return False
finally:
fileobj.seek(loc)
elif filepath is not None:
return filepath.endswith(('.wav', '.wave'))
else:
try:
wave.open(args[0])
except (wave.Error, AttributeError):
return False
else:
return True
io_registry.register_reader('wav', TimeSeries, read)
io_registry.register_writer('wav', TimeSeries, write)
io_registry.register_identifier('wav', TimeSeries, is_wav)
branches=include_names, **kwargs))
if filters:
return filter_table(t, *filters)
return t
def table_to_root(table, filename, **kwargs):
"""Write a Table to a ROOT file
"""
import root_numpy
root_numpy.array2root(table.as_array(), filename, **kwargs)
# register I/O
for table_class in (Table, EventTable):
registry.register_reader('root', table_class, table_from_root)
registry.register_writer('root', table_class, table_to_root)
registry.register_identifier('root', table_class,
identify_factory('.root'))
series.write(h5g, path=str(key), **kwargs)
# -- register -----------------------------------------------------------------
# series classes
for series_class in (TimeSeries, StateVector):
reader = read_hdf5_factory(series_class)
io_registry.register_reader('hdf5', series_class, reader)
io_registry.register_writer('hdf5', series_class, write_hdf5_series)
io_registry.register_identifier('hdf5', series_class, identify_hdf5)
# dict classes
for dict_class in (TimeSeriesDict, StateVectorDict):
reader = read_hdf5_factory(dict_class)
io_registry.register_reader('hdf5', dict_class, reader)
io_registry.register_writer('hdf5', dict_class, write_hdf5_dict)
io_registry.register_identifier('hdf5', dict_class, identify_hdf5)
----------
container : `Series`, `dict`
series class or series dict class to register
"""
def read_(*args, **kwargs):
fmt = 'gwf.{}'.format(get_default_gwf_api())
reader = get_reader(fmt, container)
return reader(*args, **kwargs)
def write_(*args, **kwargs):
fmt = 'gwf.{}'.format(get_default_gwf_api())
writer = get_writer(fmt, container)
return writer(*args, **kwargs)
register_identifier('gwf', container, identify_gwf)
register_reader('gwf', container, read_)
register_writer('gwf', container, write_)
# convert segmentlist to Table
data = numpy.zeros((len(seglist), 4), dtype=int)
for i, seg in enumerate(seglist):
start, end = map(LIGOTimeGPS, seg)
data[i, :] = (start.gpsSeconds, start.gpsNanoSeconds,
end.gpsSeconds, end.gpsNanoSeconds)
segtable = Table(data, names=['start_time', 'start_time_ns',
'end_time', 'end_time_ns'])
# write table to HDF5
return segtable.write(output, path=path, format='hdf5', **kwargs)
# -- register -----------------------------------------------------------------
register_reader('hdf5', SegmentList, read_hdf5_segmentlist)
register_writer('hdf5', SegmentList, write_hdf5_segmentlist)
register_identifier('hdf5', SegmentList, io_hdf5.identify_hdf5)
register_reader('hdf5', DataQualityFlag, read_hdf5_flag)
register_writer('hdf5', DataQualityFlag, write_hdf5_flag)
register_identifier('hdf5', DataQualityFlag, io_hdf5.identify_hdf5)
register_reader('hdf5', DataQualityDict, read_hdf5_dict)
register_writer('hdf5', DataQualityDict, write_hdf5_dict)
register_identifier('hdf5', DataQualityDict, io_hdf5.identify_hdf5)
datum = str(datum)
t = LIGOTimeGPS(datum)
setattr(row, tcols[0], t.seconds)
setattr(row, tcols[1], t.nanoseconds)
else:
try:
getattr(row, 'set_%s' % colname)(datum)
except AttributeError:
setattr(row, colname, datum)
return row
return row_from_ascii
# register generic ASCII parsing for all tables
for table in TableByName.values():
# register whitespace-delimited ASCII
register_reader(
'ascii', table, table_from_ascii_factory(
table, 'ascii', row_from_ascii_factory(table, None)))
register_identifier('ascii', table, identify_factory('txt', 'txt.gz'))
# register csv
register_reader(
'csv', table, table_from_ascii_factory(
table, 'csv', row_from_ascii_factory(table, ','), delimiter=','))
register_identifier('csv', table, identify_factory('csv', 'csv.gz'))
def register_ascii(obj):
"""Register ASCII I/O methods for given type obj
This factory method registers 'txt' and 'csv' I/O formats with
a reader, writer, and auto-identifier
"""
for form, delim in formats.iteritems():
read_, write_ = ascii_io_factory(obj, delim)
register_identifier(form, obj, identify_factory(form, '%s.gz' % form))
register_writer(form, obj, write_)
register_reader(form, obj, read_)