Skip to content

Commit b257d78

Browse files
authored
Merge pull request #250 from reillytilbury/dev
Alpha 0.10.5 Update
2 parents ba7a8b9 + f27aa9c commit b257d78

File tree

85 files changed

+4083
-4706
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+4083
-4706
lines changed

.github/workflows/pytorch_integration.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636

3737
- name: Install pytorch dependencies
3838
run: |
39-
python -m pip install -r requirements-pytorch.txt
39+
python -m pip install -r requirements.txt
4040
python -m pip install .
4141
4242
- name: Run pytorch unit tests

.gitignore

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,164 @@ coppafish.egg-info
1313
**/temp.*
1414
**/.venv/**
1515
**/.idea/**
16+
17+
# Byte-compiled / optimized / DLL files
18+
__pycache__/
19+
*.py[cod]
20+
*$py.class
21+
22+
# C extensions
23+
*.so
24+
25+
# Distribution / packaging
26+
.Python
27+
build/
28+
develop-eggs/
29+
dist/
30+
downloads/
31+
eggs/
32+
.eggs/
33+
lib/
34+
lib64/
35+
parts/
36+
sdist/
37+
var/
38+
wheels/
39+
share/python-wheels/
40+
*.egg-info/
41+
.installed.cfg
42+
*.egg
43+
MANIFEST
44+
45+
# PyInstaller
46+
# Usually these files are written by a python script from a template
47+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
48+
*.manifest
49+
*.spec
50+
51+
# Installer logs
52+
pip-log.txt
53+
pip-delete-this-directory.txt
54+
55+
# Unit test / coverage reports
56+
htmlcov/
57+
.tox/
58+
.nox/
59+
.coverage
60+
.coverage.*
61+
.cache
62+
nosetests.xml
63+
coverage.xml
64+
*.cover
65+
*.py,cover
66+
.hypothesis/
67+
.pytest_cache/
68+
cover/
69+
70+
# Translations
71+
*.mo
72+
*.pot
73+
74+
# Django stuff:
75+
*.log
76+
local_settings.py
77+
db.sqlite3
78+
db.sqlite3-journal
79+
80+
# Flask stuff:
81+
instance/
82+
.webassets-cache
83+
84+
# Scrapy stuff:
85+
.scrapy
86+
87+
# Sphinx documentation
88+
docs/_build/
89+
90+
# PyBuilder
91+
.pybuilder/
92+
target/
93+
94+
# Jupyter Notebook
95+
.ipynb_checkpoints
96+
97+
# IPython
98+
profile_default/
99+
ipython_config.py
100+
101+
# pyenv
102+
# For a library or package, you might want to ignore these files since the code is
103+
# intended to run in multiple environments; otherwise, check them in:
104+
# .python-version
105+
106+
# pipenv
107+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
108+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
109+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
110+
# install all needed dependencies.
111+
#Pipfile.lock
112+
113+
# poetry
114+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
115+
# This is especially recommended for binary packages to ensure reproducibility, and is more
116+
# commonly ignored for libraries.
117+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
118+
#poetry.lock
119+
120+
# pdm
121+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
122+
#pdm.lock
123+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
124+
# in version control.
125+
# https://pdm.fming.dev/#use-with-ide
126+
.pdm.toml
127+
128+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
129+
__pypackages__/
130+
131+
# Celery stuff
132+
celerybeat-schedule
133+
celerybeat.pid
134+
135+
# SageMath parsed files
136+
*.sage.py
137+
138+
# Environments
139+
.env
140+
.venv
141+
env/
142+
venv/
143+
ENV/
144+
env.bak/
145+
venv.bak/
146+
147+
# Spyder project settings
148+
.spyderproject
149+
.spyproject
150+
151+
# Rope project settings
152+
.ropeproject
153+
154+
# mkdocs documentation
155+
/site
156+
157+
# mypy
158+
.mypy_cache/
159+
.dmypy.json
160+
dmypy.json
161+
162+
# Pyre type checker
163+
.pyre/
164+
165+
# pytype static type analyzer
166+
.pytype/
167+
168+
# Cython debug symbols
169+
cython_debug/
170+
171+
# PyCharm
172+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
173+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
174+
# and can be added to the global gitignore or merged into this file. For a more nuclear
175+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
176+
#.idea/

changelog.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1+
2024/05/14 Alpha Update (v0.10.5):
2+
* Pytorch CPU is now a default dependency.
3+
* Optical flow results are saved as compressed zarr files instead of uncompressed numpy arrays.
4+
* Coppafish can send email notifications on completed pipelines and crashes.
5+
* OMP has been overhauled.
6+
* New diagnostic Viewer2D added.
7+
* The OMP computed spot is now computed on a subset of one tile, not the full tile.
8+
* OMP is faster and the entire tile is loaded into memory before running each tile.
9+
* Removed inputimeout package dependency.
10+
* Max Intensity Projection of background images added to main viewer as option.
11+
* Fluorescent beads registration bug fix.
12+
* New viewer for registration of fluorescent beads.
13+
* Redundant warnings silenced.
14+
* Default starting position for registration viewer now the registered image.
15+
* New diagnostic in main viewer shows top 10 best fitted genes to a given spot along with their associated scores.
16+
17+
118
2024/04/23 Alpha Update (v0.10.4):
219
* Bug in Register which was causing large shifts not to be detected has been fixed. A global shift is now computed
320
between the two images and the shift is applied to the second image before computing the local shifts.
21+
* OMP unbound variable i_added_genes bug fixed in pytorch GPU.
22+
423

524
2024/04/18 Alpha Update (v0.10.3):
625
* OMP crash on empty coef_image bug fix.

coppafish/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
from ._version import __version__
66
from . import plot
77
from .plot import Viewer
8+
from .plot.viewer2d.base import Viewer2D
89
from .plot.register.diagnostics import RegistrationViewer
910
from .pdf.base import BuildPDF

coppafish/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.10.4"
1+
__version__ = "0.10.5"

coppafish/call_spots/__init__.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
try:
2-
from .qual_check_pytorch import get_spot_intensity
3-
except ImportError:
4-
from .qual_check import get_spot_intensity
5-
6-
try:
7-
import torch
8-
9-
if torch.cuda.is_available():
10-
from .background_pytorchgpu import fit_background
11-
else:
12-
from .background_pytorch import fit_background
13-
except ImportError:
14-
from .background import fit_background
15-
1+
from .qual_check import get_spot_intensity
2+
from .background import fit_background
163
from .base import get_bled_codes, get_non_duplicate, compute_gene_efficiency
174
from .qual_check import omp_spot_score, quality_threshold, get_intensity_thresh
185
from .dot_product import dot_product_score, gene_prob_score
196

207
# Needed for working non-jax, non-pytorch software
218
from . import background
9+
10+
try:
11+
from . import background_pytorch
12+
except ImportError:
13+
pass

coppafish/call_spots/background.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,26 @@ def fit_background(spot_colors: np.ndarray, weight_shift: float = 0) -> Tuple[np
2727
- background_vectors `float [n_channels x n_rounds x n_channels]`.
2828
background_vectors[c] is the background vector for channel c.
2929
"""
30-
weight_shift = np.clip(weight_shift, 1e-20, np.inf) # ensure weight_shift > 1e-20 to avoid blow up to infinity.
30+
# Preserve the spot colours datatype throughout.
31+
dtype = spot_colors.dtype
32+
weight_shift = np.clip(
33+
weight_shift, 1e-20, np.inf, dtype=dtype
34+
) # ensure weight_shift > 1e-20 to avoid blow up to infinity.
3135

3236
n_rounds, n_channels = spot_colors[0].shape
33-
background_vectors = np.repeat(np.expand_dims(np.eye(n_channels), axis=1), n_rounds, axis=1)
37+
background_vectors = np.repeat(np.expand_dims(np.eye(n_channels), axis=1), n_rounds, axis=1).astype(dtype)
3438
# give background_vectors an L2 norm of 1 so can compare coefficients with other genes.
3539
background_vectors = background_vectors / np.linalg.norm(background_vectors, axis=(1, 2), keepdims=True)
3640

3741
weight_factor = 1 / (np.abs(spot_colors) + weight_shift)
3842
spot_weight = spot_colors * weight_factor
39-
background_weight = np.ones((1, n_rounds, n_channels)) * background_vectors[0, 0, 0] * weight_factor
43+
background_weight = np.ones((1, n_rounds, n_channels), dtype=dtype) * background_vectors[0, 0, 0] * weight_factor
44+
# Avoid overflow from squaring the background_weight.
45+
background_weight = np.clip(background_weight, None, np.sqrt(np.finfo(dtype).max))
4046
coef = np.sum(spot_weight * background_weight, axis=1) / np.sum(background_weight**2, axis=1)
41-
residual = spot_colors - np.expand_dims(coef, 1) * np.ones((1, n_rounds, n_channels)) * background_vectors[0, 0, 0]
47+
residual = (
48+
spot_colors
49+
- np.expand_dims(coef, 1) * np.ones((1, n_rounds, n_channels), dtype=dtype) * background_vectors[0, 0, 0]
50+
)
4251

4352
return residual, coef, background_vectors

coppafish/call_spots/background_pytorch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def fit_background(
4141
weight_factor = 1 / (torch.abs(spot_colors) + weight_shift)
4242
spot_weight = spot_colors * weight_factor
4343
background_weight = torch.ones((1, n_rounds, n_channels)) * background_vectors[0, 0, 0] * weight_factor
44-
coef = torch.sum(spot_weight * background_weight, dim=1) / torch.sum(background_weight ** 2, dim=1)
44+
coef = torch.sum(spot_weight * background_weight, dim=1) / torch.sum(background_weight**2, dim=1)
4545
residual = spot_colors - coef[:, None] * torch.ones((1, n_rounds, n_channels)) * background_vectors[0, 0, 0]
4646

47-
return residual.type(torch.float32), coef.type(torch.float32), background_vectors.type(torch.float32)
47+
return residual.float(), coef.float(), background_vectors.float()

coppafish/call_spots/background_pytorchgpu.py

Lines changed: 0 additions & 49 deletions
This file was deleted.

coppafish/call_spots/dot_product.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def dot_product_score(
2626
n_spots, n_rounds_channels_use = spot_colours.shape
2727
# If no weighting is given, use equal weighting
2828
if weight_squared is None:
29-
weight_squared = np.ones((n_spots, n_rounds_channels_use))
29+
weight_squared = np.ones((n_spots, n_rounds_channels_use), dtype=spot_colours.dtype)
3030

3131
weight_squared = weight_squared / np.sum(weight_squared, axis=1)[:, None]
3232
spot_colours = spot_colours / (np.linalg.norm(spot_colours, axis=1)[:, None] + norm_shift)
@@ -75,6 +75,6 @@ def gene_prob_score(spot_colours: np.ndarray, bled_codes: np.ndarray, kappa: flo
7575
dot_product = spot_colours @ bled_codes.T
7676
probability = np.exp(kappa * dot_product)
7777
# Now normalise so that each row sums to 1
78-
probability = probability / np.sum(probability, axis=1)[:, None]
78+
probability = np.nan_to_num(probability / np.sum(probability, axis=1)[:, None])
7979

8080
return probability

0 commit comments

Comments
 (0)