Skip to content
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

WIP: Maddie's ringfinding python modules development branch #83

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

maddiebrod
Copy link

@CJ-Wright @eaculb Let's make comments on this branch

@codecov-io
Copy link

codecov-io commented Mar 7, 2019

Codecov Report

Merging #83 into master will decrease coverage by 11.05%.
The diff coverage is 0%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ
xpdtools/calib2.py 0% <0%> (ø)
xpdtools/tests/test_tomo_tools.py 100% <0%> (ø) ⬆️
xpdtools/pipelines/tomo.py 97.01% <0%> (+0.65%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ccd5585...a1733cb. Read the comment docs.

Copy link
Member

@CJ-Wright CJ-Wright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if I fully understand how this is working, but it seems like a reasonable first pass.


def findringcenter(image,thres=.20,d=20):

def findcenter(image):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to pull these functions outside of the main function?

print(imarray)

class Slyce():
def __init__(self,direction,index,imarray):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to use 4 spaces rather than tabs?


coords=[]
spread=[]
for row in range (int(r-3*d),int(r+3*d)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if I understand how this works.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

imarray=tf.imread(filename)
print(imarray)

class Slyce():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long term I'm not certain if this needs a class.

Copy link
Member

@sbillinge sbillinge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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:

  1. users runs calibration
  2. xpdAcq returns image of Ni
  3. pipeline does dark subtraction, flatfield, whatever
  4. pipeline calls ringfinder
  5. ringfinder finds rings
  6. ringfinder returns approximate beam center and pixel coordinates of approximate ring positions
  7. pipeline calls pyFai, handing it the beam center and ring position coordinates
  8. pyFai uses these to seed the Ni calibration refinement
  9. 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.

Copy link
Member

@CJ-Wright CJ-Wright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@CJ-Wright
Copy link
Member

What are the differences among the files?

@maddiebrod
Copy link
Author

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.

@CJ-Wright
Copy link
Member

Would it be possible to combine these files (and remove the not used ones)? You might consider putting conditionals around the visualization chunk.

…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
@CJ-Wright
Copy link
Member

Would you be able to use black on your code? (You can conda install it from conda-forge). It might help to make the files a bit more readable.

…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
Copy link
Member

@sbillinge sbillinge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. Are we getting close to it not being WIP any more? Do we wnat to check if it works before we merge?

findrings(np.random.rand(2048))

@pytest.mark.parametrize("wrong_input",[[1,2,3],3,2.7,(2,3),'banana'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

Copy link
Member

@CJ-Wright CJ-Wright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please separate the plotting code from library code.

import matplotlib.pyplot as plt


class Slyce:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe go with a dictionary?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slyce = {'direction': 'v', 'index': 0, 'data': array, 'pixels': []}


s = image.shape
# number of rows divided by 2
r = s[0] / 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might return a float, maybe use floor division?

slyce.pixels.append(p1)


def finddistance(a, b):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use numpy.linalg.norm

self.data = list(image[self.index, :])


def findcenter(image):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would inline this.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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': ...})

maddiebrod added 5 commits May 3, 2019 10:54
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants