當前位置: 首頁>>代碼示例>>Python>>正文


Python time.Time方法代碼示例

本文整理匯總了Python中astropy.time.Time方法的典型用法代碼示例。如果您正苦於以下問題:Python time.Time方法的具體用法?Python time.Time怎麽用?Python time.Time使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在astropy.time的用法示例。


在下文中一共展示了time.Time方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_orbit

# 需要導入模塊: from astropy import time [as 別名]
# 或者: from astropy.time import Time [as 別名]
def test_orbit(self):
        """
        Test orbit method to ensure proper output
        """

        t_ref = Time(2000.0, format='jyear')
        for mod in self.allmods:
            with RedirectStreams(stdout=self.dev_null):
                if 'SotoStarshade' in mod.__name__:
                    obj = mod(f_nStars=4, **copy.deepcopy(self.spec))
                else:
                    obj = mod(**copy.deepcopy(self.spec))
            r_sc = obj.orbit(t_ref)
            # the r_sc attribute is set and is a 3-tuple of astropy Quantity's
            self.assertEqual(type(r_sc), type(1.0 * u.km))
            self.assertEqual(r_sc.shape, (1, 3)) 
開發者ID:dsavransky,項目名稱:EXOSIMS,代碼行數:18,代碼來源:test_Observatory.py

示例2: test_cent

# 需要導入模塊: from astropy import time [as 別名]
# 或者: from astropy.time import Time [as 別名]
def test_cent(self):
        r"""Test cent method.

        Approach: Probes for a range of inputs.
        """

        print('cent()')
        obs = self.fixture
        # origin at 12:00 on 2000.Jan.01
        t_ref_string = '2000-01-01T12:00:00.0'
        t_ref = Time(t_ref_string, format='isot', scale='utc')
        self.assertEqual(obs.cent(t_ref), 0.0)

        # even-julian-year probes
        t_probe = np.linspace(1950.0, 2050.0, 101)
        for t_ref in t_probe:
            # get the Time object, required by the cent() method
            t_probe_2 = Time(t_ref, format='jyear')
            # exosims century (offset from 2000)
            t_exo = obs.cent(t_probe_2)
            # reference century
            t_ref_cent = (t_ref - 2000.0) / 100.0
            # they are not exactly equal
            self.assertAlmostEqual(t_exo, t_ref_cent, places=10) 
開發者ID:dsavransky,項目名稱:EXOSIMS,代碼行數:26,代碼來源:test_Observatory.py

示例3: test_moon_earth

# 需要導入模塊: from astropy import time [as 別名]
# 或者: from astropy.time import Time [as 別名]
def test_moon_earth(self):
        r"""Test moon_earth method.

        Approach: Reference to pre-computed result from Matlab.
        """

        print('moon_earth()')
        obs = self.fixture
        # TODO: add other times besides this one
        # century = 0
        t_ref_string = '2000-01-01T12:00:00.0'
        t_ref = Time(t_ref_string, format='isot', scale='utc')
        moon = obs.moon_earth(t_ref).flatten().to(u.km)
        # print moon
        r_earth = 6378.137 # earth radius [km], as used in Vallado's code
        moon_ref = [-45.74169421, -41.80825511, -11.88954996] # pre-computed from Matlab
        for coord in range(3):
            self.assertAlmostEqual(moon[coord].value, moon_ref[coord] * r_earth, places=1) 
開發者ID:dsavransky,項目名稱:EXOSIMS,代碼行數:20,代碼來源:test_Observatory.py

示例4: eclip2equat

# 需要導入模塊: from astropy import time [as 別名]
# 或者: from astropy.time import Time [as 別名]
def eclip2equat(self, r_eclip, currentTime):
        """Rotates heliocentric coordinates from ecliptic to equatorial frame.
        
        Args:
            r_eclip (astropy Quantity nx3 array):
                Positions vector in heliocentric ecliptic frame in units of AU
            currentTime (astropy Time array):
                Current absolute mission time in MJD
        
        Returns:
            r_equat (astropy Quantity nx3 array):
                Positions vector in heliocentric equatorial frame in units of AU
        
        """
        
        r_equat = self.equat2eclip(r_eclip, currentTime, rotsign=-1)
        
        return r_equat 
