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

HotFix: SkyRegions GUI #1718

Merged
merged 6 commits into from
Nov 3, 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
2 changes: 2 additions & 0 deletions doc/releases/1.14.1dev.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,7 @@ Bug Fixes
detector for Keck/LRIS RED.
- Fixed a bug with the ``pypeit_identify`` script when using echelle data. Previously,
the sigdetect parameter was a list of all orders, instead of a single value.
- Fixed a bug with the GUI ``pypeit_skysub_regions``. Previously, the calib header
information was not included, and this led to a calibration error.


47 changes: 33 additions & 14 deletions pypeit/core/gui/skysub_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,22 +571,41 @@ def operations(self, key, axisID):
self.replot()

def get_result(self):
"""Save a mask containing the skysub regions, and print information
"""Generate a master calibration file containing a mask of the skysub regions, and print information
rcooke-ast marked this conversation as resolved.
Show resolved Hide resolved
for what the user should include in their .pypeit file

Returns
-------
msskyreg : :class:`SkyRegions`, None
Returns an instance of the :class:`SkyRegions` class. If None is returned,
the user has requested to not use the updates.
"""
if not self._use_updates:
return None

# Generate the mask
inmask = skysub.generate_mask(self.pypeline, self._skyreg, self.slits, self.slits_left, self.slits_right)
if np.all(np.logical_not(inmask)):
msgs.warn("Sky regions are empty - master calibration frame will not be generated")
return None

# Build the master Sky Regions calibration frame
rcooke-ast marked this conversation as resolved.
Show resolved Hide resolved
return buildimage.SkyRegions(image=inmask.astype(float), PYP_SPEC=self.spectrograph)

def get_outname(self):
""" Get an output filename

Returns
-------
outfil : :obj:`str`
The output filename to use for the master Sky Regions calibration frame
"""
# Only do this if the user wishes to save the result
if self._use_updates:
# Generate the mask
inmask = skysub.generate_mask(self.pypeline, self._skyreg, self.slits, self.slits_left, self.slits_right)
# Save the mask
outfil = self._outname
if os.path.exists(self._outname) and not self._overwrite:
outfil = 'temp.fits'
msgs.warn(f"A SkyRegions file already exists and you have not forced an overwrite:\n{self._outname}")
msgs.info(f"Saving regions to: {outfil}")
self._overwrite = True
msskyreg = buildimage.SkyRegions(image=inmask.astype(float), PYP_SPEC=self.spectrograph)
msskyreg.to_file(file_path=outfil)
outfil = self._outname
if os.path.exists(self._outname) and not self._overwrite:
outfil = 'temp.fits'
msgs.warn(f"A SkyRegions file already exists and you have not forced an overwrite:\n{self._outname}")
msgs.info(f"Adopting the following output filename: {outfil}")
return outfil

def recenter(self):
xlim = self.axes['main'].get_xlim()
Expand Down
9 changes: 5 additions & 4 deletions pypeit/core/skysub.py
Original file line number Diff line number Diff line change
Expand Up @@ -1592,13 +1592,14 @@ def generate_mask(pypeline, skyreg, slits, slits_left, slits_right, spat_flexure
spec_min = np.append(spec_min, slits.specmin[sl])
spec_max = np.append(spec_max, slits.specmax[sl])

# Check if no regions were added
if left_edg.shape[1] == 0:
return np.zeros((slits.nspec, slits.nspat), dtype=bool)

# Now that we have sky region traces, utilise the SlitTraceSet to define the regions.
# We will then use the slit_img task to create a mask of the sky regions.
# TODO: I don't understand why slmsk needs to be instantiated. SlitTraceSet
# does this internally.
slmsk = np.zeros(left_edg.shape[1], dtype=slittrace.SlitTraceSet.bitmask.minimum_dtype())
slitreg = slittrace.SlitTraceSet(left_edg, righ_edg, pypeline, nspec=slits.nspec,
nspat=slits.nspat, mask=slmsk, specmin=spec_min,
nspat=slits.nspat, specmin=spec_min,
specmax=spec_max, binspec=slits.binspec,
binspat=slits.binspat, pad=0)
# Generate the mask, and return
Expand Down
8 changes: 7 additions & 1 deletion pypeit/scripts/skysub_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ def main(args):
initial=args.initial, flexure=spat_flexure)

# Get the results
skyreg.get_result()
msskyreg = skyreg.get_result()

if msskyreg is not None:
outfil = skyreg.get_outname()
setup, calib_id, detname = msskyreg.parse_calib_key(calib_key)
msskyreg.set_paths(calib_dir, setup, calib_id, detname)
msskyreg.to_file(file_path=outfil)

# Reset the defaults
skyreg.finalize()