Exemple #1
0
def validate_unit_consistency(reference_object, input_object):
    if has_units(reference_object):
        input_object = units.Quantity(input_object, unit=reference_object.unit)
    else:
        if has_units(input_object):
            input_object = units.Quantity(input_object, unit=units.one)
            input_object = input_object.value
    return input_object
Exemple #2
0
def validate_unit_consistency(reference_object, input_object):
    if has_units(reference_object):
        input_object = units.Quantity(input_object, unit=reference_object.unit)
    else:
        if has_units(input_object):
            input_object = units.Quantity(input_object, unit=units.one)
            input_object = input_object.value
    return input_object
Exemple #3
0
    def _format_results(self, t_ref, objective, period, results):
        """A private method used to wrap and add units to the periodogram

        Parameters
        ----------
        t_ref : float
            The minimum time in the time series (a reference time).
        objective : str
            The name of the objective used in the optimization.
        period : array-like or `~astropy.units.Quantity`
            The set of trial periods.
        results : tuple
            The output of one of the periodogram implementations.

        """
        (power, depth, depth_err, duration, transit_time, depth_snr,
         log_likelihood) = results
        transit_time += t_ref

        if has_units(self._trel):
            transit_time = units.Quantity(transit_time, unit=self._trel.unit)
            transit_time = self._as_absolute_time_if_needed(
                'transit_time', transit_time)
            duration = units.Quantity(duration, unit=self._trel.unit)

        if has_units(self.y):
            depth = units.Quantity(depth, unit=self.y.unit)
            depth_err = units.Quantity(depth_err, unit=self.y.unit)

            depth_snr = units.Quantity(depth_snr, unit=units.one)

            if self.dy is None:
                if objective == "likelihood":
                    power = units.Quantity(power, unit=self.y.unit**2)
                else:
                    power = units.Quantity(power, unit=units.one)
                log_likelihood = units.Quantity(log_likelihood,
                                                unit=self.y.unit**2)
            else:
                power = units.Quantity(power, unit=units.one)
                log_likelihood = units.Quantity(log_likelihood, unit=units.one)

        return BoxLeastSquaresResults(objective, period, power, depth,
                                      depth_err, duration, transit_time,
                                      depth_snr, log_likelihood)
Exemple #4
0
    def _format_results(self, objective, period, results):
        """A private method used to wrap and add units to the periodogram

        Parameters
        ----------
        objective : string
            The name of the objective used in the optimization.
        period : array-like or `~astropy.units.Quantity`
            The set of trial periods.
        results : tuple
            The output of one of the periodogram implementations.

        """
        (power, depth, depth_err, duration, transit_time, depth_snr,
         log_likelihood) = results

        if has_units(self._trel):
            transit_time = units.Quantity(transit_time, unit=self._trel.unit)
            transit_time = self._as_absolute_time_if_needed('transit_time', transit_time)
            duration = units.Quantity(duration, unit=self._trel.unit)

        if has_units(self.y):
            depth = units.Quantity(depth, unit=self.y.unit)
            depth_err = units.Quantity(depth_err, unit=self.y.unit)

            depth_snr = units.Quantity(depth_snr, unit=units.one)

            if self.dy is None:
                if objective == "likelihood":
                    power = units.Quantity(power, unit=self.y.unit**2)
                else:
                    power = units.Quantity(power, unit=units.one)
                log_likelihood = units.Quantity(log_likelihood,
                                                unit=self.y.unit**2)
            else:
                power = units.Quantity(power, unit=units.one)
                log_likelihood = units.Quantity(log_likelihood, unit=units.one)

        return BoxLeastSquaresResults(
            objective, period, power, depth, depth_err, duration, transit_time,
            depth_snr, log_likelihood)
