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

flat field issue #80

Closed
mpmdean opened this issue Oct 20, 2021 · 3 comments
Closed

flat field issue #80

mpmdean opened this issue Oct 20, 2021 · 3 comments

Comments

@mpmdean
Copy link

mpmdean commented Oct 20, 2021

The calculate_flatfield function has an issue when it is used with the current state of the CSX detector.

The problem is that more than 1/2 the detector is insensitive to light, so the median is not representative of the true data. The line below then means that the data and limits get re-scaled to unreal values.

limits = np.nanmedian(image) * limits

@ambarb
Copy link
Contributor

ambarb commented Oct 20, 2021

Thanks @mpmdean . We are working on code for one big PR for various issues. For others that run into this prroblem, you may use the work around below by setting half=True.

import logging
logger = logging.getLogger(__name__)
import numpy as np

from csxtools.image import rotate90, stackmean
from csxtools.utils import  calculate_flatfield, get_images_to_3D,  get_fastccd_images

def get_fastccd_flatfield(light, dark, flat=None, limits=(0.6, 1.4), half=False, half_args = (7, 486)):
    """MODIFIED from csxtools original: Calculate a flatfield 
    This routine calculates the flatfield using the
    :func:calculate_flatfield() function after obtaining the images from
    the headers.
    Parameters
    ----------
    light : databroker header
        The header containing the light images
    dark : databroker header
        The header from the run containin the dark images
    flat : flatfield image (optional)
        The array to be used for the initial flatfield
    half : calculate for just the "good" half - hard coded
        Default is False
    half_args : Tuple for exluding entire sides of detector (left versus right)
        Left side is refers the the left side of the image after raw data is 
        processed with get_fastccd_images().  Default arguments are for the left side
        using the FrameStore mode.
    Returns
    -------
    array_like
        Flatfield correction
    """
    images = get_images_to_3D(get_fastccd_images(light, dark, flat))
    images = stackmean(images)
    if half == True:
        #rows because "super columns" are the large 10 pixel bins, but camera is on side.
        row_start, row_stop = half_args
        images[:,row_start:row_stop] = np.nan
        #plt.figure()
        #im = plt.imshow(images, vmin =0, vmax = 500)
        #cbar = plt.colorbar(im)
        #cbar.set_label('ADU gain corrected')
    flat = calculate_flatfield(images, limits)
    removed = np.sum(np.isnan(flat))
    if removed != 0:
        logger.warning("Flatfield correction removed %d pixels (%.2f %%)" %
                       (removed, removed * 100 / flat.size))
    return flat

@ambarb
Copy link
Contributor

ambarb commented Oct 20, 2021

Issue #77 covers this

@mpmdean
Copy link
Author

mpmdean commented Oct 20, 2021

I didn't spot that prior version of the same issue. I think this can be closed.

@ambarb ambarb closed this as completed Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants