Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix for python 3.11 and over #1122

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions suite2p/detection/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from dataclasses import dataclass, field
from warnings import warn

import sys
import numpy as np
from numpy.linalg import norm
from scipy.spatial import ConvexHull
Expand All @@ -26,7 +27,6 @@ def median_pix(ypix, xpix):
ymed = ypix[imin]
return [ymed, xmed]


class EllipseData(NamedTuple):
mu: float
cov: float
Expand All @@ -47,17 +47,22 @@ def radius(self) -> float:
def aspect_ratio(self) -> float:
ry, rx = self.radii
return aspect_ratio(width=ry, height=rx)


def default_rsort():
return np.sort(distance_kernel(radius=30).flatten())

@dataclass(frozen=True)
class ROI:
# To avoid the ValueError caused by using a mutable default value in your dataclass, you should use the default_factory argument of the field function.
ypix: np.ndarray
xpix: np.ndarray
lam: np.ndarray
med: np.ndarray
do_crop: bool
rsort: np.ndarray = field(default=np.sort(distance_kernel(radius=30).flatten()),
repr=False)
if sys.version_info >= (3, 11):
rsort: np.ndarray = field(default_factory=default_rsort, repr=False)
else:
rsort: np.ndarray = field(default=np.sort(distance_kernel(radius=30).flatten()), repr=False)

def __post_init__(self):
"""Validate inputs."""
Expand Down
Loading