def _save_pipeline_metadata(self, runtime_context): self.datecreated = datetime.datetime.utcnow() self.header['DATE'] = (date_utils.date_obs_to_string(self.datecreated), '[UTC] Date this FITS file was written') self.header['RLEVEL'] = (runtime_context.rlevel, 'Reduction level') self.header['PIPEVER'] = (banzai.__version__, 'Pipeline version') if file_utils.instantly_public(self.header['PROPID']): self.header['L1PUBDAT'] = (self.header['DATE-OBS'], '[UTC] Date the frame becomes public') else: # Wait a year date_observed = date_utils.parse_date_obs(self.header['DATE-OBS']) next_year = date_observed + datetime.timedelta(days=365) self.header['L1PUBDAT'] = ( date_utils.date_obs_to_string(next_year), '[UTC] Date the frame becomes public') logging_tags = { 'rlevel': int(self.header['RLEVEL']), 'pipeline_version': self.header['PIPEVER'], 'l1pubdat': self.header['L1PUBDAT'], } logger.info('Adding pipeline metadata to the header', image=self, extra_tags=logging_tags)
def do_stage(self, images): for image in images: image.header['RLEVEL'] = (self.pipeline_context.rlevel, 'Reduction level') image.header['PIPEVER'] = (banzai.__version__, 'Pipeline version') if instantly_public(image.header['PROPID']): image.header['L1PUBDAT'] = ( image.header['DATE-OBS'], '[UTC] Date the frame becomes public') else: # Wait a year date_observed = date_utils.parse_date_obs( image.header['DATE-OBS']) next_year = date_observed + timedelta(days=365) image.header['L1PUBDAT'] = ( date_utils.date_obs_to_string(next_year), '[UTC] Date the frame becomes public') logging_tags = logs.image_config_to_tags(image, self.group_by_keywords) logs.add_tag(logging_tags, 'filename', os.path.basename(image.filename)) logs.add_tag(logging_tags, 'rlevel', int(image.header['RLEVEL'])) logs.add_tag(logging_tags, 'pipeline_version', image.header['PIPEVER']) logs.add_tag(logging_tags, 'l1pubdat', image.header['L1PUBDAT']) self.logger.info('Updating header', extra=logging_tags) return images
def create_master_calibration_header(images): header = fits.Header() for h in images[0].header.keys(): try: # Dump empty header keywords if len(h) > 0: header[h] = images[0].header[h] except ValueError as e: logging_tags = logs.image_config_to_tags(images[0], None) logs.add_tag(logging_tags, 'filename', images[0].filename) logger.error('Could not add keyword {0}'.format(h), extra=logging_tags) continue header = sanitizeheader(header) observation_dates = [image.dateobs for image in images] mean_dateobs = date_utils.mean_date(observation_dates) header['DATE-OBS'] = date_utils.date_obs_to_string(mean_dateobs) header.add_history("Images combined to create master calibration image:") for image in images: header.add_history(image.filename) return header
def create_master_calibration_header(old_header, images): header = fits.Header() for key in old_header.keys(): try: # Dump empty header keywords and ignore old histories. if len(key) > 0 and key != 'HISTORY': for i in range(old_header.count(key)): header[key] = (old_header[(key, i)], old_header.comments[(key, i)]) except ValueError as e: logger.error('Could not add keyword {key}: {error}'.format( key=key, error=e)) continue header = fits_utils.sanitizeheader(header) observation_dates = [image.dateobs for image in images] mean_dateobs = date_utils.mean_date(observation_dates) header['DATE-OBS'] = (date_utils.date_obs_to_string(mean_dateobs), '[UTC] Mean observation start time') header['ISMASTER'] = (True, 'Is this a master calibration frame') header.add_history("Images combined to create master calibration image:") for image in images: header.add_history(image.filename) return header
def save_pipeline_metadata(image, pipeline_context): image.header['RLEVEL'] = (pipeline_context.rlevel, 'Reduction level') image.header['PIPEVER'] = (banzai.__version__, 'Pipeline version') if file_utils.instantly_public(image.header['PROPID']): image.header['L1PUBDAT'] = (image.header['DATE-OBS'], '[UTC] Date the frame becomes public') else: # Wait a year date_observed = date_utils.parse_date_obs(image.header['DATE-OBS']) next_year = date_observed + timedelta(days=365) image.header['L1PUBDAT'] = (date_utils.date_obs_to_string(next_year), '[UTC] Date the frame becomes public') logging_tags = logs.image_config_to_tags(image, None) logs.add_tag(logging_tags, 'filename', os.path.basename(image.filename)) logs.add_tag(logging_tags, 'rlevel', int(image.header['RLEVEL'])) logs.add_tag(logging_tags, 'pipeline_version', image.header['PIPEVER']) logs.add_tag(logging_tags, 'l1pubdat', image.header['L1PUBDAT']) logger.info('Updating header', extra=logging_tags)
def create_master_calibration_header(images): header = fits.Header() for h in images[0].header.keys(): try: # Dump empty header keywords if len(h) > 0: header[h] = images[0].header[h] except ValueError as e: logging_tags = logs.image_config_to_tags(images[0], None) logs.add_tag(logging_tags, 'filename', images[0].filename) logger.error('Could not add keyword {0}'.format(h), extra=logging_tags) continue header = sanitizeheader(header) observation_dates = [image.dateobs for image in images] mean_dateobs = date_utils.mean_date(observation_dates) header['DATE-OBS'] = date_utils.date_obs_to_string(mean_dateobs) header.add_history("Images combined to create master calibration image:") for image in images: header.add_history(image.filename) return header
def create_master_calibration_header(old_header, images): header = fits.Header() for key in old_header.keys(): try: # Dump empty header keywords if len(key) > 0: for i in range(old_header.count(key)): header[key] = (old_header[(key, i)], old_header.comments[(key, i)]) except ValueError as e: logger.error('Could not add keyword {key}: {error}'.format(key=key, error=e)) continue header = fits_utils.sanitizeheader(header) observation_dates = [image.dateobs for image in images] mean_dateobs = date_utils.mean_date(observation_dates) header['DATE-OBS'] = (date_utils.date_obs_to_string(mean_dateobs), '[UTC] Mean observation start time') header['ISMASTER'] = (True, 'Is this a master calibration frame') header.add_history("Images combined to create master calibration image:") for image in images: header.add_history(image.filename) return header
def __init__(self, runtime_context, filename=None, data=None, data_tables=None, header=None, extension_headers=None, bpm=None): if header is None: header = fits.Header() if data_tables is None: data_tables = {} if extension_headers is None: extension_headers = [] if filename is not None: data, header, bpm, extension_headers = fits_utils.open_image( filename) if '.fz' == filename[-3:]: filename = filename[:-3] self.filename = os.path.basename(filename) self.data = data self.data_tables = data_tables self.header = header self.bpm = bpm self.extension_headers = extension_headers self.request_number = header.get('REQNUM') self.instrument, self.site, self.camera = self._init_instrument_info( runtime_context) self.epoch = str(header.get('DAY-OBS')) self.nx = header.get('NAXIS1') self.ny = header.get('NAXIS2') self.block_id = header.get('BLKUID') self.block_start = date_utils.parse_date_obs( header.get('BLKSDATE', '1900-01-01T00:00:00.00000')) self.molecule_id = header.get('MOLUID') if len(self.extension_headers ) > 0 and 'GAIN' in self.extension_headers[0]: self.gain = [h['GAIN'] for h in extension_headers] else: self.gain = eval(str(header.get('GAIN'))) self.ccdsum = header.get('CCDSUM') self.configuration_mode = fits_utils.get_configuration_mode(header) self.filter = header.get('FILTER') self.obstype = header.get('OBSTYPE') self.exptime = float(header.get('EXPTIME', 0.0)) self.dateobs = date_utils.parse_date_obs( header.get('DATE-OBS', '1900-01-01T00:00:00.00000')) self.datecreated = date_utils.parse_date_obs( header.get('DATE', date_utils.date_obs_to_string(self.dateobs))) self.readnoise = float(header.get('RDNOISE', 0.0)) self.ra, self.dec = fits_utils.parse_ra_dec(header) self.pixel_scale = float(header.get('PIXSCALE', 0.0)) self.is_bad = False self.is_master = header.get('ISMASTER', False) self.attributes = settings.CALIBRATION_SET_CRITERIA.get( self.obstype, {})