開發者ID:dsavransky,項目名稱:EXOSIMS,代碼行數:20,代碼來源:Observatory.py

示例5: cent

# 需要導入模塊: from astropy import time [as 別名]
# 或者: from astropy.time import Time [as 別名]
def cent(self, currentTime):
        """Finds time in Julian centuries since J2000 epoch
        
        This quantity is needed for many algorithms from Vallado 2013.
        
        Args:
            currentTime (astropy Time array):
                Current absolute mission time in MJD
            
        Returns:
            float ndarray:
                time in Julian centuries since the J2000 epoch 
        
        """
        
        j2000 = Time(2000., format='jyear',scale='tai')
        TDB = (currentTime.jd - j2000.jd)/36525.
        
        return TDB 
開發者ID:dsavransky,項目名稱:EXOSIMS,代碼行數:21,代碼來源:Observatory.py

示例6: set_jds

# 需要導入模塊: from astropy import time [as 別名]
# 或者: from astropy.time import Time [as 別名]
def set_jds(self, val1, val2):
        """Parse the time strings contained in val1 and set jd1, jd2"""
        iterator = np.nditer([val1, None, None, None, None, None, None],
                             op_dtypes=([val1.dtype] + 5 * [np.intc]
                                        + [np.double]))
        try:
            for val, iy, im, id, ihr, imin, dsec in iterator:
                timestr = val.item()
                components = timestr.split()
                iy[...], im[...], id[...], ihr[...], imin[...], sec = (
                    int(component) for component in components[:-1])
                dsec[...] = sec + float(components[-1])
        except Exception:
            raise ValueError('Time {0} does not match {1} format'
                             .format(timestr, self.name))

        self.jd1, self.jd2 = erfa.dtf2d(
            self.scale.upper().encode('utf8'), *iterator.operands[1:]) 
開發者ID:mhvk,項目名稱:baseband,代碼行數:20,代碼來源:header.py

示例7: test_rawdump_header

# 需要導入模塊: from astropy import time [as 別名]
# 或者: from astropy.time import Time [as 別名]
def test_rawdump_header(self):
        with open(SAMPLE_RAWDUMP_HEADER, 'rt') as fh:
            header = gsb.GSBHeader.fromfile(fh, verify=True)
        assert header.mode == 'rawdump'
        assert header['gps'] == '2015 04 27 18 45 00 0.000000240'
        # Includes UTC offset.
        assert abs(header.time
                   - Time('2015-04-27T13:15:00.000000240')) < 1.*u.ns
        header2 = gsb.GSBHeader.fromkeys(**header)
        assert header2 == header
        header3 = gsb.GSBHeader.fromvalues(mode='rawdump', **header2)
        assert header3 == header2
        with pytest.raises(TypeError):
            gsb.GSBHeader.fromvalues(**header)
        with pytest.raises(TypeError):
            gsb.GSBHeader(None)
        # Check that recovering with the actual header type works as well.
        header4 = type(header).fromkeys(**header)
        assert header4 == header
        # Check that trying to initialize a phased header doesn't work.
        with pytest.raises(KeyError):
            gsb.header.GSBPhasedHeader.fromkeys(**header)
        header5 = header.copy()
        assert header5 == header 
開發者ID:mhvk,項目名稱:baseband,代碼行數:26,代碼來源:test_gsb.py

示例8: test_rawdump_header_seek_offset

