Exemple #1
0
def setup_cube(ngroups, nrows, ncols):
    ''' Set up fake data to test.'''

    nints = 1

    data_model = RampModel()
    data_model.data = np.zeros(shape=(nints, ngroups, nrows, ncols), dtype=np.float32)
    data_model.pixeldq = np.zeros(shape=(nrows, ncols), dtype=np.int32)
    data_model.groupdq = np.zeros(shape=(nints, ngroups, nrows, ncols), dtype=np.float32)
    data_model.meta.subarray.xstart = 1
    data_model.meta.subarray.ystart = 1
    data_model.meta.subarray.xsize = ncols
    data_model.meta.subarray.ysize = nrows
    data_model.meta.exposure.ngroups = ngroups
    data_model.meta.instrument.name = 'NIRCAM'

    saturation_model = SaturationModel()
    saturation_model.data = np.zeros(shape=(2048, 2048), dtype=np.float32)
    saturation_model.dq = np.zeros(shape=(2048, 2048), dtype=np.int32)
    saturation_model.meta.subarray.xstart = 1
    saturation_model.meta.subarray.ystart = 1
    saturation_model.meta.subarray.xsize = 2048
    saturation_model.meta.subarray.ysize = 2048
    saturation_model.meta.instrument.name = 'NIRCAM'
    saturation_model.meta.description = 'Fake data.'
    saturation_model.meta.telescope = 'JWST'
    saturation_model.meta.reftype = 'SaturationModel'
    saturation_model.meta.author = 'Alicia'
    saturation_model.meta.pedigree = 'Dummy'
    saturation_model.meta.useafter = '2015-10-01T00:00:00'

    return data_model, saturation_model
Exemple #2
0
    def _cube(ngroups, nrows, ncols):

        nints = 1

        data_model = RampModel((nints, ngroups, nrows, ncols))
        data_model.meta.subarray.xstart = 1
        data_model.meta.subarray.ystart = 1
        data_model.meta.subarray.xsize = ncols
        data_model.meta.subarray.ysize = nrows
        data_model.meta.exposure.ngroups = ngroups
        data_model.meta.instrument.name = 'NIRCAM'
        data_model.meta.instrument.detector = 'NRCA1'
        data_model.meta.observation.date = '2017-10-01'
        data_model.meta.observation.time = '00:00:00'

        saturation_model = SaturationModel((2048, 2048))
        saturation_model.meta.subarray.xstart = 1
        saturation_model.meta.subarray.ystart = 1
        saturation_model.meta.subarray.xsize = 2048
        saturation_model.meta.subarray.ysize = 2048
        saturation_model.meta.instrument.name = 'NIRCAM'
        saturation_model.meta.description = 'Fake data.'
        saturation_model.meta.telescope = 'JWST'
        saturation_model.meta.reftype = 'SaturationModel'
        saturation_model.meta.author = 'Alicia'
        saturation_model.meta.pedigree = 'Dummy'
        saturation_model.meta.useafter = '2015-10-01T00:00:00'

        return data_model, saturation_model
    def get_sat_vals(self, file):
        """Read in SSB-format saturation reference file
        and deal with bad values
        """
        sat_model = SaturationModel(file)
        svals = sat_model.data

        #set pixels with saturation level of 0.
        #to 65535
        bad = svals == 0
        svals[bad] = 65535
        return svals
Exemple #4
0
    def _cube():

        # create a JWST datamodel for NIRSPEC IRS2 data
        data_model = RampModel((1, 5, 3200, 2048))
        data_model.data = np.ones(((1, 5, 3200, 2048)))
        data_model.groupdq = np.zeros(((1, 5, 3200, 2048)))
        data_model.pixeldq = np.zeros(((3200, 2048)))
        data_model.meta.instrument.name = 'NIRSPEC'
        data_model.meta.instrument.detector = 'NRS1'
        data_model.meta.instrument.filter = 'F100LP'
        data_model.meta.observation.date = '2019-07-19'
        data_model.meta.observation.time = '23:23:30.912'
        data_model.meta.exposure.type = 'NRS_LAMP'
        data_model.meta.subarray.name = 'FULL'
        data_model.meta.subarray.xstart = 1
        data_model.meta.subarray.xsize = 2048
        data_model.meta.subarray.ystart = 1
        data_model.meta.subarray.ysize = 2048
        data_model.meta.exposure.nrs_normal = 16
        data_model.meta.exposure.nrs_reference = 4
        data_model.meta.exposure.readpatt = 'NRSIRS2RAPID'

        # create a saturation model for the saturation step
        saturation_model = SaturationModel((2048, 2048))
        saturation_model.data = np.ones(
            (2048, 2048)) * 60000  # saturation limit for every pixel is 60000
        saturation_model.meta.description = 'Fake data.'
        saturation_model.meta.telescope = 'JWST'
        saturation_model.meta.reftype = 'SaturationModel'
        saturation_model.meta.useafter = '2015-10-01T00:00:00'
        saturation_model.meta.instrument.name = 'NIRSPEC'
        saturation_model.meta.instrument.detector = 'NRS1'
        saturation_model.meta.author = 'Clare'
        saturation_model.meta.pedigree = 'Dummy'
        saturation_model.meta.subarray.xstart = 1
        saturation_model.meta.subarray.xsize = 2048
        saturation_model.meta.subarray.ystart = 1
        saturation_model.meta.subarray.ysize = 2048

        return data_model, saturation_model
Exemple #5
0
    def _cube(xstart, ystart, ngroups, nrows, ncols):

        nints = 1

        # create a JWST datamodel for MIRI data
        data_model = RampModel((nints, ngroups, nrows, ncols))
        data_model.data += 1
        data_model.meta.instrument.name = 'MIRI'
        data_model.meta.instrument.detector = 'MIRIMAGE'
        data_model.meta.instrument.filter = 'F1500W'
        data_model.meta.instrument.band = 'N/A'
        data_model.meta.observation.date = '2016-06-01'
        data_model.meta.observation.time = '00:00:00'
        data_model.meta.exposure.type = 'MIR_IMAGE'
        data_model.meta.subarray.name = 'MASK1550'
        data_model.meta.subarray.xstart = xstart
        data_model.meta.subarray.xsize = ncols
        data_model.meta.subarray.ystart = ystart
        data_model.meta.subarray.ysize = nrows

        # create a saturation model for the saturation step
        saturation_model = SaturationModel((1032, 1024))
        saturation_model.meta.description = 'Fake data.'
        saturation_model.meta.telescope = 'JWST'
        saturation_model.meta.reftype = 'SaturationModel'
        saturation_model.meta.author = 'Alicia'
        saturation_model.meta.pedigree = 'Dummy'
        saturation_model.meta.useafter = '2015-10-01T00:00:00'
        saturation_model.meta.instrument.name = 'MIRI'
        saturation_model.meta.instrument.detector = 'MIRIMAGE'
        saturation_model.meta.subarray.xstart = 1
        saturation_model.meta.subarray.xsize = 1024
        saturation_model.meta.subarray.ystart = 1
        saturation_model.meta.subarray.ysize = 1032

        return data_model, saturation_model
