Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
510a9d5
Update types.py
giovannivolpe Dec 5, 2024
5bb4f8e
Update types.py
giovannivolpe Dec 5, 2024
c13d100
Update math.py
giovannivolpe Dec 5, 2024
36e56bf
Update types.py
giovannivolpe Dec 5, 2024
be723c7
Update utils.py
giovannivolpe Dec 5, 2024
13d6f80
Update utils.py
giovannivolpe Dec 5, 2024
0b4d198
Update test_utils.py
giovannivolpe Dec 5, 2024
e646838
Update test_optics.py
giovannivolpe Dec 5, 2024
6d65a5d
Update test_utils.py
giovannivolpe Dec 5, 2024
c343ca0
Update requirements.txt
giovannivolpe Dec 5, 2024
9d65ead
Update optics.py
giovannivolpe Dec 5, 2024
0aa4363
Update features.py
giovannivolpe Dec 5, 2024
77295d9
Update requirements.txt
giovannivolpe Dec 6, 2024
63604c5
removed isiterable
giovannivolpe Dec 6, 2024
3378939
Merge branch 'GV/documentation-01' of https://github.com/DeepTrackAI/…
giovannivolpe Dec 6, 2024
cc5cb16
Update utils.py
giovannivolpe Dec 6, 2024
1379acc
Update utils_example.ipynb
giovannivolpe Dec 6, 2024
4e0ea40
Update properties.py
giovannivolpe Dec 6, 2024
4f94e98
Update utils.rst
giovannivolpe Dec 6, 2024
79fffda
Update python-app.yml
giovannivolpe Dec 6, 2024
eedf6e7
Update properties.py
giovannivolpe Dec 6, 2024
99b8526
Update python-app.yml
giovannivolpe Dec 6, 2024
298bce0
Update python-app.yml
giovannivolpe Dec 6, 2024
6d5f055
Update __init__.py
giovannivolpe Dec 6, 2024
3393ded
removed pkg_resources
giovannivolpe Dec 6, 2024
0277bae
Update __init__.py
giovannivolpe Dec 6, 2024
4217249
Delete pint_definition.py
giovannivolpe Dec 6, 2024
268dd9e
Merge branch 'develop' into GV/documentation-01
giovannivolpe Dec 6, 2024
28b6b6b
Create pint_definition.py
giovannivolpe Dec 6, 2024
39616fe
Merge branch 'GV/documentation-01' of https://github.com/DeepTrackAI/…
giovannivolpe Dec 6, 2024
7e2c8f8
Update __init__.py
giovannivolpe Dec 6, 2024
3aa4baa
Update __init__.py
giovannivolpe Dec 6, 2024
385d8a0
pixel > img_pixel
giovannivolpe Dec 6, 2024
e195138
Update __init__.py
giovannivolpe Dec 6, 2024
9bbb95f
u
giovannivolpe Dec 6, 2024
147d431
Delete pint_definition.py
giovannivolpe Dec 6, 2024
5f8dc29
Revert "Delete pint_definition.py"
giovannivolpe Dec 6, 2024
8cae448
u
giovannivolpe Dec 6, 2024
dac07e7
u
giovannivolpe Dec 6, 2024
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
11 changes: 2 additions & 9 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest, windows-latest]
install-deeplay: ["", "deeplay"]
install-tensorflow: ["", "tensorflow"]
exclude:
- python-version: "3.11"
install-tensorflow: "tensorflow"

if:
steps:
- uses: actions/checkout@v3
Expand All @@ -38,10 +35,6 @@ jobs:
if: ${{ matrix.install-deeplay == 'deeplay' }}
run: |
python -m pip install deeplay
- name: Install tensorflow
if: ${{ matrix.install-tensorflow == 'tensorflow' }}
run: |
python -m pip install tensorflow==2.10 tensorflow-probability tensorflow-datasets
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
Expand Down
5 changes: 0 additions & 5 deletions _src/source/utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ hasmethod

.. autofunction:: deeptrack.utils.hasmethod

isiterable
^^^^^^^^^^

