-
Notifications
You must be signed in to change notification settings - Fork 14
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
roi argument for get_fastccd_images() is broken ... plus some flatfield dependency discussion #68
Comments
This will make the obtained diff --git a/csxtools/utils.py b/csxtools/utils.py
index 62d3b98..1fcf686 100644
--- a/csxtools/utils.py
+++ b/csxtools/utils.py
@@ -213,6 +213,8 @@ def _crop(image, roi):
image_shape = image.shape
# Assuming ROI is specified in the "rotated" (correct) orientation
roi = [image_shape[-2]-roi[3], roi[0], image_shape[-1]-roi[1], roi[2]]
+ # need to perform an "unsafe" cast here, or fastccd.correct_images would be cranky!
+ image = np.asarray(image, dtype=np.uint16)
return image.T[roi[1]:roi[3], roi[0]:roi[2]].T |
To correct flat field, type in 7, instead of 3, scan ids in the Associate Scans window, in this order: (dark8, dark2, dark1, flat_scan_num, flat_dark8, flat_dark2, flat_dark1). Two notes: 1. To use this feature, must apply the patch in NSLS-II-CSX/csxtools#68 (comment) to csxtools, otherwise the error from NSLS-II-CSX/csxtools#68 would happen. 2. I observed a horizontal black stripe in the corrected image, not sure if this is expected.
To correct flat field, type in 7, instead of 3, scan ids in the Associate Scans window, in this order: (dark8, dark2, dark1, flat_scan_num, flat_dark8, flat_dark2, flat_dark1). Two notes: 1. To use this feature, must apply the patch in NSLS-II-CSX/csxtools#68 (comment) to csxtools, otherwise the error from NSLS-II-CSX/csxtools#68 would happen. 2. I observed a vertical black stripe in the corrected image, not sure if this is expected.
@leofang I know @stuwilkins wanted to rotate the images at particular times. Maybe you can speak with him. I haven't had issues with the flatfield myself. What version of csxtool are you and @wen-hu using? |
@leofang. Sorry, I did not see the version that you provided. I am using 0.1.13 csxtools and my code implementation of the flat field works correctly. Also, there is discussion with @danielballan @mrakitin and @jklynch to put data streams that contact a fully correct flatfield. |
note this is this discussion of the flatfield stream is to make things play nicely with xi-cam |
Disregard location of version. I see that master is at 0.1.15 and just has not been pushed to the facilities current standard conda version for analysis at CSX. I will clone and update so I can test my notebooks. |
Oh, Andi, sorry for my long silence! I just found the notification from my GitHub email sea 😅 Yes, I used 0.1.15 to test it. Please try it with the reproducer from #68 (comment). Also, please let me know how you made it work with 0.1.13, so that I can investigate further. It could be that I was misled by the documentation and used the API wrong. Thanks! |
I as on vacation part of last week. For 0.1.13, you can get the flatfield to generally work with from csxtools.utils import get_fastccd_images,get_images_to_3D, get_images_to_4D, get_fastccd_flatfield,fccd_mask
from csxtools.ipynb import image_stack_to_movie, show_image_stack
from csxtools.image import stackmean, images_mean, images_sum
bgnd1 = db[117332+3]
bgnd2 = db[117332+2]
bgnd8 = db[117332+1]
flat = db[117332]
ff = get_fastccd_flatfield(flat, (bgnd8, bgnd2, bgnd1))
n=0
bgnd2 = None
bgnd1 = None
scans_no = [117493 for i in range(117493, 117499+1,2)] #Escans for 300K for 4 Ls
scans_bgnd8 = [x-1 for x in scans_no]
bgnd8 = db[scans_bgnd8[n],]#db[111531,]
scan_no = scans_no[n] # random sat thing
h = db[scan_no]
#gains, most to least sensiteve
images = get_fastccd_images(h, (bgnd8[0], bgnd2, bgnd1), flat=ff)
#### FOR A SCAN ###
stack = get_images_to_4D(images) YOu should be able to just copy and paste to test in the conda env for CSX analysis from 2019-1.2 ("current" on nsls-ii notebook jupyternub) There are options to the function like |
There is also a pre-dated issue #69 for the whole story for anyone who is interested. |
oops. i added the line you need |
|
Yes, the fastest way to get your path. I sometimes use: import os
print(os.__file__) but it's longer to type. As for the example, it works for me now, but returns this (I assume it's OK): /opt/conda_envs/analysis-2018-2.1/lib/python3.6/site-packages/csxtools/utils.py:181: UserWarning: Images and get_images are deprecated. Use Header.data('fccd_image') instead.
images = header.db.get_images(header, tag)
/opt/conda_envs/analysis-2018-2.1/lib/python3.6/site-packages/csxtools/utils.py:262: RuntimeWarning: invalid value encountered in greater
flat[flat > limits[1]] = np.nan
Flatfield correction removed 74169 pixels (7.73 %)
Missing dark image for gain setting 2
Missing dark image for gain setting 1 |
YEs, that is correct. There was a issue for that, but it was closed after some changes before christmas. |
If there is confusion about which Python you are currently in, use |
@ambarb @mrakitin Thanks for the discussion. I think the problem in my reproducer was that I also set Lines 125 to 127 in 81a64d7
the _crop() function was invoked and hence led to the reported error, which can be fixed by the patch (#68 (comment)). This bug has been there since at least 0.1.13, so you can try it out yourselves.
If I am still a bit concerned with the rotation of the flat field in |
@leofang thanks for explaining your use case with the roi. As for the rotation, I will have a look, but the output from The reason this work flow makes sense to me is that however we configure the camera to run, all the image normalization is done on raw images so you don't have to worry about the cropping, extra added columns, addition of overscan, frame store versus non-frame store, binning of columns to decrease readout time. |
@leofang To keep our existing workflow described, do you think we need to think about refactoring the roi argument usage so that we are more future proof to the camera configurations? |
Thanks for the detailed explanation, Andi! I think as long as the I know almost nothing about the experimental setup, and by inspecting the code currently I see two problems:
|
I see your point for the rotation. I am doing some image math to make sure that this is brought out by some analysis. Almost finished with it and will update here. |
I suggest we make a new issue report for the roi and leave it as an enhancement. I think whomever wants to tackle this will have to also keep in mind the "future proof-ness" of it and the plans to add metadata for concatenating the normalized images to be done by wrapper function or optional argument for Any objections to this approach? |
Sounds good. Let me know if it is indeed a bug.
I suppose we could just rename the title of this issue to indicate this is an |
I don't think there is a bug for the flatfield usage at large. Images E and F are 100% manual flatflield correction to the data used to generate the flatfield using a flatfield that was either rotated cw or ccw.
If the code in the repo is correct, D should match F. H shows the difference between D and F which is very small. G and F have Now, I am not sure if we want to chase down where the correction for the inconsistency that you point out is. But we should make sure that the unit test for the flat field is in place and that it is always used whenever someone touches |
rel: #73 |
@wen-hu needs the flatfield support to process some ptychography datasets, but I found an error with the latest csxtools (0.1.15):
Seems like
image
in_crop
is assumed to be a numpy array but it actually isn't (or is not handled correctly by@pipeline
). Perhaps we can hot-fix it by not doing arotate90
ornp.rot90
to avoid transpose (T
) operation to the flatfield? But not sure if this would break existing code, or if existing code just never worked 🤣Any thoughts? @danielballan @mrakitin
The text was updated successfully, but these errors were encountered: