Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch data sets based on run_id. Modif. in select_runs #192

Merged
merged 3 commits into from
Jun 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 18 additions & 8 deletions strax/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,13 +916,14 @@ def scan_runs(self,

return self.runs

def select_runs(self, run_mode=None,
def select_runs(self, run_mode=None, run_id=None,
include_tags=None, exclude_tags=None,
available=tuple(),
pattern_type='fnmatch', ignore_underscore=True):
"""Return pandas.DataFrame with basic info from runs
that match selection criteria.
:param run_mode: Pattern to match run modes (reader.ini.name)
:param run_id: Pattern to match a run_id or run_ids
:param available: str or tuple of strs of data types for which data
must be available according to the runs DB.

Expand Down Expand Up @@ -957,16 +958,25 @@ def select_runs(self, run_mode=None,
if pattern_type not in ('re', 'fnmatch'):
raise ValueError("Pattern type must be 're' or 'fnmatch'")

if run_mode is not None:
modes = dsets['mode'].values
mask = np.zeros(len(modes), dtype=np.bool_)

# get the data set for either run_ids only or given mode only or for both
for field_name, requested_value in (('run_id', run_id), ('mode', run_mode)):

if requested_value is None:
continue

values = dsets[field_name].values
mask = np.zeros(len(values), dtype=np.bool_)

if pattern_type == 'fnmatch':
for i, x in enumerate(modes):
mask[i] = fnmatch.fnmatch(x, run_mode)
for i, x in enumerate(values):
mask[i] = fnmatch.fnmatch(x, requested_value)
elif pattern_type == 're':
for i, x in enumerate(modes):
mask[i] = bool(re.match(run_mode, x))
for i, x in enumerate(values):
mask[i] = bool(re.match(requested_value, x))

dsets = dsets[mask]


if include_tags is not None:
dsets = dsets[_tags_match(dsets,
Expand Down