Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 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
03145b6
Update pint_definition.py
giovannivolpe Dec 6, 2024
1f7f471
Update __init__.py
giovannivolpe Dec 6, 2024
2a0a448
Update __init__.py
giovannivolpe Dec 6, 2024
de9a2fe
Update pint_definition.py
giovannivolpe Dec 6, 2024
6c6a316
u
giovannivolpe Dec 6, 2024
5d4efa9
Update pint_definition.py
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
10 changes: 5 additions & 5 deletions deeptrack/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# 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

# Create a unit registry with custom pixel-related units.
units = UnitRegistry(pint_definitions.split("\n"))

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

installed = [pkg.key for pkg in pkg_resources.working_set]
Expand All @@ -23,7 +23,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
53 changes: 52 additions & 1 deletion deeptrack/backend/pint_definition.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
"""Pint constants and units definition for DeepTrack2.

This file consolidates and extends the default definitions provided by Pint's
`default_en.txt` and `constants_en.txt` files. These files define physical
constants and unit systems based on internationally recognized standards, such
as the International System of Units (SI), and additional systems like CGS,
Planck units, and atomic units.

Sources
-------
- Pint's default unit definitions:
https://github.com/hgrecco/pint/blob/main/pint/default_en.txt
- Pint's default constants definitions:
https://github.com/hgrecco/pint/blob/main/pint/constants_en.txt

Content
-------
- Mathematical Constants: Includes key values like π, Euler's number,
and the natural logarithm of 10.
- Physical Constants: Covers fundamental constants like the speed of light,
Planck constant, and Boltzmann constant.
- Derived Constants: Defines values such as the fine-structure constant and
classical electron radius.
- Units: Provides base and derived units for length, mass, time, energy, etc.,
with precise conversion factors.
- Prefixes and Aliases: Defines standard prefixes (e.g., milli-, kilo-, mega-)
and unit aliases to ensure flexibility.
- Unit Systems: Details unit systems, including SI, MKS, CGS, Planck, and
imperial units.
- Contexts and Conversion: Includes context-specific definitions to facilitate
domain-specific conversions.

Key Modifications
-----------------
This file is derived from the default Pint files with the adjustments:
1. Groups Removed: Unit group definitions (e.g., `@group`) have been excluded
to avoid conflicts with the definition of pixel.
2. Final Variables Added: Defines constants and variables required for the
project-specific context (e.g., pixel-related units).

Usage
-----
To create a unit registry with custom pixel-related units:

>>> from pint import UnitRegistry
>>> from .backend.pint_definition import pint_definitions
>>>
>>> units = UnitRegistry(pint_definitions.split("\n"))

"""


pint_constants = """
# Default Pint constants definition file
# Based on the International System of Units
Expand Down Expand Up @@ -939,5 +991,4 @@
simulation_xpixel = 1 micrometer = sxpx
simulation_ypixel = 1 micrometer = sypx
simulation_zpixel = 1 micrometer = szpx

"""
2 changes: 1 addition & 1 deletion 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
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
2 changes: 1 addition & 1 deletion deeptrack/test/test_optics.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_upscale_fluorescence(self):
error = np.abs(
output_image_2x_upscale - output_image_no_upscale
).mean() # Mean absolute error
self.assertLess(error, 0.005)
self.assertLess(error, 0.01)

def test_upscale_brightfield(self):
microscope = optics.Fluorescence(
Expand Down
18 changes: 4 additions & 14 deletions deeptrack/test/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,25 @@
import sys

# sys.path.append(".") # Adds the module to path

import unittest

from .. import utils


class TestUtils(unittest.TestCase):

def test_hasmethod(self):
self.assertTrue(utils.hasmethod(utils, "hasmethod"))
self.assertFalse(
utils.hasmethod(utils, "this_is_definetely_not_a_method_of_utils")
)

def test_isiterable(self):
self.assertFalse(utils.isiterable(1))

non_iterable_obj = ("apple", "banana", "cherry")
self.assertFalse(utils.isiterable(non_iterable_obj))

iterable_obj = iter(("apple", "banana", "cherry"))
self.assertTrue(utils.isiterable(iterable_obj))


def test_as_list(self):

obj = 1
self.assertEqual(utils.as_list(obj), [obj])

list_obj = [1, 2, 3]
self.assertEqual(utils.as_list(list_obj), list_obj)


def test_get_kwarg_names(self):
def func1():
pass
Expand Down Expand Up @@ -67,6 +56,7 @@ def func7(key1, key2=1, key3=3, **kwargs):

self.assertEqual(utils.get_kwarg_names(func7), ["key1", "key2", "key3"])


def test_safe_call(self):

arguments = {
Expand Down
18 changes: 14 additions & 4 deletions deeptrack/types.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
""" Type declarations for internal use
"""
"""Type declarations for internal use.

import typing
This module defines type aliases and utility types to standardize the type
annotations used throughout the codebase. It enhances code readability,
maintainability, and reduces redundancy in type annotations. These types are
particularly useful for properties and array-like structures used within the
library.
"""

import numpy as np
import typing

# Property type declaration
# T is a generic type variable defining generic types for reusability.
T = typing.TypeVar("T")

# PropertyLike is a type alias representing a value of type T
# or a callable returning type T.
PropertyLike = typing.Union[T, typing.Callable[..., T]]

# ArrayLike is a type alias representing any array-like structure.
# It supports tuples, lists, and numpy arrays containing elements of type T.
ArrayLike = typing.Union[typing.Tuple[T], typing.List[T], np.ndarray]
Loading
Loading