diff --git a/jwst_magic/fsw_file_writer/detector_effects.py b/jwst_magic/fsw_file_writer/detector_effects.py index 215e0a20..dc0a0154 100644 --- a/jwst_magic/fsw_file_writer/detector_effects.py +++ b/jwst_magic/fsw_file_writer/detector_effects.py @@ -44,8 +44,8 @@ __location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__))) PACKAGE_PATH = os.path.split(__location__)[0] DATA_PATH = os.path.join(PACKAGE_PATH, 'data') -BIASZERO_G1 = fits.getdata(os.path.join(DATA_PATH, 'g1bias0.fits')) -BIASZERO_G2 = fits.getdata(os.path.join(DATA_PATH, 'g2bias0.fits')) +BIASZERO_G1 = os.path.join(DATA_PATH, 'g1bias0.fits') +BIASZERO_G2 = os.path.join(DATA_PATH, 'g2bias0.fits') READ_NOISE = os.path.join(DATA_PATH, 'readnoise.yaml') @@ -209,7 +209,10 @@ def add_zeroth_read_bias(self): """Add zeroth read bias structure to every frame. """ # Open the zeroth read bias structure file - bias_file = os.path.join(DATA_PATH, 'g{}bias0.fits'.format(self.guider)) + if self.guider == 1: + bias_file = BIASZERO_G1 + else: + bias_file = BIASZERO_G2 bias0 = np.copy(fits.getdata(bias_file)) xlow, xhigh, ylow, yhigh = self.array_bounds diff --git a/jwst_magic/tests/data/parametrized_test_data.yml b/jwst_magic/tests/data/parametrized_test_data.yml index e03db083..2e86de42 100644 --- a/jwst_magic/tests/data/parametrized_test_data.yml +++ b/jwst_magic/tests/data/parametrized_test_data.yml @@ -16,25 +16,25 @@ test_buildfgssteps: bias: [1150.0, 30070.0] time_normed_im: [-5.68109e-05, 5920.4453] cds: [0.0, 6040.0] - strips: [0.0, 28030.0] - ID: [0.0, 28030.0] + strips: [0.0, 29340.0] + ID: [0.0, 29340.0] ACQ1: countrates: [65596.0] bias: [6340.0, 26740.0] time_normed_im: [0.0036995418, 2201.8406] cds: [0.0, 4430.0] - ACQ1: [0.0, 20300.0] + ACQ1: [0.0, 26740.0] ACQ2: countrates: [65596.0] bias: [6350.0, 16930.0] time_normed_im: [0.019422999, 152.88527] cds: [0.0, 660.0] - ACQ2: [6350.0, 16940.0] + ACQ2: [0.0, 16940.0] TRK: countrates: [65596.0] bias: [6270.0, 17040.0] time_normed_im: [0.019422999, 152.88527] - TRK: [6270.0, 17050.0] + TRK: [0.0, 17050.0] LOSTRK: countrates: [65596.0] time_normed_im: [0.00661816, 152.88527] @@ -42,34 +42,34 @@ test_buildfgssteps: guider2: CAL: countrates: [65596.0, 91475.0, 91549.0, 95731.0, 95747.0] - bias: [-60.0, 29250.0] + bias: [-30.0, 29420.0] time_normed_im: [-0.001770345, 184493.3] cds: [0.0, 25000.0] - CAL: [0.0, 387660.0] + CAL: [0.0, 383260.0] ID: countrates: [65596.0, 91475.0, 91549.0, 95731.0, 95747.0] - bias: [-30.0, 29310.0] + bias: [-40.0, 29380.0] time_normed_im: [-5.68109e-05, 5920.4453] cds: [0.0, 6010.0] - strips: [0.0, 30460.0] - ID: [0.0, 30460.0] + strips: [0.0, 28840.0] + ID: [0.0, 28840.0] ACQ1: countrates: [65596.0] - bias: [6470.0, 27730.0] + bias: [6520.0, 27630.0] time_normed_im: [0.0036995418, 2201.8406] cds: [0.0, 4440.0] - ACQ1: [0.0, 27670.0] + ACQ1: [0.0, 22610.0] ACQ2: countrates: [65596.0] - bias: [7620.0, 21250.0] + bias: [7630.0, 21250.0] time_normed_im: [0.019422999, 152.88527] cds: [0.0, 640.0] - ACQ2: [0.0, 21230.0] + ACQ2: [0.0, 19340.0] TRK: countrates: [65596.0] bias: [7510.0, 21360.0] time_normed_im: [0.019422999, 152.88527] - TRK: [0.0, 21370.0] + TRK: [0.0, 19490.0] LOSTRK: countrates: [65596.0] time_normed_im: [0.00661816, 152.88527] diff --git a/jwst_magic/utils/utils.py b/jwst_magic/utils/utils.py index 33b92d80..1d758a4e 100644 --- a/jwst_magic/utils/utils.py +++ b/jwst_magic/utils/utils.py @@ -783,12 +783,15 @@ def convert_bad_pixel_mask_data(bad_pix_data, bad_pix_values=None, nircam=True): return data, pix_dict -def convert_nircam_bad_pixel_mask_files(filepath): +def convert_bad_pixel_mask_files(filepath, nircam): """ - Converts a NIRCam bad pixel mask file to a format MAGIC can use, + Converts a NIRCam or FGS bad pixel mask file to a format MAGIC can use, switching from bit values to 1s and 0s, where 0s are good and 1s are bad. Pixels counted as bad in the new mask were originally do_not_use, dead, hot, telegraph, bad_ref_pix, and RC. + + filepath : str path to input file + nircam: bool for if NIRCam data. True includes the do not use flag """ # Read in file with fits.open(filepath) as bad_pix_hdu: @@ -800,7 +803,7 @@ def convert_nircam_bad_pixel_mask_files(filepath): bad_pix_values = np.delete(bad_pix_values, np.where(bad_pix_values == 0)) # Update file to be only 1s and 0s to match FGS - data, pix_dict = convert_bad_pixel_mask_data(bad_pix_data, bad_pix_values, nircam=True) + data, pix_dict = convert_bad_pixel_mask_data(bad_pix_data, bad_pix_values, nircam=nircam) # Write header bad_pix_hdr['ORIGFILE'] = os.path.basename(filepath) @@ -810,5 +813,12 @@ def convert_nircam_bad_pixel_mask_files(filepath): # Save out file det = bad_pix_hdr['DETECTOR'] - filepath_new = os.path.join(os.path.dirname(filepath), f'nircam_dq_{det.lower()}.fits') + if nircam: + filepath_new = os.path.join(os.path.dirname(filepath), f'nircam_dq_{det.lower()}.fits') + else: + guider = det.replace('UIDER', '') + if 'stacked' in filepath.lower(): + filepath_new = os.path.join(os.path.dirname(filepath), f'fgs_dq_{guider}_stacked.fits') + else: + filepath_new = os.path.join(os.path.dirname(filepath), f'fgs_dq_{guider}.fits') write_fits(filepath_new, [data], header=[bad_pix_hdr], log=LOGGER)