Skip to content

Commit

Permalink
Add skip existing param to decoding with linear shift
Browse files Browse the repository at this point in the history
  • Loading branch information
bjhardcastle committed Dec 5, 2024
1 parent 6f23a6c commit 68d5cbb
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/dynamic_routing_analysis/decoding_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ def decode_context_from_units_all_timebins(session,params):
# incorporate additional parameters
# add option to decode from timebins
# add option to use inputs with top decoding weights (use_coefs)
def decode_context_with_linear_shift(session=None,params=None,trials=None,units=None,session_info=None,use_zarr=False):
def decode_context_with_linear_shift(session=None,params=None,trials=None,units=None,session_info=None,use_zarr=False, skip_existing=True):

decoder_results={}

Expand Down Expand Up @@ -903,6 +903,11 @@ def decode_context_with_linear_shift(session=None,params=None,trials=None,units=
elif session_info is not None:
session_id=str(session_info.id)

path = upath.UPath(savepath) / f"{session_id}_{filename}.pkl"
if skip_existing and path.exists():
print(f'Skipping {session_id} as {path} already exists and skip_existing=True')
return

##Option to input session or trials/units/session_info directly
##note: inputting session may not work with Code Ocean

Expand Down Expand Up @@ -1216,10 +1221,8 @@ def decode_context_with_linear_shift(session=None,params=None,trials=None,units=
print(f'finished {session_id} {aa}')
#save results
#make directory if does not exist
if not upath.UPath(savepath).is_dir():
upath.UPath(savepath).mkdir(parents=True)

(upath.UPath(savepath) / f"{session_id}_{filename}.pkl").write_bytes(
path.parent.mkdir(parents=True, exist_ok=True)
path.write_bytes(
pickle.dumps(decoder_results, protocol=pickle.HIGHEST_PROTOCOL)
)
if use_zarr:
Expand Down

0 comments on commit 68d5cbb

Please sign in to comment.