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

ENH: Automatically reject bad frames due to cosmic rays #194

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

DrSoulain
Copy link
Collaborator

@DrSoulain DrSoulain commented Sep 12, 2023

In some NIRISS data cases, we've detected problematic pixels (cosmic rays or other anomalous events) that can disrupt the centring step during cleaning, causing errors. These misbehaving pixels can pop up when only a few data groups are involved. To address this, we use a frame index list automatically generated by the centring function to identify and exclude these "bad frames."

Comment on lines +588 to +590
"[AMICAL] %i unusable frames have been identified in the data cube,"
% (len(bad_frames))
+ " primarily due to cosmic rays or persistent bad pixels."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"[AMICAL] %i unusable frames have been identified in the data cube,"
% (len(bad_frames))
+ " primarily due to cosmic rays or persistent bad pixels."
f"[AMICAL] {len(bad_frames)} unusable frames have been identified in the data cube,"
" primarily due to cosmic rays or persistent bad pixels.",
file=sys.stderr,

amical/data_processing.py Outdated Show resolved Hide resolved
@@ -79,7 +79,7 @@ def find_max(img, filtmed=True, f=3):
return X, Y


def crop_max(img, dim, offx=0, offy=0, filtmed=True, f=3):
def crop_max(img, dim, iframe=0, offx=0, offy=0, filtmed=True, f=3):
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is an unwarranted breaking change: new arguments should always be added at the end of an existing signature, and preferably be made keyword-only

@@ -117,13 +117,22 @@ def select_data(cube, clip_fact=0.5, clip=False, verbose=True, display=True):
ind_clip = []
cube_cleaned_checked = np.array(good_fram)

cube_cleaned_checked = np.array(cube_cleaned_checked)
Copy link
Collaborator

Choose a reason for hiding this comment

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

np.array unconditionally copies data, even if the input variable is already an array. Since the input and output variable are the same, it's clear you don't mean to copy, so np.asarray is better suited here

Suggested change
cube_cleaned_checked = np.array(cube_cleaned_checked)
cube_cleaned_checked = np.asarray(cube_cleaned_checked)


med_flux = np.median(fluxes_check)
std_flux = np.std(fluxes_check)
diffmm = 100 * abs(np.max(fluxes_check) - np.min(fluxes_check)) / med_flux
Copy link
Collaborator

Choose a reason for hiding this comment

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

np.ptp(x) does the same as np.max(x) - np.min(x), but in a single data pass

Suggested change
diffmm = 100 * abs(np.max(fluxes_check) - np.min(fluxes_check)) / med_flux
diffmm = 100 * abs(np.ptp(fluxes_check)) / med_flux

@DrSoulain DrSoulain added the enhancement New feature or request label Jan 3, 2024
@DrSoulain DrSoulain marked this pull request as draft January 3, 2024 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants