PtyLab / PtyLab.py

Python implementation of ptylab
Other
18 stars 8 forks source link

issue from ploting of phase or need to minimize the phase gradient within the scan region #34

Closed XLIU-1993 closed 1 year ago

XLIU-1993 commented 1 year ago

I used mPIE to reconstruct my simulated obj= ampexp(1jphase); obj amplitude and phase are shown on the right side figure, and the probe has a constant phase value.

Firstly, I wonder if the reconstruction worked properly because applying np.angle(object) does not resolve the phase. Is it related to the minimization of the phase gradient which caused the phase jump? Function in BaseEngine _setObjectProbeROI seems not to calculate a polygon ROI. Can I use this ROI as a mask to write a minimization of phase gradient?

image

Secondly, the obj amplitude is obtained by doing abs(object), it seems like the reconstructed obj amplitude has some 'footprints' of the obj phase; check the 'wrinkles' on the left side obj amplitude image. It feels like the abs(object) = abs(abs(fft(obj amplitude))+np.angle(fft(obj phase))). I don't really understand how it looks like this, could you give some insights please?

image
dboonz commented 1 year ago

Hi Xliu,

Could you give us a bit more specifics about your simulation? It looks a bit like your algorithm didn't converge. How many iterations did you run? What is the size of your scan grid? Do you have a simulation script that you're willing to share? In other words, could you give us a reproducible example?

My first estimate would be that you may not have enough diffraction patterns, or that you need to run more iterations.

kind regards, Dirk

XLIU-1993 commented 1 year ago

Dear Dirk,

Thank you for the response! Firstly, for your questions, the cam_pxlnb is (256,256), the probe is a Gaussian distribution with sigma=32 pixels, and the scan pattern is generated using Archimedes spiral function with a scan_step = 38 pixels. 100 scan steps were used. And the iteration number of mPIE is 300.

I found out that the 'phase jump' was caused by the 'params.backgroundModeSwitch = True', the phase is well resolved as long as this parameter is switched back to False. I did reconstruction with the same dataset by only switching this parameter on and off, results are shown below. Do you know how could this parameter influence the reconstruction?

At last, you may notice that the probe is not centered on the matrix, is this normal?

Best regards, Xu

image
roflmaostc commented 1 year ago

Try to set comStabilizationSwitch=true for the Params object such that the probe is forced to the center after each iteration through the ptychogram.

XLIU-1993 commented 1 year ago

It works fine with rofmaostc's suggestion! I read your arvix preprint on Ptylab and the wavefront measuring technique with Ptychography, very impressing work guys! I close this issue, but I think you might need to check the estimation of the background in the future, have a good day!

image

roflmaostc commented 1 year ago

Another recommendation: Try to zero-pad your probe with zeros around before starting the reconstruction. There might be some boundary effects because of that.

Which propagator are you using?

XLIU-1993 commented 1 year ago

The sampling ratio is well satisfied if your recommendation concerns this. I was using the Fraunhofer propagator. And I checked again by plotting the amplitude and phase separately, there are still some phase wrapping , check the red arrow part. Does it connect to the minimization of the phase gradient? Or is this already implemented in PtyLab?

image
roflmaostc commented 1 year ago

Ah I see, your previous image was cropped :smile:

The raw data looks good in terms of sampling of the probe shape. My concern was that your previous FoV was too small to capture the probe sufficiently.

dboonz commented 1 year ago

Hi Xliu,

The overall phase of the reconstruction is not normalized, so that could be any arbitrary number. You can try to use something like this: https://scikit-image.org/docs/stable/auto_examples/filters/plot_phase_unwrap.html to unwrap the phase, or set a single pixel to a known value for your simulation.