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


Python time.TimeDelta方法代码示例

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


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

示例1: test_fold_v2

# 需要导入模块: from astropy import time [as 别名]
# 或者: from astropy.time import TimeDelta [as 别名]
def test_fold_v2():
    """The API of LightCurve.fold() changed in Lightkurve v2.x when we adopted
    AstroPy's TimeSeries.fold() method. This test verifies the new API."""
    lc = LightCurve(time=np.linspace(0, 10, 100), flux=np.zeros(100)+1)

    # Can period be passed as a float?
    fld = lc.fold(period=1)
    fld2 = lc.fold(period=1*u.day)
    assert_array_equal(fld.phase, fld2.phase)
    assert isinstance(fld.time, TimeDelta)
    fld.plot_river()
    plt.close()

    # Does phase normalization work?
    fld = lc.fold(period=1, normalize_phase=True)
    assert isinstance(fld.time, u.Quantity)
    fld.plot_river()
    plt.close() 
开发者ID:KeplerGO,项目名称:lightkurve,代码行数:20,代码来源:test_lightcurve.py

示例2: test_quantity_output_errors

# 需要导入模块: from astropy import time [as 别名]
# 或者: from astropy.time import TimeDelta [as 别名]
def test_quantity_output_errors(self):
        dt = TimeDelta(250., format='sec')
        with pytest.raises(u.UnitsError):
            dt.to(u.m)
        with pytest.raises(u.UnitsError):
            dt.to_value(u.m)
        with pytest.raises(u.UnitsError):
            dt.to_value(unit=u.m)
        with pytest.raises(ValueError, match=("not one of the known formats.*"
                                              "failed to parse as a unit")):
            dt.to_value('parrot')
        with pytest.raises(TypeError):
            dt.to_value('sec', unit=u.s)
        with pytest.raises(TypeError):
            # TODO: would be nice to make this work!
            dt.to_value(u.s, subfmt='str') 
开发者ID:holzschu,项目名称:Carnets,代码行数:18,代码来源:test_quantity_interaction.py

示例3: test_valid_quantity_operations1

# 需要导入模块: from astropy import time [as 别名]
# 或者: from astropy.time import TimeDelta [as 别名]
def test_valid_quantity_operations1(self):
        """Check adding/substracting/comparing a time-valued quantity works
        with a TimeDelta.  Addition/subtraction should give TimeDelta"""
        t0 = TimeDelta(106400., format='sec')
        q1 = 10.*u.second
        t1 = t0 + q1
        assert isinstance(t1, TimeDelta)
        assert t1.value == t0.value+q1.to_value(u.second)
        q2 = 1.*u.day
        t2 = t0 - q2
        assert isinstance(t2, TimeDelta)
        assert allclose_sec(t2.value, t0.value-q2.to_value(u.second))
        # now comparisons
        assert t0 > q1
        assert t0 < 1.*u.yr
        # and broadcasting
        q3 = np.arange(12.).reshape(4, 3) * u.hour
        t3 = t0 + q3
        assert isinstance(t3, TimeDelta)
        assert t3.shape == q3.shape
        assert allclose_sec(t3.value, t0.value + q3.to_value(u.second)) 
开发者ID:holzschu,项目名称:Carnets,代码行数:23,代码来源:test_quantity_interaction.py

示例4: test_quantity_conversion_rounding

# 需要导入模块: from astropy import time [as 别名]
# 或者: from astropy.time import TimeDelta [as 别名]
def test_quantity_conversion_rounding(q1, q2):
    """Check that no rounding errors are incurred by unit conversion.

    This occurred before as quantities in seconds were converted to days
    before trying to split them into two-part doubles.  See gh-7622.
    """
    t = Time('2001-01-01T00:00:00.', scale='tai')
    expected = Time('2016-11-05T00:53:20.', scale='tai')
    if q2 is None:
        t0 = t + q1
    else:
        t0 = t + q1 + q2
    assert abs(t0 - expected) < 20 * u.ps
    dt1 = TimeDelta(q1, q2)
    t1 = t + dt1
    assert abs(t1 - expected) < 20 * u.ps
    dt2 = TimeDelta(q1, q2, format='sec')
    t2 = t + dt2
    assert abs(t2 - expected) < 20 * u.ps 
开发者ID:holzschu,项目名称:Carnets,代码行数:21,代码来源:test_quantity_interaction.py

示例5: __init__

