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

status flag added to fits headers #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
27 changes: 24 additions & 3 deletions pp_calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,14 +478,26 @@ def calibrate(filenames, minstars, manfilter, manualcatalog,
# read in ldac data into catalogs
catalogs, filternames = [], {}
for filename in filenames:
hdulist = fits.open(filename, ignore_missing_end=True)
hdulist = fits.open(filename, mode='update', ignore_missing_end=True)

# add flag keyword to header and set it to FAILED
header = hdulist[0].header
try:
header.set('PP_CALIB', 'FAILED', 'PP: pp_calibrate status flag',
after='PP_PHOTO')
except KeyError:
print(('%s image header incomplete, have the data run ' +
'through pp_photometry?') % filename)
return None

try:
filtername = hdulist[0].header[obsparam['filter']]
except KeyError:
print('Cannot read filter name from file %s' % filename)
logging.error('Cannot read filter name from file %s' % filename)
return None

finally:
hdulist.close()
# translate filtername, if available
try:
filtername = obsparam['filter_translations'][filtername]
Expand Down Expand Up @@ -655,6 +667,15 @@ def calibrate(filenames, minstars, manfilter, manualcatalog,

logging.info('Done! -----------------------------------------------------')

# set flag keyword to SUCCESS
for filename in filenames:
hdulist = fits.open(filename, mode='update', verify='silentfix',
ignore_missing_end=True)
header = hdulist[0].header
header.set('PP_CALIB', 'SUCCESS')
hdulist.close()


return zp_data


Expand Down Expand Up @@ -710,7 +731,7 @@ def calibrate(filenames, minstars, manfilter, manualcatalog,
telescope = hdulist[0].header['TEL_KEYW']
except KeyError:
print('ERROR: cannot find telescope keyword in image header;',
'has this image run through pp_prepare?')
'has this image run through pp_photometry?')
sys.exit(0)
obsparam = _pp_conf.telescope_parameters[telescope]

Expand Down
27 changes: 27 additions & 0 deletions pp_distill.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,24 @@ def distill(catalogs, man_targetname, offset, fixed_targets_file, posfile,
logging.info('starting distill with parameters: %s' %
(', '.join([('%s: %s' % (var, str(val))) for
var, val in list(locals().items())])))

# add flag keyword to header and set it to FAILED
filenames_status_flag = []
for cat in catalogs:
filename = cat.catalogname.replace('ldac', 'fits')
filenames_status_flag.append(filename)
hdulist = fits.open(filename, mode='update', verify='silentfix',
ignore_missing_end=True)
header = hdulist[0].header
try:
header.set('PP_DISTI', 'FAILED', 'PP: pp_distill status flag',
after='PP_CALIB')
except KeyError:
print(('%s image header incomplete, have the data run ' +
'through pp_calibrate?') % filename)
return None
finally:
hdulist.close()

output = {}

Expand Down Expand Up @@ -729,6 +747,15 @@ def distill(catalogs, man_targetname, offset, fixed_targets_file, posfile,
# img_y, origin, flags, fwhm],
# }
###


# set flag keyword to SUCCESS
for filename in filenames_status_flag:
hdulist = fits.open(filename, mode='update', verify='silentfix',
ignore_missing_end=True)
header = hdulist[0].header
header.set('PP_DISTI', 'SUCCESS')
hdulist.close()

# create diagnostics
if diagnostics:
Expand Down
18 changes: 18 additions & 0 deletions pp_photometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,16 @@ def photometry(filenames, sex_snr, source_minarea, aprad,
for filename in filenames:
hdu = fits.open(filename, mode='update',
ignore_missing_end=True)

# add flag keyword to header and set it to FAILED
try:
header = hdu[0].header
header.set('PP_PHOTO', 'FAILED', 'PP: pp_photometry status flaag',
after='PP_REGIS')
except KeyError:
print(('%s image header incomplete, have the data run ' +
'through pp_register?') % filename)

hdu[0].header['PHOTMODE'] = (_pp_conf.photmode,
'PP photometry mode')
hdu.flush()
Expand Down Expand Up @@ -414,6 +424,14 @@ def photometry(filenames, sex_snr, source_minarea, aprad,
pp_extract.extract_multiframe(filenames, photpar)

logging.info('Done! -----------------------------------------------------')

# set flag keyword to SUCCESS
for filename in filenames:
hdulist = fits.open(filename, mode='update', verify='silentfix',
ignore_missing_end=True)
header = hdulist[0].header
header.set('PP_PHOTO', 'SUCCESS')
hdulist.close()

if 'cog' in list(locals().keys()):
return cog
Expand Down
8 changes: 7 additions & 1 deletion pp_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ def prepare(filenames, obsparam, header_update, keep_wcs=False,
hdulist = fits.open(filename, mode='update', verify='silentfix',
ignore_missing_end=True)
header = hdulist[0].header


# add flag keyword to header and set it to FAILED
header.set('PP_PREPA', 'FAILED', 'PP: pp_prepare status flag')

# add other headers, if available
if len(hdulist) > 1:
for i in range(len(hdulist)):
Expand Down Expand Up @@ -431,6 +434,9 @@ def prepare(filenames, obsparam, header_update, keep_wcs=False,
# overwrite imdata in case something has been modified
hdulist[0].data = imdata

# set flag keyword to SUCCESS
header.set('PP_PREPA', 'SUCCESS')

hdulist.flush()
hdulist.close()

Expand Down
25 changes: 24 additions & 1 deletion pp_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ def register(filenames, telescope, sex_snr, source_minarea, aprad,
raise KeyError(('%s image header incomplete, have the data run ' +
'through pp_prepare?') % filenames[0])
return None

# add flag keyword to header and set it to FAILED
for filename in filenames:
hdulist = fits.open(filename, mode='update', verify='silentfix',
ignore_missing_end=True)
header = hdulist[0].header
try:
header.set('PP_REGIS', 'FAILED', 'PP: pp_register status flag',
after='PP_PREPA')
except KeyError:
print(('%s image header incomplete, have the data run ' +
'through pp_prepare?') % filename)
return None
finally:
hdulist.close()

# run scamp on all image catalogs using different catalogs
if mancat is not None:
Expand Down Expand Up @@ -406,7 +421,15 @@ def register(filenames, telescope, sex_snr, source_minarea, aprad,
diag.add_registration(output, extraction)

logging.info('Done! -----------------------------------------------------')


# set flag keyword to SUCCESS
for filename in filenames:
hdulist = fits.open(filename, mode='update', verify='silentfix',
ignore_missing_end=True)
header = hdulist[0].header
header.set('PP_REGIS', 'SUCCESS')
hdulist.close()

return output


Expand Down