Exemple #5
0
    def _format_results(self, objective, period, results):
        """A private method used to wrap and add units to the periodogram

        Parameters
        ----------
        objective : string
            The name of the objective used in the optimization.
        period : array-like or Quantity
            The set of trial periods.
        results : tuple
            The output of one of the periodogram implementations.

        """
        (power, depth, depth_err, transit_time, duration, depth_snr,
         log_likelihood) = results

        if has_units(self.t):
            transit_time = units.Quantity(transit_time, unit=self.t.unit)
            duration = units.Quantity(duration, unit=self.t.unit)

        if has_units(self.y):
            depth = units.Quantity(depth, unit=self.y.unit)
            depth_err = units.Quantity(depth_err, unit=self.y.unit)

            depth_snr = units.Quantity(depth_snr, unit=units.one)

            if self.dy is None:
                if objective == "likelihood":
                    power = units.Quantity(power, unit=self.y.unit**2)
                else:
                    power = units.Quantity(power, unit=units.one)
                log_likelihood = units.Quantity(log_likelihood,
                                                unit=self.y.unit**2)
            else:
                power = units.Quantity(power, unit=units.one)
                log_likelihood = units.Quantity(log_likelihood, unit=units.one)

        return BoxLeastSquaresResults(objective, period, power, depth,
                                      depth_err, transit_time, duration,
                                      depth_snr, log_likelihood)
Exemple #6
0
def test_results_units(data, method, with_err, t_unit, y_unit, objective):
    t, y, dy, params = data

    periods = np.linspace(params["period"] - 1.0, params["period"] + 1.0, 3)

    if t_unit is not None:
        t = t * t_unit
    if y_unit is not None:
        y = y * y_unit
        dy = dy * y_unit
    if not with_err:
        dy = None

    model = BoxLeastSquares(t, y, dy)
    results = model.power(periods,
                          params["duration"],
                          method=method,
                          objective=objective)

    if t_unit is None:
        assert not has_units(results.period)
        assert not has_units(results.duration)
        assert not has_units(results.transit_time)
    else:
        assert results.period.unit == t_unit
        assert results.duration.unit == t_unit
        assert results.transit_time.unit == t_unit

    if y_unit is None:
        assert not has_units(results.power)
        assert not has_units(results.depth)
        assert not has_units(results.depth_err)
        assert not has_units(results.depth_snr)
        assert not has_units(results.log_likelihood)
    else:
        assert results.depth.unit == y_unit
        assert results.depth_err.unit == y_unit
        assert results.depth_snr.unit == units.one

        if dy is None:
            assert results.log_likelihood.unit == y_unit * y_unit
            if objective == "snr":
                assert results.power.unit == units.one
            else:
                assert results.power.unit == y_unit * y_unit
        else:
            assert results.log_likelihood.unit == units.one
            assert results.power.unit == units.one
Exemple #7
0
def test_results_units(data, method, with_err, t_unit, y_unit, objective):
    t, y, dy, params = data

    periods = np.linspace(params["period"]-1.0, params["period"]+1.0, 3)

    if t_unit is not None:
        t = t * t_unit
    if y_unit is not None:
        y = y * y_unit
        dy = dy * y_unit
    if not with_err:
        dy = None

    model = BoxLeastSquares(t, y, dy)
    results = model.power(periods, params["duration"], method=method,
                          objective=objective)

    if t_unit is None:
        assert not has_units(results.period)
        assert not has_units(results.duration)
        assert not has_units(results.transit_time)
    else:
        assert results.period.unit == t_unit
        assert results.duration.unit == t_unit
        assert results.transit_time.unit == t_unit

    if y_unit is None:
        assert not has_units(results.power)
        assert not has_units(results.depth)
        assert not has_units(results.depth_err)
        assert not has_units(results.depth_snr)
        assert not has_units(results.log_likelihood)
    else:
        assert results.depth.unit == y_unit
        assert results.depth_err.unit == y_unit
        assert results.depth_snr.unit == u.one

        if dy is None:
            assert results.log_likelihood.unit == y_unit * y_unit
            if objective == "snr":
                assert results.power.unit == u.one
            else:
                assert results.power.unit == y_unit * y_unit
        else:
            assert results.log_likelihood.unit == u.one
            assert results.power.unit == u.one
Exemple #8
0
 def _y_unit(self):
     if has_units(self.y):
         return self.y.unit
     else:
         return 1
Exemple #9
0
 def _t_unit(self):
     if has_units(self._trel):
         return self._trel.unit
     else:
         return 1
Exemple #10
0
 def _t_unit(self):
     if has_units(self.t):
         return self.t.unit
     else:
         return 1
Exemple #11
0
 def _y_unit(self):
     if has_units(self.y):
         return self.y.unit
     else:
         return 1
Exemple #12
0
 def _t_unit(self):
     if has_units(self._trel):
         return self._trel.unit
     else:
         return 1