Skip to content
Snippets Groups Projects
Commit 6c0e7579 authored by Patrick Godwin's avatar Patrick Godwin Committed by Patrick Godwin
Browse files

datafind.py: allow searching for files in DataCache by extension

parent d8bda01b
No related branches found
No related tags found
1 merge request!115Change inspiral DAG architecture regarding expected SNR calc, simplify generation of workflows, add documentation
......@@ -49,8 +49,10 @@ class DataFileMixin:
extension = self.extension
return T050017_filename(ifos, self.description(svd_bin, subtype), span, extension)
def file_pattern(self, svd_bin=None, subtype=None):
return f"*-{self.description(svd_bin, subtype)}-*-*{self.extension}"
def file_pattern(self, svd_bin=None, subtype=None, extension=None):
if not extension:
extension = self.extension
return f"*-{self.description(svd_bin, subtype)}-*-*{extension}"
def directory(self, root=None, start=None):
path = self.name.lower()
......@@ -217,7 +219,7 @@ class DataCache:
return cls(name, [CacheEntry.from_T050017(entry) for entry in cache])
@classmethod
def find(cls, name, start=None, end=None, root=None, segments=None, svd_bins=None, subtype=None):
def find(cls, name, start=None, end=None, root=None, segments=None, svd_bins=None, extension=None, subtype=None):
cache = []
if svd_bins:
svd_bins = set([svd_bins]) if isinstance(svd_bins, str) else set(svd_bins)
......@@ -227,8 +229,8 @@ class DataCache:
subtype = [subtype]
for svd_bin in svd_bins:
for stype in subtype:
cache.extend(glob.glob(cls._glob_path(name, root, svd_bin, stype)))
cache.extend(glob.glob(cls._glob_path(name, root, svd_bin, stype, gps_dir=False)))
cache.extend(glob.glob(cls._glob_path(name, root, svd_bin, stype, extension=extension)))
cache.extend(glob.glob(cls._glob_path(name, root, svd_bin, stype, extension=extension, gps_dir=False)))
cache = [CacheEntry.from_T050017(entry) for entry in cache]
if segments:
......@@ -249,11 +251,11 @@ class DataCache:
return path
@staticmethod
def _glob_path(name, root=None, svd_bin=None, subtype=None, gps_dir=True):
def _glob_path(name, root=None, svd_bin=None, subtype=None, extension=None, gps_dir=True):
if gps_dir:
glob_path = os.path.join(str(name).lower(), "*", name.file_pattern(svd_bin, subtype))
glob_path = os.path.join(str(name).lower(), "*", name.file_pattern(svd_bin, subtype, extension=extension))
else:
glob_path = os.path.join(str(name).lower(), name.file_pattern(svd_bin, subtype))
glob_path = os.path.join(str(name).lower(), name.file_pattern(svd_bin, subtype, extension=extension))
if root:
glob_path = os.path.join(root, glob_path)
return glob_path
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment