Skip to content

Commit

Permalink
Merge pull request #35 from stuwilkins/fix_vivek
Browse files Browse the repository at this point in the history
Fix Vivek's Additions
  • Loading branch information
stuwilkins committed Mar 1, 2016
2 parents ee278dc + e35776a commit 0110635
Showing 1 changed file with 29 additions and 39 deletions.
68 changes: 29 additions & 39 deletions csxtools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@


def get_fastccd_images(light_header, dark_headers=None,
flat=None, gain=(1, 4, 8), tag=None,
roi=None):
flat=None, gain=(1, 4, 8), tag=None, roi=None):
"""Retreive and correct FastCCD Images from associated headers
Retrieve FastCCD Images from databroker and correct for:
Expand Down Expand Up @@ -49,8 +48,8 @@ def get_fastccd_images(light_header, dark_headers=None,
the settings.
roi : tuple
tuple with 4 integers to crop images
(row_start, column_start, row_end, column_end)
coordinates of the upper-left corner and width and height of
the ROI: e.g., (x, y, w, h)
Returns
-------
Expand All @@ -61,6 +60,14 @@ def get_fastccd_images(light_header, dark_headers=None,
if tag is None:
tag = detectors['fccd']

# Now lets sort out the ROI
if roi is not None:
roi = list(roi)
# Convert ROI to start:stop from start:size
roi[2] = roi[0] + roi[2]
roi[3] = roi[1] + roi[3]
logger.info("Computing with ROI of %s", str(roi))

if dark_headers is None:
bgnd = None
logger.warning("Processing without dark images")
Expand Down Expand Up @@ -107,9 +114,9 @@ def get_fastccd_images(light_header, dark_headers=None,

# Ok, so lets return a pims pipeline which does the image conversion

# Crop Flat image
# Crop Flatfield image
if flat is not None and roi is not None:
flat = crop_flat(flat, roi)
flat = _crop(flat, roi)

return _correct_fccd_images(events, bgnd, flat, gain)

Expand Down Expand Up @@ -138,49 +145,32 @@ def get_images_to_4D(images, dtype=None):
return im


def get_images_to_3D(images):
"""Return a 3D array from the "slicerator" object
Parameters
----------
slicerator object : generator returning pims images
This is the output of get_fastccd_images
Returns
-------
array: 3D numpy array
"""

ims = images[0]
for im in images[1:]:
ims = np.vstack((ims, im))

return ims


@pipeline
def _correct_fccd_images(image, bgnd, flat, gain):
return rotate90(correct_images(image, bgnd, flat, gain), 'cw')


def _get_images(header, tag, roi=None):
t = ttime.time()
images = get_images(header, tag)
t = ttime.time() - t
logger.info("Took %.3f seconds to read data using get_images", t)

if roi is not None:
return crop(images, roi)
images = _crop_images(images, roi)

return images


@pipeline
def crop(image, roi=None):
# Assuming ROI is specified in the "rotated" (correct) orientation
roi = [960-roi[3], roi[0], 960-roi[1], roi[2]]
return image[:, roi[0]:roi[2], roi[1]:roi[3]]
def _correct_fccd_images(image, bgnd, flat, gain):
image = correct_images(image, bgnd, flat, gain)
image = rotate90(image, 'cw')
return image


@pipeline
def _crop_images(image, roi):
return _crop(image, roi)


def crop_flat(image, roi=None):
roi = [960-roi[3], roi[0], 960-roi[1], roi[2]]
return image[roi[0]:roi[2], roi[1]:roi[3]]
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]]
return image.T[roi[1]:roi[3], roi[0]:roi[2]].T

0 comments on commit 0110635

Please sign in to comment.