# 需要导入模块: from astropy import time [as 别名]
# 或者: from astropy.time import TimeDelta [as 别名]
def __init__(self, t, y, dy=None):

        # If t is a TimeDelta, convert it to a quantity. The units we convert
        # to don't really matter since the user gets a Quantity back at the end
        # so can convert to any units they like.
        if isinstance(t, TimeDelta):
            t = t.to('day')

        # We want to expose self.t as being the times the user passed in, but
        # if the times are absolute, we need to convert them to relative times
        # internally, so we use self._trel and self._tstart for this.

        self.t = t

        if isinstance(self.t, Time):
            self._tstart = self.t[0]
            trel = (self.t - self._tstart).to(u.day)
        else:
            self._tstart = None
            trel = self.t

        self._trel, self.y, self.dy = self._validate_inputs(trel, y, dy) 
开发者ID:holzschu,项目名称:Carnets,代码行数:24,代码来源:core.py

示例6: _as_relative_time

# 需要导入模块: from astropy import time [as 别名]
# 或者: from astropy.time import TimeDelta [as 别名]
def _as_relative_time(self, name, times):
        """
        Convert the provided times (if absolute) to relative times using the
        current _tstart value. If the times provided are relative, they are
        returned without conversion (though we still do some checks).
        """

        if isinstance(times, TimeDelta):
            times = times.to('day')

        if self._tstart is None:
            if isinstance(times, Time):
                raise TypeError('{} was provided as an absolute time but '
                                'the LombScargle class was initialized '
                                'with relative times.'.format(name))
        else:
            if isinstance(times, Time):
                times = (times - self._tstart).to(u.day)
            else:
                raise TypeError('{} was provided as a relative time but '
                                'the LombScargle class was initialized '
                                'with absolute times.'.format(name))

        return times 
开发者ID:holzschu,项目名称:Carnets,代码行数:26,代码来源:core.py

示例7: test_mixin_pandas_masked

# 需要导入模块: from astropy import time [as 别名]
# 或者: from astropy.time import TimeDelta [as 别名]
def test_mixin_pandas_masked(self):
        tm = Time([1, 2, 3], format='cxcsec')
        dt = TimeDelta([1, 2, 3], format='sec')
        tm[1] = np.ma.masked
        dt[1] = np.ma.masked
        t = table.QTable([tm, dt], names=['tm', 'dt'])

        tp = t.to_pandas()
        assert np.all(tp['tm'].isnull() == [False, True, False])
        assert np.all(tp['dt'].isnull() == [False, True, False])

        t2 = table.Table.from_pandas(tp)

        assert np.all(t2['tm'].mask == tm.mask)
        assert np.ma.allclose(t2['tm'].jd, tm.jd, rtol=1e-14, atol=1e-14)

        assert np.all(t2['dt'].mask == dt.mask)
        assert np.ma.allclose(t2['dt'].jd, dt.jd, rtol=1e-14, atol=1e-14) 
开发者ID:holzschu,项目名称:Carnets,代码行数:20,代码来源:test_table.py

示例8: get_time

# 需要导入模块: from astropy import time [as 别名]
# 或者: from astropy.time import TimeDelta [as 别名]
def get_time(self, frame_rate=None):
        """Converts ref_epoch, seconds, and frame_nr to Time object.

        Uses 'ref_epoch', which stores the number of half-years from 2000,
        and 'seconds'.  By default, it also calculates the offset using
        the current frame number.  For non-zero 'frame_nr', this requires the
        frame rate, which is calculated from the sample rate in the header.

        Parameters
        ----------
        frame_rate : `~astropy.units.Quantity`, optional
            For non-zero 'frame_nr', this is required to calculate the
            corresponding offset.

        Returns
        -------
        time : `~astropy.time.Time`
        """
        frame_nr = self['frame_nr']
        if frame_nr == 0:
            offset = 0.
        else:
            if frame_rate is None:
                raise ValueError("this header does not provide a frame "
                                 "rate. Pass it in explicitly.")

            offset = (frame_nr / frame_rate).to_value(u.s)

        return (self.ref_time
                + TimeDelta(self['seconds'], offset, format='sec')) 
开发者ID:mhvk,项目名称:baseband,代码行数:32,代码来源:header.py

示例9: test_readmiriad_write_miriad_check_time_format

# 需要导入模块: from astropy import time [as 别名]
# 或者: from astropy.time import TimeDelta [as 别名]
def test_readmiriad_write_miriad_check_time_format(tmp_path):
    """
    test time_array is converted properly from Miriad format
    """
    from pyuvdata.uvdata import aipy_extracts

    # test read-in
    fname = os.path.join(DATA_PATH, "zen.2457698.40355.xx.HH.uvcA")
    uvd = UVData()
    uvd.read(fname)
    uvd_t = uvd.time_array.min()
    uvd_l = uvd.lst_array.min()
    uv = aipy_extracts.UV(fname)
    uv_t = uv["time"] + uv["inttime"] / (24 * 3600.0) / 2

    lat, lon, alt = uvd.telescope_location_lat_lon_alt
    t1 = Time(uv["time"], format="jd", location=(lon, lat))
    dt = TimeDelta(uv["inttime"] / 2, format="sec")
    t2 = t1 + dt
    lsts = uvutils.get_lst_for_time(np.array([t1.jd, t2.jd]), lat, lon, alt)
    delta_lst = lsts[1] - lsts[0]
    uv_l = uv["lst"] + delta_lst

    # assert starting time array and lst array are shifted by half integration
    assert np.isclose(uvd_t, uv_t)

    # avoid errors if IERS table is too old (if the iers url is down)
    tolerance = 1e-8
    assert np.allclose(uvd_l, uv_l, atol=tolerance)
    # test write-out
    fout = str(tmp_path / "ex_miriad")
    uvd.write_miriad(fout, clobber=True)
    # assert equal to original miriad time
    uv2 = aipy_extracts.UV(fout)
    assert np.isclose(uv["time"], uv2["time"])
    assert np.isclose(uv["lst"], uv2["lst"], atol=tolerance) 
开发者ID:RadioAstronomySoftwareGroup,项目名称:pyuvdata,代码行数:38,代码来源:test_miriad.py

示例10: epoch

# 需要导入模块: from astropy import time [as 别名]
# 或者: from astropy.time import TimeDelta [as 别名]
def epoch(self):
        """Current epoch calculated from time since ref_epoch."""
        return self.ref_epoch + time.TimeDelta(self.t, format='sec') 
开发者ID:RazerM,项目名称:orbital,代码行数:5,代码来源:elements.py

示例11: _set_xlabel

# 需要导入模块: from astropy import time [as 别名]
# 或者: from astropy.time import TimeDelta [as 别名]
def _set_xlabel(self, kwargs):
        """Helper function for plot, scatter, and errorbar.
        Ensures the xlabel is correctly set for folded light curves.
        """
        if 'xlabel' not in kwargs:
            kwargs['xlabel'] = "Phase"
            if isinstance(self.time, TimeDelta):
                kwargs['xlabel'] += f" [{self.time.format.upper()}]"
        return kwargs 
开发者ID:KeplerGO,项目名称:lightkurve,代码行数:11,代码来源:lightcurve.py

示例12: test_timedelta

# 需要导入模块: from astropy import time [as 别名]
# 或者: from astropy.time import TimeDelta [as 别名]
def test_timedelta(self):
        dt = self.t2 - self.t1
        with pytest.raises(TypeError):
            self.t1 > dt
        dt_gt_td0 = dt > TimeDelta(0., format='sec')
        assert np.all(dt_gt_td0 == np.array([False, False, False, False, False,
                                             False, True, True, True, True])) 
开发者ID:holzschu,项目名称:Carnets,代码行数:9,代码来源:test_comparisons.py

示例13: test_heliocentric

# 需要导入模块: from astropy import time [as 别名]
# 或者: from astropy.time import TimeDelta [as 别名]
def test_heliocentric(self):
        hval = self.obstime.light_travel_time(self.star, 'heliocentric')
        assert isinstance(hval, TimeDelta)
        assert hval.scale == 'tdb'
        assert abs(hval - 461.43037870502235 * u.s) < 1. * u.us 
开发者ID:holzschu,项目名称:Carnets,代码行数:7,代码来源:test_corrs.py

示例14: test_barycentric

# 需要导入模块: from astropy import time [as 别名]
# 或者: from astropy.time import TimeDelta [as 别名]
def test_barycentric(self):
        bval = self.obstime.light_travel_time(self.star, 'barycentric')
        assert isinstance(bval, TimeDelta)
        assert bval.scale == 'tdb'
        assert abs(bval - 460.58538779827836 * u.s) < 1. * u.us 
开发者ID:holzschu,项目名称:Carnets,代码行数:7,代码来源:test_corrs.py

示例15: test_mult_div

# 需要导入模块: from astropy import time [as 别名]
# 或者: from astropy.time import TimeDelta [as 别名]
def test_mult_div():
    """Test precision with multiply and divide"""
    dt_small = 6 * dt_tiny
    # pick a number that will leave remainder if divided by 6.
    dt_big = TimeDelta(20000., format='jd')
    dt_big_small_by_6 = (dt_big + dt_small) / 6.
    dt_frac = dt_big_small_by_6 - TimeDelta(3333., format='jd')
    assert allclose_jd2(dt_frac.jd2, 0.33333333333333354) 
开发者ID:holzschu,项目名称:Carnets,代码行数:10,代码来源:test_precision.py


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