当前位置: 首页>>代码示例>>Python>>正文


Python astropy.time方法代码示例

本文整理汇总了Python中astropy.time方法的典型用法代码示例。如果您正苦于以下问题:Python astropy.time方法的具体用法?Python astropy.time怎么用?Python astropy.time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在astropy的用法示例。


在下文中一共展示了astropy.time方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import time [as 别名]
def __init__(self, frequency, power, nyquist=None, label=None,
                 targetid=None, default_view='frequency', meta={}):
        # Input validation
        if not isinstance(frequency, u.quantity.Quantity):
            raise ValueError('frequency must be an `astropy.units.Quantity` object.')
        if not isinstance(power, u.quantity.Quantity):
            raise ValueError('power must be an `astropy.units.Quantity` object.')
        # Frequency must have frequency units
        try:
            frequency.to(u.Hz)
        except u.UnitConversionError:
            raise ValueError('Frequency must be in units of 1/time.')
        # Frequency and power must have sensible shapes
        if frequency.shape[0] <= 1:
            raise ValueError('frequency and power must have a length greater than 1.')
        if frequency.shape != power.shape:
            raise ValueError('frequency and power must have the same length.')

        self.frequency = frequency
        self.power = power
        self.nyquist = nyquist
        self.label = label
        self.targetid = targetid
        self.default_view = self._validate_view(default_view)
        self.meta = meta 
开发者ID:KeplerGO,项目名称:lightkurve,代码行数:27,代码来源:periodogram.py

示例2: model

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import time [as 别名]
def model(self, time, frequency=None):
        """Obtain the flux model for a given frequency and time

        Parameters
        ----------
        time : np.ndarray
            Time points to evaluate model.
        frequency : frequency to evaluate model. Default is the frequency at
                    max power.

        Returns
        -------
        result : lightkurve.LightCurve
            Model object with the time and flux model
        """
        if self._LS_object is None:
            raise ValueError('No `astropy` Lomb Scargle object exists.')
        if frequency is None:
            frequency = self.frequency_at_max_power
        f = self._LS_object.model(time, frequency)
        return LightCurve(time, f, label='LS Model', meta={'frequency':frequency},
                            targetid='{} LS Model'.format(self.targetid)).normalize() 
开发者ID:KeplerGO,项目名称:lightkurve,代码行数:24,代码来源:periodogram.py

示例3: red_noise

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import time [as 别名]
def red_noise(time):
    """ Simulate red moise as a sum of 10 low amplitudes/period sinusoidals.

        :param array_like time: the time in JD where you simulate red noise

        :return: a numpy array which represents the red noise

        :rtype: array_like

    """

    red_noise_amplitude = np.random.random_sample(10) * 0.5 / 100
    red_noise_period = np.random.random_sample(10)
    red_noise_phase = np.random.random_sample(10) * 2 * np.pi

    red_noise = 0
    for j in range(10):
        red_noise += np.sin(2 * np.pi * time / red_noise_period[j] + red_noise_phase[j]) * red_noise_amplitude[j]

    return red_noise 
开发者ID:ebachelet,项目名称:pyLIMA,代码行数:22,代码来源:microlsimulator.py

示例4: __init__

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import time [as 别名]
def __init__(self, campaign=0, channel=1, cadenceno=1, data_store=None,
                 shape=KEPLER_CHANNEL_SHAPE, add_background=False, time=None,
                 quality=None, dateobs=None, dateend=None, mjdbeg=None, 
                 mjdend=None, template_tpf_header0=None,
                 template_tpf_header1=None):
        self.campaign = campaign
        self.channel = channel
        self.cadenceno = cadenceno
        self.data_store = data_store
        self.header = fits.Header()
        self.data = np.empty(shape, dtype=np.float32)
        self.data[:] = np.nan
        self.uncert = np.empty(shape, dtype=np.float32)
        self.uncert[:] = np.nan
        self.add_background = add_background
        self.time = time
        self.quality = quality
        self.template_tpf_header0 = template_tpf_header0
        self.template_tpf_header1 = template_tpf_header1
        self.dateobs = dateobs
        self.dateend = dateend
        self.mjdbeg = mjdbeg
        self.mjdend = mjdend 