Exemple #6
0
    def make_files(self):

        #loop over detector
        for det in self.detectors:

            satfile = [s for s in self.satfiles if det in s][0]
            sat_model = SaturationModel(satfile)
            sat = sat_model.data

            #pixels with saturation level of 0.
            #set sat level to 65535
            bad = sat == 0
            sat[bad] = 65535

            linfile = [s for s in self.linfiles if det in s][0]
            lin_model = LinearityModel(linfile)
            lin = lin_model.coeffs

            #pixels with bad linearity coeffs
            #set so no correction is applied
            nans = np.isnan(lin[1, :, :])
            tmp = lin[1, :, :]
            tmp[nans] = 1.
            lin[1, :, :] = tmp
            for i in range(2, 7):
                tmp = lin[i, :, :]
                nans = np.isnan(tmp)
                tmp[nans] = 0.
                lin[i, :, :] = tmp

            #superbias file
            sbfile = [s for s in self.sbfiles if det in s][0]
            sb_model = SuperBiasModel(sbfile)
            superbias = sb_model.data

            #linearize the saturation values
            sat_lin = self.linearize(sat - superbias, lin)

            #loop over readout patterns
            for readpat in self.readpatts:

                nframe, nskip = self.readpatts[readpat]

                #optional output plot
                if self.plot:
                    xx = 400
                    yy = 400
                    fsize = 12
                    f = plt.figure()
                    a = f.add_subplot(111)
                    a2 = a.twiny()
                    f.subplots_adjust(bottom=0.2)
                    xs = np.arange(self.maxgroups * (nframe + nskip))
                    a.plot(xs,
                           np.repeat(sat[yy, xx], len(xs)),
                           linestyle=':',
                           color='blue',
                           linewidth=2,
                           label='Original Saturation')
                    a.plot(xs,
                           np.repeat(sat_lin[yy, xx] + superbias[yy, xx],
                                     len(xs)),
                           linestyle=':',
                           color='red',
                           linewidth=2,
                           label='Linearized Saturation')
                    a.plot(xs,
                           np.repeat(superbias[yy, xx], len(xs)),
                           linestyle=':',
                           color='black',
                           linewidth=2,
                           label='Superbias Level')

                #loop over groups
                satramp = np.zeros((self.maxgroups, 2048, 2048))
                linsatramp = np.zeros((self.maxgroups, 2048, 2048))
                xfmeans = []
                for i in range(self.maxgroups):

                    #exposure time to the final frame in the group
                    exptime = self.frametime * (nframe + nskip) * (i + 1)
                    satslope = sat_lin / exptime

                    #now calculate signals for each frame within the
                    #group, by reducing exposure time by one frametime
                    #for each
                    fsigs = np.zeros((nframe, 2048, 2048))
                    fsigs[0, :, :] = sat_lin
                    for frame in range(1, nframe):
                        fsigs[frame, :, :] = satslope * (
                            exptime - (self.frametime * frame))
                        linsatramp[i, :, :] = np.mean(fsigs,
                                                      axis=0) + superbias

                    #non-linearize fsigs
                    fsigs_nl = self.unlinearize(fsigs, lin, sat - superbias)

                    #add superbias back in
                    fsigs_nl += superbias

                    satramp[i, :, :] = np.mean(fsigs_nl, axis=0)

                    #print("Group: {}".format(i))
                    #print("Exptime: {}".format(exptime))
                    #print("Sat: {}, Lin Sat: {}".format(sat[yy,xx],sat_lin[yy,xx]))
                    #print("Satslope: {}".format(satslope[yy,xx]))
                    #print("Frame exps: {}".format(exptime-(self.frametime*np.arange(1,nframe))))
                    #print("signals: {}".format(fsigs[:,yy,xx]))
                    #print("mean signal: {}".format(satramp[i,yy,xx]))
                    #if i == 1:
                    #    stop

                    if self.plot:
                        xf = np.array([-1])
                        xf = np.append(
                            xf,
                            np.arange((i + 1) * (nframe + nskip) - nframe,
                                      (i + 1) * (nframe + nskip)))
                        yf = np.array([superbias[yy, xx]])
                        yf = np.append(
                            yf, fsigs[:, yy, xx][::-1] + superbias[yy, xx])
                        yfnl = np.array([superbias[yy, xx]])
                        yfnl = np.append(yfnl, fsigs_nl[:, yy, xx][::-1])
                        if i == 9:
                            a.plot(xf,
                                   yf,
                                   mfc='red',
                                   mec='red',
                                   color='black',
                                   marker='o',
                                   linestyle='-',
                                   label='Linearized Frames',
                                   alpha=0.5)
                            #a.plot(np.mean(xf[1:]),linsatramp[i,yy,xx],color='red',marker='8',mfc='none',mec='red',markersize=10,label='Linearized Frames Mean')
                            a.plot(xf,
                                   yfnl,
                                   mfc='black',
                                   mec='black',
                                   color='black',
                                   marker='o',
                                   linestyle='-',
                                   label='Non-Linearized Frames',
                                   alpha=0.5)
                            #a.plot(np.mean(xf[1:]),linsatramp[i,yy,xx],color='red',marker='8',mfc='none',mec='red',markersize=10,label='Linearized Frames Mean')
                        else:
                            a.plot(xf,
                                   yf,
                                   mfc='red',
                                   mec='red',
                                   color='black',
                                   marker='o',
                                   linestyle='-',
                                   alpha=0.5)
                            #a.plot(np.mean(xf[1:]),linsatramp[i,yy,xx],color='red',mfc='none',mec='red',marker='8',markersize=10)
                            a.plot(xf,
                                   yfnl,
                                   mfc='black',
                                   mec='black',
                                   color='black',
                                   marker='o',
                                   linestyle='-',
                                   alpha=0.5)
                        xfmeans.append(np.mean(xf[1:]))

                #optional plot
                if self.plot:
                    new_tick_locations = np.array(xfmeans)
                    a.plot(xfmeans,
                           satramp[:, yy, xx],
                           color='blue',
                           marker='8',
                           markersize=10,
                           label='Non-Linear Frames Mean')

                    a.legend(loc='lower right', numpoints=1, fontsize=fsize)
                    a.set_xlabel('Frame Number')
                    a.set_ylabel('Signal (DN)')
                    a.set_title('NRC{}, Readpattern: {}, Pixel ({},{})'.format(
                        det, readpat, xx, yy))
                    a.set_xlim(-1, np.max(xf) + 1)

                    a.set_ylim(0, 60000)

                    # Move twinned axis ticks and label from top to bottom
                    a2.xaxis.set_ticks_position("bottom")
                    a2.xaxis.set_label_position("bottom")

                    # Offset the twin axis below the host
                    a2.spines["bottom"].set_position(("axes", -0.15))

                    # Turn on the frame for the twin axis, but then hide all
                    # but the bottom spine
                    a2.set_frame_on(True)
                    a2.patch.set_visible(False)
                    for sp in a2.spines.itervalues():
                        sp.set_visible(False)
                    a2.spines["bottom"].set_visible(True)

                    a2.set_xticks(new_tick_locations)
                    a2.set_xticklabels(np.arange(len(new_tick_locations)))
                    a2.set_xlabel("Group Number")

                    f.savefig(
                        'GroupSatPlot_forTR_{}_{}_C_filledcircs.png'.format(
                            det, readpat))

                #save output file
                self.savefile(satramp, det, readpat)