-
Notifications
You must be signed in to change notification settings - Fork 103
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
Spatial flexure reorganisation #1860
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
731bb3f
manual flexure
rcooke-ast 09c5497
mv manual flexure to rawimage
rcooke-ast 872dbec
mv manual flexure to rawimage
rcooke-ast e8f1426
flexure only for when slits is not None
rcooke-ast e5112b1
flexure only for when slits is not None
rcooke-ast f48c767
deal with masked values
rcooke-ast 11e2100
masked manual extraction
rcooke-ast 30022e3
testing
rcooke-ast 4e10c8b
masked header cards
rcooke-ast e80f42e
masked header cards
rcooke-ast 0056842
masked header cards
rcooke-ast 06b95d5
Update pypeit/calibrations.py
rcooke-ast 8dbf228
update docstrings
rcooke-ast 0dce8e9
consistent setting of pixel indices
rcooke-ast File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -401,7 +401,7 @@ | |
return np.array(rn2) | ||
|
||
def process(self, par, bpm=None, scattlight=None, flatimages=None, bias=None, slits=None, dark=None, | ||
mosaic=False, debug=False): | ||
mosaic=False, manual_spat_flexure=None, debug=False): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also done :-) |
||
""" | ||
Process the data. | ||
|
||
|
@@ -519,6 +519,9 @@ | |
mosaic. If flats or slits are provided (and used), this *must* | ||
be true because these objects are always defined in the mosaic | ||
frame. | ||
manual_spat_flexure (:obj:`float`, optional): | ||
The spatial flexure of the image. This is only set if the user wishes to | ||
manually correct the slit traces of this image for spatial flexure. | ||
debug (:obj:`bool`, optional): | ||
Run in debug mode. | ||
|
||
|
@@ -671,9 +674,11 @@ | |
# bias and dark subtraction) and before field flattening. Also the | ||
# function checks that the slits exist if running the spatial flexure | ||
# correction, so no need to do it again here. | ||
self.spat_flexure_shift = self.spatial_flexure_shift(slits, method=self.par['spat_flexure_method'], | ||
maxlag=self.par['spat_flexure_maxlag']) \ | ||
if self.par['spat_flexure_method'] != "skip" else None | ||
self.spat_flexure_shift = None | ||
if self.par['spat_flexure_method'] != "skip" or not np.ma.is_masked(manual_spat_flexure): | ||
self.spat_flexure_shift = self.spatial_flexure_shift(slits, method=self.par['spat_flexure_method'], | ||
manual_spat_flexure=manual_spat_flexure, | ||
maxlag=self.par['spat_flexure_maxlag']) | ||
|
||
# - Subtract scattered light... this needs to be done before flatfielding. | ||
if self.par['subtract_scattlight']: | ||
|
@@ -766,19 +771,26 @@ | |
return _det, self.image, self.ivar, self.datasec_img, self.det_img, self.rn2img, \ | ||
self.base_var, self.img_scale, self.bpm | ||
|
||
def spatial_flexure_shift(self, slits, force=False, method="detector", maxlag=20): | ||
def spatial_flexure_shift(self, slits, force=False, manual_spat_flexure=np.ma.masked, method="detector", maxlag=20): | ||
""" | ||
Calculate a spatial shift in the edge traces due to flexure. | ||
|
||
This is a simple wrapper for | ||
:func:`~pypeit.core.flexure.spat_flexure_shift`. | ||
|
||
Args: | ||
slits (:class:`~pypeit.slittrace.SlitTraceSet`, optional): | ||
slits (:class:`~pypeit.slittrace.SlitTraceSet`): | ||
Slit edge traces | ||
force (:obj:`bool`, optional): | ||
Force the image to be field flattened, even if the step log | ||
(:attr:`steps`) indicates that it already has been. | ||
manual_spat_flexure (:obj:`float`, optional): | ||
Manually set the spatial flexure shift. If provided, this | ||
value is used instead of calculating the shift. The default | ||
value is `np.ma.masked`, which means the shift is calculated | ||
from the image data. The only way this value is used is if | ||
the user sets the `shift` parameter in their pypeit file to | ||
be a float. | ||
method (:obj:`str`, optional): | ||
Method to use to calculate the spatial flexure shift. Options | ||
are 'detector' (default), 'slit', and 'edge'. The 'detector' | ||
|
@@ -801,10 +813,34 @@ | |
if self.nimg > 1: | ||
msgs.error('CODING ERROR: Must use a single image (single detector or detector ' | ||
'mosaic) to determine spatial flexure.') | ||
self.spat_flexure_shift = flexure.spat_flexure_shift(self.image[0], slits, method=method, maxlag=maxlag) | ||
|
||
# Check if the slits are provided | ||
if slits is None: | ||
if not np.ma.is_masked(manual_spat_flexure): | ||
msgs.warn('Manual spatial flexure provided without slits - assuming no spatial flexure.') | ||
else: | ||
msgs.warn('Cannot calculate spatial flexure without slits - assuming no spatial flexure.') | ||
return | ||
|
||
# First check for manual flexure | ||
if not np.ma.is_masked(manual_spat_flexure): | ||
msgs.info(f'Adopting a manual spatial flexure of {manual_spat_flexure} pixels') | ||
spat_flexure = np.full((slits.nslits, 2), np.float64(manual_spat_flexure)) | ||
else: | ||
spat_flexure = flexure.spat_flexure_shift(self.image[0], slits, method=method, maxlag=maxlag) | ||
|
||
# Print the flexure values | ||
if np.all(spat_flexure == spat_flexure[0, 0]): | ||
msgs.info(f'Spatial flexure is: {spat_flexure[0, 0]} pixels') | ||
else: | ||
# Print the flexure values for each slit separately | ||
for slit in range(spat_flexure.shape[0]): | ||
msgs.info( | ||
f'Spatial flexure for slit {slits.spat_id[slit]} is: left={spat_flexure[slit, 0]} pixels; right={spat_flexure[slit, 1]} pixels') | ||
|
||
self.steps[step] = True | ||
# Return | ||
return self.spat_flexure_shift | ||
return spat_flexure | ||
|
||
def flatfield(self, flatimages, slits=None, force=False, debug=False): | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
add
manual_spat_flexure
description in the docstringThere 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.
Thanks, added 👍