Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phase 2D + 3D refactor #117

Merged
merged 47 commits into from
Apr 22, 2023
Merged

Phase 2D + 3D refactor #117

merged 47 commits into from
Apr 22, 2023

Conversation

talonchandler
Copy link
Collaborator

@talonchandler talonchandler commented Apr 20, 2023

This PR makes the following changes to the "Phase2D" and "Phase3D" reconstructions methods:

  • moves these code paths from waveorder_reconstructor into their own files in /waveorder/models/phase2D_3D.py and waveorder/models/phase3D_3D.py.
  • refactors both of these reconstruction paths into the following methods: calculate_transfer_function, visualize_transfer_function (for napari viewing), apply_transfer_function (very simple simulation), and apply_inverse_transfer_function. These methods are in preparation for direct calls from the recOrder CLI.
  • performs all calculations with torch
  • performs all calculations in CZYX order
  • adds tests to the key parts of optics, utils, and the new examples
  • preserves the code paths for the PTI and Birefringence_recon (S1&S2 diffraction-aware reconstruction) in waveorder_reconstructor. I am now testing several example scripts to alert me to breaking changes.

I suggest starting your review by running the new examples scripts in /examples/PODT_Phase_simulation/. This will demonstrate a simplified form of what I expect on the recOrder side: the TF is calculated (and optionally viewed in napari), saved to a file, then used to reconstruct the data.

Next, I suggest you take a look at the (currently under-documented but hopefully much clearer than before) function signatures for calculate_transfer_function and apply_inverge_transfer_function in models/phase2D_3D.py and models/phase3D_3D.py. These function signatures have a nearly direct correspondence with recOrder's GUI parameters.

Finally, I'll request your thoughts on my models format that arose naturally during my refactor. I've temporarily named the three models after our assumption about the sample (phase2D,phase3D, planaranisoND) and the data we acquire (3D, polND). To my eye, this seems to be an extensible way to split up the code since different assumptions about the object and/or different data will lead to different models (and code). I'm also very aware that this could be a good application for an abstract base class (especially since I expect to implement calculate_transfer_function and apply_inverse_transfer_function methods for planaranisoND_polND), but I've chosen to delay this for now in fear of premature abstraction.

I'm happy to chat in person anytime tomorrow. My immediate focus is on the interface for the "Retardance + Orientation" pipeline which I expect to require about 3/4 of my day tomorrow. After that PR, I am planning to start working on the recOrder CLI side and link everything up.

@talonchandler talonchandler requested a review from ziw-liu April 20, 2023 18:25
mattersoflight and others added 6 commits April 20, 2023 16:23
Return the 2D absorption along with phase. Viewing OTFs in napari is very nice. I changed the axis order to be able to compare phase and absorption OTFs at focal plane.
I suggest changing this example to be simulation and reconstruction of 2D specimens, thinner than the depth of field of the microscope.
@talonchandler
Copy link
Collaborator Author

Thanks for the contributions and in-person chat @mattersoflight. I've made the following changes:

  • renamed the models using the schema <object-type>_<object-thickness>_<data-shape> . We're starting with isotropic_thin_3d, phase_thick_3d, and inplane_anisotropic_thin_pol3d.
  • fixed isotropic_thin_3d so that it handle absorption, and fixed the example to simulate a thin object.
  • renamed from 2D/3D -> 2d/3d following PEP8 and one of Keith's comments in the dragonfly repo.

@talonchandler
Copy link
Collaborator Author

Merging into alg-dev...we can discuss more when I open a PR into main