开发者ID:KeplerGO,项目名称:k2mosaic,代码行数:25,代码来源:mosaic.py

示例5: test_deltat_astropy

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import time [as 别名]
def test_deltat_astropy():
    # Can't do a full range of tests because astropy doesn't have 
    # answers before 1960, after 1999 in this version
    from astropy.time import Time
    from datetime import datetime
    def delta_t_astropy(dt):
        t = Time(dt, scale='utc')
        return -(dt - t.tt.value).total_seconds()
    
#    years = range(1, 3000, 100) + [3000]
    years = range(1960, 1999, 1)
    
    months = range(1, 13)
    for year in years:
        for month in months:
            delta_t_pvlib = spa.calculate_deltat(year, month)
            dt = datetime(year, month, 1)
            delta_t_external = delta_t_astropy(dt)
            assert_allclose(delta_t_pvlib, delta_t_external, atol=.5, rtol=.01)

#suite = unittest.TestSuite()
#suite.addTest(NumpySpaTest("testItIsHot"))
#runner = unittest.TextTestRunner()
#runner.run(suite)
#
#NumpySpaTest.test_calculate_deltat() 
开发者ID:CalebBell,项目名称:fluids,代码行数:28,代码来源:test_spa.py

示例6: compute_stats

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import time [as 别名]
def compute_stats(self, period=None, duration=None, transit_time=None):
        """Computes commonly used vetting statistics for a transit model.

        See astropy.stats.bls docs for further details.

        Parameters
        ----------
        period : float or Quantity
            Period of the transits. Default is `period_at_max_power`
        duration : float or Quantity
            Duration of the transits. Default is `duration_at_max_power`
        transit_time : float or Quantity
            Transit midpoint of the transits. Default is `transit_time_at_max_power`

        Returns
        -------
        stats : dict
            Dictionary of vetting statistics
        """
        if period is None:
            period = self.period_at_max_power
            log.warning('No period specified. Using period at max power')
        if duration is None:
            duration = self.duration_at_max_power
            log.warning('No duration specified. Using duration at max power')
        if transit_time is None:
            transit_time = self.transit_time_at_max_power
            log.warning('No transit time specified. Using transit time at max power')
        if not isinstance(transit_time, Time):
            transit_time = Time(transit_time, format=self.time.format, scale=self.time.scale)

        return self._BLS_object.compute_stats(u.Quantity(period, 'd').value,
                                              u.Quantity(duration, 'd').value,
                                              transit_time) 
开发者ID:KeplerGO,项目名称:lightkurve,代码行数:36,代码来源:periodogram.py

示例7: get_transit_model

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import time [as 别名]
def get_transit_model(self, period=None, duration=None, transit_time=None):
        """Computes the transit model using the BLS, returns a lightkurve.LightCurve

        See astropy.stats.bls docs for further details.

        Parameters
        ----------
        period : float or Quantity
            Period of the transits. Default is `period_at_max_power`
        duration : float or Quantity
            Duration of the transits. Default is `duration_at_max_power`
        transit_time : float or Quantity
            Transit midpoint of the transits. Default is `transit_time_at_max_power`

        Returns
        -------
        model : lightkurve.LightCurve
            Model of transit
        """
        from .lightcurve import LightCurve

        if period is None:
            period = self.period_at_max_power
            log.warning('No period specified. Using period at max power')
        if duration is None:
            duration = self.duration_at_max_power
            log.warning('No duration specified. Using duration at max power')
        if transit_time is None:
            transit_time = self.transit_time_at_max_power
            log.warning('No transit time specified. Using transit time at max power')
        if not isinstance(transit_time, Time):
            transit_time = Time(transit_time, format=self.time.format, scale=self.time.scale)

        model_flux = self._BLS_object.model(self.time, u.Quantity(period, 'd').value,
                                            u.Quantity(duration, 'd').value,
                                            transit_time)
        model = LightCurve(time=self.time, flux=model_flux, label='Transit Model Flux')
        return model 
开发者ID:KeplerGO,项目名称:lightkurve,代码行数:40,代码来源:periodogram.py

