find_row

jwst.lib.reffile_utils.find_row(ldict, match_keys, require_one=True)[source]

Find a row in a FITS table matching fields.

Parameters:
ldictlist of dict or FITS_rec

A list of dictionaries or a record array. The record may have any number of items but must include all keys in match_keys.

match_keysdict

{key: value} pairs are matched against all items in ldict to find the dict which matches them.

require_onebool, optional

If True, an error is raised if more than one row matches.

Returns:
rowdict, or FITS_rec, or None

Matching table row. None if no match.

Raises:
MatchRowError

When more than one row matches and require_one is True.

Examples

>>> ldict = [
...     {"row_offset": 2.1, "col_offset": 1.3, "filter": "F444W", "pupil": "CLEAR"},
...     {"row_offset": 1, "col_offset": 3, "filter": "F277W", "pupil": "FLAT"},
... ]
>>> match_keys = {"filter": "F444W", "pupil": "CLEAR"}
>>> result = find_row(ldict, match_keys)
>>> print(result)
{'row_offset': 2.1, 'col_offset': 1.3, 'filter': 'F444W', 'pupil': 'CLEAR'}