Skip to content

Commit

Permalink
Merge pull request #147 from AllenInstitute/feature-channel_timestamps
Browse files Browse the repository at this point in the history
Fix for Pamela's Barcode Paths
  • Loading branch information
Ahad-Allen committed Aug 16, 2023
2 parents bd2bc9e + 956917c commit 99ba522
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 7 deletions.
17 changes: 15 additions & 2 deletions scripts/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,27 @@
python_path + " -d " + utils_dir + " -v " + proj_dandi_value
print(shlex.split(cmd))
subprocess.call(shlex.split(cmd))
fb.update_session_status(project, session, "Conversion Running")

# Trigger uploads for sessions with upload status
print("List of sessions to upload")
upload_list = fb.get_dandi_statuses()
for session in upload_list:
dandi_file = fb.view_session(project, sess)['allen']
match = re.search(r'specimen_(\d+)', fb.view_session(project, sess)['path'])
if match:
specimen_number = match.group(1)
with open("dandi_ephys_uploads.py") as upload:
code = compile(upload.read(), "dandi_ephys_uploads.py", "exec")
exec(code, {"dandi_val": proj_dandi_value, "sess_id":session, "dandi_file": dandi_file, "subject_id": specimen_number})
dandi.find_dandiset_sessions(project, proj_dandi_value)
fb.update_session_status(project, session, "Conversion Running")

Check failure on line 117 in scripts/cron.py

View workflow job for this annotation

GitHub Actions / Flake8

scripts/cron.py#L117

IndentationError: unexpected indent (E999)

# Update the dandi locations for the project
dandi.find_dandiset_sessions(project, proj_dandi_value)



for project in o_proj_list:
current_dir = os.path.abspath(__file__)
current_dir = current_dir.replace('scripts/cron.py', '')
Expand Down Expand Up @@ -204,6 +219,4 @@
subprocess.run(shlex.split(cmd))
fb.update_session_status(
project, session, "Raw Conversion Running")

# Update the dandi locations for the project
dandi.find_dandiset_sessions(project, proj_dandi_value)
11 changes: 6 additions & 5 deletions src/openscopenwb/ecephys_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,16 @@ def ecephys_align_timestamps(module_params):
})
print("File was found: " + str(file_found))
if (file_found):
channel_states_path = glob(join(module_params['base_directory'],
'**/**' + probe_idx, '**/**', "*channel_states.npy"), recursive=True)[0]

Check failure on line 308 in src/openscopenwb/ecephys_modules.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/ecephys_modules.py#L308

Line too long (112 > 79 characters) (E501)
timestamp_path = glob(join(module_params['base_directory'],
'**/**' + probe_idx, '**/**', "*stamps.npy"), recursive=True)[0]

Check failure on line 310 in src/openscopenwb/ecephys_modules.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/ecephys_modules.py#L310

Continuation line over-indented for visual indent (E127)

Check failure on line 310 in src/openscopenwb/ecephys_modules.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/ecephys_modules.py#L310

Line too long (104 > 79 characters) (E501)
probe_dict = {
'name': probe_idx,
'sampling_rate': 30000.,
'lfp_sampling_rate': 2500.,
'barcode_channel_states_path': join(events_directory,
'channel_states.npy'),
'barcode_timestamps_path': join(
events_directory,
'event_timestamps.npy'),
'barcode_channel_states_path': channel_states_path,
'barcode_timestamps_path': timestamp_path,
'mappable_timestamp_files': timestamp_files
}

Expand Down
118 changes: 118 additions & 0 deletions src/openscopenwb/utils/dandi_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import os
import re

import fsspec

Check failure on line 4 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L4

'fsspec' imported but unused (F401)
import h5py

Check failure on line 5 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L5

'h5py' imported but unused (F401)
import pandas as pd

Check failure on line 6 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L6

'pandas as pd' imported but unused (F401)
import json
import shutil

Check failure on line 8 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L8

'shutil' imported but unused (F401)
import time

Check failure on line 9 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L9

'time' imported but unused (F401)


from pathlib import Path

Check failure on line 12 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L12

'pathlib.Path' imported but unused (F401)
from dandi import dandiapi
from fsspec.implementations.cached import CachingFileSystem

Check failure on line 14 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L14

'fsspec.implementations.cached.CachingFileSystem' imported but unused (F401)
from pynwb import NWBHDF5IO

Check failure on line 15 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L15

'pynwb.NWBHDF5IO' imported but unused (F401)
from pynwb.base import Images

Check failure on line 16 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L16