# 需要導入模塊: from astropy import time [as 別名]
# 或者: from astropy.time import Time [as 別名]
def test_rawdump_header_seek_offset(self):
        fh = open(SAMPLE_RAWDUMP_HEADER, 'rt')

        header = gsb.GSBHeader.fromfile(fh, verify=True)
        # Includes 1 trailing blank space, one line separator
        header_nbytes = header.nbytes
        assert (header_nbytes
                == len(' '.join(header.words) + ' ' + os.linesep))
        assert header.seek_offset(1) == header_nbytes
        assert header.seek_offset(12) == 12 * header_nbytes

        # Note that text pointers can't seek from current position.
        # Seek 2nd header.
        fh.seek(header.seek_offset(1))
        header1 = gsb.GSBHeader.fromfile(fh, verify=True)
        assert abs(header1.time
                   - Time('2015-04-27T13:15:00.251658480')) < 1.*u.ns

        fh.seek(header.seek_offset(9))
        header2 = gsb.GSBHeader.fromfile(fh, verify=True)
        assert abs(header2.time
                   - Time('2015-04-27T13:15:02.264924400')) < 1.*u.ns

        fh.close() 
開發者ID:mhvk,項目名稱:baseband,代碼行數:26,代碼來源:test_gsb.py

示例9: test_stream

# 需要導入模塊: from astropy import time [as 別名]
# 或者: from astropy.time import Time [as 別名]
def test_stream(self, tmpdir):
        with vdif.open(SAMPLE_VDIF, 'rs') as fr:
            vh = fr.header0
            data = fr.read(20000)  # enough to fill two Mark 5B frames.

        fl = str(tmpdir.join('test.m5b'))
        with mark5b.open(fl, 'ws', sample_rate=vh.sample_rate,
                         nchan=data.shape[1], bps=vh.bps, time=vh.time) as fw:
            fw.write(data)

        with vdif.open(SAMPLE_VDIF, 'rs') as fv, mark5b.open(
                fl, 'rs', sample_rate=32.*u.MHz,
                ref_time=Time(57000, format='mjd'), nchan=8, bps=2) as fm:
            assert fv.header0.time == fm.header0.time
            dv = fv.read(20000)
            dm = fm.read(20000)
            assert np.all(dm == dv)
            assert fm.offset == fv.offset
            assert fm.tell(unit='time') == fv.tell(unit='time') 
開發者ID:mhvk,項目名稱:baseband,代碼行數:21,代碼來源:test_conversion.py

示例10: time

# 需要導入模塊: from astropy import time [as 別名]
# 或者: from astropy.time import Time [as 別名]
def time(self, time):
        """Set header time.

        If ``start_time`` is not already set, this sets it using the time and
        ``offset``.  Otherwise, this sets ``offset`` using the time and
        ``start_time``.

        Parameters
        ----------
        time : `~astropy.time.Time`
            Time for the first sample associated with this header.
        """
        if 'MJD_START' not in self.keys():
            self.start_time = time - self.offset
        else:
            self.offset = time - self.start_time 
開發者ID:mhvk,項目名稱:baseband,代碼行數:18,代碼來源:header.py

示例11: time

# 需要導入模塊: from astropy import time [as 別名]
# 或者: from astropy.time import Time [as 別名]
def time(self, time):
        """Set header time.

        If ``start_time`` is not already set, this sets it using the time and
        ``offset``.  Otherwise, this sets ``offset`` using the time and
        ``start_time``.

        Parameters
        ----------
        time : `~astropy.time.Time`
            Time for the first sample associated with this header.
        """
        if 'STT_IMJD' not in self.keys():
            self.start_time = time - self.offset
        else:
            self.offset = time - self.start_time 
開發者ID:mhvk,項目名稱:baseband,代碼行數:18,代碼來源:header.py

示例12: set_time

# 需要導入模塊: from astropy import time [as 別名]
# 或者: from astropy.time import Time [as 別名]
def set_time(self, time):
        """Convert Time object to BCD timestamp elements.

        Parameters
        ----------
        time : `~astropy.time.Time`
            The time to use for this header.
        """
        old_precision = time.precision
        try:
            time.precision = 5
            yday = time.yday.split(':')
        finally:
            time.precision = old_precision
        # Set fraction first since that checks precision.
        self.fraction = float(yday[4]) % 1
        self.decade = int(yday[0][:3]) * 10
        self['bcd_unit_year'] = int(yday[0][3], base=16)
        self['bcd_day'] = int(yday[1], base=16)
        self['bcd_hour'] = int(yday[2], base=16)
        self['bcd_minute'] = int(yday[3], base=16)
        self['bcd_second'] = int(yday[4][:2], base=16) 
