Example #1
0
    def get_corrections(self, seeing_wlen=5400.*u.Angstrom):

        # Precompute wlen ratio for wavelength dependent seeing adjustment
        wlen_ratio = (self.wlen_grid / seeing_wlen).si

        # Initialize acceptance ratio grid
        corrections = np.empty(
            (self.spec_file.num_exposures, self.num_offset_targets, self.wlen_grid_steps, self.steps_per_exposure),
            dtype=float)

        guided_centroids = []

        # Loop over exposures
        for exp_index in range(self.spec_file.num_exposures):

            # Estimate the actual offset target paths during the exposure
            guided_x, guided_y = self.get_exp_centroids(exp_index)
            guided_centroids.append((guided_x, guided_y))

            # Calculate centroid offsets for each offset target, relative to its nominal fiber center.
            offset = np.sqrt(
                (guided_x - self.offset_x0[:, np.newaxis, np.newaxis])**2 +
                (guided_y - self.offset_y0[:, np.newaxis, np.newaxis])**2)
            
            # Calculate centroid offsets for each offset target, relative to where its fiber center would
            # be if it were designed for the same wavelength as the standard stars.
            offset_std = np.sqrt(
                (guided_x - self.offset_x0_std[:, np.newaxis, np.newaxis])**2 +
                (guided_y - self.offset_y0_std[:, np.newaxis, np.newaxis])**2)

            seeing = self.seeing[exp_index]
            # psf = sdss_25m.get_atmospheric_psf(seeing_wlen, seeing, gauss=False)
            # acceptance_model = sdss_25m.calculate_fiber_acceptance(psf)

            seeing_wlen_adjusted = seeing*wlen_ratio**(-0.2)
            # acceptance_model_grid = map(tpcorr.acceptance_model.AcceptanceModel, seeing_wlen_adjusted)
            max_offset = 1.1/2.0*max(np.max((offset / self.pointing.platescale).to(u.arcsec)).value,
                    np.max((offset_std / self.pointing.platescale).to(u.arcsec)).value)

            for wlen_index in range(self.wlen_grid_steps):
                # Build acceptance model for this wavelength
                acceptance_model = tpcorr.acceptance_model.AcceptanceModel(seeing_wlen_adjusted[wlen_index], max_offset=max_offset)

                # Calculate the acceptance fractions for both sets of centroid offsets.
                acceptance = acceptance_model((offset[:,wlen_index,:] / self.pointing.platescale).to(u.arcsec))
                acceptance_std = acceptance_model((offset_std[:,wlen_index,:] / self.pointing.platescale).to(u.arcsec))
                
                # Calculate the acceptance fraction ratios, tabulated for each offset target, wavelength and time.
                # The ratio calculated this way gives the correction of eqn (13).
                corrections[exp_index,:,wlen_index,:] = acceptance_std / acceptance

        # Average the correction over each exposure time slice.
        avg_corrections = np.mean(np.mean(corrections, axis=-1), axis=0)

        return corrections, avg_corrections, guided_centroids
Example #2
0
    def get_mean_correction(self, extrap_wlen=False):

        corrections = np.empty((self.num_offset_targets, self.wlen_grid_steps, 1))

        # Estimate the actual offset target paths during the exposure
        # (offset_x0, offset_y0), (offset_x0_std, offset_y0_std), (guided_x, guided_y) = self.get_mean_exp_centroids()
        guided_x, guided_y = self.get_mean_exp_centroids(extrap_wlen=extrap_wlen)

        # Calculate centroid offsets for each offset target, relative to its nominal fiber center.
        offset = np.sqrt(
            (guided_x - self.offset_x0[:, np.newaxis, np.newaxis])**2 +
            (guided_y - self.offset_y0[:, np.newaxis, np.newaxis])**2)

        # Calculate centroid offsets for each offset target, relative to where its fiber center would
        # be if it were designed for the same wavelength as the standard stars.
        offset_std = np.sqrt(
            (guided_x - self.offset_x0_std[:, np.newaxis, np.newaxis])**2 +
            (guided_y - self.offset_y0_std[:, np.newaxis, np.newaxis])**2)

        seeing = np.mean(self.seeing)

        max_offset = 1.1/2.0*max(np.max((offset / self.pointing.platescale).to(u.arcsec)).value,
                                 np.max((offset_std / self.pointing.platescale).to(u.arcsec)).value)

        acceptance_model = tpcorr.acceptance_model.AcceptanceModel(seeing, max_offset=max_offset)

        # Calculate the acceptance fractions for both sets of centroid offsets.
        acceptance = acceptance_model((offset / self.pointing.platescale).to(u.arcsec))
        acceptance_std = acceptance_model((offset_std / self.pointing.platescale).to(u.arcsec))
        
        # Calculate the acceptance fraction ratios, tabulated for each offset target, wavelength and time.
        # The ratio calculated this way gives the correction of eqn (13).
        corrections = acceptance_std / acceptance

        mean_correction = np.mean(corrections, axis=-1)

        return mean_correction, guided_x, guided_y