m-beau / NeuroPyxels

NeuroPyxels (npyx) is a python library built for electrophysiologists using Neuropixels electrodes. This package stems from the need of a pythonist who really did not want to transition to MATLAB to work with Neuropixels: it features a suite of core utility functions for loading, processing and plotting Neuropixels data.
GNU General Public License v3.0
112 stars 27 forks source link

Error when explore functional connectivity between neurons #379

Closed Virginia9733 closed 5 months ago

Virginia9733 commented 6 months ago

Thank you so much for the great tool!

When I tried the NeuroPyxels quickstart.ipnyb, I have some errors:

2.4 - Easily explore functional connectivity between neurons

CCGs parameters

cbin=0.5 cwin=100 n_consec_bins=3 corr_type='inhibitions' #'synchrony'

significance test parameters

p_th=0.01 fract_baseline=4./5 W_sd=10 test='Poisson_Stark'

mfr_th = 40

units=[u for u in get_units(dp) if mfr(dp,u)>mfr_th] print(f'Found {len(units)} units above {mfr_th}Hz.')

fig=plot_sfcm(dp, corr_type=corr_type, metric='amp_z', cbin=cbin, cwin=cwin, p_th=p_th, n_consec_bins=n_consec_bins, fract_baseline=fract_baseline, W_sd=W_sd, test=test, drop_seq=['sign', 'time', 'max_amplitude'], units=units, name=f'all_unitsmove{mfr_th}Hz', text=False, markers=False, ticks=True, depth_ticks=False, regions={},reg_colors={}, vminmax=[-7,7], figsize=(4,4), saveFig=False, saveDir=dp, again=False, againCCG=0, use_template_for_peakchan=True, periods='all')


Error:

Looking for significant CCGs over 16 cores: 0%| | 0/136 [00:00<?, ?it/s]

_RemoteTraceback Traceback (most recent call last) _RemoteTraceback: """ Traceback (most recent call last): File "C:\Users\muhang\miniconda3\envs\npyx\lib\site-packages\joblib\externals\loky\process_executor.py", line 463, in _process_worker r = call_item() File "C:\Users\muhang\miniconda3\envs\npyx\lib\site-packages\joblib\externals\loky\process_executor.py", line 291, in call return self.fn(*self.args, self.kwargs) File "C:\Users\muhang\miniconda3\envs\npyx\lib\site-packages\joblib\parallel.py", line 598, in call return [func(*args, *kwargs) File "C:\Users\muhang\miniconda3\envs\npyx\lib\site-packages\joblib\parallel.py", line 598, in return [func(args, kwargs) File "D:\repos\NeuroPyxels\npyx\corr.py", line 1258, in get_ccg_sig crosses+=StarkAbeles2009_ccg_significance(CCG, cbin, p_th, n_consec_bins, 1, W_sd, ret_values=True, only_max=False) File "D:\repos\NeuroPyxels\npyx\corr.py", line 1162, in StarkAbeles2009_ccg_significance pred, pvals = StarkAbeles2009_ccg_sig(CCG, W=2W_sd, WINTYPE='gauss', HF=None, CALCP=True, sgn=sgn) File "D:\repos\NeuroPyxels\npyx\corr.py", line 1115, in StarkAbeles2009_ccg_sig winlist[2]:{0: (sgnl.triang(2W+1), W), # triang even W AttributeError: module 'scipy.signal' has no attribute 'triang' """

The above exception was the direct cause of the following exception:

AttributeError Traceback (most recent call last) Cell In[167], line 18 15 units=[u for u in get_units(dp) if mfr(dp,u)>mfr_th] 16 print(f'Found {len(units)} units above {mfr_th}Hz.') ---> 18 fig=plot_sfcm(dp, corr_type=corr_type, metric='amp_z', cbin=cbin, cwin=cwin, 19 p_th=p_th, n_consec_bins=n_consec_bins, fract_baseline=fract_baseline, W_sd=W_sd, test=test, 20 drop_seq=['sign', 'time', 'max_amplitude'], 21 units=units, name=f'all_unitsmove{mfr_th}Hz', 22 text=False, markers=False, ticks=True, depth_ticks=False, 23 regions={},reg_colors={}, 24 vminmax=[-7,7], figsize=(4,4), 25 saveFig=False, saveDir=dp, again=False, againCCG=0, use_template_for_peakchan=True, 26 periods='all')

File D:\repos\NeuroPyxels\npyx\plot.py:2799, in plot_sfcm(dp, corr_type, metric, cbin, cwin, p_th, n_consec_bins, fract_baseline, W_sd, test, drop_seq, units, name, text, markers, ticks, depth_ticks, regions, reg_colors, vminmax, figsize, saveFig, saveDir, _format, again, againCCG, use_template_for_peakchan, periods) 2781 def plot_sfcm(dp, corr_type='connections', metric='amp_z', cbin=0.5, cwin=100, 2782 p_th=0.02, n_consec_bins=3, fract_baseline=4./5, W_sd=10, test='Poisson_Stark', 2783 drop_seq=['sign', 'time', 'max_amplitude'], units=None, name=None, (...) 2786 saveFig=False, saveDir=None, _format='pdf', 2787 again=False, againCCG=False, use_template_for_peakchan=False, periods='all'): 2788 f''' 2789 Visually represents the connectivity matrix sfcm computed with npyx.corr.gen_sfc(). 2790 Each line/row is a unit, sorted by depth, and the colormap corresponds to the 'metric' parameter. (...) 2796 - fig: matplotlib figure 2797 ''' -> 2799 sfc, sfcm, peakChs, sigstack, sigustack = gen_sfc(dp, corr_type, metric, cbin, cwin, 2800 p_th, n_consec_bins, fract_baseline, W_sd, test, 2801 again, againCCG, drop_seq, None, None, units=units, name=name, 2802 use_template_for_peakchan=use_template_for_peakchan, 2803 periods=periods) 2804 gu = peakChs[:,0] 2805 ch = peakChs[:,1].astype(np.int64)