'pynwb.base.Images' imported but unused (F401)
from glob import glob

Check failure on line 17 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L17

'glob.glob' imported but unused (F401)
from os.path import join

Check failure on line 18 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L18

'os.path.join' imported but unused (F401)
from shutil import rmtree

Check failure on line 19 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L19

'shutil.rmtree' imported but unused (F401)

from openscopenwb.utils import clean_up_functions as cuf
from openscopenwb.utils import firebase_functions as fb


from dandi.dandiapi import DandiAPIClient as dandi

Check failure on line 25 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L25

'dandi.dandiapi.DandiAPIClient as dandi' imported but unused (F401)
def check_sess_info(project, dandi_id, path):

Check failure on line 26 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L26

Expected 2 blank lines, found 0 (E302)
"""Update a session's dandi location
Parameters
----------
project : str
The project id
dandi_id : str
The dandi id
path : str
The path to the file
Returns
-------
"""
if "probe" in path:
return None
sess_id = ""
sub_id = ""
print(str(path))
match = re.search(r'ses-(\d+)', str(path))
if match:
sess_id = match.group(1)
print("Session ID: " + sess_id)
else:
print("Session ID not found.")
if sess_id == "":
return None
if project !='OpenScopeDendriteCoupling':

Check failure on line 54 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L54

Missing whitespace around operator (E225)
fb.update_session_dandi(project, sess_id, str(path))
else:
match = re.search(r'sub-(\d+)', str(path))
if match:
sub_id = match.group(1)
print(sub_id)
fb.update_session_dandi(project, sess_id, r'https://dandiarchive.org/dandiset/000336/draft/files?location=' + "sub-" + sub_id )

Check failure on line 61 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L61

Line too long (139 > 79 characters) (E501)

Check failure on line 61 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L61

Whitespace before ')' (E202)

Check failure on line 61 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L61

Trailing whitespace (W291)
return None

def find_dandiset_sessions(project, dandi_id):

Check failure on line 64 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L64

Expected 2 blank lines, found 1 (E302)
"""Update a project's dandi locations
Parameters
----------
project : str
The project id
dandi_id : str
The dandi id
Returns
-------
"""
os.environ['DANDI_API_KEY'] = cuf.get_creds()
dandi_api_key = os.environ['DANDI_API_KEY']
my_dandiset = dandiapi.DandiAPIClient(
token=dandi_api_key).get_dandiset(dandi_id)
for file in my_dandiset.get_assets():
path = file.path
check_sess_info(project, dandi_id, path)

def generate_exp_list(project, dandi_id):

Check failure on line 85 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L85

Expected 2 blank lines, found 1 (E302)
os.environ['DANDI_API_KEY'] = cuf.get_creds()
dandi_api_key = os.environ['DANDI_API_KEY']

Check failure on line 87 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L87

Trailing whitespace (W291)
my_dandiset = dandiapi.DandiAPIClient(token=dandi_api_key).get_dandiset(dandi_id)

Check failure on line 88 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L88

Line too long (85 > 79 characters) (E501)

Check failure on line 89 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L89

Blank line contains whitespace (W293)
session_experiments = {} # Dictionary to store experiments per session

Check failure on line 91 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L91

Blank line contains whitespace (W293)
for file in my_dandiset.get_assets():
path = file.path
match = re.search(r'ses-(\d+)', str(path))
if match:
sess_id = match.group(1)
else:
print("ses_id not found for: " + str(path))
continue
match = re.search(r'acq-(\d+)', str(path))
if match:
exp_id = match.group(1)
else:
print("exp_id not found for: " + str(path))
continue

Check failure on line 106 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L106

Blank line contains whitespace (W293)
if sess_id not in session_experiments:
session_experiments[sess_id] = [] # Create an empty list for a new session

Check failure on line 108 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L108

Line too long (87 > 79 characters) (E501)
if exp_id not in session_experiments[sess_id]: # Check if the experiment ID is not already present

Check failure on line 109 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L109

Line too long (107 > 79 characters) (E501)
session_experiments[sess_id].append(exp_id)

Check failure on line 110 in src/openscopenwb/utils/dandi_functions.py

View workflow job for this annotation

GitHub Actions / Flake8

src/openscopenwb/utils/dandi_functions.py#L110

Trailing whitespace (W291)
for i in session_experiments:
session_experiments[i].append(len(session_experiments[i]))
return session_experiments


def save_as_json(session_experiments, filename):
with open(filename, 'w') as file:
json.dump(session_experiments, file)

0 comments on commit 99ba522

Please sign in to comment.