5
5
import numpy as np
6
6
import numpy .typing as npt
7
7
8
+ from ...detail .utilities import find_stack_level
9
+
8
10
9
11
@dataclass (frozen = True )
10
12
class DiffusionEstimate :
@@ -472,7 +474,10 @@ def _diffusion_gls(lag_idx, mean_squared_displacements, num_points, tolerance=1e
472
474
473
475
def fallback (warning_message ):
474
476
"""Fallback method if the GLS fails"""
475
- warnings .warn (RuntimeWarning (f"{ warning_message } Reverting to two-point OLS." ))
477
+ warnings .warn (
478
+ RuntimeWarning (f"{ warning_message } Reverting to two-point OLS." ),
479
+ stacklevel = find_stack_level (),
480
+ )
476
481
return _diffusion_ols (lag_idx [:2 ], mean_squared_displacements [:2 ], num_points )
477
482
478
483
# Since the covariance matrix depends on the parameters for the intercept and slope, we obtain
@@ -600,7 +605,7 @@ def estimate_diffusion_constant_simple(
600
605
"`help(lk.refine_tracks_centroid)` or `help(lk.refine_tracks_gaussian)` for "
601
606
"more information."
602
607
),
603
- stacklevel = 2 ,
608
+ stacklevel = find_stack_level () ,
604
609
)
605
610
606
611
frame_lags , msd = calculate_msd (frame_idx , coordinate , max_lag )
@@ -718,7 +723,8 @@ def determine_optimal_points(frame_idx, coordinate, max_iterations=100):
718
723
RuntimeWarning (
719
724
"Your tracks have missing frames. Note that this can lead to a suboptimal "
720
725
"estimate of the optimal number of lags when using OLS."
721
- )
726
+ ),
727
+ stacklevel = find_stack_level (),
722
728
)
723
729
724
730
num_slope = max (2 , len (coordinate ) // 10 ) # Need at least two points for a linear regression!
@@ -750,7 +756,8 @@ def determine_optimal_points(frame_idx, coordinate, max_iterations=100):
750
756
return num_slope , num_intercept
751
757
752
758
warnings .warn (
753
- RuntimeWarning ("Warning, maximum number of iterations exceeded. Returning best solution." )
759
+ RuntimeWarning ("Warning, maximum number of iterations exceeded. Returning best solution." ),
760
+ stacklevel = find_stack_level (),
754
761
)
755
762
return num_slope , num_intercept
756
763
@@ -1129,7 +1136,8 @@ def _determine_optimal_points_ensemble(frame_lags, msds, n_coord, max_iterations
1129
1136
return num_slope
1130
1137
1131
1138
warnings .warn (
1132
- RuntimeWarning ("Warning, maximum number of iterations exceeded. Returning best solution." )
1139
+ RuntimeWarning ("Warning, maximum number of iterations exceeded. Returning best solution." ),
1140
+ stacklevel = find_stack_level (),
1133
1141
)
1134
1142
1135
1143
return num_slope
@@ -1143,7 +1151,8 @@ def ensemble_ols(kymotracks, max_lag):
1143
1151
warnings .warn (
1144
1152
RuntimeWarning (
1145
1153
"Your tracks have missing frames. Note that this can lead to a suboptimal estimates"
1146
- )
1154
+ ),
1155
+ stacklevel = find_stack_level (),
1147
1156
)
1148
1157
1149
1158
optimal_lags = (
0 commit comments