@talonchandler talonchandler merged commit 1e31be1 into alg-dev Apr 22, 2023
talonchandler added a commit that referenced this pull request Jul 25, 2023
* New Stokes and Mueller module (#110)

* Initial fwd and inv w/ tests

* Add A-matrix and mueller-from-projection functions

* Debug AR_mueller

* Add convenience functions

* Make 4d transposes nd with moveaxis

* Add documentation

* Improve module docstring

* Change `KeyError` to `ValueError`

* Improved docs

* Remove unnecessary test

* Removed "float" from docs

* Revert "Removed "float" from docs"

This reverts commit d9dd7e3.

* Use `assert_almost_equal`

* fixed couple of  typos

* `A` -> `I2S` & new `S2I`

* comprehensive renaming

* copy `s0` <-> `tra`

* `np.array(s0)` so that it always has `.copy()`

* Set default to "inverse"

---------

Co-authored-by: Shalin Mehta <[email protected]>

* PR docs (#111)

* Add .git-blame-ignore-revs (#109)

* Add #110 pr doc

* Phase 2D + 3D refactor (#117)

* black formatting

* move 2D-to-3D phase recon to phase.py

* convert gen_HZ_stack to ZYX

* keep existing gpu handling

* add 3D_to_3D phase OTF

* improve naming consistency in phase_2D_to_3D_OTF

* Add kwargs to recon params

* change axes for 2D recon preparation

* simplify 2D_to_3D recon with kwargs

* handle padding and simplify OTFs

* add 3D_to_3D recon with kwargs

* temporarily remove docs for rewriting

* first dependence on torch

* move gen_Hz_stack to torch

* convert 2d wotf to torch

* move gen_Greens_function_z to torch

* move important utils to torch

* phase3Dto3D complete overhaul

* refactor

* optics.py to torch

* high-level tests

* splitt phase.py into models

* clean up 3D script

* cleaning and notes

* phase2Dto3D placeholders

* clean tests

* use napari in tests

* better skipping

* reduce dependencies

* update tests

* maintiain PTI simulation's compatibility revised optics functions

* drop pdb

* Preserve birefringence recon

* fix transpose bug

* transpose bug

* phase2Dto3D.py example

* support padding

* empty model for planaraniso

* improved names

* broad renaming of phase2D_3D and phase3D_3D

* updated 2D phase and absorption recon

Return the 2D absorption along with phase. Viewing OTFs in napari is very nice. I changed the axis order to be able to compare phase and absorption OTFs at focal plane.

* display OTFs with Z-axis as a slider

* changes to 2D phase/absorption simulation

I suggest changing this example to be simulation and reconstruction of 2D specimens, thinner than the depth of field of the microscope.

* rename models to <object-type>_<object-thickness>_<data_shape>

* fix isotropic_thin_3d example, include absorption

* 2D -> 2d, 3D -> 3d

---------

Co-authored-by: Shalin Mehta <[email protected]>

* Prepare polarization algorithms for integration with `recOrder` (#118)

* black formatting

* move 2D-to-3D phase recon to phase.py

* convert gen_HZ_stack to ZYX

* keep existing gpu handling

* add 3D_to_3D phase OTF

* improve naming consistency in phase_2D_to_3D_OTF

* Add kwargs to recon params

* change axes for 2D recon preparation

* simplify 2D_to_3D recon with kwargs

* handle padding and simplify OTFs

* add 3D_to_3D recon with kwargs

* temporarily remove docs for rewriting

* first dependence on torch

* move gen_Hz_stack to torch

* convert 2d wotf to torch

* move gen_Greens_function_z to torch

* move important utils to torch

* phase3Dto3D complete overhaul

* refactor

* optics.py to torch

* high-level tests

* splitt phase.py into models

* clean up 3D script

* cleaning and notes

* phase2Dto3D placeholders

* clean tests

* use napari in tests

* better skipping

* reduce dependencies

* update tests

* maintiain PTI simulation's compatibility revised optics functions

* drop pdb

* Preserve birefringence recon

* fix transpose bug

* transpose bug

* phase2Dto3D.py example

* support padding

* empty model for planaraniso

* improved names

* broad renaming of phase2D_3D and phase3D_3D

* Rename variables in `stokes.py`.

* updated 2D phase and absorption recon

Return the 2D absorption along with phase. Viewing OTFs in napari is very nice. I changed the axis order to be able to compare phase and absorption OTFs at focal plane.

* display OTFs with Z-axis as a slider

* changes to 2D phase/absorption simulation

I suggest changing this example to be simulation and reconstruction of 2D specimens, thinner than the depth of field of the microscope.

* convert stokes to torch

* initial draft of planaraniso model

* rename models to <object-type>_<object-thickness>_<data_shape>

* fix isotropic_thin_3d example, include absorption

* 2D -> 2d, 3D -> 3d

* calculate background corrections with transfer function

* rearrange examples folder

* rearrange examples folder

* rearrange `isotropic` and `phase` examples

* add `inplane_anisotropic` model and example

* fix inplane tests

* fix maintenance scripts

* remove deprecated

* use `np.meshgrid` for consistency

* minor bug

* integration changes

---------

Co-authored-by: Shalin Mehta <[email protected]>

* Remove kwargs from reconstructions (#119)

* remove kwargs

* fix estimated background bug

* `illumination_wavelength` -> `wavelength_illumination` (#123)

* Remove duplicate test (#125)

remove duplicate test

* Add option for axial flip of `phase_thick_3d` transfer function (#124)

* `illumination_wavelength` -> `wavelength_illumination`

* add option for axial flip of transfer function

* test axial flip

---------

Co-authored-by: Ziwen Liu <[email protected]>

* Rename model from `anisotropic_thin` to `oriented_thick` (#127)

`anisotropic_thin` -> `oriented_thick`

* `isotropic_fluorescent_thick_3d` model (#128)

* typo

* model outline

* prototype transfer function

* 3d phantom + visualize transfer function

* refactor apply_transfer_function

* typo

* refactor padding (with gpt docs + tests)

* complete example

* test apply_inverse_transfer_function

* TV reconstructions raise NotImplementedError

* `pad_zyx` -> `pad_zyx_along_z`

* Simplify `data += 10`

* Update tests/test_util.py

Co-authored-by: Ziwen Liu <[email protected]>

---------

Co-authored-by: Ziwen Liu <[email protected]>

* Match parameters to simplify `recOrder`-`waveorder` interface (#131)

* add axial_flip to `isotropic_thin_3d`

* `illumination` -> `emission` for fluorescence

* simplify parameters for usage with recOrder

* fix test

* pin torch>=2.0.0

* `z_position_list` should accept a list

---------

Co-authored-by: Shalin Mehta <[email protected]>
Co-authored-by: Ziwen Liu <[email protected]>
@talonchandler talonchandler deleted the phase-refactor branch August 5, 2023 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants