Skip to content

Commit

Permalink
Added makefile and reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rhoitink committed Nov 30, 2022
1 parent e6ec11a commit 84fa632
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
venv:
python -m venv venv

install:
python -m pip install .

dev:
python -m pip install -e .[dev]

test:
pytest tests

coverage:
pytest --cov simulatedmicroscopy --cov-report html

clean:
rm -rf __pycache__ .pytest_cache htmlcov .coverage

flake:
flake8 simulatedmicroscopy tests

black:
black simulatedmicroscopy tests

check: black flake test
6 changes: 3 additions & 3 deletions simulatedmicroscopy/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def downsample(self, downsample_factor: list[int]) -> type[Image]:

return self

def convolve(self, other : type[Image]) -> type[Image]:
def convolve(self, other: type[Image]) -> type[Image]:
"""Convolve this image with another image (a PSF). The image is overwritten by the result of the convolution.
Parameters
Expand All @@ -183,8 +183,8 @@ def convolve(self, other : type[Image]) -> type[Image]:
"""
if not (self.pixel_sizes == other.pixel_sizes).all():
raise ValueError("Cannot convolve images with different pixel sizes")
self.image = scipy.signal.convolve(self.image, other.image, mode='same')

self.image = scipy.signal.convolve(self.image, other.image, mode="same")

return self

Expand Down
4 changes: 2 additions & 2 deletions simulatedmicroscopy/psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ def __init__(
"""
sigmas_nm = np.array(sigmas)
pixel_sizes_nm = np.round(np.array(pixel_sizes) * 1e9).astype(int)

if not (pixel_sizes_nm < sigmas_nm).all():
raise ValueError("Pixel sizes should be smaller than given sigmas")

# image size in nm, 4 sigma on all sides of the Gaussian
image_size_nm = 4 * 2 * sigmas_nm

Expand Down
13 changes: 7 additions & 6 deletions tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,22 @@ def test_downsample(downsample_factor):
"multiplication_factor",
[
0.5,
1.,
2.,
1.0,
2.0,
],
)
def test_convolution(multiplication_factor):
im = Image(np.ones(shape=(10,10,10)))
psf = Image(np.ones(shape=(1,1,1))*multiplication_factor)
im = Image(np.ones(shape=(10, 10, 10)))
psf = Image(np.ones(shape=(1, 1, 1)) * multiplication_factor)

convolved = im.convolve(psf)

assert im == convolved


def test_convolution_wrongpixelsize():
im = create_demo_image()
psf = Image(np.ones(shape=(1,1,1)), pixel_sizes=(10.,10.,10.))
psf = Image(np.ones(shape=(1, 1, 1)), pixel_sizes=(10.0, 10.0, 10.0))

with pytest.raises(ValueError):
im.convolve(psf)
im.convolve(psf)
8 changes: 5 additions & 3 deletions tests/test_psf.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from simulatedmicroscopy.psf import GaussianPSF
import pytest


def test_can_create_gaussian_psf():
psf = GaussianPSF([250.,250.,600.])
psf = GaussianPSF([250.0, 250.0, 600.0])

assert psf.image.sum() > 0.0

assert psf.image.sum() > 0.

def test_can_gaussian_psf_wrongpixelsize():
with pytest.raises(ValueError):
GaussianPSF([250.,250.,600.], pixel_sizes=[1e-6, 1e-6, 1e-6])
GaussianPSF([250.0, 250.0, 600.0], pixel_sizes=[1e-6, 1e-6, 1e-6])

0 comments on commit 84fa632

Please sign in to comment.