WIP: Maddie's ringfinding python modules development branch#83
WIP: Maddie's ringfinding python modules development branch#83maddiebrod wants to merge 15 commits intoxpdAcq:masterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #83 +/- ##
===========================================
- Coverage 91.95% 80.89% -11.06%
===========================================
Files 20 21 +1
Lines 1007 1178 +171
===========================================
+ Hits 926 953 +27
- Misses 81 225 +144
Continue to review full report at Codecov.
|
CJ-Wright
left a comment
There was a problem hiding this comment.
I don't know if I fully understand how this is working, but it seems like a reasonable first pass.
xpdtools/calib2.py
Outdated
|
|
||
| def findringcenter(image,thres=.20,d=20): | ||
|
|
||
| def findcenter(image): |
There was a problem hiding this comment.
Would it be possible to pull these functions outside of the main function?
xpdtools/calib2.py
Outdated
| print(imarray) | ||
|
|
||
| class Slyce(): | ||
| def __init__(self,direction,index,imarray): |
There was a problem hiding this comment.
Would it be possible to use 4 spaces rather than tabs?
xpdtools/calib2.py
Outdated
|
|
||
| coords=[] | ||
| spread=[] | ||
| for row in range (int(r-3*d),int(r+3*d)): |
There was a problem hiding this comment.
I don't know if I understand how this works.
There was a problem hiding this comment.
The for loop goes through points reasonably close to the center of the image (not necessary the rings which could pose a problem in some cases). It them finds the distance between that point and all the points that had been identified as being on the center ring. The point that is closest to being equidistant from the points on the inner ring is identified as the center point.
xpdtools/calib2.py
Outdated
| imarray=tf.imread(filename) | ||
| print(imarray) | ||
|
|
||
| class Slyce(): |
There was a problem hiding this comment.
Long term I'm not certain if this needs a class.
sbillinge
left a comment
There was a problem hiding this comment.
@maddiebrod I think it would be helpful if you could put in some one-line comments here and there thay say what the program is doing.
Also, I think we need a use-case so we can understand how it is supposed to be used. It could be something like this:
- users runs calibration
- xpdAcq returns image of Ni
- pipeline does dark subtraction, flatfield, whatever
- pipeline calls ringfinder
- ringfinder finds rings
- ringfinder returns approximate beam center and pixel coordinates of approximate ring positions
- pipeline calls pyFai, handing it the beam center and ring position coordinates
- pyFai uses these to seed the Ni calibration refinement
- pipeline continues as usual.
In this scenario we do need a single function that takes in a numpy array and returns something like a dictionary of coordinates.
…umpy array as an input instead of a str
CJ-Wright
left a comment
There was a problem hiding this comment.
Would it be possible to pull all the classes and functions outside the findrings function?
… the main findrings function. calib4.py includes a visualization of the center point and points on rings, while calib5.py just returns the pixel indices of these points.
|
What are the differences among the files? |
|
calib4.py produces an image using matplotlib of the PDF with the center pixel and the pixels of the points that would be clicked in red (actually a square of pixels because one pixel is too difficult to see). This portion of code starts on line 239 of calib4.py. calib5.py is the same except it does not include the visualization. |
|
Would it be possible to combine these files (and remove the not used ones)? You might consider putting conditionals around the visualization chunk. |
…sualization portion conditional
…gs() function on 5 Ni tiff images. This version of the test function tests whether or not the x and y pixel coordinates of the center point given by findrings() are within 10 pixels of that given by paiFAI
|
Would you be able to use |
…ests if findrings() raises IndexError if input is 1D numpy array and one that determines if it raises an attributeError if given an input that is not a numpy array
…nput is not ndarray and modified test_ringfinding by adding a test function to test whether or not runtime error is raised when input is not ndarray
sbillinge
left a comment
There was a problem hiding this comment.
looks good. Are we getting close to it not being WIP any more? Do we wnat to check if it works before we merge?
xpdtools/tests/test_ringfinding.py
Outdated
| with pytest.raises(IndexError): | ||
| findrings(np.random.rand(2048)) | ||
|
|
||
| @pytest.mark.parametrize("wrong_input",[[1,2,3],3,2.7,(2,3),'banana']) |
CJ-Wright
left a comment
There was a problem hiding this comment.
Please separate the plotting code from library code.
xpdtools/calib4.py
Outdated
| import matplotlib.pyplot as plt | ||
|
|
||
|
|
||
| class Slyce: |
There was a problem hiding this comment.
slyce = {'direction': 'v', 'index': 0, 'data': array, 'pixels': []}
xpdtools/calib4.py
Outdated
|
|
||
| s = image.shape | ||
| # number of rows divided by 2 | ||
| r = s[0] / 2 |
There was a problem hiding this comment.
This might return a float, maybe use floor division?
| slyce.pixels.append(p1) | ||
|
|
||
|
|
||
| def finddistance(a, b): |
xpdtools/calib4.py
Outdated
| self.data = list(image[self.index, :]) | ||
|
|
||
|
|
||
| def findcenter(image): |
xpdtools/calib4.py
Outdated
| r, c = findcenter(image) | ||
|
|
||
| # take 10 slices within a range of 'd' away from the cetner of the image and puts them into a list | ||
| slyce1 = Slyce("v", c - d, image) |
There was a problem hiding this comment.
slices = []
for k in ['v', 'h']:
if k == 'v':
row_column = c
else:
row_column = r
for dd in [0, -d, d, -d/2, d/2]:
# handle data direction here
slices.append({'direction': k, 'index': row_column + dd, 'data': ...})…intergers, got rid of the function that finds the center of the image and incorporated that part of the code directly into the findringcenter() function
… the points on the tiff image where the findrings() function identifies the center point and a point onrings 0,1,2,5
@CJ-Wright @eaculb Let's make comments on this branch