.. autofunction:: deeptrack.utils.isiterable

kwarg_has_default
^^^^^^^^^^^^^^^^^

Expand Down
20 changes: 14 additions & 6 deletions deeptrack/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
# flake8: noqa
from pint import UnitRegistry, Context
from .backend.pint_definition import pint_definitions
import lazy_import
import importlib
from pint import UnitRegistry

'''from .backend.pint_definition import pint_definitions
units = UnitRegistry(pint_definitions.split("\n"))'''#TBE

units = UnitRegistry(pint_definitions.split("\n"))
# Create a UnitRegistry and add custom units.
units = UnitRegistry()
units.define("img_pixel = 1 * micrometer = ipx")
units.define("xpixel = 1 * micrometer = xpx")
units.define("ypixel = 1 * micrometer = ypx")
units.define("zpixel = 1 * micrometer = zpx")
units.define("simulation_xpixel = 1 * micrometer = sxpx")
units.define("simulation_ypixel = 1 * micrometer = sypx")
units.define("simulation_zpixel = 1 * micrometer = szpx")

# Check if tensorflow is installed without importing it
'''# Check if tensorflow is installed without importing it
import pkg_resources

installed = [pkg.key for pkg in pkg_resources.working_set]
Expand All @@ -23,7 +31,7 @@
HAS_TORCH = False

if HAS_TENSORFLOW and HAS_TORCH:
import torch # torch must be imported before tensorflow
import torch # torch must be imported before tensorflow'''#TBE

from deeptrack.features import *
from deeptrack.aberrations import *
Expand Down
4 changes: 2 additions & 2 deletions deeptrack/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import random

import numpy as np
from pint.quantity import Quantity
from pint import Quantity
# import tensorflow as tf
import skimage
import skimage.measure
Expand Down Expand Up @@ -2313,7 +2313,7 @@ def _resample_volume_position(self, volume):
if "position" in pdict and "_position_sampler" in pdict:
new_position = pdict["_position_sampler"]()
if isinstance(new_position, Quantity):
new_position = new_position.to("pixel").magnitude
new_position = new_position.to("img_pixel").magnitude
pdict["position"] = new_position

return volume
Expand Down
15 changes: 10 additions & 5 deletions deeptrack/math.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
""" Mathematical oprations and structures
"""Mathematical operations and structures.

Classses
--------
This module provides classes and utilities to perform common mathematical
operations and transformations on images, including clipping, normalization,
blurring, and pooling. These are implemented as subclasses of `Feature` for
seamless integration with the feature-based design of the library.

Classes
-------
Clip
Clip the input within a minimum and a maximum value.
Clip the input values within a specified minimum and maximum range.
NormalizeMinMax
Min-max image normalization.
Perform min-max normalization on images.
"""

from typing import Callable, List
Expand Down
8 changes: 4 additions & 4 deletions deeptrack/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
ImportWarning,
)

import pkg_resources
'''import pkg_resources

installed_pkg = [pkg.key for pkg in pkg_resources.working_set]
installed_pkg = [pkg.key for pkg in pkg_resources.working_set]'''#TBE

__all__ = [
"compile",
Expand Down Expand Up @@ -96,8 +96,8 @@ def _get_norm_by_name(x):
"""Returns a normalization layer by name."""
if hasattr(layers, x):
return getattr(layers, x)
elif "tensorflow-addons" in installed_pkg and hasattr(tfa.layers, x):
return getattr(tfa.layers, x)
'''elif "tensorflow-addons" in installed_pkg and hasattr(tfa.layers, x):
return getattr(tfa.layers, x)'''#TBE
else:
raise ValueError(f"Unknown normalization {x}.")

Expand Down
2 changes: 1 addition & 1 deletion deeptrack/optics.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"""


