示例#1
0
    def slitmask(tslits_dict, pad=None, binning=None):
        """
         Generic routine ton construct a slitmask image from a tslits_dict. Children of this class can
         overload this function to implement instrument specific slitmask behavior, for example setting
         where the orders on an echelle spectrograph end

         Parameters
         -----------
         tslits_dict: dict
            Trace slits dictionary with slit boundary information

         Optional Parameters
         pad: int or float
            Padding of the slit boundaries
         binning: tuple
            Spectrograph binning in spectral and spatial directions

         Returns
         -------
         slitmask: ndarray int
            Image with -1 where there are no slits/orders, and an integer where there are slits/order with the integer
            indicating the slit number going from 0 to nslit-1 from left to right.

         """

        # These lines are always the same
        pad = tslits_dict['pad'] if pad is None else pad
        slitmask = pixels.slit_pixels(tslits_dict['lcen'],
                                      tslits_dict['rcen'],
                                      tslits_dict['nspat'],
                                      pad=pad)

        return slitmask
示例#2
0
    def slitmask(self, tslits_dict, pad=None):
        """
         Generic routine ton construct a slitmask image from a tslits_dict. Children of this class can
         overload this function to implement instrument specific slitmask behavior, for example setting
         where the orders on an echelle spectrograph end

         Parameters
         -----------
         tslits_dict: dict
            Trace slits dictionary with slit boundary information

         Optional Parameters
         pad: int or float
            Padding of the slit boundaries
         binning: tuple
            Spectrograph binning in spectral and spatial directions

         Returns
         -------
         slitmask: ndarray int
            Image with -1 where there are no slits/orders, and an integer where there are slits/order with the integer
            indicating the slit number going from 0 to nslit-1 from left to right.

         """

        # These lines are always the same
        pad = tslits_dict['pad'] if pad is None else pad
        slitmask = pixels.slit_pixels(tslits_dict['lcen'],
                                      tslits_dict['rcen'],
                                      tslits_dict['nspat'],
                                      pad=pad)

        spec_img = np.outer(
            np.arange(tslits_dict['nspec'], dtype=int),
            np.ones(tslits_dict['nspat'],
                    dtype=int))  # spectral position everywhere along image

        nslits = tslits_dict['lcen'].shape[1]
        if nslits != self.norders:
            msgs.error(
                'There is a problem with your slit bounadries. You have nslits={:d} orders, whereas NIR has norders={:d}'
                .format(nslits, self.norders))
        # These are the order boundaries determined by eye by JFH. 2025 is used as the maximum as the upper bit is not illuminated
        order_max = [
            1467, 1502, 1540, 1580, 1620, 1665, 1720, 1770, 1825, 1895, 1966,
            2000, 2000, 2000, 2000, 2000
        ]
        order_min = [
            420, 390, 370, 345, 315, 285, 248, 210, 165, 115, 63, 10, 0, 0, 0,
            0
        ]
        for islit in range(nslits):
            orderbad = (slitmask == islit) & ((spec_img < order_min[islit]) |
                                              (spec_img > order_max[islit]))
            slitmask[orderbad] = -1
        return slitmask
