-
Notifications
You must be signed in to change notification settings - Fork 17
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
Enquiry about fixing the probe during reconstruction #595
Comments
Hi, have you checked that the initial probe from the '..._None_0000.ptyr' dump file that goes into the iterations (where it is not touched anymore) matches the probe you put in. Do you have images of the probe you load and the one that goes into the iterations? |
Here is my code, yes, I found that the probe reconstructed from the code is added with a support, my original probe was in 64 64, but now what I have is a 6464 probe but with only central part having amplitude. besides, the max amplitude is 120 while what I gave to it is actually around 1200
|
I am checking the aperture code you mentioned, thank you for the guidance!!! |
Try adding the following lines when using a loaded probe that you want to keep unchanged:
|
Hi everyone, If I understood the problem well, one should notice from the PtyPy Tree Structure in the documentation that the array you pass in In case you have the In addition, concerning the issue you had about the amplitudes only being modified on the central region, this happens because the defaults for the parameter for I hope this will help you. |
@kahntm Thank you! I tried your advised code. Now the ground truth (up) and recovered probe (down) are looking like this, they are already very similar, except seems still remaining a little support at edges. And the max amplitude is still 120 while ground truth is around 1200. I think this should be the reason that I am providing a wave but not the probe directly. I will try to modify some parameters to make it better. @jcesardasilva thank you for the guidance! Now I know that it is not directly providing the probe to the algorithm, instead it is a wave. However, in this case, if I am not running a .ptyr file before, instead, I am providing a numpy probe to it during the updates. Because for most methods especially deep methods in my research on ptychography, they assume the probe to be known. So to be fair to the iterative methods, the probe should also be known and fixed. That is why I want to provide a probe numpy file to it directly and hope it could be fixed. |
Looking sharply at the features in your probe, it looks the one you end up with somehow is a pixel shifted compared to the "original one". And that in both directions. And if for some reason the first line and column are ignored ptypy will add zeros to create a probe of the correct size. |
I tried to recreate your problem... When creating the a numpy array as initial probe and setting all "processing" steps to None, I get the right probe phase in the dump file, just that the amplitudes have been scaled by a factor: When changing the relative intensities in the probe I model, the overall integrated intensity in the probe that I get in the dump file stays constant. This sounds like ptypy is trying to set the initial probe intensity ... which is generally a good approach with modeled probes... For example to make the probe just as bright as the first / average diffraction pattern. Looking at ptypy/ptypy/core/illumination.py, I can not quite see how / why that happens: If an array is passed p.model is set to that array... aperture, propagation and diversity are set to None, the storage is initalized. If p.model is now that array, model is set to point at p.model If model has the wrong size, it is made to have the right size finally aperture, propagation and diversity are applied |
You might want to refer to issue #417, where this question has already been addressed. |
Thanks guys for looking into this. Like posted above I looked into a similar issue when loading from .ptyr files. @kahntm maybe you could make a PR with the change suggested above which also works for ndarray probes? |
Hi, yes... later today I will make a clean PR. right now I was just fiddling around in my messy version of ptypy. |
Thank all of you so much for the discussions and suggestions! with @kahntm code, I think the only thing I need to see is the shift and scale problems, but it should be my own problems, I will solve myself. And I look forward to the new version of ptypy you will update, it will create great convenience for those people who try to comapre their algorithms with known probe to those iterative methods. |
|
To summarize, if I want to fix the probe, the below code is needed p.scans.scan_00.illumination.model = np.load("probe.npy") if I want to fix the probe amplitude as well, I need to change the inside code in illumination by setting p.photons = None in line 476 in illumination. but I think the scale is not a problem, I can scale back after reconstruction by using distribution median. |
Yes, if you do not care about the scaling of the probe amplitude by a factor you can go ahead with those lines. |
Pushed the changes: commit Created a pull request Be aware... this fix makes it now impossible to scale the loaded probe (if it is coming as a numpy array) to a specific photon count. |
Thank you so much for the updated version!!! I have no more questions on the issue. |
Dear Contributors,
Happy New Year!
I tried to fix a ground truth probe during reconstruction, this probe is what I used for simulating the diffraction patterns. To do this, I tried set
probe=np.load("data/probe.npy")
p.scans.scan_00.illumination.model = probe
p.engines.engine.probe_update_start = 10000
here, the probe_update_start is large than the total steps, so it won't update the probe until end.
Though the model seems to work well with the output, I carefully checked find that the probe that comes last after reconstruction is not the same as what I fixed in the illumination.model. I want the final reconstructed probe is the same as the probe loaded here.
e.g. list(P.probe.S.values())[0] is equal to np.load("data/probe.npy").
I don't know what is wrong with this, can you help me identify what is wrong with this code?
Thank you so much!!!
The text was updated successfully, but these errors were encountered: