#! /usr/bin/env python ''' Modify a superbias reference file for pipeline testing. Currently all we should need to do is make sure that the reference file contains at least one pixel flagged with UNRELIABLE_BIAS, so that in testing we can make sure that the superbias is still subtracted from this pixel ''' from jwst.datamodels import SuperBiasModel infile = '../reffiles/A1_superbias_from_list_of_biasfiles.list.fits' outfile = 'modified_superbias_reffile.fits' #read in reffile sb = SuperBiasModel(infile) #set the unreliable_bias flag for one pixel sb.dq[50, 50] = 2 #save sb.save(outfile)
def save_superbias(superbias, error, dq, instrument='', detector='', subarray='GENERIC', readpatt='ANY', outfile='superbias_jwst_reffiles.fits', author='jwst_reffiles', description='Super Bias Image', pedigree='GROUND', useafter='2000-01-01T00:00:00', history='', fastaxis=-1, slowaxis=2, substrt1=1, substrt2=1, filenames=[]): """Saves a CRDS-formatted superbias reference file. Parameters ---------- superbias : numpy.ndarray The 2D superbias image. error : numpy.ndarray The 2D superbias error image. dq : numpy.ndarray The 2D superbias data quality image. instrument : str CRDS-required instrument for which to use this reference file for. detector : str CRDS-required detector for which to use this reference file for. subarray : str CRDS-required subarray for which to use this reference file for. readpatt : str CRDS-required read pattern for which to use this reference file for. outfile : str Name of the CRDS-formatted superbias reference file to save the final superbias map to. author : str CRDS-required name of the reference file author, to be placed in the referece file header. description : str CRDS-required description of the reference file, to be placed in the reference file header. pedigree : str CRDS-required pedigree of the data used to create the reference file. useafter : str CRDS-required date of earliest data with which this referece file should be used. (e.g. '2019-04-01T00:00:00'). history : str CRDS-required history section to place in the reference file header. fastaxis : int CRDS-required fastaxis of the reference file. slowaxis : int CRDS-required slowaxis of the reference file. substrt1 : int CRDS-required starting pixel in axis 1 direction. substrt2 : int CRDS-required starting pixel in axis 2 direction. filenames : list List of dark current files that were used to generate the reference file. """ s = SuperBiasModel() s.data = superbias s.err = error s.dq = dq s.dq_def = [(0, 0, 'GOOD', ''), (0, 1, 'DO_NOT_USE', ''), (1, 2, 'UNRELIABLE_BIAS', '')] s.meta.instrument.name = instrument s.meta.instrument.detector = detector s.meta.subarray.name = subarray s.meta.exposure.readpatt = readpatt s.meta.author = author s.meta.description = description s.meta.pedigree = pedigree s.meta.useafter = useafter s.meta.subarray.fastaxis = fastaxis s.meta.subarray.slowaxis = slowaxis s.meta.reftype = 'SUPERBIAS' yd, xd = superbias.shape s.meta.subarray.xstart = substrt1 s.meta.subarray.xsize = xd s.meta.subarray.ystart = substrt2 s.meta.subarray.ysize = yd package_note = ('This file was created using the superbias.py module ' 'within the jwst_reffiles package.') software_dict = {'name': 'jwst_reffiles.superbias.py', 'author': 'STScI', 'homepage': 'https://github.com/spacetelescope/jwst_reffiles', 'version': '0.0.0'} entry = util.create_history_entry(package_note, software=software_dict) s.history.append(entry) # Add the list of input files used to create the superbias reference file s.history.append('DATA USED:') for f in filenames: f = os.path.basename(f) totlen = len(f) div = np.arange(0, totlen, 60) for val in div: if totlen > (val+60): s.history.append(util.create_history_entry(f[val:val+60])) else: s.history.append(util.create_history_entry(f[val:])) if history != '': s.history.append(util.create_history_entry(history)) s.save(outfile, overwrite=True) print('Final CRDS-formatted superbias map saved to {}'.format(outfile))