Esempio n. 1
0
    def _sample_pressure(self, samples, N=100, percentiles=False):
        """
        Draw random samples of the gas pressure in [Pa] from the sampled
        posterior distributions.

        Args:
            samples (ndarray): Samples of the posterior distributions from
                ``fit_vphi`` including the ``mstar``, ``gamma`` and ``mdisk``
                values. Should be of shape ``[nsamples, ndim]``.
            N (Optional[int]): Number of random samples to draw.
            percentiles (Optional[bool]): If ``True``, take the 16th, 50th and
                84th percentiles of the ``n_mol`` samples to estimate the
                uncertainty.
            perturbations_only (Optional[bool]): If ``True``, only plot the
                perturbations rather than the full radial profile.
        Returns:
            P (ndarray): Array of the ``P`` samples. If ``percentiles=True``
                this will be a ``[3, rvals.size]`` shaped array with
                ``[y, -dy, +dy]`` values based on the 16th, 50th and 84th
                percentiles of the ``N`` random samples. Otherwise will be a
                ``[N, rvals.size]`` array of ``P`` profiles.
        """
        P = self._sample_n_mol(samples=samples, N=N) * sc.k * self.T_gas * 1e6
        if percentiles:
            P = np.percentiles(P, [16, 50, 84], axis=0)
            P = np.array([P[1], P[1] - P[0], P[2] - P[1]])
        return P
Esempio n. 2
0
def weightsFromPrecentiles(intensities, percentiles=[25, 50, 75, 100]):
    perc = numpy.percentiles(intensities, percentiles)
    weights = numpy.zeros(intensities.shape)
    for p in perc:
        ii = intensities > p
        weights[ii] = weights[ii] + 1

    return weights
Esempio n. 3
0
def weightsFromPrecentiles(intensities, percentiles = [25,50,75,100]):
    perc = numpy.percentiles(intensities, percentiles);
    weights = numpy.zeros(intensities.shape);
    for p in perc:
        ii = intensities > p;
        weights[ii] = weights[ii] + 1;
    
    return weights;
Esempio n. 4
0
    def run(self, ccdExposure, bias=None, dark=None, flat=None, defects=None, fringes=None, bfKernel=None,
            linearizer=None):
        """!Perform instrument signature removal on an exposure

        Steps include:
        - Detect saturation, apply overscan correction, bias, dark and flat
        - Perform CCD assembly
        - Interpolate over defects, saturated pixels and all NaNs

        \param[in] ccdExposure  -- lsst.afw.image.exposure of detector data
        \param[in] bias -- exposure of bias frame
        \param[in] dark -- exposure of dark frame
        \param[in] flat -- exposure of flatfield
        \param[in] defects -- list of detects
        \param[in] fringes -- a pipe_base.Struct with field fringes containing
                              exposure of fringe frame or list of fringe exposure
        \param[in] bfKernel -- kernel for brighter-fatter correction
        \param[in] linearizer -- object for applying linearization

        \return a pipe_base.Struct with field:
         - exposure
        """

        # Validate Input
        if self.config.doBias and bias is None:
            raise RuntimeError("Must supply a bias exposure if config.doBias True")
        if self.config.doDark and dark is None:
            raise RuntimeError("Must supply a dark exposure if config.doDark True")
        if self.config.doFlat and flat is None:
            raise RuntimeError("Must supply a flat exposure if config.doFlat True")
        if self.config.doBrighterFatter and bfKernel is None:
            raise RuntimeError("Must supply a kernel if config.doBrighterFatter True")
        if fringes is None:
            fringes = pipe_base.Struct(fringes=None)
        if self.config.doFringe and not isinstance(fringes, pipe_base.Struct):
            raise RuntimeError("Must supply fringe exposure as a pipe_base.Struct")

        defects = [] if defects is None else defects

        ccd = ccdExposure.getDetector()

        if self.config.doBias:
            self.biasCorrection(ccdExposure, bias)

        if self.config.doBrighterFatter:
            self.brighterFatterCorrection(ccdExposure, bfKernel,
                                          self.config.brighterFatterMaxIter,
                                          self.config.brighterFatterThreshold,
                                          self.config.brighterFatterApplyGain,
                                          )

        if self.config.doDark:
            self.darkCorrection(ccdExposure, dark)

        for amp in ccd:
            # if ccdExposure is one amp, check for coverage to prevent performing ops multiple times
            if ccdExposure.getBBox().contains(amp.getBBox()):
                ampExposure = ccdExposure.Factory(ccdExposure, amp.getBBox())
                self.updateVariance(ampExposure, amp)

        # Don't trust the variance not to be negative (over-subtraction of dark?)
        # Where it's negative, set it to a robust measure of the variance on the image.
        variance = ccdExposure.getMaskedImage().getVariance().getArray()
        quartiles = numpy.percentiles(ccdExposure.getMaskedImage().getImage().getArray(), [25.0, 75.0])
        stdev = 0.74*(quartiles[1] - quartiles[0])
        variance[:] = numpy.where(variance > 0, variance, stdev**2)

        if self.config.doFringe and not self.config.fringeAfterFlat:
            self.fringe.run(ccdExposure, **fringes.getDict())

        if self.config.doFlat:
            self.flatCorrection(ccdExposure, flat)

        self.maskAndInterpDefect(ccdExposure, defects)

        self.saturationInterpolation(ccdExposure)

        self.maskAndInterpNan(ccdExposure)

        if self.config.doFringe and self.config.fringeAfterFlat:
            self.fringe.run(ccdExposure, **fringes.getDict())

        ccdExposure.getCalib().setFluxMag0(self.config.fluxMag0T1 * ccdExposure.getCalib().getExptime())

        return pipe_base.Struct(
            exposure=ccdExposure,
        )
# Variance pop vs sample variance

# sample variance is different because you divide by sample -1

# probability distribution function = probability of data falling within a given value
#pribabilty desnity function for discrete data

# pdf can be normal, uniform (ie uniform even chance) of exponential

#percentiles divide data according to % at what is x% of the values are less than that value. ie income
# distribution the 99%

import numpy as np
vals = np.random.normal(0, 0.5, 10000)
np.percentiles(vals, 50)

# Covariance

# see https://www.youtube.com/watch?v=0nZT9fqr2MU
# see https://www.youtube.com/watch?v=9Y0Alg8huJk - this is the best video

# covariance = sum ((x -mean) * (y - mean)) /n -1

# correlation is dividing the covariance by the standard deviation of both variables - should
# be range -1 (negative correlation) 0 (no correlation) and 1 positive correlation

# a simpler equation uses dot product


def de_mean(x):  #work out deviation from mean
Esempio n. 6
0
 def ppf(self, q):
     return np.percentiles(self.dataset, np.asarray(q)/100., axis=0)