開發者ID:mhvk,項目名稱:baseband,代碼行數:24,代碼來源:header.py

示例13: test_start_at_last_frame

# 需要導入模塊: from astropy import time [as 別名]
# 或者: from astropy.time import Time [as 別名]
def test_start_at_last_frame(tmpdir):
    """Regression test for files where first frame is last in a second.

    Previously, this caused the frame rate and thus the sample rate to
    be calculated wrongly.  See gh-340.
    """
    fl = str(tmpdir.join('test.m4'))
    sample_rate = 32*u.MHz
    frame_rate = sample_rate / 80000
    start_time = Time('2012-01-02') - 1/frame_rate
    with mark4.open(fl, 'ws', sample_rate=sample_rate, time=start_time,
                    ntrack=32, sample_shape=(4,), fanout=4, bps=2) as fw:
        fw.write(np.ones((80000*2, 4)))

    with mark4.open(fl, 'rs', decade=2010) as fr:
        assert fr.sample_rate == sample_rate 
開發者ID:mhvk,項目名稱:baseband,代碼行數:18,代碼來源:test_mark4.py

示例14: make_cphase_df

# 需要導入模塊: from astropy import time [as 別名]
# 或者: from astropy.time import Time [as 別名]
def make_cphase_df(obs,band='unknown',polarization='unknown',mode='all',count='max',round_s=0.1,snrcut=0.,uv_min=False):

    """generate DataFrame of closure phases

    Args: 
        obs: ObsData object
        round_s: accuracy of datetime object in seconds

    Returns:
        df: closure phase data in DataFrame format
    """

    data=obs.c_phases(mode=mode,count=count,snrcut=snrcut,uv_min=uv_min)
    sour=obs.source
    df = pd.DataFrame(data=data).copy()
    df['fmjd'] = df['time']/24.
    df['mjd'] = obs.mjd + df['fmjd']
    df['triangle'] = list(map(lambda x: x[0]+'-'+x[1]+'-'+x[2],zip(df['t1'],df['t2'],df['t3'])))
    df['datetime'] = Time(df['mjd'], format='mjd').datetime
    df['datetime'] =list(map(lambda x: round_time(x,round_s=round_s),df['datetime']))
    df['jd'] = Time(df['mjd'], format='mjd').jd
    df['polarization'] = polarization
    df['band'] = band
    df['source'] = sour
    return df 
開發者ID:achael,項目名稱:eht-imaging,代碼行數:27,代碼來源:dataframes.py

示例15: haloPosition

# 需要導入模塊: from astropy import time [as 別名]
# 或者: from astropy.time import Time [as 別名]
def haloPosition(self,currentTime):
        """Finds orbit positions of spacecraft in a halo orbit in rotating frame
        
        This method returns the telescope L2 Halo orbit position vector in an ecliptic, 
        rotating frame as dictated by the Circular Restricted Three Body-Problem. 
        The origin of this frame is the centroid of the Sun and Earth-Moon system.
        
        Args:
            currentTime (astropy Time array):
                Current absolute mission time in MJD

        Returns:
            r_halo (astropy Quantity nx3 array):
                Observatory orbit positions vector in an ecliptic, rotating frame 
                in units of AU
        
        """
        
        # Find the time between Earth equinox and current time(s)
        dt = (currentTime - self.equinox).to('yr').value
        t_halo = dt % self.period_halo
        
        # Interpolate to find correct observatory position(s)
        r_halo = self.r_halo_interp_L2(t_halo).T*u.AU
        
        return r_halo 
開發者ID:dsavransky,項目名稱:EXOSIMS,代碼行數:28,代碼來源:ObservatoryL2Halo.py


注:本文中的astropy.time.Time方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。