Skip to content

Commit

Permalink
small fix to chk_tilts
Browse files Browse the repository at this point in the history
  • Loading branch information
debora-pe committed Oct 19, 2024
1 parent 1d6197a commit 242f664
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
9 changes: 7 additions & 2 deletions pypeit/scripts/chk_tilts.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@ def get_parser(cls, width=None):

@staticmethod
def main(args):
from pathlib import Path

Check warning on line 35 in pypeit/scripts/chk_tilts.py

View check run for this annotation

Codecov / codecov/patch

pypeit/scripts/chk_tilts.py#L35

Added line #L35 was not covered by tests
from pypeit import wavetilts

chk_version = not args.try_old

# tilts file path
file = Path(args.file).absolute()

Check warning on line 41 in pypeit/scripts/chk_tilts.py

View check run for this annotation

Codecov / codecov/patch

pypeit/scripts/chk_tilts.py#L41

Added line #L41 was not covered by tests

# Load
tilts = wavetilts.WaveTilts.from_file(args.file, chk_version=chk_version)
tilts = wavetilts.WaveTilts.from_file(file, chk_version=chk_version)
embed()

Check warning on line 45 in pypeit/scripts/chk_tilts.py

View check run for this annotation

Codecov / codecov/patch

pypeit/scripts/chk_tilts.py#L44-L45

Added lines #L44 - L45 were not covered by tests
tilts.show(in_ginga=np.logical_not(args.mpl), show_traces=args.show_traces,
chk_version=chk_version)
calib_dir=file.parent, chk_version=chk_version)



18 changes: 14 additions & 4 deletions pypeit/wavetilts.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def spatid_to_zero(self, spat_id):
return np.where(mtch)[0][0]

def show(self, waveimg=None, wcs_match=True, in_ginga=True, show_traces=False,
chk_version=True):
calib_dir=None, chk_version=True):
"""
Show in ginga or mpl Tiltimg with the tilts traced and fitted overlaid
Expand All @@ -189,22 +189,32 @@ def show(self, waveimg=None, wcs_match=True, in_ginga=True, show_traces=False,
If True, show the image in ginga. Otherwise, use matplotlib.
show_traces (bool, optional):
If True, show the traces of the tilts on the image.
calib_dir (`Path`_):
Path to the calibration directory. If None, the path is taken from the
WaveTilts object.
chk_version (:obj:`bool`, optional):
When reading in existing files written by PypeIt, perform strict
version checking to ensure a valid file. If False, the code
will try to keep going, but this may lead to faults and quiet
failures. User beware!
"""
# get tilt_img_dict
cal_file = Path(self.calib_dir).absolute() / self.tiltimg_filename
_calib_dir = self.calib_dir
if calib_dir is not None and calib_dir.exists():
_calib_dir = calib_dir
msgs.info(f'Searching for other calibration files in {str(_calib_dir)}')

Check warning on line 205 in pypeit/wavetilts.py

View check run for this annotation

Codecov / codecov/patch

pypeit/wavetilts.py#L202-L205

Added lines #L202 - L205 were not covered by tests
else:
msgs.info(f'Searching for other calibration files in the default directory {str(_calib_dir)}')

Check warning on line 207 in pypeit/wavetilts.py

View check run for this annotation

Codecov / codecov/patch

pypeit/wavetilts.py#L207

Added line #L207 was not covered by tests

cal_file = Path(_calib_dir).absolute() / self.tiltimg_filename

Check warning on line 209 in pypeit/wavetilts.py

View check run for this annotation

Codecov / codecov/patch

pypeit/wavetilts.py#L209

Added line #L209 was not covered by tests
if cal_file.exists():
tilt_img_dict = buildimage.TiltImage.from_file(cal_file, chk_version=chk_version)
else:
msgs.error(f'Tilt image {str(cal_file)} NOT FOUND.')

# get slits
slitmask = None
cal_file = Path(self.calib_dir).absolute() / self.slits_filename
cal_file = Path(_calib_dir).absolute() / self.slits_filename

Check warning on line 217 in pypeit/wavetilts.py

View check run for this annotation

Codecov / codecov/patch

pypeit/wavetilts.py#L217

Added line #L217 was not covered by tests
if cal_file.exists():
slits = slittrace.SlitTraceSet.from_file(cal_file, chk_version=chk_version)
_slitmask = slits.slit_img(initial=True, flexure=self.spat_flexure)
Expand All @@ -221,7 +231,7 @@ def show(self, waveimg=None, wcs_match=True, in_ginga=True, show_traces=False,
# get waveimg
same_size = (slits.nspec, slits.nspat) == tilt_img_dict.image.shape
if waveimg is None and slits is not None and same_size and in_ginga:
wv_calib_name = wavecalib.WaveCalib.construct_file_name(self.calib_key, calib_dir=self.calib_dir)
wv_calib_name = wavecalib.WaveCalib.construct_file_name(self.calib_key, calib_dir=_calib_dir)

Check warning on line 234 in pypeit/wavetilts.py

View check run for this annotation

Codecov / codecov/patch

pypeit/wavetilts.py#L234

Added line #L234 was not covered by tests
if Path(wv_calib_name).absolute().exists():
wv_calib = wavecalib.WaveCalib.from_file(wv_calib_name, chk_version=chk_version)
tilts = self.fit2tiltimg(slitmask, flexure=self.spat_flexure)
Expand Down

0 comments on commit 242f664

Please sign in to comment.