Ejemplo n.º 1
0
    def orbital_correction(self, line_guess=None, yrange=None, **kwargs):
        """
        Calculates the corrections for orbital and slit tilt deviation.
        Calculates the average over a given y-range which ideally should be
        over quiet sun. If this is not given, then the whole cube will be used.
        A line guess may be given, the default is Fe XII. Extra arguments are
        given to the individual spectra's gaussian fit function.
        After this method is called, the corrections must be applied using the
        apply_corrections method. This is so that corrections are only
        calculated once and can be applied to cubes holding different peak
        wavelengths.

        Parameters
        ----------
        line_guess: tuple of three floats
            A guess for a strong line present in the data. The temperature
            drift is independent of wavelength, so this should simply be an
            easily fitted, strong, clear line present in the data.
        yrange: tuple of 2 Quantities
            The y-range to get the average from. This range should avoid active
            regions that may disrupt the fit. The default is to use the entire
            cube.
        """
        # TODO: handle multiple exposures in a single window
        line_guess = (1000, 195.12, 0.1) if not line_guess else line_guess
        if not yrange:
            yrange = (0, self.spectra.shape[1])
        else:
            ymin = cu.convert_point(yrange[0].value, yrange[0].unit,
                                    self.wcs, 1)
            ymax = cu.convert_point(yrange[1].value, yrange[1].unit,
                                    self.wcs, 1)
            yrange = (ymin, ymax)
        # First, get the centers of the line we're correcting for, throughout
        # the whole cube. This is a 2D array. Force a recalculation and clip
        # the fitting window as well.
        x_range = kwargs.get('x_range', (194.9, 195.3))
        kwargs.update({'recalc': True, 'x_range': x_range})
        centers = self._param_array(1, line_guess, **kwargs)
        # Now get a 1-D array of the average intensities along the y-axis.
        # Ideally the range should be chosen so that this is quiet sun.
        averages = [np.average(arr[ymin:ymax]) for arr in centers]
        # Calculate the offset from the centroid of the emission line over the
        # given data range.
        corrections = line_guess[1] - averages
        # Remove noise by appplying a smoothing filter and getting rid of
        # the less important frequencies.
        window_size = int(corrections.shape[0] / 3)
        window_size += 1 if window_size % 2 == 0 else 0
        smooth_averages = savitzky_golay(corrections, window_size, 3)
        return smooth_averages
Ejemplo n.º 2
0
def test_convert_point():
    assert cu.convert_point(10.0, u.Angstrom, wm, 1) == 0
    assert cu.convert_point(10.2, u.Angstrom, wm, 1) == 1
    assert cu.convert_point(9.6, u.Angstrom, wm, 1) == -2
    assert cu.convert_point(10.3, u.Angstrom, wm, 1) == 2
    assert cu.convert_point(0.001, u.mm, wm, 1) == 49950

    assert cu.convert_point(0, u.min, wt, 0) == 0
    assert cu.convert_point(3.1, u.min, wt, 0) == 8
    assert cu.convert_point(-2.4, u.min, wt, 0) == -6
    assert cu.convert_point(0, u.s, wt, 0) == 0
    assert cu.convert_point(24, u.s, wt, 0) == 1
    assert cu.convert_point(-72, u.s, wt, 0) == -3

    assert cu.convert_point(0.2, u.Angstrom, wt, 1) == 1
    assert cu.convert_point(12, None, wt, 0) == 12
    assert cu.convert_point(15.7, None, wm, 3) == 15
    assert cu.convert_point(4, u.pix, wm, 2) == 4
    assert cu.convert_point(7.2, u.pixel, wt, 1) == 7