def open_data_source(source): """Open a GWF file source into a `lalframe.XLALFrStream` object Parameters ---------- source : `str`, `file`, `list` Data source to read. Returns ------- stream : `lalframe.FrStream` An open `FrStream`. Raises ------ ValueError If the input format cannot be identified. """ # -- preformatting try: source = file_path(source) except ValueError: # not parsable as a single file pass # import cache from file if ( isinstance(source, str) and source.endswith(('.lcf', '.cache')) ): source = lal.CacheImport(source) # reformat cache (or any list of files) as a lal cache object if isinstance(source, list) and is_cache(source): cache = lal.Cache() for entry in file_list(source): cache = lal.CacheMerge(cache, lal.CacheGlob(*os.path.split(entry))) source = cache # -- now we have a lal.Cache or a filename # read lal cache object if isinstance(source, lal.Cache): return lalframe.FrStreamCacheOpen(source) # read single file if isinstance(source, str): return lalframe.FrStreamOpen(*map(str, os.path.split(source))) raise ValueError("Don't know how to open data source of type %r" % type(source))
def open_data_source(source): """Open a GWF file source into a `lalframe.XLALFrStream` object Parameters ---------- source : `str`, `file`, `lal.Cache`, :class:`glue.lal.Cache` data source to read Returns ------- stream : `lalframe.FrStream` an open `FrStream` Raises ------ ValueError if the input format cannot be identified """ if isinstance(source, FILE_LIKE): source = source.name if isinstance(source, GlueCacheEntry): source = source.path # read cache file if (isinstance(source, string_types) and source.endswith( ('.lcf', '.cache'))): return lalframe.FrStreamCacheOpen(lal.CacheImport(source)) # read glue cache object if isinstance(source, GlueCache): cache = lal.Cache() for entry in source: cache = lal.CacheMerge(cache, lal.CacheGlob(*os.path.split(entry.path))) return lalframe.FrStreamCacheOpen(cache) # read lal cache object if isinstance(source, lal.Cache): return lalframe.FrStreamCacheOpen(source) # read single file if isinstance(source, string_types): return lalframe.FrStreamOpen(*os.path.split(source)) raise ValueError("Don't know how to open data source of type %r" % type(source))
def open_data_source(source): """Open a GWF file source into a `lalframe.XLALFrStream` object Parameters ---------- source : `str`, `file`, `list` Data source to read. Returns ------- stream : `lalframe.FrStream` An open `FrStream`. Raises ------ ValueError If the input format cannot be identified. """ if isinstance(source, io_cache.FILE_LIKE): source = source.name if isinstance(source, CacheEntry): source = source.path # read cache file if (isinstance(source, string_types) and source.endswith(('.lcf', '.cache'))): return lalframe.FrStreamCacheOpen(lal.CacheImport(source)) # read glue cache object if isinstance(source, list) and io_cache.is_cache(source): cache = lal.Cache() for entry in io_cache.file_list(source): cache = lal.CacheMerge(cache, lal.CacheGlob(*os.path.split(entry))) return lalframe.FrStreamCacheOpen(cache) # read lal cache object if isinstance(source, lal.Cache): return lalframe.FrStreamCacheOpen(source) # read single file if isinstance(source, string_types): return lalframe.FrStreamOpen(*map(str, os.path.split(source))) raise ValueError("Don't know how to open data source of type %r" % type(source))