one.util¶
Decorators and small standalone functions for api module
Functions
Validate search term and return complete name, e.g. |
|
Extract datasets DataFrame from one or more Alyx dataset records |
|
Ensure input is a list |
|
Filter the datasets cache table by the relative path (dataset name, collection and revision). |
|
Filter datasets by revision, returning previous revision in ordered list if revision doesn’t exactly match. |
|
Returns the index of string that occurs directly before the provided revision string when lexicographic sorted. |
|
Ensures the input experiment identifier is an experiment UUID string |
|
Refresh cache depending of query_type kwarg |
|
Extract session cache record and datasets cache from a remote session data record TODO Fix for new tables; use to update caches from remote queries |
|
Validates and arrange date range in a 2 elements list |
Classes
Using a paginated response object or list of session records, extracts eid string when required |
-
ses2records
(ses: dict) → [<class ‘pandas.core.series.Series’>, <class ‘pandas.core.frame.DataFrame’>][source]¶ Extract session cache record and datasets cache from a remote session data record TODO Fix for new tables; use to update caches from remote queries
- Parameters
ses – session dictionary from rest endpoint
- Returns
session record, datasets frame
-
datasets2records
(datasets) → pandas.core.frame.DataFrame[source]¶ Extract datasets DataFrame from one or more Alyx dataset records
- Parameters
datasets (dict, list) – One or more records from the Alyx ‘datasets’ endpoint
- Returns
- Return type
Datasets frame
Examples
datasets = one.alyx.rest(‘datasets’, ‘list’, subject=’foobar’) df = datasets2records(datasets)
-
parse_id
(method)[source]¶ Ensures the input experiment identifier is an experiment UUID string
- Parameters
method (function) – An ONE method whose second arg is an experiment ID
- Returns
- Return type
A wrapper function that parses the ID to the expected string
-
validate_date_range
(date_range)[source]¶ Validates and arrange date range in a 2 elements list
Examples
_validate_date_range(‘2020-01-01’) # On this day _validate_date_range(datetime.date(2020, 1, 1)) _validate_date_range(np.array([‘2022-01-30’, ‘2022-01-30’], dtype=’datetime64[D]’)) _validate_date_range(pd.Timestamp(2020, 1, 1)) _validate_date_range(np.datetime64(2021, 3, 11)) _validate_date_range([‘2020-01-01’]) # from date _validate_date_range([‘2020-01-01’, None]) # from date _validate_date_range([None, ‘2020-01-01’]) # up to date
-
filter_datasets
(all_datasets, filename=None, collection=None, revision=None, revision_last_before=True, assert_unique=True, wildcards=False)[source]¶ Filter the datasets cache table by the relative path (dataset name, collection and revision). When None is passed, all values will match. To match on empty parts, use an empty string. When revision_last_before is true, None means return latest revision.
- Parameters
all_datasets (pandas.DataFrame) – A datasets cache table
filename (str, dict, None) – A filename str or a dict of alf parts. Regular expressions permitted.
collection (str, None) – A collection string. Regular expressions permitted.
revision (str, None) – A revision string to match. If revision_last_before is true, regular expressions are not permitted.
revision_last_before (bool) – When true and no exact match exists, the (lexicographically) previous revision is used instead. When false the revision string is matched like collection and filename, with regular expressions permitted.
assert_unique (bool) – When true an error is raised if multiple collections or datasets are found
wildcards (bool) – If true, use unix shell style matching instead of regular expressions
- Returns
- Return type
A slice of all_datasets that match the filters
Examples
# Filter by dataset name and collection datasets = filter_datasets(all_datasets, ‘.spikes.times.’, ‘alf/probe00’) # Filter datasets not in a collection datasets = filter_datasets(all_datasets, collection=’’) # Filter by matching revision datasets = filter_datasets(all_datasets, ‘spikes.times.npy’,
revision=’2020-01-12’, revision_last_before=False)
# Filter by filename parts datasets = filter_datasets(all_datasets, {object=’spikes’, attribute=’times’})
-
filter_revision_last_before
(datasets, revision=None, assert_unique=True)[source]¶ Filter datasets by revision, returning previous revision in ordered list if revision doesn’t exactly match.
- Parameters
datasets (pandas.DataFrame) – A datasets cache table
revision (str) – A revision string to match (regular expressions not permitted)
assert_unique (bool) – When true an alferr.ALFMultipleRevisionsFound exception is raised when multiple default revisions are found; an alferr.ALFError when no default revision is found
- Returns
- Return type
A datasets DataFrame with 0 or 1 row per unique dataset
-
index_last_before
(revisions: List[str], revision: Optional[str]) → Optional[int][source]¶ Returns the index of string that occurs directly before the provided revision string when lexicographic sorted. If revision is None, the index of the most recent revision is returned.
- Parameters
revisions (list of strings) – A list of revision strings
revision (None, str) – The revision string to match on
- Returns
- Return type
Index of revision before matching string in sorted list or None
Examples
idx = _index_last_before([], ‘2020-08-01’)