示例#3
0
    def slitmask(tslits_dict, pad=None, binning=None):
        """
         Generic routine ton construct a slitmask image from a tslits_dict. Children of this class can
         overload this function to implement instrument specific slitmask behavior, for example setting
         where the orders on an echelle spectrograph end

         Parameters
         -----------
         tslits_dict: dict
            Trace slits dictionary with slit boundary information

         Optional Parameters
         pad: int or float
            Padding of the slit boundaries
         binning: tuple
            Spectrograph binning in spectral and spatial directions

         Returns
         -------
         slitmask: ndarray int
            Image with -1 where there are no slits/orders, and an integer where there are slits/order with the integer
            indicating the slit number going from 0 to nslit-1 from left to right.

         """

        # These lines are always the same
        pad = tslits_dict['pad'] if pad is None else pad
        slitmask = pixels.slit_pixels(tslits_dict['lcen'],
                                      tslits_dict['rcen'],
                                      tslits_dict['nspat'],
                                      pad=pad)

        spec_img = np.outer(
            np.arange(tslits_dict['nspec'], dtype=int),
            np.ones(tslits_dict['nspat'],
                    dtype=int))  # spectral position everywhere along image

        nslits = tslits_dict['lcen'].shape[1]
        # These are the order boundaries determined by eye by JFH. 2025 is used as the maximum as the upper bit is not illuminated
        order_max = [
            1476, 1513, 1551, 1592, 1687, 1741, 1801, 1864, 1935, 2007, 2025,
            2025, 2025, 2025, 2025, 2025
        ]
        order_min = [
            418, 385, 362, 334, 303, 268, 230, 187, 140, 85, 26, 0, 0, 0, 0, 0
        ]
        # TODO add binning adjustments to these
        for islit in range(nslits):
            orderbad = (slitmask == islit) & ((spec_img < order_min[islit]) |
                                              (spec_img > order_max[islit]))
            slitmask[orderbad] = -1
        return slitmask
示例#4
0
    def slitmask(self, tslits_dict, pad=None):
        """
         Generic routine ton construct a slitmask image from a tslits_dict. Children of this class can
         overload this function to implement instrument specific slitmask behavior, for example setting
         where the orders on an echelle spectrograph end

         Parameters
         -----------
         tslits_dict: dict
            Trace slits dictionary with slit boundary information

         Optional Parameters
         pad: int or float
            Padding of the slit boundaries
         binning: tuple
            Spectrograph binning in spectral and spatial directions

         Returns
         -------
         slitmask: ndarray int
            Image with -1 where there are no slits/orders, and an integer where there are slits/order with the integer
            indicating the slit number going from 0 to nslit-1 from left to right.

         """

        # These lines are always the same
        pad = tslits_dict['pad'] if pad is None else pad
        nslits = tslits_dict['lcen'].shape[1]
        if nslits != self.norders:
            msgs.error('Not all the orders were identified!')

        slitmask = pixels.slit_pixels(tslits_dict['lcen'],
                                      tslits_dict['rcen'],
                                      tslits_dict['nspat'],
                                      pad=pad)
        spec_img = np.outer(
            np.arange(tslits_dict['nspec'], dtype=int),
            np.ones(tslits_dict['nspat'],
                    dtype=int))  # spectral position everywhere along image

        binning = tslits_dict['binning']
        binspectral, binspatial = parse.parse_binning(binning)
        # These are the order boundaries determined by eye by JFH.
        order_max = np.asarray([4000] * 14 + [3000]) // binspectral
        order_min = np.asarray([2000, 1000] + [0] * 13) // binspectral
        # TODO add binning adjustments to these
        for iorder in range(self.norders):
            orderbad = (slitmask == iorder) & ((spec_img < order_min[iorder]) |
                                               (spec_img > order_max[iorder]))
            slitmask[orderbad] = -1

        return slitmask
示例#5
0
                                    file_list=pixflat_image_files,
                                    det=det,
                                    par=par['calibrations']['pixelflatframe'],
                                    msbias=msbias)
    flatimg = flatField.build_pixflat()
    # Read in the tilts
    tiltsfile = masterpath + 'MasterTilts_A_' + sdet + '_aa.fits'
    mstilts = fits.getdata(tiltsfile)
    # Read in the tslits_dict
    traceslitsroot = masterpath + 'MasterTrace_A_' + sdet + '_aa'
    Tslits = traceslits.TraceSlits.from_master_files(traceslitsroot)
    tslits_dict = {}
    tslits_dict['lcen'] = Tslits.lcen
    tslits_dict['rcen'] = Tslits.rcen
    tslits_dict['slitpix'] = pixels.slit_pixels(tslits_dict['lcen'],
                                                tslits_dict['rcen'],
                                                flatimg.shape,
                                                Tslits.par['pad'])
elif type == 'ESI':
    flatfile = '/Users/joe/REDUX/esi_redux/Mar_2008/Flats/FlatECH10_1x1_D.fits.gz'
    piximgfile = '/Users/joe/REDUX/esi_redux/Mar_2008/Final/f_esi1044.fits.gz'
    waveimgfile = '/Users/joe/REDUX/esi_redux/Mar_2008/Arcs/ArcECH10_1x1IMG.fits.gz'
    sedg_file = '/Users/joe/REDUX/esi_redux/Mar_2008/Flats/SEdgECH10_1x1.fits.gz'
    flatimg = fits.getdata(flatfile)
    (nspec, nspat) = flatimg.shape
    piximg = fits.getdata(piximgfile, 3)
    mstilts = piximg / nspec
    slit_edges = fits.getdata(sedg_file, 0)
    tslits_dict = {}
    tslits_dict['lcen'] = slit_edges[0, :, :].T
    tslits_dict['rcen'] = slit_edges[1, :, :].T
    tslits_dict['slitpix'] = pixels.slit_pixels(tslits_dict['lcen'],
    #slit_righ = readsav(user + '/Dropbox/hires_fndobj/GNIRS/J021514.76+004223.8/right_edge_J0215.sav',python_dict=False)['right_edge'].T
    #slit_left = readsav(user + '/Dropbox/hires_fndobj/GNIRS/J005424.45+004750.2/left_edge_J0054.sav',python_dict=False)['left_edge'].T
    #slit_righ = readsav(user + '/Dropbox/hires_fndobj/GNIRS/J005424.45+004750.2/right_edge_J0054.sav',python_dict=False)['right_edge'].T
    slit_left = readsav(user + 'Dropbox/hires_fndobj/GNIRS/J002407.02-001237.2/left_edge_J0024.sav',python_dict=False)['left_edge'].T
    slit_righ = readsav(user + 'Dropbox/hires_fndobj/GNIRS/J002407.02-001237.2/right_edge_J0024.sav',python_dict=False)['right_edge'].T
    plate_scale = 0.15
    #Use std. Telluric directory. Extension 4 is the object structure, and you want xpos and ypos. Xpos is the spatial trace that you want
    # to pass in. ypos is just np.arange(nspec)
    hdu_std =fits.open(user + 'Dropbox/hires_fndobj/GNIRS/J002407.02-001237.2/Science/HIP117774_5/tel-N20171006S0228-231.fits')
    std_xpos = hdu_std[4].data['XPOS'].T
    std_trace = np.zeros(np.shape(slit_left))
    for i in range(6):
        std_trace[:,i] = std_xpos[:,2*i]


ordermask = pixels.slit_pixels(slit_left, slit_righ, objminsky.shape[1])

#viewer, ch = ginga.show_image(objminsky)
#ginga.show_slits(viewer,ch, slit_left, slit_righ)

#yvec = np.outer(np.ones(norders), spec_vec)

#tset_left = pydl.xy2traceset(yvec, slit_left.T, ncoeff=ncoeff)
#slit_left_fit = tset_left.yfit.T

#tset_righ = pydl.xy2traceset(yvec, slit_righ.T, ncoeff=ncoeff)
#slit_righ_fit = tset_righ.yfit.T

#ginga.show_slits(viewer,ch, slit_left_fit, slit_righ_fit)

slit_mid = (slit_left + slit_righ)/2.0
    mask = (ivar > 0.0)
    #slit_left = readsav('/Users/feige/Dropbox/hires_fndobj/left_edge.sav', python_dict=False)['left_edge'].T
    #slit_righ = readsav('/Users/feige/Dropbox/hires_fndobj/right_edge.sav', python_dict=False)['right_edge'].T
    #slit_left = readsav('/Users/feige/Dropbox/hires_fndobj/GNIRS/J021514.76+004223.8/left_edge_J0215.sav',python_dict=False)['left_edge'].T
    #slit_righ = readsav('/Users/feige/Dropbox/hires_fndobj/GNIRS/J021514.76+004223.8/right_edge_J0215.sav',python_dict=False)['right_edge'].T
    #slit_left = readsav('/Users/feige/Dropbox/hires_fndobj/GNIRS/J005424.45+004750.2/left_edge_J0054.sav',python_dict=False)['left_edge'].T
    #slit_righ = readsav('/Users/feige/Dropbox/hires_fndobj/GNIRS/J005424.45+004750.2/right_edge_J0054.sav',python_dict=False)['right_edge'].T
    slit_left = readsav(
        '/Users/feige/Dropbox/hires_fndobj/GNIRS/J002407.02-001237.2/left_edge_J0024.sav',
        python_dict=False)['left_edge'].T
    slit_righ = readsav(
        '/Users/feige/Dropbox/hires_fndobj/GNIRS/J002407.02-001237.2/right_edge_J0024.sav',
        python_dict=False)['right_edge'].T
    plate_scale = 0.15

ordermask = pixels.slit_pixels(slit_left, slit_righ, objminsky.shape, 0)

#viewer, ch = ginga.show_image(objminsky)
#ginga.show_slits(viewer,ch, slit_left, slit_righ)

#yvec = np.outer(np.ones(norders), spec_vec)

#tset_left = pydl.xy2traceset(yvec, slit_left.T, ncoeff=ncoeff)
#slit_left_fit = tset_left.yfit.T

#tset_righ = pydl.xy2traceset(yvec, slit_righ.T, ncoeff=ncoeff)
#slit_righ_fit = tset_righ.yfit.T

#ginga.show_slits(viewer,ch, slit_left_fit, slit_righ_fit)

slit_mid = (slit_left + slit_righ) / 2.0
    spectro_name = 'keck_lris_red'
    spectrograph = load_spectrograph(spectrograph=spectro_name)
    par = spectrograph.default_pypeit_par()
    flatField = flatfield.FlatField(spectrograph, file_list=pixflat_image_files,det=det, par=par['calibrations']['pixelflatframe']
                                    , msbias = msbias)
    flatimg = flatField.build_pixflat()
    # Read in the tilts
    tiltsfile = masterpath + 'MasterTilts_A_' + sdet + '_aa.fits'
    mstilts = fits.getdata(tiltsfile)
    # Read in the tslits_dict
    traceslitsroot = masterpath + 'MasterTrace_A_' + sdet + '_aa'
    Tslits = traceslits.TraceSlits.from_master_files(traceslitsroot)
    tslits_dict = {}
    tslits_dict['lcen']=Tslits.lcen
    tslits_dict['rcen']=Tslits.rcen
    tslits_dict['slitpix'] = pixels.slit_pixels(tslits_dict['lcen'],tslits_dict['rcen'], flatimg.shape, Tslits.par['pad'])
elif type == 'ESI':
    flatfile = '/Users/joe/REDUX/esi_redux/Mar_2008/Flats/FlatECH10_1x1_D.fits.gz'
    piximgfile = '/Users/joe/REDUX/esi_redux/Mar_2008/Final/f_esi1044.fits.gz'
    waveimgfile = '/Users/joe/REDUX/esi_redux/Mar_2008/Arcs/ArcECH10_1x1IMG.fits.gz'
    sedg_file = '/Users/joe/REDUX/esi_redux/Mar_2008/Flats/SEdgECH10_1x1.fits.gz'
    flatimg = fits.getdata(flatfile)
    (nspec, nspat) = flatimg.shape
    piximg = fits.getdata(piximgfile, 3)
    mstilts = piximg/nspec
    slit_edges = fits.getdata(sedg_file,0)
    tslits_dict = {}
    tslits_dict['lcen']=slit_edges[0,:,:].T
    tslits_dict['rcen']=slit_edges[1,:,:].T
    tslits_dict['slitpix'] = pixels.slit_pixels(tslits_dict['lcen'],tslits_dict['rcen'], flatimg.shape, 0)