コード例 #1
0
ファイル: psf.py プロジェクト: michaelJwilson/specter
    def __init__(self, filename):
        """
        Load PSF parameters from a file

        Loads x, y, wavelength information for spectral traces and fills:
            self.npix_x   #- number of columns in the target image
            self.npix_y   #- number of rows in the target image
            self.nspec    #- number of spectra (fibers)
            self.nwave    #- number of wavelength samples per spectrum

        Subclasses of this class define the xypix(ispec, wavelength) method
        to access the projection of this PSF into pixels.
        """

        #- Load basic dimensions
        hdr = fits.getheader(filename)
        self.npix_x = hdr['NPIX_X']
        self.npix_y = hdr['NPIX_Y']
        self.nspec = hdr['NSPEC']

        #- PSF model error
        if 'PSFERR' in hdr:
            self.psferr = hdr['PSFERR']
        else:
            self.psferr = 0.01

        #- Load x, y legendre coefficient tracesets
        with fits.open(filename) as fx:
            xc = fx['XCOEFF'].data
            hdr = fx['XCOEFF'].header
            self._x = TraceSet(xc, domain=(hdr['WAVEMIN'], hdr['WAVEMAX']))
            yc = fx['YCOEFF'].data
            hdr = fx['YCOEFF'].header
            self._y = TraceSet(yc, domain=(hdr['WAVEMIN'], hdr['WAVEMAX']))

        #- Create inverse y -> wavelength mapping
        self._w = self._y.invert()

        #- Cache min/max wavelength per fiber at pixel edges
        self._wmin_spec = self.wavelength(None, -0.5)
        self._wmax_spec = self.wavelength(None, self.npix_y - 0.5)
        self._wmin = np.min(self._wmin_spec)
        self._wmin_all = np.max(self._wmin_spec)
        self._wmax = np.max(self._wmax_spec)
        self._wmax_all = np.min(self._wmax_spec)

        #- Filled only if needed
        self._xsigma = None
        self._ysigma = None
コード例 #2
0
    def __init__(self, filename):
        """
        Initialize GaussHermitePSF from input file
        """
        #- Check that this file is a current generation Gauss Hermite PSF
        fx = fits.open(filename, memmap=False)
        self._polyparams = hdr = fx[1].header
        if 'PSFTYPE' not in hdr:
            raise ValueError('Missing PSFTYPE keyword')

        if hdr['PSFTYPE'] != 'GAUSS-HERMITE2':
            raise ValueError('PSFTYPE {} is not GAUSS-HERMITE'.format(hdr['PSFTYPE']))

        if 'PSFVER' not in hdr:
            raise ValueError("PSFVER missing; this version not supported")

        if hdr['PSFVER'] < '1':
            raise ValueError("Only GAUSS-HERMITE versions 1.0 and greater are supported")

        #- Calculate number of spectra from FIBERMIN and FIBERMAX (inclusive)
        self.nspec = hdr['FIBERMAX'] - hdr['FIBERMIN'] + 1

        #- Other necessary keywords
        self.npix_x = hdr['NPIX_X']
        self.npix_y = hdr['NPIX_Y']

        #- PSF model error
        if 'PSFERR' in hdr:
            self.psferr = hdr['PSFERR']
        else:
            self.psferr = 0.01

        #- Load the parameters into self.coeff dictionary keyed by PARAM
        #- with values as TraceSets for evaluating the Legendre coefficients
        data = fx[1].data
        self.coeff = dict()
        for p in data:
            domain = (p['WAVEMIN'], p['WAVEMAX'])
            for p in data:
                name = p['PARAM'].strip()
                self.coeff[name] = TraceSet(p['COEFF'], domain=domain)

        #- Pull out x and y as special tracesets
        self._x = self.coeff['X']
        self._y = self.coeff['Y']

        #- Create inverse y -> wavelength mapping
        self._w = self._y.invert()

        #- Cache min/max wavelength per fiber at pixel edges
        self._wmin_spec = self.wavelength(None, -0.5)
        self._wmax_spec = self.wavelength(None, self.npix_y-0.5)
        self._wmin = np.min(self._wmin_spec)
        self._wmin_all = np.max(self._wmin_spec)
        self._wmax = np.max(self._wmax_spec)
        self._wmax_all = np.min(self._wmax_spec)

        #- Filled only if needed
        self._xsigma = None
        self._ysigma = None

        #- Cache hermitenorm polynomials so we don't have to create them
        #- every time xypix is called
        self._hermitenorm = list()
        maxdeg = max(hdr['GHDEGX'], hdr['GHDEGY'], hdr['GHDEGX2'], hdr['GHDEGY2'])
        for i in range(maxdeg+1):
            self._hermitenorm.append( sp.hermitenorm(i) )

        fx.close()