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))
except ImportError: Cache = None else: Cache.entry_class = CacheEntry # find test GWF file TEST_PATH = Path(os.getenv( "LAL_TEST_SRCDIR", Path(__file__).parent, )).absolute().parent TEST_GWF = TEST_PATH / "F-TEST-600000060-60.gwf" # parametrize sources SOURCES = [ str(TEST_GWF), lal.CacheGlob(str(TEST_GWF.parent), TEST_GWF.name), ] if Cache is not None: SOURCES.append(Cache([CacheEntry.from_T050017(str(TEST_GWF))])) @pytest.mark.parametrize("source", SOURCES) def test_read_timeseries(source): ts = frread.read_timeseries( source, "H1:LSC-AS_Q", ) assert ts.name == "H1:LSC-AS_Q" assert ts.data.length == 16384 * 60 assert ts.deltaT == 6.103515625e-05