-
Notifications
You must be signed in to change notification settings - Fork 9
OneSdsc usability: specifying locations (popeye/SDSC) by kwarg, rest caching disabled by default #121
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
Open
grg2rsr
wants to merge
3
commits into
develop
Choose a base branch
from
OneSDSC_locations
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
OneSdsc usability: specifying locations (popeye/SDSC) by kwarg, rest caching disabled by default #121
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,36 +6,63 @@ | |
| - the cache is read-only | ||
| - the cache is a constant | ||
| - each file is stored with an UUID between the file stem and the extension | ||
| - rest caching is disabled by default (no write permissions from popeye) | ||
|
|
||
| The limitations of this implementation are: | ||
| - alfio.load methods will load objects with long keys containing UUIDS | ||
|
|
||
| Note: | ||
| - use the location kwarg to specify if you are datauser on SDSC or regular user on popeye | ||
|
|
||
| Recommended usage: just monkey patch the ONE import and run your code as usual on Popeye ! | ||
| >>> from deploy.iblsdsc import OneSdsc as ONE | ||
| """ | ||
|
|
||
| import logging | ||
| from pathlib import Path | ||
| from itertools import filterfalse | ||
|
|
||
| from one.api import OneAlyx | ||
| from one.alf.spec import is_uuid_string | ||
| import one.params | ||
|
|
||
| from ibllib.oneibl.patcher import SDSC_ROOT_PATH | ||
| from typing import Literal | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
| CACHE_DIR = Path('/mnt/sdceph/users/ibl/data') | ||
| CACHE_DIR_FI = Path(SDSC_ROOT_PATH) | ||
| CACHE_DIR_POPEYE = Path("/mnt/sdceph/users/ibl/data") | ||
| CACHE_DIR_SDSC = Path("/mnt/ibl") | ||
|
|
||
| # keeping those variables for downward compatibility | ||
| CACHE_DIR = CACHE_DIR_POPEYE | ||
| CACHE_DIR_FI = CACHE_DIR_SDSC | ||
|
|
||
|
|
||
| class OneSdsc(OneAlyx): | ||
| def __init__( | ||
| self, | ||
| *args, | ||
| cache_dir: str | Path = CACHE_DIR_POPEYE, | ||
| location: Literal["popeye", "SDSC"] = "popeye", | ||
| disable_rest_caching: bool = True, | ||
| **kwargs, | ||
| ): | ||
| # set cache dir according to location | ||
| if location == "popeye": | ||
| if cache_dir is not None and cache_dir != CACHE_DIR_POPEYE: | ||
| raise ValueError("both location and cache dir are specified, and they are incompatible") | ||
| cache_dir = CACHE_DIR_POPEYE | ||
| elif location == "SDSC": | ||
| if cache_dir is not None and cache_dir != CACHE_DIR_SDSC: | ||
| raise ValueError("both location and cache dir are specified, and they are incompatible") | ||
| cache_dir = CACHE_DIR_SDSC | ||
|
|
||
| def __init__(self, *args, cache_dir=CACHE_DIR, **kwargs): | ||
| if not kwargs.get('tables_dir'): | ||
| if not kwargs.get("tables_dir"): | ||
| # Ensure parquet tables downloaded to separate location to the dataset repo | ||
| kwargs['tables_dir'] = one.params.get_cache_dir() # by default this is user downloads | ||
| kwargs["tables_dir"] = one.params.get_cache_dir() # by default this is user downloads | ||
| if disable_rest_caching: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to overload the original kwarg rather than adding a new one to avoid parameter conflicts. You could simply add |
||
| kwargs["cache_rest"] = None | ||
|
|
||
| super().__init__(*args, cache_dir=cache_dir, **kwargs) | ||
| self.alyx.rest_cache_dir = self._tables_dir / '.rest' | ||
| self.alyx.rest_cache_dir = self._tables_dir / ".rest" | ||
| # assign property here as it is set by the parent OneAlyx class at init | ||
| self.uuid_filenames = True | ||
|
|
||
|
|
@@ -46,7 +73,7 @@ def load_object(self, *args, **kwargs): | |
| return obj | ||
| # pops the UUID in the key names | ||
| for k in list(obj.keys()): | ||
| new_key = '.'.join(filterfalse(is_uuid_string, k.split('.'))) | ||
| new_key = ".".join(filterfalse(is_uuid_string, k.split("."))) | ||
| obj[new_key] = obj.pop(k) | ||
| return obj | ||
|
|
||
|
|
@@ -62,18 +89,19 @@ def _test_one_sdsc(): | |
| :return: | ||
| """ | ||
| from brainbox.io.one import SpikeSortingLoader, SessionLoader | ||
|
|
||
| one = OneSdsc() | ||
| pid = "069c2674-80b0-44b4-a3d9-28337512967f" | ||
| eid, _ = one.pid2eid(pid) | ||
| dsets = one.list_datasets(eid=eid) | ||
| assert len(dsets) > 0 | ||
| # checks that this is indeed the short key version when using load object | ||
| trials = one.load_object(eid, obj='trials') | ||
| assert 'intervals' in trials | ||
| trials = one.load_object(eid, obj="trials") | ||
| assert "intervals" in trials | ||
| # checks that this is indeed the short key version when using the session loader and spike sorting loader | ||
| sl = SessionLoader(eid=eid, one=one) # noqa | ||
| sl.load_wheel() | ||
| assert 'position' in sl.wheel.columns | ||
| assert "position" in sl.wheel.columns | ||
| ssl = SpikeSortingLoader(pid=pid, one=one) | ||
| spikes, clusters, channels = ssl.load_spike_sorting() # noqa | ||
| assert 'amps' in spikes | ||
| assert "amps" in spikes | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you've changed the default to popeye. You should make others aware of this.
Also all previous code will raise a value error because neither cache_dir, nor location are None by default so if they pass in any other cache dir path without passing location=None they're get a value error. Personally I find having two related parameters confusing and a little redundant given that you've already renamed the cache dir variables to clearer names. If this location field is not used for anything else I'd rather remove it