Skip to content

Commit

Permalink
1.5.1 (#152)
Browse files Browse the repository at this point in the history
* chore: autopublish 2022-07-26T13:54:44Z

* Remove create-badges job

* Delete test.py

* Add multi-head masked attention

* Update multi-head gated attention to match parent layer

* Update documentation

* Test multi-head masked attention

* allow gated attention layers to use bias

* test bias in gated attention layers

* set return_attention_weights to False to avoid multi-outputs

Use MultiHeadSelfAttention and MultiHeadGatedSelfAttention if want to return the attention weights

* reformat gnns/layers.py

This commit adds new message-passing graph layers (MPN) and graph convolutional layers to dt, including vanilla MPN, GRUMPN, Masked-attention FGNN, and GraphTransformer.

* Update layers.py

* Update test_layers.py

* Update models.py

* Update test_models.py

* Update test_models.py

* Fix indexing problems related to tf.gather

* Allow multi-inputs in ContinuousGenerator

* Fix bad conversion to integer

* version bump

* Fix phase correction at focus and offset calculation

* Fix phase correction in propagation

* Fix mie phase out of foucs

* Fix mie phase out of foucs

* Update README.md

* Bm/version 1.4.0 (#137)

* Update layers.py

* Update convolutional.py

Transformer-based models can now be reused and expanded quickly and easily

* Update documentation

* Update Transformer-based models

* Delete classifying_MNIST_vit_tutorial.ipynb

* Create classifying_MNIST_vit_tutorial.ipynb

* Update datasets.py

* Allows kwargs as inputs in single_layer_call

* Update embeddings.py

* masked transformers

* reformat transformer models

* Create trajectory_analysis_tutorial.ipynb

* Add Variational autoencoders

* Add variational autoencoders

* Update vae.py

* Create MNIST_VAE_tutorial.ipynb

* Update MNIST_VAE_tutorial.ipynb

* Create folder for course examples

* Update README.md

* Update README.md

* Update examples

* Update README.md

* Update README.md

* Update MNIST VAE examples

* Added MLP regression example

* Update README.md

* Create image_segmentation_Unet.ipynb

* Update README.md

* Documented and tested cell_counting_tutorial.ipynb

* improve dnn example

* Shift variant mie

* Position mie scatterer correctly

* implement set z

* implement mnist v1

* implement z dependence

* remove logging

* Implement flattening methods

* Implement pooling and resizing

* Implement TensorflowDataset

* Finalize MNIST

* Implement Malaria classification

* alpha0 release

* fix batchsize in fit

* implement dataset.take

* Implement datasets

* fix phase in mie

* Fix mie positioning and focusing

* Commit to new branch

* add tensorflow datasets dependence

* remove test

Co-authored-by: Jesús Pineda <[email protected]>
Co-authored-by: Jesús Pineda <[email protected]>
Co-authored-by: Benjamin Midtvedt <[email protected]>
Co-authored-by: Ccx55 <[email protected]>

* Add tensorflow datasets to the list of dependencies.

* Read requirements.txt into setup.py

* remove sphinx from build

* remove create badges

* Create CITATION.cff

* Create .zenodo.json

* Update transformer models

* Update pint_definition.py

* Update requirements.txt

* create TimeDistributed CNN

* small fixes to lodestar

* remove direct getter of properties

* Update scatterers.py

Coherence length fix for MieScatterer

* Update scatterers.py

Added coherence length to the conversion table

* mie phase fix

Co-authored-by: BenjaminMidtvedt <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Jesús Pineda <[email protected]>
Co-authored-by: Benjamin Midtvedt <[email protected]>
Co-authored-by: Jesús Pineda <[email protected]>
Co-authored-by: Ccx55 <[email protected]>
Co-authored-by: Harshith Bachimanchi <[email protected]>
  • Loading branch information
8 people authored Nov 21, 2022
1 parent 8685af1 commit 1b5305b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
10 changes: 5 additions & 5 deletions deeptrack/optics.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,11 +687,11 @@ def get(self, illuminated_volume, limits, fields, **kwargs):

if not kwargs.get("return_field", False):
output_image = np.square(np.abs(output_image))
else:
# Fudge factor. Not sure why this is needed.
output_image = output_image - 1
output_image = output_image * np.exp(1j * -np.pi / 4)
output_image = output_image + 1
# else:
# Fudge factor. Not sure why this is needed.
# output_image = output_image - 1
# output_image = output_image * np.exp(1j * -np.pi / 4)
# output_image = output_image + 1

output_image.properties = illuminated_volume.properties

Expand Down
58 changes: 41 additions & 17 deletions deeptrack/scatterers.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,9 @@ class MieScatterer(Scatterer):
return_fft : bool
If True, the feature returns the fft of the field, rather than the
field itself.
coherence_length : float
The temporal coherence length of a partially coherent light given in meters. If None, the illumination is
assumed to be coherent.
"""

__gpu_compatible__ = True
Expand All @@ -508,6 +511,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),
)

def __init__(
Expand All @@ -527,6 +531,7 @@ def __init__(
working_distance=1000000, # large value to avoid numerical issues unless the user specifies a smaller value
position_objective=(0, 0),
return_fft=False,
coherence_length=None,
**kwargs,
):
if polarization_angle is not None:
Expand Down Expand Up @@ -555,6 +560,7 @@ def __init__(
working_distance=working_distance,
position_objective=position_objective,
return_fft=return_fft,
coherence_length=coherence_length,
**kwargs,
)

Expand All @@ -574,20 +580,22 @@ def _process_properties(self, properties):
)

if properties["offset_z"] == "auto":
size = (
np.array(properties["output_region"][2:])
- properties["output_region"][:2]
)
xSize, ySize = size
arr = pad_image_to_fft(np.zeros((xSize, ySize))).astype(complex)
min_edge_size = np.min(arr.shape)
properties["offset_z"] = (
np.min(
np.array(properties["output_region"][2:])
- properties["output_region"][:2]
)
* 0.75
min_edge_size
* 0.45
* min(properties["voxel_size"][:2])
/ np.tan(properties["collection_angle"])
)
return properties

def get_xy_size(self):
output_region = self.properties["output_region"]()
padding = self.properties["padding"]()
def get_xy_size(self, output_region, padding):
return (
output_region[2] - output_region[0] + padding[0] + padding[2],
output_region[3] - output_region[1] + padding[1] + padding[3],
Expand All @@ -599,7 +607,7 @@ def get_XY(self, shape, voxel_size):
return np.meshgrid(x * voxel_size[0], y * voxel_size[1], indexing="ij")

def get_detector_mask(self, X, Y, radius):
return np.sqrt(X ** 2 + Y ** 2) < radius
return np.sqrt(X**2 + Y**2) < radius

def get_plane_in_polar_coords(self, shape, voxel_size, plane_position):

Expand All @@ -612,8 +620,8 @@ def get_plane_in_polar_coords(self, shape, voxel_size, plane_position):
Y = Y + plane_position[1]
Z = plane_position[2] # might be +z or -z

R2_squared = X ** 2 + Y ** 2
R3 = np.sqrt(R2_squared + Z ** 2) # might be +z instead of -z
R2_squared = X**2 + Y**2
R3 = np.sqrt(R2_squared + Z**2) # might be +z instead of -z

# get the angles
cos_theta = Z / R3
Expand All @@ -639,11 +647,13 @@ def get(
working_distance,
position_objective,
return_fft,
coherence_length,
output_region,
**kwargs,
):

# Get size of the output
xSize, ySize = self.get_xy_size()
xSize, ySize = self.get_xy_size(output_region, padding)
voxel_size = get_active_voxel_size()
arr = pad_image_to_fft(np.zeros((xSize, ySize))).astype(complex)
arr = image.maybe_cupy(arr)
Expand Down Expand Up @@ -672,11 +682,11 @@ def get(
# x and y position of a beam passing through field evaluation plane on the objective
x_farfield = (
position[0]
+ R3_field * np.sqrt(1 - cos_theta_field ** 2) * cos_phi_field / ratio
+ R3_field * np.sqrt(1 - cos_theta_field**2) * cos_phi_field / ratio
)
y_farfield = (
position[1]
+ R3_field * np.sqrt(1 - cos_theta_field ** 2) * sin_phi_field / ratio
+ R3_field * np.sqrt(1 - cos_theta_field**2) * sin_phi_field / ratio
)

# if the beam is within the pupil
Expand Down Expand Up @@ -720,19 +730,33 @@ def get(
S2 = sum([E[i] * B[i] * PI[i] + E[i] * A[i] * TAU[i] for i in range(0, L)])

arr[pupil_mask] = (
1j
-1j
/ (k * R3_field)
* np.exp(1j * k * R3_field)
* (S2 * S2_coef + S1 * S1_coef)
)

# For partially coherent illumination
if coherence_length:
sigma = z * np.sqrt((coherence_length / z + 1) ** 2 - 1)
sigma = sigma * (offset_z / z)

mask = np.zeros_like(arr)
y, x = np.ogrid[
-mask.shape[0] // 2 : mask.shape[0] // 2,
-mask.shape[1] // 2 : mask.shape[1] // 2,
]
mask = np.exp(-0.5 * (x**2 + y**2) / ((sigma) ** 2))

arr = arr * mask

fourier_field = np.fft.fft2(arr)

propagation_matrix = get_propagation_matrix(
fourier_field.shape,
pixel_size=voxel_size[2],
wavelength=wavelength,
to_z=(-offset_z - z) / refractive_index_medium,
wavelength=wavelength / refractive_index_medium,
to_z=(-offset_z - z),
dy=(
relative_position[0] * ratio
+ position[0]
Expand Down

0 comments on commit 1b5305b

Please sign in to comment.