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

Calibration group hotfix #1824

Merged
merged 4 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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.16.1dev.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ Under-the-hood Improvements
Bug Fixes
---------

- Fixed a fault caused when all frames in a pypeit file are identified as being
part of ``all`` calibration groups.
- Allow for empty 2D wavecal solution in HDU extension of WaveCalib file

23 changes: 17 additions & 6 deletions pypeit/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,18 +1033,28 @@ def _set_calib_group_bits(self):
Set the calibration group bit based on the string values of the
'calib' column.
"""
# NOTE: This is a hack to ensure the type of the *elements* of the calib
# column are all strings, but that the type of the column remains as
# "object". I'm calling this a hack because doing this is easier than
# Ensure that the type of the *elements* of the calib column are all
# strings, but that the type of the column remains as "object".
# NOTE: This is effectively a hack because doing this is easier than
# trying to track down everywhere calib is changed to values that may or
# may not be integers instead of strings.
self['calib'] = np.array([str(c) for c in self['calib']], dtype=object)

# Collect and expand any lists
# group_names = np.unique(np.concatenate(
# [s.split(',') for s in self['calib'] if s not in ['all', 'None']]))
# DP changed to below because np.concatenate does not accept an empty list,
# which is the case when calib is None for all frames. This should avoid the code to crash
group_names = np.unique(sum([s.split(',') for s in self['calib'] if s not in ['all', 'None']], []))
# NOTE: The above doesn't always work because np.concatenate does not
# accept an empty list, which is the case when calib is None or 'all'
# for all frames.
group_names = np.unique(sum([s.split(',') for s in self['calib']
if s not in ['all', 'None']], []))

# If all the calibration groups are set to None or 'all', group_names
# can be an empty list. But we need to identify at least one
# calibration group, so I insert a mock value.
if group_names.size == 0:
group_names = np.array(['0'], dtype=object)

# Expand any ranges
keep_group = np.ones(group_names.size, dtype=bool)
added_groups = []
Expand All @@ -1053,6 +1063,7 @@ def _set_calib_group_bits(self):
# Parse the range
keep_group[i] = False
added_groups += [str(n) for n in parse.str2list(name)]

# Combine and find the unique *integer* identifiers
group_names = np.unique(np.asarray(added_groups +
(group_names[keep_group]).tolist()).astype(int))
Expand Down
Loading