Skip to content

Commit

Permalink
moved overlaps() calculations to stats.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdelgrosso committed Jul 2, 2020
1 parent 54bc5e2 commit 943832c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .dvc/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@
/tmp
/tmp
/tmp
/tmp
/tmp
/tmp
2 changes: 1 addition & 1 deletion .dvc/tmp/gdrive-user-credentials.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"access_token": "ya29.a0AfH6SMDT2-KRaVTkIpEA1HbHKYwBs5C3xrpo3DdzOdGUmNLRAdpwsIQ1Kgn3EJgupEJa2AoHBBoJVIr-daQv9Yliouekcr7LjtZCB630JHDyGrWEsUi4buKl_EgpSZXBEip4AFejpNcssMSqoMMloRRtL53W4B5FZka2", "client_id": "710796635688-iivsgbgsb6uv1fap6635dhvuei09o66c.apps.googleusercontent.com", "client_secret": "a1Fz59uTpVNeG_VGuSKDLJXv", "refresh_token": "1//0fpJK6wboLxL7CgYIARAAGA8SNwF-L9IrKmhg8LLnJuWRCiN_YIE88ImD9Y0yV6iCIw220vP3gD4nISe-K5aq8l_r0m1qcUW1D_w", "token_expiry": "2020-07-02T15:36:52Z", "token_uri": "https://oauth2.googleapis.com/token", "user_agent": null, "revoke_uri": "https://oauth2.googleapis.com/revoke", "id_token": null, "id_token_jwt": null, "token_response": {"access_token": "ya29.a0AfH6SMDT2-KRaVTkIpEA1HbHKYwBs5C3xrpo3DdzOdGUmNLRAdpwsIQ1Kgn3EJgupEJa2AoHBBoJVIr-daQv9Yliouekcr7LjtZCB630JHDyGrWEsUi4buKl_EgpSZXBEip4AFejpNcssMSqoMMloRRtL53W4B5FZka2", "expires_in": 3599, "scope": "https://www.googleapis.com/auth/drive.appdata https://www.googleapis.com/auth/drive", "token_type": "Bearer"}, "scopes": ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/drive.appdata"], "token_info_uri": "https://oauth2.googleapis.com/tokeninfo", "invalid": false, "_class": "OAuth2Credentials", "_module": "oauth2client.client"}
{"access_token": "ya29.a0AfH6SMA4on6-UlQWL1FDRFX1fhQoNnAQ5v6fnXVb0assyzvK3KabjC3LDymkf7KCo8EFFyL5OIZhQnRYgW0ULFaBtKL_Cw6nOEzabtw0-nUJT7iTN36oANBD1LVNXcArLbQM7teTmjbBS7-KiZRkWOgcPMndbcwZwLlg", "client_id": "710796635688-iivsgbgsb6uv1fap6635dhvuei09o66c.apps.googleusercontent.com", "client_secret": "a1Fz59uTpVNeG_VGuSKDLJXv", "refresh_token": "1//0fpJK6wboLxL7CgYIARAAGA8SNwF-L9IrKmhg8LLnJuWRCiN_YIE88ImD9Y0yV6iCIw220vP3gD4nISe-K5aq8l_r0m1qcUW1D_w", "token_expiry": "2020-07-02T16:37:51Z", "token_uri": "https://oauth2.googleapis.com/token", "user_agent": null, "revoke_uri": "https://oauth2.googleapis.com/revoke", "id_token": null, "id_token_jwt": null, "token_response": {"access_token": "ya29.a0AfH6SMA4on6-UlQWL1FDRFX1fhQoNnAQ5v6fnXVb0assyzvK3KabjC3LDymkf7KCo8EFFyL5OIZhQnRYgW0ULFaBtKL_Cw6nOEzabtw0-nUJT7iTN36oANBD1LVNXcArLbQM7teTmjbBS7-KiZRkWOgcPMndbcwZwLlg", "expires_in": 3599, "scope": "https://www.googleapis.com/auth/drive.appdata https://www.googleapis.com/auth/drive", "token_type": "Bearer"}, "scopes": ["https://www.googleapis.com/auth/drive.appdata", "https://www.googleapis.com/auth/drive"], "token_info_uri": "https://oauth2.googleapis.com/tokeninfo", "invalid": false, "_class": "OAuth2Credentials", "_module": "oauth2client.client"}
4 changes: 2 additions & 2 deletions suite2p/detection/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import numpy as np
from pathlib import Path
from . import sourcery, sparsedetect, chan2detect
from .stats import ROI
from .masks import filter_overlappers, create_cell_masks, create_neuropil_masks, create_cell_pix
from .stats import ROI, filter_overlappers
from .masks import create_cell_masks, create_neuropil_masks, create_cell_pix


