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

Remove kachery storage check, fix name splitting, fix sample rate calc #333

Merged
merged 9 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/spyglass/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@
# Important to do this so that we add the franklab namespace for pynwb
# Note: This is franklab-specific
import ndx_franklab_novela

from .data_import.insert_sessions import insert_sessions
from .data_import.storage_dirs import base_dir, check_env, kachery_storage_dir
4 changes: 2 additions & 2 deletions src/spyglass/common/common_ephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def make(self, key):
interval_dict['nwb_file_name'] = key['nwb_file_name']
interval_dict['interval_list_name'] = raw_interval_name
if rawdata.rate is not None:
interval_dict['valid_times'] = np.array([[0, len(rawdata.data)*rawdata.rate]])
interval_dict['valid_times'] = np.array([[0, len(rawdata.data)/rawdata.rate]])
else:
# get the list of valid times given the specified sampling rate.
interval_dict['valid_times'] = get_valid_intervals(np.asarray(rawdata.timestamps), key['sampling_rate'],
Expand All @@ -159,7 +159,7 @@ def make(self, key):
key['raw_object_id'] = rawdata.object_id
key['sampling_rate'] = sampling_rate
print(
f'Importing raw data: Estimated sampling rate:\t{key["sampling_rate"]} Hz')
f'Importing raw data: Sampling rate:\t{key["sampling_rate"]} Hz')
print(
f'Number of valid intervals:\t{len(interval_dict["valid_times"])}')
key['interval_list_name'] = raw_interval_name
Expand Down
5 changes: 3 additions & 2 deletions src/spyglass/common/common_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ def insert_from_name(cls, full_name):
"""
labmember_dict = dict()
labmember_dict['lab_member_name'] = full_name
labmember_dict['first_name'] = str.split(full_name)[:-1]
rly marked this conversation as resolved.
Show resolved Hide resolved
labmember_dict['last_name'] = str.split(full_name)[-1]
full_name_split = str.split(full_name)
labmember_dict['first_name'] = " ".join(full_name_split[:-1])
labmember_dict['last_name'] = full_name_split[-1]
cls.insert1(labmember_dict, skip_duplicates=True)


Expand Down
8 changes: 7 additions & 1 deletion src/spyglass/common/populate_all_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,27 @@ def populate_all_common(nwb_file_name):
# Insert session one by one
fp = [(Nwbfile & {'nwb_file_name': nwb_file_name}).proj()]
print('Populate Session...')
# Session().populate()
Session.populate(fp)

# If we use Kachery for data sharing we can uncomment the following two lines. TBD
# print('Populate NwbfileKachery...')
# NwbfileKachery.populate()

print('Populate ExperimenterList...')
ExperimenterList.populate(fp)

print('Populate ElectrodeGroup...')
ElectrodeGroup.populate(fp)

print('Populate Electrode...')
Electrode.populate(fp)

print('Populate Raw...')
Raw.populate(fp)

print('Populate SampleCount...')
SampleCount.populate(fp)

print('Populate DIOEvents...')
DIOEvents.populate(fp)
# sensor data (from analog ProcessingModule) is temporarily removed from NWBFile
Expand Down
2 changes: 1 addition & 1 deletion src/spyglass/data_import/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .insert_sessions import insert_sessions
from .storage_dirs import base_dir, check_env, kachery_storage_dir
from .storage_dirs import base_dir, check_env
7 changes: 4 additions & 3 deletions src/spyglass/data_import/insert_sessions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Union, List
import os
import stat
import warnings
Expand All @@ -8,14 +9,14 @@
from .storage_dirs import check_env


def insert_sessions(nwb_file_names):
def insert_sessions(nwb_file_names: Union[str, List[str]]):
"""
Populate the dj database with new sessions.

Parameters
----------
nwb_file_names : string or List of strings
nwb_file_names is a list of relative file paths, relative to $SPYGLASS_BASE_DIR, pointing to
nwb_file_names : str or List of str
File paths (relative to $SPYGLASS_BASE_DIR) pointing to
existing .nwb files. Each file represents a session.
"""
check_env()
Expand Down
31 changes: 0 additions & 31 deletions src/spyglass/data_import/storage_dirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ def check_env():
Raise an exception if not.
"""
base_dir()
# kachery_storage_dir()


def base_dir():
Expand All @@ -18,36 +17,6 @@ def base_dir():
p = os.getenv('SPYGLASS_BASE_DIR', None)
assert p is not None, '''
You must set the SPYGLASS_BASE_DIR environment variable.
You MUST also set the $KACHERY_STORAGE_DIR environment variable
to be equal to $SPYGLASS_BASE_DIR/kachery-storage
'''
return p


def kachery_storage_dir():
"""Get the kachery storage directory from $KACHERY_STORAGE_DIR
And verifies that it is equal to $SPYGLASS_BASE_DIR/kachery-storage
Raise an exception if not.

Returns:
str: The kachery storage directory
"""
base = base_dir()
p = os.getenv('KACHERY_STORAGE_DIR', None)
assert p is not None, '''
You must set the KACHERY_STORAGE_DIR environment variable.
And it should be equal to $SPYGLASS_BASE_DIR/kachery-storage
'''

assert p == os.path.join(base, 'kachery-storage'), f'''
Although KACHERY_STORAGE_DIR is set, it is not equal to $SPYGLASS_BASE_DIR/kachery-storage

Current values:
SPYGLASS_BASE_DIR={base}
KACHERY_STORAGE_DIR={p}

You must update these variables before proceeding
'''
if not os.path.exists(p):
os.mkdir(p)
return p