示例8: time_simulation

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import time [as 别名]
def time_simulation(time_start, time_end, sampling, bad_weather_percentage):
    """ Simulate observing time during the observing windows, rejecting windows with bad weather.

    :param float time_start: the start of observations in JD
    :param float time_end: the end of observations in JD
    :param float sampling: the number of points observed per hour.
    :param float bad_weather_percentage: the percentage of bad nights

    :return: a numpy array which represents the time of observations

    :rtype: array_like

    """

    total_number_of_days = int(time_end - time_start)
    time_step_observations = sampling / 24.0
    number_of_day_exposure = int(np.floor(
        1.0 / time_step_observations))  # less than expected total, more likely in a telescope :)
    night_begin = time_start

    time_observed = []
    for i in range(total_number_of_days):

        good_weather = np.random.uniform(0, 1)

        if good_weather > bad_weather_percentage:
            random_begin_of_the_night = 0
            night_end = night_begin + 1
            time_observed += np.linspace(night_begin + time_step_observations + random_begin_of_the_night, night_end,
                                         number_of_day_exposure).tolist()

        night_begin += 1

    time_of_observations = np.array(time_observed)

    return time_of_observations 
开发者ID:ebachelet,项目名称:pyLIMA,代码行数:38,代码来源:microlsimulator.py

示例9: add_pixels

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import time [as 别名]
def add_pixels(self, tpf):
        tpfdata = tpf[1].read()
        aperture_shape = tpfdata['FLUX'][0].shape
        # Get the pixel coordinates of the corner of the aperture
        col, row = (self.template_tpf_header1['1CRV5P'], self.template_tpf_header1['2CRV5P'])
        height, width = aperture_shape[0], aperture_shape[1]

        # Fill the data
        mask = tpf[2].read() > 0
        idx = self.cadenceno - tpfdata["CADENCENO"][0]

        # When quality flag 65536 is raised, there is no data and the times are NaN.
        if (tpfdata['QUALITY'][idx] & int(65536) > 0): 
            raise Exception('Error: Cadence {} does not appear to contain data!'.format(self.cadenceno))

        if self.add_background:
            self.data[row:row+height, col:col+width][mask] = \
                tpfdata['FLUX'][idx][mask] \
                + tpfdata['FLUX_BKG'][idx][mask]
            self.uncert[row:row+height, col:col+width][mask] = \
                np.sqrt(
                    (tpfdata['FLUX_ERR'][idx][mask])**2 +
                    (tpfdata['FLUX_BKG_ERR'][idx][mask])**2
                )
        else:
            self.data[row:row+height, col:col+width][mask] = \
                tpfdata['FLUX'][idx][mask]
            self.uncert[row:row+height, col:col+width][mask] = \
                tpfdata['FLUX_ERR'][idx][mask]

        # If this is the first TPF being added, record the time and calculate DATE-OBS/END
        if self.time is None:
            self.time = tpfdata['TIME'][idx]
            self.quality = tpfdata['QUALITY'][idx]
            frametim = np.float(self.template_tpf_header1['FRAMETIM'])
            num_frm = np.float(self.template_tpf_header1['NUM_FRM'])

            # Calculate DATE-OBS from BJD time:
            mjd_start = self.time \
                + np.float(self.template_tpf_header1['BJDREFI']) \
                - frametim/3600./24./2. * num_frm \
                - 2400000.5
            self.mjdbeg = mjd_start
            starttime = Time(mjd_start, format='mjd')
            starttime = str(starttime.datetime)
            self.dateobs = starttime.replace(' ', 'T') + 'Z'

            # Calculate DATE-END:
            mjd_end = self.time \
                + np.float(self.template_tpf_header1['BJDREFI']) \
                + frametim/3600./24./2. * num_frm \
                - 2400000.5
            self.mjdend = mjd_end
            endtime = Time(mjd_end, format='mjd')
            endtime = str(endtime.datetime)
            self.dateend = endtime.replace(' ', 'T') + 'Z' 
开发者ID:KeplerGO,项目名称:k2mosaic,代码行数:58,代码来源:mosaic.py


注:本文中的astropy.time方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。