yaksilab / silver-dollop

This repo contains analysis tools for astroglial cells
MIT License
0 stars 0 forks source link

TypeError: m > k must hold #3

Closed AhmedJamali closed 4 weeks ago

AhmedJamali commented 4 weeks ago

..... Extracting Trace for subsegmented masks Masks created, 1.90 sec. Extracted fluorescence from 151 ROIs in 111060 frames, 2573.40 sec. ['npix_norm', 'compact', 'skew'] Matrix saved to Z:\Ahmed\PhD\Experiments\2P\LDN\RESO\GFAP\Double_extraction\20240118_13_03_15_AJ_GFAP_Gal4_UAS_GCaMP6s_Evoked_4_LP1\suite2p\plane0\trace_matrix.mat as a .mat file Matrix saved to Z:\Ahmed\PhD\Experiments\2P\LDN\RESO\GFAP\Double_extraction\20240118_13_03_15_AJ_GFAP_Gal4_UAS_GCaMP6s_Evoked_4_LP1\suite2p\plane0\correspondence_matrix.mat as a .mat file c:\Users\ahmedj\AppData\Local\anaconda3\envs\astroglial_analysis\lib\site-packages\numpy\core\fromnumeric.py:3504: RuntimeWarning: Mean of empty slice. return _methods._mean(a, axis=axis, dtype=dtype, c:\Users\ahmedj\AppData\Local\anaconda3\envs\astroglial_analysis\lib\site-packages\numpy\core_methods.py:129: RuntimeWarning: invalid value encountered in scalar divide ret = ret.dtype.type(ret / rcount) c:\Users\ahmedj\AppData\Local\anaconda3\envs\astroglial_analysis\lib\site-packages\astroglial_analysis\interpolated_function.py:45: RuntimeWarning: invalid value encountered in divide u = cumulative_length / total_length # Normalize to [0, 1]

.....

Error:

{ "name": "TypeError", "message": "m > k must hold", "stack": "--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[4], line 3 1 for entry in db: 2 working_dir = entry['data_path'][0] ----> 3 run_pipeline(working_dir, 12)

File c:\Users\ahmedj\AppData\Local\anaconda3\envs\astroglial_analysis\lib\site-packages\astroglial_analysis\run_pipline.py:98, in run_pipeline(working_directory, segment_length) 95 new_maskfile = mask_file.copy() 96 masks = mask_file.item()[\"masks\"] ---> 98 total_cor_matrix = get_correspondence_matrix(masks) 100 sub_segmented_data = sub_segment(total_cor_matrix, segment_length) 101 subsegmented_mask = create_cp_mask(sub_segmented_data, masks)

File c:\Users\ahmedj\AppData\Local\anaconda3\envs\astroglial_analysis\lib\site-packages\astroglial_analysis\run_pipline.py:49, in get_correspondence_matrix(masks) 47 upper_points = np.array([point[0] for point in line_upper]) 48 lower_points = np.array([point[0] for point in line_lower]) ---> 49 t_upper, tckupper, , , = parametrize_curve(upper_points) 50 t_lower, tcklower, , , = parametrize_curve(lower_points) 52 intersection_list_upper = get_all_intersections( 53 tck_upper, t_upper, ab_list_upper, upper=True 54 )

File c:\Users\ahmedj\AppData\Local\anaconda3\envs\astroglial_analysis\lib\site-packages\astroglial_analysis\interpolated_function.py:48, in parametrize_curve(points) 45 u = cumulative_length / total_length # Normalize to [0, 1] 47 # Fit parametric splines for x(t) and y(t) ---> 48 spline_x = splrep(u, points[:, 0], s=0, k=1) 49 spline_y = splrep(u, points[:, 1], s=0, k=1) 51 u_fit = np.linspace(0, 1, int(total_length))

File c:\Users\ahmedj\AppData\Local\anaconda3\envs\astroglial_analysis\lib\site-packages\scipy\interpolate\_fitpack_py.py:295, in splrep(x, y, w, xb, xe, k, task, s, t, full_output, per, quiet) 160 def splrep(x, y, w=None, xb=None, xe=None, k=3, task=0, s=None, t=None, 161 full_output=0, per=0, quiet=1): 162 \"\"\" 163 Find the B-spline representation of a 1-D curve. 164 (...) 293 294 \"\"\" --> 295 res = _impl.splrep(x, y, w, xb, xe, k, task, s, t, full_output, per, quiet) 296 return res

File c:\Users\ahmedj\AppData\Local\anaconda3\envs\astroglial_analysis\lib\site-packages\scipy\interpolate\_fitpack_impl.py:239, in splrep(x, y, w, xb, xe, k, task, s, t, full_output, per, quiet) 236 raise TypeError('Given degree of the spline (k=%d) is not supported. ' 237 '(1<=k<=5)' % k) 238 if m <= k: --> 239 raise TypeError('m > k must hold') 240 if xb is None: 241 xb = x[0]

TypeError: m > k must hold" }

javidaf commented 4 weeks ago

..... Extracting Trace for subsegmented masks Masks created, 1.90 sec. Extracted fluorescence from 151 ROIs in 111060 frames, 2573.40 sec. ['npix_norm', 'compact', 'skew'] Matrix saved to Z:\Ahmed\PhD\Experiments\2P\LDN\RESO\GFAP\Double_extraction\20240118_13_03_15_AJ_GFAP_Gal4_UAS_GCaMP6s_Evoked_4_LP1\suite2p\plane0\trace_matrix.mat as a .mat file Matrix saved to Z:\Ahmed\PhD\Experiments\2P\LDN\RESO\GFAP\Double_extraction\20240118_13_03_15_AJ_GFAP_Gal4_UAS_GCaMP6s_Evoked_4_LP1\suite2p\plane0\correspondence_matrix.mat as a .mat file c:\Users\ahmedj\AppData\Local\anaconda3\envs\astroglial_analysis\lib\site-packages\numpy\core\fromnumeric.py:3504: RuntimeWarning: Mean of empty slice. return _methods._mean(a, axis=axis, dtype=dtype, c:\Users\ahmedj\AppData\Local\anaconda3\envs\astroglial_analysis\lib\site-packages\numpy\core_methods.py:129: RuntimeWarning: invalid value encountered in scalar divide ret = ret.dtype.type(ret / rcount) c:\Users\ahmedj\AppData\Local\anaconda3\envs\astroglial_analysis\lib\site-packages\astroglial_analysis\interpolated_function.py:45: RuntimeWarning: invalid value encountered in divide u = cumulative_length / total_length # Normalize to [0, 1]

.....

Error:

{ "name": "TypeError", "message": "m > k must hold", "stack": "--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[4], line 3 1 for entry in db: 2 working_dir = entry['data_path'][0] ----> 3 run_pipeline(working_dir, 12)

File c:\Users\ahmedj\AppData\Local\anaconda3\envs\astroglial_analysis\lib\site-packages\astroglial_analysis\run_pipline.py:98, in run_pipeline(working_directory, segment_length) 95 new_maskfile = mask_file.copy() 96 masks = mask_file.item()["masks"] ---> 98 total_cor_matrix = get_correspondence_matrix(masks) 100 sub_segmented_data = sub_segment(total_cor_matrix, segment_length) 101 subsegmented_mask = create_cp_mask(sub_segmented_data, masks)

File c:\Users\ahmedj\AppData\Local\anaconda3\envs\astroglial_analysis\lib\site-packages\astroglial_analysis\run_pipline.py:49, in get_correspondence_matrix(masks) 47 upper_points = np.array([point[0] for point in line_upper]) 48 lower_points = np.array([point[0] for point in line_lower]) ---> 49 t_upper, tckupper, , , = parametrize_curve(upper_points) 50 t_lower, tcklower, , , = parametrize_curve(lower_points) 52 intersection_list_upper = get_all_intersections( 53 tck_upper, t_upper, ab_list_upper, upper=True 54 )

File c:\Users\ahmedj\AppData\Local\anaconda3\envs\astroglial_analysis\lib\site-packages\astroglial_analysis\interpolated_function.py:48, in parametrize_curve(points) 45 u = cumulative_length / total_length # Normalize to [0, 1] 47 # Fit parametric splines for x(t) and y(t) ---> 48 spline_x = splrep(u, points[:, 0], s=0, k=1) 49 spline_y = splrep(u, points[:, 1], s=0, k=1) 51 u_fit = np.linspace(0, 1, int(total_length))

File c:\Users\ahmedj\AppData\Local\anaconda3\envs\astroglial_analysis\lib\site-packages\scipy\interpolate_fitpack_py.py:295, in splrep(x, y, w, xb, xe, k, task, s, t, full_output, per, quiet) 160 def splrep(x, y, w=None, xb=None, xe=None, k=3, task=0, s=None, t=None, 161 full_output=0, per=0, quiet=1): 162 """ 163 Find the B-spline representation of a 1-D curve. 164 (...) 293 294 """ --> 295 res = _impl.splrep(x, y, w, xb, xe, k, task, s, t, full_output, per, quiet) 296 return res

File c:\Users\ahmedj\AppData\Local\anaconda3\envs\astroglial_analysis\lib\site-packages\scipy\interpolate_fitpack_impl.py:239, in splrep(x, y, w, xb, xe, k, task, s, t, full_output, per, quiet) 236 raise TypeError('Given degree of the spline (k=%d) is not supported. ' 237 '(1<=k<=5)' % k) 238 if m <= k: --> 239 raise TypeError('m > k must hold') 240 if xb is None: 241 xb = x[0]

TypeError: m > k must hold" }

This occures becasue the segmentation did not do well, there are not enough complete cells extending from the brain part. I will add handling of such cases. When you run this pipline make sure you have enough complete cells that can be used to estimate the brain part the cells are extending from. I have added that there are at least 4 such cells present to run the pipline properly.