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

fccd flatfield function doesn't handle the broken part of the camera very well #77

Closed
1 of 2 tasks
ambarb opened this issue Nov 24, 2020 · 5 comments
Closed
1 of 2 tasks
Assignees

Comments

@ambarb
Copy link
Contributor

ambarb commented Nov 24, 2020

@patryk-w figured this out and has some temporary code he is using.

to move forward, do we want a bandaid function that we deprecate later?

Or do we want to alter the existing flatfield function to be configurable for bad areas of the ccd?
options in clude using argments to exclude areas or referencing a bad pixel mask.

  • fast fix
  • sophisticated fix
@ambarb
Copy link
Contributor Author

ambarb commented Jan 13, 2021

From @patryk-w

def get_half_fastccd_flatfield(light, darks, flat=None, limits=(0.6, 1.4),
                               module_width=480, right_side=0):
    """Calculate flat field for the working module of the fCCD
    This function calculates the flat field correction array for the fCCD
    detector with only one of the modules working (right module), setting the
    other half to NaNs.
    Parameters:
    -----------
    light (int): transient scan id for the flat field,
    darks (array of ints): transient scan id for the dark images,
    flat (ndarray): flatfield image (optional)
    Returns
    -------
    flat_corrected (ndarray): corrected flat field array for the whole fccd
        detector including only the working module
    """
    light = db[int(light)]
    dark = []
    if darks is not None:
        for d in darks:
            if d is not None:
                dark.append(db[(int(d))])
            else:
                dark.append(None)
    else:
        dark = None
    flat_images = get_images_to_3D(get_fastccd_images(light, dark))
    flat_image = stackmean(flat_images)
    flat = flat_image[:, flat_image.shape[-1] - module_width : flat_image.shape[-1] - right_side]
    limits = np.array(limits)
    limits = np.nanmedian(flat) * limits
    flat[flat < np.min(limits)] = np.nan
    flat[flat > np.max(limits)] = np.nan
    flat = np.nanmean(flat) / flat
    flat_corrected = np.empty_like(flat_image)
    flat_corrected[:, :] = np.nan
    flat_corrected[:, flat_image.shape[-1] - module_width:flat_image.shape[-1] - right_side] = flat
    flat_corrected = np.rot90(flat_corrected)
    removed = np.sum(np.isnan(flat))
    if removed != 0:
        msg = 'Flat field correction removed {} pixels'.format(removed)
        msg += ' ({:.2f}%) out of the working part of the detector'.format(removed * 100 / flat.size)
        print(msg)
    return flat_corrected

@ambarb ambarb mentioned this issue Oct 20, 2021
@mpmdean
Copy link

mpmdean commented Oct 20, 2021

Hi @ambarb and @patryk-w

Thanks for posting the modified function.

I think what we actually want, however, is an additional argument to get_half_fastccd_flatfield that specifies a minimum_ADUs, below which we consider the fCCD to have not detected any phonons. This can be a variable number, which is set to a default that we consider sensible. If pixels are below this they are set to np.NaN from the outset.

@ambarb
Copy link
Contributor Author

ambarb commented Oct 20, 2021

@mpmdean I think using a threshold makes for the most generic solution. However, we should either edit the original function or make a new function that isn't specified for half of the ccd.

In this way, the new function can be generically applied no matter the mode the ccd is running (framestore, non-framestore, with or without overscan) and is more robust than the original function created many years ago.

@ambarb
Copy link
Contributor Author

ambarb commented Sep 2, 2022

we've noticed that the levels on the broken side change. This makes it a little hard to use a general threshold in an automated way. Lets just get something that works now.

For future threshold, we can now build some historical data for generalized testing of whatever this new function will be. There is a new function that labels the flatfield data appropriately at csx ct_flatfield()

@ambarb ambarb self-assigned this Sep 2, 2022
@ambarb
Copy link
Contributor Author

ambarb commented Apr 26, 2023

sophisticated fix is a global issue (half or not, FCCD or not). Making new issue for enhancement request.

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

No branches or pull requests

2 participants