Пример #1
0
    def light_curve_chain(self, model, time_array, period, sma_over_rs,
                          eccentricity, inclination, periastron,
                          mid_time, ldcoeff, Nfactor):
        """Create model light-curve and lightcurve chain."""
        from taurex.model import TransmissionModel, EmissionModel
        result = []
        sqrt_model = np.sqrt(model)
        # self.info('Creating Lightcurve chain.')
        for n in range(len(sqrt_model)):
            if isinstance(self._forward_model, TransmissionModel):
                self.debug('Using Transit')
                transit_light_curve = plc.transit('claret', ldcoeff[n],
                                                  sqrt_model[n], period,
                                                  sma_over_rs, eccentricity,
                                                  inclination, periastron,
                                                  mid_time, time_array)
                result.append(transit_light_curve * Nfactor[n])
            elif isinstance(self._forward_model, EmissionModel):
                self.debug('Using Eclipse')
                rp_over_rs = (self._forward_model.planet.fullRadius /
                              self._forward_model.star.radius)
                self.debug('rp_over_rs %s', rp_over_rs)
                self.debug('fp_over_fs %s', sqrt_model)

                eclipse_light_curve = plc.eclipse(sqrt_model[n], rp_over_rs,
                                                  period,
                                                  sma_over_rs, eccentricity,
                                                  inclination, periastron,
                                                  mid_time, time_array)
                result.append(eclipse_light_curve * Nfactor[n])

        self.debug('Result %s', result)
        return np.concatenate(result)
def test_eclipse_compat():
    try:
        import pylightcurve as plc
    except ImportError:
        pytest.skip(
            "pylightcurve package can't be found." +
            "Skipping the comparison tests with original pylightcurve functions."
        )
    """Tests the precision and compatibility with original pylightcurve eclipse function"""

    for i in range(10):
        pars_np, pars_torch = sample_pars('eclipse')
        flux_plc_np = plc.eclipse(time_array=time_array, **pars_np)
        flux_plc_torch = pt.functional.eclipse(time_array=time_tensor,
                                               **pars_torch,
                                               n_pars=1)
        tm = TransitModule(time_array,
                           secondary=True,
                           primary=False,
                           epoch_type='primary',
                           **pars_torch)
        try:
            assert 1 - flux_plc_np.min() > (pars_np['fp_over_fs']**2) / 2
        except:
            print('eclipse probably just out of time array...')
            continue
        passed = True
        try:
            assert np.allclose(flux_plc_np, tm(), atol=1e-6, rtol=1e-2)
        except AssertionError:
            mae = np.abs(flux_plc_np - tm().numpy()).max()
            raise RuntimeError(f'Eclipse precision unacceptable (MaxAE={mae})')
        try:
            assert np.allclose(flux_plc_torch,
                               flux_plc_np,
                               atol=1e-6,
                               rtol=1e-2)
        except AssertionError:
            mae = np.abs(flux_plc_np - flux_plc_torch.numpy()).max()
            import matplotlib.pylab as plt
            plt.plot(time_array, flux_plc_np)
            plt.plot(time_array, flux_plc_torch[0])
            plt.show()
            raise RuntimeError(f'Eclipse precision unacceptable (MaxAE={mae})')
    if not passed:
        raise ValueError('first step never passed')
Пример #3
0
    def generate_lightcurves(self, time_array, depth=False):
        """ Generates lightcurves samples a the time array using pylightcurve.
         orbital parameters are pulled from the planet object given in
         intialisation

        :param time_array: list of times (JD) to sample at
        :type time_array: numpy.ndarray
        :param depth: a signle depth or array of depths to generate for
        :type depth: float or numpy.ndarray

        :return: models, a 2d array containing a lightcurve per depth, sampled
         at timearray
        :rtype: numpy.ndarray
        """

        # TODO (ryan) quick check if out of transit, in that case ones!

        # TODO (ryan) should this be in generate exposure?

        planet = self.planet
        star = self.planet.star

        P = float(planet.P.rescale(pq.day))
        a = float((planet.a / star.R).simplified)
        rp = float((planet.R / star.R).simplified)
        i = float(planet.i.rescale(pq.deg))
        e = planet.e
        W = float(planet.periastron)
        transittime = float(planet.transittime)

        if np.isnan(W):
            W = 0

        time_array = time_array.to(u.day).value
        # model for each resolution element.

        if depth:
            planet_spectrum = np.array(
                [depth])  # an array as we want to perform ndim later.
        else:
            planet_spectrum = self.planet_spectrum

        models = np.zeros((len(time_array), len(planet_spectrum)))

        planet_spectrum = np.sqrt(
            planet_spectrum)  # pylc wants Rp/Rs not transit depth

        time_array = tools.jd_to_hjd(time_array,
                                     planet)  # pylc wants hjd not jd

        logger.debug(
            "Generating lightcurves with P={}, a={}, i={}, e={}, W={}, T14={},"
            " mean_depth={}".format(P, a, i, e, W, transittime,
                                    np.mean(planet_spectrum)))

        for j, spec_elem in enumerate(planet_spectrum):
            models[:, j] = pylc.transit('claret', self.ldcoeffs, spec_elem, P, a, e, i,
                                        W, transittime, time_array) - \
                           (
                               1. - pylc.eclipse(spec_elem ** 2, rp, P, a, e,
                                                 i, W,
                                                 transittime, time_array))

        return models