Skip to content

Commit

Permalink
Remove clean option to FitsReader.read_params, which isn't actually n…
Browse files Browse the repository at this point in the history
…ecessary
  • Loading branch information
rmjarvis committed Mar 1, 2024
1 parent d4cf8ac commit 01fa3bb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
2 changes: 1 addition & 1 deletion tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def test_fits_reader():
with make_writer(os.path.join('output','test_fits_writer.fits')) as w:
w.write(['KAPPA', 'MU'], [kappa, mu])
with make_reader(os.path.join('output','test_fits_writer.fits')) as r:
params = r.read_params(clean=False)
params = r.read_params()
data = r.read_data()
assert 'test' not in params # The test key isn't in params
assert params['naxis1'] == 16 # But there are all the regular fits header items.
Expand Down
19 changes: 3 additions & 16 deletions treecorr/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,32 +555,19 @@ def read(self, cols, s=slice(None), *, ext=None):
ext = self._update_ext(ext)
return self.file[ext][cols][s]

def read_params(self, *, ext=None, clean=True):
def read_params(self, *, ext=None):
"""Read the params in the given extension, if any.
Parameters:
ext (str/int): The FITS extension to use. (default: 1)
clean (bool): Whether to remove all FITS-specific things in the header and
convert to a regular python dict. (default: True)
Returns:
params
"""
ext = self._update_ext(ext)
params = self.file[ext].read_header()
if clean:
# Convert to dict for convience downstream
# and remove all the standard FITS header keys while we're at it.
new_params = {}
for k in params:
if k in ['XTENSION', 'BITPIX', 'PCOUNT', 'GCOUNT', 'TFIELDS', 'EXTNAME']: continue
if k.startswith('NAXIS'): continue
if k.startswith('NAXIS'): continue
if k.startswith('TTYPE'): continue
if k.startswith('TFORM'): continue
new_params[k.lower()] = params[k]
params = new_params
return params
# Convert to dict for convience downstream, and make all keys lowercase.
return { k.lower() : params[k] for k in params }

def read_data(self, *, ext=None, max_rows=None):
"""Read all data in the file, and the parameters in the header, if any.
Expand Down

0 comments on commit 01fa3bb

Please sign in to comment.