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

Echelle improvements #1693

Merged
merged 8 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/releases/1.14.1dev.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Functionality/Performance Improvements and Additions

- Started the development of instrument-specific scattered light removal. In this
release, we only model KCWI/KCRM scattered light.
- Turned on usage of the use_2dmodel_mask parameter for echelle spectrographs
- Allow one to turn off reinit of reduce_bpm in global_skysub and made this
the default for the final pass

Instrument-specific Updates
---------------------------
Expand Down
4 changes: 4 additions & 0 deletions pypeit/core/skysub.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,7 @@ def ech_local_skysub_extract(sciimg, sciivar, fullmask, tilts, waveimg,
slitmask, sobjs, spat_pix=None,
fit_fwhm=False,
min_snr=2.0, bsp=0.6, trim_edg=(3,3), std=False, prof_nsigma=None,
use_2dmodel_mask=True,
niter=4, sigrej=3.5, bkpts_optimal=True,
force_gauss=False, sn_gauss=4.0, model_full_slit=False,
model_noise=True, debug_bkpts=False, show_profile=False,
Expand Down Expand Up @@ -1119,6 +1120,8 @@ def ech_local_skysub_extract(sciimg, sciivar, fullmask, tilts, waveimg,
light profile like elliptical galaxies. If prof_nsigma is
set then the profiles will no longer be apodized by an
exponential at large distances from the trace.
use_2dmodel_mask : bool, optional
Use the mask made from profile fitting when extracting?
niter : int, optional
Number of iterations for successive profile fitting and local sky-subtraction
sigrej : :obj:`float`, optional
Expand Down Expand Up @@ -1377,6 +1380,7 @@ def ech_local_skysub_extract(sciimg, sciivar, fullmask, tilts, waveimg,
spat_pix=spat_pix, ingpm=inmask, std=std, bsp=bsp,
trim_edg=trim_edg, prof_nsigma=prof_nsigma, niter=niter,
sigrej=sigrej,
use_2dmodel_mask=use_2dmodel_mask,
bkpts_optimal=bkpts_optimal, force_gauss=force_gauss,
sn_gauss=sn_gauss, model_full_slit=model_full_slit,
model_noise=model_noise, debug_bkpts=debug_bkpts,
Expand Down
2 changes: 2 additions & 0 deletions pypeit/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ def local_skysub_extract(self, global_sky, sobjs,
sn_gauss = self.par['reduce']['extraction']['sn_gauss']
model_full_slit = self.par['reduce']['extraction']['model_full_slit']
force_gauss = self.par['reduce']['extraction']['use_user_fwhm']
use_2dmodel_mask = self.par['reduce']['extraction']['use_2dmodel_mask']
self.skymodel, self.objmodel, self.ivarmodel, self.outmask, self.sobjs \
= skysub.ech_local_skysub_extract(self.sciImg.image, self.sciImg.ivar,
self.sciImg.fullmask, self.tilts, self.waveimg,
Expand All @@ -858,6 +859,7 @@ def local_skysub_extract(self, global_sky, sobjs,
std=self.std_redux, fit_fwhm=fit_fwhm,
min_snr=min_snr, bsp=bsp, sigrej=sigrej,
force_gauss=force_gauss, sn_gauss=sn_gauss,
use_2dmodel_mask=use_2dmodel_mask,
model_full_slit=model_full_slit,
model_noise=model_noise,
show_profile=show_profile,
Expand Down
12 changes: 10 additions & 2 deletions pypeit/find_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ def run(self, std_trace=None, show_peaks=False, show_skysub_fit=False):
skymask_init = self.create_skymask(sobjs_obj)
# Global sky subtract now using the skymask defined by object positions
initial_sky = self.global_skysub(skymask=skymask_init, show_fit=show_skysub_fit)

# Second pass object finding on sky-subtracted image with updated sky
# created after masking objects
if not self.std_redux and not self.par['reduce']['findobj']['skip_second_find']:
Expand Down Expand Up @@ -481,7 +482,9 @@ def get_platescale(self, slitord_id=None):


def global_skysub(self, skymask=None, update_crmask=True, trim_edg = (0, 0),
previous_sky=None, show_fit=False, show=False, show_objs=False, objs_not_masked=False):
previous_sky=None, show_fit=False, show=False,
profxj marked this conversation as resolved.
Show resolved Hide resolved
show_objs=False, objs_not_masked=False,
reinit_bpm:bool=True):
"""
Perform global sky subtraction, slit by slit

Expand All @@ -507,13 +510,18 @@ def global_skysub(self, skymask=None, update_crmask=True, trim_edg = (0, 0),
Set this to be True if there are objects on the slit/order that are not being masked
by the skymask. This is typically the case for the first pass sky-subtraction
before object finding, since a skymask has not yet been created.
reinit_bpm (:obj:`bool`, optional):
If True (default), the bpm is reinitialized to the initial bpm
Should be False on the final run in case there was a failure
upstream and no sources were found in the slit/order

Returns:
`numpy.ndarray`_: image of the the global sky model

"""
# reset bpm since global sky is run several times and reduce_bpm is here updated.
self.reduce_bpm = self.reduce_bpm_init.copy()
if reinit_bpm:
self.reduce_bpm = self.reduce_bpm_init.copy()
# Prep
global_sky = np.zeros_like(self.sciImg.image)
# Parameters for a standard star
Expand Down
5 changes: 4 additions & 1 deletion pypeit/pypeit.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ def reduce_exposure(self, frames, bg_frames=None, std_outfile=None):
sciImg_list.append(sciImg)
objFind_list.append(objFind)


# slitmask stuff
if len(calibrated_det) > 0 and self.par['reduce']['slitmask']['assign_obj']:
# get object positions from slitmask design and slitmask offsets for all the detectors
Expand Down Expand Up @@ -952,7 +953,9 @@ def extract_one(self, frames, det, sciImg, objFind, initial_sky, sobjs_obj):
else:
# Update the skymask
skymask = objFind.create_skymask(sobjs_obj)
final_global_sky = objFind.global_skysub(previous_sky=initial_sky, skymask=skymask, show=self.show)
final_global_sky = objFind.global_skysub(previous_sky=initial_sky,
skymask=skymask, show=self.show,
reinit_bpm=False)
scaleImg = objFind.scaleimg

# Each spec2d file includes the slits object with unique flagging
Expand Down