File D:\repos\NeuroPyxels\npyx\corr.py:1507, in gen_sfc(dp, corr_type, metric, cbin, cwin, p_th, n_consec_bins, fract_baseline, W_sd, test, again, againCCG, drop_seq, pre_chanrange, post_chanrange, units, name, use_template_for_peakchan, periods) 1504 peakChs = npyx.spk_wvf.get_depthSort_peakChans(dp, quality='good', use_template=use_template_for_peakchan) 1505 gu = peakChs[:,0] -> 1507 sigstack, sigustack, sfc = ccg_sig_stack(dp, gu, gu, cbin, cwin, name, 1508 p_th, n_consec_bins, sgn, fract_baseline, W_sd, test, again, againCCG, ret_features=True, only_max=only_max, 1509 periods=periods) 1512 sfc['t_ms_center'] = sfc.l_ms+(sfc.r_ms-sfc.l_ms)/2 1514 # If filtering of connections wishes to be done at a later stage, simply return

File D:\repos\NeuroPyxels\npyx\corr.py:1373, in ccg_sig_stack(dp, U_src, U_trg, cbin, cwin, name, p_th, n_consec_bins, sgn, fract_baseline, W_sd, test, again, againCCG, ret_features, only_max, periods) 1370 ccgsig_ids.append((i,j)) 1371 ccgsig_args.append((CCG, cbin, cwin, p_th, n_consec_bins, sgn, fract_baseline, W_sd, test, ret_features, only_max)) -> 1373 ccgsig_results = Parallel(n_jobs=-2)(\ 1374 delayed(get_ccg_sig)(*ccgsig_args[i]) for i in tqdm(range(len(ccgsig_args)), 1375 desc=f'Looking for significant CCGs over {num_cores} cores')) 1377 sigustack=[] 1378 sigstack=[]

File ~\miniconda3\envs\npyx\lib\site-packages\joblib\parallel.py:2007, in Parallel.call(self, iterable) 2001 # The first item from the output is blank, but it makes the interpreter 2002 # progress until it enters the Try/Except block of the generator and 2003 # reach the first yield statement. This starts the aynchronous 2004 # dispatch of the tasks to the workers. 2005 next(output) -> 2007 return output if self.return_generator else list(output)

File ~\miniconda3\envs\npyx\lib\site-packages\joblib\parallel.py:1650, in Parallel._get_outputs(self, iterator, pre_dispatch) 1647 yield 1649 with self._backend.retrieval_context(): -> 1650 yield from self._retrieve() 1652 except GeneratorExit: 1653 # The generator has been garbage collected before being fully 1654 # consumed. This aborts the remaining tasks if possible and warn 1655 # the user if necessary. 1656 self._exception = True

File ~\miniconda3\envs\npyx\lib\site-packages\joblib\parallel.py:1754, in Parallel._retrieve(self) 1747 while self._wait_retrieval(): 1748 1749 # If the callback thread of a worker has signaled that its task 1750 # triggered an exception, or if the retrieval loop has raised an 1751 # exception (e.g. GeneratorExit), exit the loop and surface the 1752 # worker traceback. 1753 if self._aborting: -> 1754 self._raise_error_fast() 1755 break 1757 # If the next job is not ready for retrieval yet, we just wait for 1758 # async callbacks to progress.

File ~\miniconda3\envs\npyx\lib\site-packages\joblib\parallel.py:1789, in Parallel._raise_error_fast(self) 1785 # If this error job exists, immediatly raise the error by 1786 # calling get_result. This job might not exists if abort has been 1787 # called directly or if the generator is gc'ed. 1788 if error_job is not None: -> 1789 error_job.get_result(self.timeout)

File ~\miniconda3\envs\npyx\lib\site-packages\joblib\parallel.py:745, in BatchCompletionCallBack.get_result(self, timeout) 739 backend = self.parallel._backend 741 if backend.supports_retrieve_callback: 742 # We assume that the result has already been retrieved by the 743 # callback thread, and is stored internally. It's just waiting to 744 # be returned. --> 745 return self._return_or_raise() 747 # For other backends, the main thread needs to run the retrieval step. 748 try:

File ~\miniconda3\envs\npyx\lib\site-packages\joblib\parallel.py:763, in BatchCompletionCallBack._return_or_raise(self) 761 try: 762 if self.status == TASK_ERROR: --> 763 raise self._result 764 return self._result 765 finally:

AttributeError: module 'scipy.signal' has no attribute 'triang'

m-beau commented 6 months ago

Hi there,

You didn't do anything wrong, it seems like scipy.signal deprecated the triang function in their lastest version.

This should fix it for you: pip install scipy==1.10

Let me know if it fixes your problem.

m-beau commented 5 months ago

no reply - assuming that the issue is fixed.