Skip to content

Commit

Permalink
recursive keyword removal based on obsparam
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Mommert committed Mar 23, 2017
1 parent 1bfde83 commit c1e9037
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pp_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,13 @@ def prepare(filenames, obsparam, header_update, flipx=False,
header['PHOTFLAG'] = ('F', 'PP: data is not photometric (SCAMP)')
header['PHOT_K'] = (0.05, 'PP: assumed extinction coefficient')


# remove keywords that might collide with fake wcs
for key in list(header.keys()):
if 'CD' in key and '_' in key:
if key not in obsparam.values():
# if key not in obsparam.values():
# header.remove(key)
if not toolbox.if_val_in_dict(key, obsparam):
header.remove(key)
elif 'PV' in key and '_' in key:
header.remove(key)
Expand All @@ -240,7 +243,7 @@ def prepare(filenames, obsparam, header_update, flipx=False,
'AP_2_0', 'BP_ORDER', 'BP_0_0', 'BP_0_1',
'BP_0_2', 'BP_1_0', 'BP_1_1', 'BP_2_0', 'CDELT1',
'CDELT2', 'CRDELT1', 'CRDELT2']:
if key not in obsparam.values():
if toolbox.if_val_in_dict(key, obsparam):
header.remove(key)

# if GENERIC telescope, add implants to header
Expand Down
13 changes: 13 additions & 0 deletions toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,16 @@ def skycenter(catalogs, ra_key='ra.deg', dec_key='dec.deg'):
(old_div((max_dec-min_dec),2.))**2)

return ra, dec, rad


## miscellaneous tools

def if_val_in_dict(target_val, dic):
"""check if a value appears in a nested dict structure"""
for key, val in dic.items():
if type(val) is dict:
return if_val_in_dict(target_val, val)
elif type(val) is list:
return target_val in val
else:
return target_val == val

0 comments on commit c1e9037

Please sign in to comment.