-
Notifications
You must be signed in to change notification settings - Fork 167
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
JP-3755: Remove unused options and add unit tests to SOSS extraction algorithm #9000
base: main
Are you sure you want to change the base?
Conversation
…tests for that function
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #9000 +/- ##
==========================================
+ Coverage 76.81% 78.28% +1.47%
==========================================
Files 496 504 +8
Lines 45610 46039 +429
==========================================
+ Hits 35034 36042 +1008
+ Misses 10576 9997 -579
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Sentry. |
wave_grid : (N_k) array_like, required. | ||
The grid on which f(lambda) will be projected. | ||
mask_trace_profile : (N_ord, N, M) list or array of 2-D arrays[bool], required. | ||
A list or array of the pixel that need to be used for extraction, | ||
for each order on the detector. It has to have the same (N_ord, N, M) as `trace_profile`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made these two parameters required because they were always specified explicitly when the ExtractionEngine was instantiated.
raise ValueError(msg.format(self.n_orders, len(wave_map))) | ||
|
||
# Detector image. | ||
self.data = np.full(self.data_shape, fill_value=np.nan) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
having attributes self.data and self.error is unnecessary. The ExtractionEngine does not itself need any data to set up a model of the detector and use most of the functionality. The only functions where these were accessed had optional data
and error
parameters, and in reality these were always set non-trivially when calling the pipeline. These were made required for those specific functions, specifically get_detector_model()
, get_pixel_mapping()
, and compute_likelihood()
. estimate_noise()
was unused in the pipeline and removed
# Set all reference file quantities to None. | ||
self.wave_map = None | ||
self.trace_profile = None | ||
self.throughput = None | ||
self.kernels = None | ||
|
||
# Set the wavelength map and trace_profile for each order. | ||
self.update_wave_map(wave_map) | ||
self.update_trace_profile(trace_profile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are all set to something other than None later in the __init__
, so there was no point setting them to None. The update_wave_map()
function was removed because this was the only place it was called, and it could be replaced with a one-liner. The same is true for update_trace_profile()
: its use in get_detector_model()
turned out to also be unnecessary because the option to pass trace_profile
into get_detector_model()
was never used in the pipeline.
self.update_trace_profile(trace_profile) | ||
|
||
# Set the mask based on trace profiles and save | ||
if mask_trace_profile is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mask_trace_profile
was never set to None in real calls to this class, so I made it required and removed the option to set it to None
self.mask_trace_profile = mask_trace_profile | ||
|
||
# Generate a wavelength grid if none was provided. | ||
if wave_grid is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wave_grid
was never set to None in real calls to this class, so I made it required and removed the option to set it to None
return bkg_mask | ||
|
||
|
||
def soss_oneoverf_correction(scidata, scimask, deepstack, bkg_mask=None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused
log.setLevel(logging.DEBUG) | ||
|
||
|
||
def zero_roll(a, shift): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused
return result | ||
|
||
|
||
def robust_polyfit(x, y, order, maxiter=5, nstd=3.): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only used as a helper to unused code in soss_centroids
return param | ||
|
||
|
||
def get_image_dim(image, header=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only used as a helper to unused code in soss_centroids
# In both orders, the errors on the replaced pixels are roughly | ||
# half of the errors on the original good pixels | ||
# There are enough replaced pixels here (~30) that small-number statistics cannot account for this | ||
# The reason is because the code chooses the lower error between the two nearest-flux | ||
# data points, and since the errors in our tests are uncorrelated with the flux values, | ||
# this leads to a factor-of-2 decrease | ||
# It's not clear to me that picking the smaller of two error values is the right thing to do | ||
# but that behavior is documented |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if this is actually the intended behavior or not, because it seems like a questionable choice to me (although admittedly I don't know very much).
Resolves JP-3755
Closes #8804
This PR addresses reducing the technical debt of the SOSS ATOCA algorithm. There are a lot of changed lines, so I'm annotating this PR with comments during a self-review. The high-level changes are:
There are several outstanding items to complete before this can be merged:
Tasks
Build 11.3
(use the latest build if not sure)no-changelog-entry-needed
)changes/
:echo "changed something" > changes/<PR#>.<changetype>.rst
(see below for change types)docs/
pageokify_regtests
to update the truth filesnews fragment change types...
changes/<PR#>.general.rst
: infrastructure or miscellaneous changechanges/<PR#>.docs.rst
changes/<PR#>.stpipe.rst
changes/<PR#>.datamodels.rst
changes/<PR#>.scripts.rst
changes/<PR#>.fits_generator.rst
changes/<PR#>.set_telescope_pointing.rst
changes/<PR#>.pipeline.rst
stage 1
changes/<PR#>.group_scale.rst
changes/<PR#>.dq_init.rst
changes/<PR#>.emicorr.rst
changes/<PR#>.saturation.rst
changes/<PR#>.ipc.rst
changes/<PR#>.firstframe.rst
changes/<PR#>.lastframe.rst
changes/<PR#>.reset.rst
changes/<PR#>.superbias.rst
changes/<PR#>.refpix.rst
changes/<PR#>.linearity.rst
changes/<PR#>.rscd.rst
changes/<PR#>.persistence.rst
changes/<PR#>.dark_current.rst
changes/<PR#>.charge_migration.rst
changes/<PR#>.jump.rst
changes/<PR#>.clean_flicker_noise.rst
changes/<PR#>.ramp_fitting.rst
changes/<PR#>.gain_scale.rst
stage 2
changes/<PR#>.assign_wcs.rst
changes/<PR#>.badpix_selfcal.rst
changes/<PR#>.msaflagopen.rst
changes/<PR#>.nsclean.rst
changes/<PR#>.imprint.rst
changes/<PR#>.background.rst
changes/<PR#>.extract_2d.rst
changes/<PR#>.master_background.rst
changes/<PR#>.wavecorr.rst
changes/<PR#>.srctype.rst
changes/<PR#>.straylight.rst
changes/<PR#>.wfss_contam.rst
changes/<PR#>.flatfield.rst
changes/<PR#>.fringe.rst
changes/<PR#>.pathloss.rst
changes/<PR#>.barshadow.rst
changes/<PR#>.photom.rst
changes/<PR#>.pixel_replace.rst
changes/<PR#>.resample_spec.rst
changes/<PR#>.residual_fringe.rst
changes/<PR#>.cube_build.rst
changes/<PR#>.extract_1d.rst
changes/<PR#>.resample.rst
stage 3
changes/<PR#>.assign_mtwcs.rst
changes/<PR#>.mrs_imatch.rst
changes/<PR#>.tweakreg.rst
changes/<PR#>.skymatch.rst
changes/<PR#>.exp_to_source.rst
changes/<PR#>.outlier_detection.rst
changes/<PR#>.tso_photometry.rst
changes/<PR#>.stack_refs.rst
changes/<PR#>.align_refs.rst
changes/<PR#>.klip.rst
changes/<PR#>.spectral_leak.rst
changes/<PR#>.source_catalog.rst
changes/<PR#>.combine_1d.rst
changes/<PR#>.ami.rst
other
changes/<PR#>.wfs_combine.rst
changes/<PR#>.white_light.rst
changes/<PR#>.cube_skymatch.rst
changes/<PR#>.engdb_tools.rst
changes/<PR#>.guider_cds.rst