ri-imaging / odtbrain Goto Github PK
View Code? Open in Web Editor NEWPython library for diffraction tomography with the Born and Rytov approximations
Home Page: https://odtbrain.readthedocs.io
License: BSD 3-Clause "New" or "Revised" License
Python library for diffraction tomography with the Born and Rytov approximations
Home Page: https://odtbrain.readthedocs.io
License: BSD 3-Clause "New" or "Revised" License
Dear @paulmueller,
I am currently working on my Bachelor Thesis and I used your code as a basis for different testings. I discovered some inconsistencies in the _alg2d_fmp.py file. The function fourier_map_2d adds a filter to Fcomp to only include the wave with a wavenumber smaller then \sqrt{2} k_m in line 255. However, I believe this conditions isn't applied correctly. The results are now inconsistent for different units (one can apply dimensionless code by compensating for the resolution on the detector or compute the results with units). I believe the mistake is in line 255 and it should be corrected as follows:
Fcomp[np.where(np.sqrt(kinx * * 2 + kiny * * 2) > np.sqrt(2) * km)] = 0
With the square root added the units are correct in that equation. Do you agree?
Thanks in advance!
Best regards,
Bernd
Good morning all
So, I would like to do some tomography reconstruction simulation but before that, I have to create phantom object and collected projections using meep package, I saw that you already did this but I didn't find it on your GitHub. please could you tell me where to find the script to generate in silico data set created with the software meep.
PS: I'm using python
Hi,
I correctly installed odtbrain with all dependencies. When I try to run "backprop_from_fdtd_3d.py" or any other examples which includes multiprocessing codes, terminal shows an error like given below.
I checked from stackoverflow, it seems that multiprocessing codes should be integrated into" init", but I could not succeed. Can you please check, if possible ?
Thanks in advance.
Traceback (most recent call last):
File "", line 1, in
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/spawn.py", line 125, in _main
prepare(preparation_data)
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/spawn.py", line 236, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/spawn.py", line 287, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/runpy.py", line 268, in run_path
return _run_module_code(code, init_globals, run_name,
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Users/gkirabali/examples/backprop_from_fdtd_3d.py", line 37, in
f = odt.backpropagate_3d(uSin=sinoRytov,
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/site-packages/odtbrain/_alg3d_bpp.py", line 486, in backpropagate_3d
pool4loop = mp.Pool(processes=num_cores,
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/context.py", line 119, in Pool
return Pool(processes, initializer, initargs, maxtasksperchild,
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/pool.py", line 212, in init
self._repopulate_pool()
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/pool.py", line 303, in _repopulate_pool
return self._repopulate_pool_static(self._ctx, self.Process,
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/pool.py", line 326, in _repopulate_pool_static
w.start()
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/process.py", line 121, in start
self._popen = self._Popen(self)
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/context.py", line 284, in _Popen
return Popen(process_obj)
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 32, in init
Traceback (most recent call last):
File "", line 1, in
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/spawn.py", line 116, in spawn_main
super().init(process_obj)
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/popen_fork.py", line 19, in init
exitcode = _main(fd, parent_sentinel)
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/spawn.py", line 125, in _main
prepare(preparation_data)
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/spawn.py", line 236, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/spawn.py", line 287, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/runpy.py", line 268, in run_path
self._launch(process_obj)
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 42, in _launch
return _run_module_code(code, init_globals, run_name,
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/runpy.py", line 97, in _run_module_code
prep_data = spawn.get_preparation_data(process_obj._name)
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/spawn.py", line 154, in get_preparation_data
_check_not_importing_main()
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/spawn.py", line 134, in _check_not_importing_main
raise RuntimeError('''
_run_code(code, mod_globals, init_globals,
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/runpy.py", line 87, in _run_code
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
exec(code, run_globals)
File "/Users/gkirabali/examples/backprop_from_fdtd_3d.py", line 37, in
f = odt.backpropagate_3d(uSin=sinoRytov,
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/site-packages/odtbrain/_alg3d_bpp.py", line 486, in backpropagate_3d
pool4loop = mp.Pool(processes=num_cores,
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/context.py", line 119, in Pool
return Pool(processes, initializer, initargs, maxtasksperchild,
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/pool.py", line 212, in init
self._repopulate_pool()
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/pool.py", line 303, in _repopulate_pool
return self._repopulate_pool_static(self._ctx, self.Process,
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/pool.py", line 326, in _repopulate_pool_static
w.start()
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/process.py", line 121, in start
self._popen = self._Popen(self)
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/context.py", line 284, in _Popen
return Popen(process_obj)
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 32, in init
super().init(process_obj)
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/popen_fork.py", line 19, in init
self._launch(process_obj)
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 42, in _launch
prep_data = spawn.get_preparation_data(process_obj._name)
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/spawn.py", line 154, in get_preparation_data
_check_not_importing_main()
File "/Users/gkirabali/opt/miniconda3/envs/myenv/lib/python3.9/multiprocessing/spawn.py", line 134, in _check_not_importing_main
raise RuntimeError('''
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
via iterative method and constraints (n>1.333, n real).
TODO:
Dear Paul,
In the Fourier domain reconstruction in alg2d_fmp.py there is a check on the sampling of the projected value
line 169 np.max(kx**2) <= km**2
print("......Measurement data is oversampled.")
However, changing the sampling of the detector can never remove this error as the command fx = np.fft.fftfreq(len(uSin[0]))
generates frequencies between $- \pi $ and res
.
Also, it seems that the activation of this error does not hamper the output of the program. It therefore should be more like a warning.
Could you comment on this and/or change the code?
Best regards,
Jeroen Kalkman
TU Delft
www.jkalkman.nl
This bug affects at least backpropagate_3d_tilted
. Workaround is to just use square-shaped sinogram slices.
https://github.com/RI-imaging/ODTbrain/blob/master/odtbrain/_Back_3D_tilted.py#L376
Dear Paul,
The function fourier_map_2d
reconstructs the scattering potential from the measured scattered wavefields. However, when reconstructing this for a real-valued refractive index distribution (in my case a cylinder( the imaginary part is not zero and in fact is about 40% of the real value (hence substantial). According to the theory in your document it should be zero. In your Mie numerical example you just discard the imaginary part.
Please comment on this, is this an error, numerical artifact, or something else?
Thanks,
Jeroen Kalkman
How does that affect the reconstruction?
https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.affine_transform.html
This issue can be reproduced for very specific python versions and so far happens consistently only on specific CI runs.
It must have something to do with the environment. Python packages on GH Actions are all from PyPI...
import numpy as np
import pathlib
import matplotlib.pylab as plt
paths = ["data_expected.txt", "data_curious.txt"]
data = [np.loadtxt(f) for f in paths]
p1 = data[0].view(complex).reshape(22, 22)
p2 = data[1].view(complex).reshape(22, 22)
ax1 = plt.subplot(221, title="expected real")
ax1.imshow(p1.real)
ax2 = plt.subplot(222, title="expected imag")
ax2.imshow(p2.real)
ax3 = plt.subplot(223, title="diff real")
ax3.imshow(p2.real - p1.real)
ax4 = plt.subplot(224, title="diff imag")
ax4.imshow(p2.imag- p1.imag)
plt.show()
... to make sure ODTbrain runs with -o
Not sure where this issue came from? Might actually not apply to ODTbrain...
numpy.pad
is not memory-efficient. At least replace it for the 3D algorithms.
Apparently this is not straight-forward to test and there have been changes due to #19
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.