44import os
55import pickle
66import time
7+ import traceback
78
89import npc_lims
910import numpy as np
@@ -844,7 +845,8 @@ def decode_context_from_units_all_timebins(session,params):
844845 print (session .id + ' done' )
845846
846847 path = upath .UPath (savepath , filename )
847- path .mkdir (parents = True , exist_ok = True )
848+ if not upath .UPath (savepath ).is_dir ():
849+ upath .UPath (savepath ).mkdir (parents = True )
848850 path .write_bytes (
849851 pickle .dumps (svc_results , protocol = pickle .HIGHEST_PROTOCOL )
850852 )
@@ -892,9 +894,10 @@ def decode_context_with_linear_shift(session=None,params=None,trials=None,units=
892894 # generate_labels=params['generate_labels']
893895
894896 logger = logging .getLogger (__name__ )
897+ FORMAT = '%(asctime)s %(message)s'
895898 logging_savepath = os .path .join (savepath ,'log.txt' )
896- logging .basicConfig (filename = logging_savepath ,level = logging .INFO )
897- logger .info ('Starting decoding analysis' )
899+ logging .basicConfig (filename = logging_savepath ,level = logging .DEBUG , format = FORMAT )
900+ logger .debug ('Starting decoding analysis' )
898901
899902 try :
900903
@@ -1064,31 +1067,32 @@ def decode_context_with_linear_shift(session=None,params=None,trials=None,units=
10641067 else :
10651068 areas = units ['structure' ].unique ()
10661069 areas = np .concatenate ([areas ,['all' ]])
1067- elif input_data_type == 'facemap' or input_data_type == 'LP' :
1068- # areas = list(mean_trial_behav_SVD.keys())
1069- areas = [0 ]
10701070
1071- #add non-probe-specific area to areas
1072- all_probe_areas = []
1073- if len (units .query ('structure.str.contains("probe")' ))> 0 :
1074- probe_areas = units .query ('structure.str.contains("probe")' )['structure' ].unique ()
1075- for pa in probe_areas :
1076- all_probe_areas .append ([pa .split ('_' )[0 ]+ '_all' ])
1071+ #add non-probe-specific area to areas
1072+ all_probe_areas = []
1073+ if len (units .query ('structure.str.contains("probe")' ))> 0 :
1074+ probe_areas = units .query ('structure.str.contains("probe")' )['structure' ].unique ()
1075+ for pa in probe_areas :
1076+ all_probe_areas .append ([pa .split ('_' )[0 ]+ '_all' ])
10771077
1078- general_areas = np .unique (np .array (all_probe_areas ))
1079- areas = np .concatenate ([areas ,general_areas ])
1078+ general_areas = np .unique (np .array (all_probe_areas ))
1079+ areas = np .concatenate ([areas ,general_areas ])
10801080
1081- #consolidate SC areas
1082- for aa in areas :
1083- if aa in ['SCop' ,'SCsg' ,'SCzo' ]:
1084- if 'SCs' not in areas :
1085- areas = np .concatenate ([areas ,['SCs' ]])
1086- elif aa in ['SCig' ,'SCiw' ,'SCdg' ,'SCdw' ]:
1087- if 'SCm' not in areas :
1088- areas = np .concatenate ([areas ,['SCm' ]])
1081+ #consolidate SC areas
1082+ for aa in areas :
1083+ if aa in ['SCop' ,'SCsg' ,'SCzo' ]:
1084+ if 'SCs' not in areas :
1085+ areas = np .concatenate ([areas ,['SCs' ]])
1086+ elif aa in ['SCig' ,'SCiw' ,'SCdg' ,'SCdw' ]:
1087+ if 'SCm' not in areas :
1088+ areas = np .concatenate ([areas ,['SCm' ]])
1089+
1090+ elif input_data_type == 'facemap' or input_data_type == 'LP' :
1091+ # areas = list(mean_trial_behav_SVD.keys())
1092+ areas = [0 ]
10891093
10901094 decoder_results [session_id ]['areas' ] = areas
1091-
1095+
10921096 for aa in areas :
10931097 #make shifted trial data array
10941098 if input_data_type == 'spikes' :
@@ -1226,9 +1230,11 @@ def decode_context_with_linear_shift(session=None,params=None,trials=None,units=
12261230 break
12271231
12281232 print (f'finished { session_id } { aa } ' )
1233+
12291234 #save results
1230- path = upath .UPath (savepath , filename )
1231- path .mkdir (parents = True , exist_ok = True )
1235+ path = upath .UPath (savepath , session_id + '_' + filename )
1236+ if not upath .UPath (savepath ).is_dir ():
1237+ upath .UPath (savepath ).mkdir (parents = True )
12321238 path .write_bytes (
12331239 pickle .dumps (decoder_results , protocol = pickle .HIGHEST_PROTOCOL )
12341240 )
@@ -1250,22 +1256,25 @@ def decode_context_with_linear_shift(session=None,params=None,trials=None,units=
12501256 return decoder_results
12511257
12521258 except Exception as e :
1259+ tb_str = traceback .format_exception (e , value = e , tb = e .__traceback__ )
1260+ tb_str = '' .join (tb_str )
12531261 print (f'error in session { session_id } ' )
1254- print (e )
1255- logger .error (f'error in session { session_id } ' )
1256- logger .error ( e )
1262+ print (tb_str )
1263+ logger .debug (f'error in session { session_id } ' )
1264+ logger .debug ( tb_str )
12571265 return None
12581266
12591267
12601268def concat_decoder_results (files ,savepath = None ,return_table = True ,single_session = False ,use_zarr = False ):
12611269
12621270 logger = logging .getLogger (__name__ )
1271+ FORMAT = '%(asctime)s %(message)s'
12631272 if savepath is None :
1264- logging .basicConfig (filename = logging_savepath , level = logging .INFO )
1273+ logging .basicConfig (level = logging .DEBUG , format = FORMAT )
12651274 else :
12661275 logging_savepath = os .path .join (savepath ,'log.txt' )
1267- logging .basicConfig (filename = logging_savepath ,level = logging .INFO )
1268- logger .info ('Making decoder analysis summary tables' )
1276+ logging .basicConfig (filename = logging_savepath ,level = logging .DEBUG , format = FORMAT )
1277+ logger .debug ('Making decoder analysis summary tables' )
12691278
12701279 try :
12711280 use_half_shifts = False
@@ -1488,7 +1497,9 @@ def concat_decoder_results(files,savepath=None,return_table=True,single_session=
14881497 print ('saved decoder results table to:' ,savepath )
14891498
14901499 except Exception as e :
1491- print (e )
1500+ tb_str = traceback .format_exception (e , value = e , tb = e .__traceback__ )
1501+ tb_str = '' .join (tb_str )
1502+ print (tb_str )
14921503 print ('error saving linear shift df' )
14931504
14941505 del decoder_results
@@ -1498,10 +1509,12 @@ def concat_decoder_results(files,savepath=None,return_table=True,single_session=
14981509 return linear_shift_df
14991510
15001511 except Exception as e :
1501- print (e )
1502- print ('error with decoding results' )
1503- logger .error (e )
1504- logger .error ('error with decoding results' )
1512+ tb_str = traceback .format_exception (e , value = e , tb = e .__traceback__ )
1513+ tb_str = '' .join (tb_str )
1514+ print (f'error with decoding results summary for { session_id } ' )
1515+ print (tb_str )
1516+ logger .debug (f'error with decoding results summary for { session_id } ' )
1517+ logger .debug (tb_str )
15051518 return None
15061519
15071520
@@ -1623,12 +1636,13 @@ def compute_significant_decoding_by_area(all_decoder_results):
16231636def concat_trialwise_decoder_results (files ,savepath = None ,return_table = False ,n_units = None ,single_session = False ,use_zarr = False ):
16241637
16251638 logger = logging .getLogger (__name__ )
1639+ FORMAT = '%(asctime)s %(message)s'
16261640 if savepath is None :
1627- logging .basicConfig (filename = logging_savepath , level = logging .INFO )
1641+ logging .basicConfig (level = logging .DEBUG , format = FORMAT )
16281642 else :
16291643 logging_savepath = os .path .join (savepath ,'log.txt' )
1630- logging .basicConfig (filename = logging_savepath ,level = logging .INFO )
1631- logger .info ('Making trialwise decoder analysis summary tables' )
1644+ logging .basicConfig (filename = logging_savepath ,level = logging .DEBUG , format = FORMAT )
1645+ logger .debug ('Making trialwise decoder analysis summary tables' )
16321646
16331647 #load sessions as we go
16341648 try :
@@ -2454,10 +2468,12 @@ def concat_trialwise_decoder_results(files,savepath=None,return_table=False,n_un
24542468 return decoder_confidence_versus_response_type ,decoder_confidence_dprime_by_block ,decoder_confidence_by_switch ,decoder_confidence_versus_trials_since_rewarded_target ,decoder_confidence_before_after_target
24552469
24562470 except Exception as e :
2457- print (e )
2458- print ('error with decoding results' )
2459- logger .error (e )
2460- logger .error ('error with decoding results' )
2471+ tb_str = traceback .format_exception (e , value = e , tb = e .__traceback__ )
2472+ tb_str = '' .join (tb_str )
2473+ print (f'error with trialwise decoding results summary for { session_id } ' )
2474+ print (tb_str )
2475+ logger .debug (f'error with trialwise decoding results summary for { session_id } ' )
2476+ logger .debug (tb_str )
24612477 return None
24622478
24632479
0 commit comments