def main_detect(ops):
Expand Down
18 changes: 0 additions & 18 deletions suite2p/detection/masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,6 @@

from suite2p.detection.sparsedetect import extendROI

def count_overlaps(Ly: int, Lx: int, ypixs, xpixs) -> np.ndarray:
overlap = np.zeros((Ly, Lx))
for xpix, ypix in zip(xpixs, ypixs):
overlap[ypix, xpix] += 1
return overlap


def filter_overlappers(ypixs, xpixs, max_overlap: float, Ly: int, Lx: int) -> List[int]:
"""returns ROI indices are remain after removing those that overlap more than fraction max_overlap with other ROIs"""
overlaps = count_overlaps(Ly=Ly, Lx=Lx, ypixs=ypixs, xpixs=xpixs)
ix = []
for i, (ypix, xpix) in reversed(list(enumerate(zip(ypixs, xpixs)))): # todo: is there an ordering effect here that affects which rois will be removed and which will stay?
if np.mean(overlaps[ypix, xpix] > 1) > max_overlap: # note: fancy indexing returns a copy
overlaps[ypix, xpix] -= 1
else:
ix.append(i)
return ix[::-1]


def create_cell_pix(stats, Ly, Lx, allow_overlap=False) -> np.ndarray:
"""Returns Ly x Lx array of whether it contains a cell (1) or not (0)."""
Expand Down
22 changes: 20 additions & 2 deletions suite2p/detection/stats.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from __future__ import annotations

from typing import Tuple, Optional, NamedTuple, Sequence
from typing import Tuple, Optional, NamedTuple, Sequence, List
from dataclasses import dataclass, field
from warnings import warn

import numpy as np
from numpy.linalg import norm
from cached_property import cached_property

from .masks import count_overlaps
from .utils import norm_by_average


Expand Down Expand Up @@ -178,3 +177,22 @@ def fitMVGaus(y, x, lam, thres=2.5, npts: int = 100) -> EllipseData:
radii = np.sort(radii)[::-1]

return EllipseData(mu=mu, cov=cov, radii=radii, ellipse=ellipse)


def count_overlaps(Ly: int, Lx: int, ypixs, xpixs) -> np.ndarray:
overlap = np.zeros((Ly, Lx))
for xpix, ypix in zip(xpixs, ypixs):
overlap[ypix, xpix] += 1
return overlap


def filter_overlappers(ypixs, xpixs, max_overlap: float, Ly: int, Lx: int) -> List[int]:
"""returns ROI indices are remain after removing those that overlap more than fraction max_overlap with other ROIs"""
overlaps = count_overlaps(Ly=Ly, Lx=Lx, ypixs=ypixs, xpixs=xpixs)
ix = []
for i, (ypix, xpix) in reversed(list(enumerate(zip(ypixs, xpixs)))): # todo: is there an ordering effect here that affects which rois will be removed and which will stay?
if np.mean(overlaps[ypix, xpix] > 1) > max_overlap: # note: fancy indexing returns a copy
overlaps[ypix, xpix] -= 1
else:
ix.append(i)
return ix[::-1]

0 comments on commit 943832c

Please sign in to comment.