from pint.quantity import Quantity
from pint import Quantity
from deeptrack.backend.units import (
ConversionTable,
create_context,
Expand Down
7 changes: 2 additions & 5 deletions deeptrack/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"""

import numpy as np
from .utils import (
isiterable,
get_kwarg_names,
)
from .utils import get_kwarg_names


from .backend.core import DeepTrackNode
Expand Down Expand Up @@ -58,7 +55,7 @@ def create_action(self, sampling_rule, **dependencies):
if isinstance(sampling_rule, (tuple, np.ndarray)):
return lambda _ID=(): sampling_rule

if isiterable(sampling_rule):
if hasattr(sampling_rule, "__next__"):
# If it's iterable, return the next value
def wrapped_iterator():
while True:
Expand Down
8 changes: 4 additions & 4 deletions deeptrack/scatterers.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Scatterer(Feature):
A default value of the characteristic of the particle. Used by
optics unless a more direct property is set (eg. `refractive_index`
for `Brightfield` and `intensity` for `Fluorescence`).
position_unit : "meter" or "pixel"
position_unit : "meter" or "img_pixel"
The unit of the provided position property.

Other Parameters
Expand All @@ -80,7 +80,7 @@ class Scatterer(Feature):
__list_merge_strategy__ = MERGE_STRATEGY_APPEND
__distributed__ = False
__conversion_table__ = ConversionTable(
position=(u.pixel, u.pixel),
position=(u.img_pixel, u.img_pixel),
z=(u.zpixel, u.zpixel),
voxel_size=(u.meter, u.meter),
)
Expand All @@ -90,7 +90,7 @@ def __init__(
position: PropertyLike[ArrayLike[float]] = (32, 32),
z: PropertyLike[float] = 0.0,
value: PropertyLike[float] = 1.0,
position_unit: PropertyLike[str] = "pixel",
position_unit: PropertyLike[str] = "img_pixel",
upsample: PropertyLike[int] = 1,
voxel_size=None,
pixel_size=None,
Expand Down Expand Up @@ -529,7 +529,7 @@ class MieScatterer(Scatterer):
collection_angle=(u.radian, u.radian),
wavelength=(u.meter, u.meter),
offset_z=(u.meter, u.meter),
coherence_length=(u.meter, u.pixel),
coherence_length=(u.meter, u.img_pixel),
)

def __init__(
Expand Down
2 changes: 1 addition & 1 deletion deeptrack/test/test_aberrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class TestAberrations(unittest.TestCase):

particle = PointParticle(position=(32, 32), position_unit="pixel", intensity=1)
particle = PointParticle(position=(32, 32), position_unit="img_pixel", intensity=1)

def testGaussianApodization(self):
aberrated_optics = Fluorescence(
Expand Down
30 changes: 15 additions & 15 deletions deeptrack/test/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ def test_NonOverlapping_resample_volume_position(self):
)

positions_no_unit = [1, 2]
positions_with_unit = [1 * units.px, 2 * units.px]
positions_with_unit = [1 * units.ipx, 2 * units.ipx]

positions_no_unit_iter = iter(positions_no_unit)
positions_with_unit_iter = iter(positions_with_unit)
Expand All @@ -963,7 +963,7 @@ def test_NonOverlapping_resample_volume_position(self):
self.assertEqual(volume_1.get_property("position"), positions_no_unit[0])
self.assertEqual(
volume_2.get_property("position"),
positions_with_unit[0].to("px").magnitude,
positions_with_unit[0].to("ipx").magnitude,
)

nonOverlapping._resample_volume_position(volume_1)
Expand All @@ -972,7 +972,7 @@ def test_NonOverlapping_resample_volume_position(self):
self.assertEqual(volume_1.get_property("position"), positions_no_unit[1])
self.assertEqual(
volume_2.get_property("position"),
positions_with_unit[1].to("px").magnitude,
positions_with_unit[1].to("ipx").magnitude,
)

def test_NonOverlapping_check_volumes_non_overlapping(self):
Expand Down Expand Up @@ -1170,53 +1170,53 @@ def test_NonOverlapping_check_non_overlapping(self):

# Two spheres at the same position
volume_test0_a = scatterers.Sphere(
radius=5 * units.px, position=(0, 0, 0) * units.px
radius=5 * units.ipx, position=(0, 0, 0) * units.ipx
)()
volume_test0_b = scatterers.Sphere(
radius=5 * units.px, position=(0, 0, 0) * units.px
radius=5 * units.ipx, position=(0, 0, 0) * units.ipx
)()

# Two spheres of the same size, one under the other
volume_test1_a = scatterers.Sphere(
radius=5 * units.px, position=(0, 0, 0) * units.px
radius=5 * units.ipx, position=(0, 0, 0) * units.ipx
)()
volume_test1_b = scatterers.Sphere(
radius=5 * units.px, position=(0, 0, 10) * units.px
radius=5 * units.ipx, position=(0, 0, 10) * units.ipx
)()

# Two spheres of the same size, one under the other, but with a
# spacing of 1
volume_test2_a = scatterers.Sphere(
radius=5 * units.px, position=(0, 0, 0) * units.px
radius=5 * units.ipx, position=(0, 0, 0) * units.ipx
)()
volume_test2_b = scatterers.Sphere(
radius=5 * units.px, position=(0, 0, 11) * units.px
radius=5 * units.ipx, position=(0, 0, 11) * units.ipx
)()

# Two spheres of the same size, one under the other, but with a
# spacing of -1
volume_test3_a = scatterers.Sphere(
radius=5 * units.px, position=(0, 0, 0) * units.px
radius=5 * units.ipx, position=(0, 0, 0) * units.ipx
)()
volume_test3_b = scatterers.Sphere(
radius=5 * units.px, position=(0, 0, 9) * units.px
radius=5 * units.ipx, position=(0, 0, 9) * units.ipx
)()

# Two spheres of the same size, diagonally next to each other
volume_test4_a = scatterers.Sphere(
radius=5 * units.px, position=(0, 0, 0) * units.px
radius=5 * units.ipx, position=(0, 0, 0) * units.ipx
)()
volume_test4_b = scatterers.Sphere(
radius=5 * units.px, position=(6, 6, 6) * units.px
radius=5 * units.ipx, position=(6, 6, 6) * units.ipx
)()

# Two spheres of the same size, diagonally next to each other, but
# with a spacing of 1
volume_test5_a = scatterers.Sphere(
radius=5 * units.px, position=(0, 0, 0) * units.px
radius=5 * units.ipx, position=(0, 0, 0) * units.ipx
)()
volume_test5_b = scatterers.Sphere(
radius=5 * units.px, position=(7, 7, 7) * units.px
radius=5 * units.ipx, position=(7, 7, 7) * units.ipx
)()

# Run tests
Expand Down
10 changes: 5 additions & 5 deletions deeptrack/test/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_Generator(self):
)
scatterer = PointParticle(
intensity=100,
position_unit="pixel",
position_unit="img_pixel",
position=lambda: np.random.rand(2) * 128,
)
imaged_scatterer = optics(scatterer)
Expand Down Expand Up @@ -59,7 +59,7 @@ def test_ContinuousGenerator(self):
)
scatterer = PointParticle(
intensity=100,
position_unit="pixel",
position_unit="img_pixel",
position=lambda: np.random.rand(2) * 128,
)
imaged_scatterer = optics(scatterer)
Expand Down Expand Up @@ -89,12 +89,12 @@ def test_MultiInputs_ContinuousGenerator(self):
)
scatterer_A = PointParticle(
intensity=100,
position_unit="pixel",
position_unit="img_pixel",
position=lambda: np.random.rand(2) * 128,
)
scatterer_B = PointParticle(
intensity=10,
position_unit="pixel",
position_unit="img_pixel",
position=lambda: np.random.rand(2) * 128,
)
imaged_scatterer_A = optics(scatterer_A)
Expand Down Expand Up @@ -135,7 +135,7 @@ def test_CappedContinuousGenerator(self):
)
scatterer = PointParticle(
intensity=100,
position_unit="pixel",
position_unit="img_pixel",
position=lambda: np.random.rand(2) * 128,
)
imaged_scatterer = optics(scatterer)
Expand Down
Loading
Loading