How to use the pymap3d.timeconv.str2dt function in pymap3d

To help you get started, we’ve selected a few pymap3d examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scivision / pymap3d / tests / test_time.py View on Github external
def test_types():
    np = pytest.importorskip("numpy")
    assert str2dt(t0) == t0  # passthrough
    assert str2dt("2014-04-06T08:00:00") == t0
    ti = [str2dt("2014-04-06T08:00:00"), str2dt("2014-04-06T08:01:02")]
    to = [t0, datetime(2014, 4, 6, 8, 1, 2)]
    assert ti == to  # even though ti is numpy array of datetime and to is list of datetime

    t1 = [t0, t0]
    assert (np.asarray(str2dt(t1)) == t0).all()
github scivision / pymap3d / tests / test_time.py View on Github external
def test_xarray_time():
    xarray = pytest.importorskip("xarray")

    t = {"time": t0}
    ds = xarray.Dataset(t)
    assert str2dt(ds["time"]) == t0

    t2 = {"time": [t0, t0]}
    ds = xarray.Dataset(t2)
    assert (str2dt(ds["time"]) == t0).all()
github scivision / pymap3d / tests / test_time.py View on Github external
def test_types():
    np = pytest.importorskip("numpy")
    assert str2dt(t0) == t0  # passthrough
    assert str2dt("2014-04-06T08:00:00") == t0
    ti = [str2dt("2014-04-06T08:00:00"), str2dt("2014-04-06T08:01:02")]
    to = [t0, datetime(2014, 4, 6, 8, 1, 2)]
    assert ti == to  # even though ti is numpy array of datetime and to is list of datetime

    t1 = [t0, t0]
    assert (np.asarray(str2dt(t1)) == t0).all()
github scivision / pymap3d / tests / test_time.py View on Github external
def test_types():
    np = pytest.importorskip("numpy")
    assert str2dt(t0) == t0  # passthrough
    assert str2dt("2014-04-06T08:00:00") == t0
    ti = [str2dt("2014-04-06T08:00:00"), str2dt("2014-04-06T08:01:02")]
    to = [t0, datetime(2014, 4, 6, 8, 1, 2)]
    assert ti == to  # even though ti is numpy array of datetime and to is list of datetime

    t1 = [t0, t0]
    assert (np.asarray(str2dt(t1)) == t0).all()
github scivision / pymap3d / tests / test_time.py View on Github external
def test_pandas_time():
    pandas = pytest.importorskip("pandas")

    t = pandas.Series(t0)
    assert (str2dt(t) == t0).all()

    t = pandas.Series([t0, t0])
    assert (str2dt(t) == t0).all()
github scivision / pymap3d / pymap3d / azelradec.py View on Github external
Returns
    -------
    az_deg : "ndarray"
             azimuth [degrees clockwize from North]
    el_deg : "ndarray"
             elevation [degrees above horizon (neglecting aberration)]
    """

    if usevallado or Time is None:
        return vradec2azel(ra_deg, dec_deg, lat_deg, lon_deg, time)

    obs = EarthLocation(lat=lat_deg * u.deg, lon=lon_deg * u.deg)

    points = SkyCoord(Angle(ra_deg, unit=u.deg), Angle(dec_deg, unit=u.deg), equinox="J2000.0")

    altaz = points.transform_to(AltAz(location=obs, obstime=Time(str2dt(time))))

    return altaz.az.degree, altaz.alt.degree
github scivision / pymap3d / pymap3d / sidereal.py View on Github external
longitude (radians)
    usevallado : bool, optional
        use vallado instead of AstroPy (default is Vallado)

    Results
    -------

    tsr : float
        Sidereal time
    """
    if isinstance(time, (tuple, list)):
        return [datetime2sidereal(t, lon_radians) for t in time]

    usevallado = usevallado or Time is None
    if usevallado:
        jd = juliandate(str2dt(time))
        # %% Greenwich Sidereal time RADIANS
        gst = julian2sidereal(jd)
        # %% Algorithm 15 p. 188 rotate GST to LOCAL SIDEREAL TIME
        tsr = gst + lon_radians
    else:
        tsr = Time(time).sidereal_time(kind="apparent", longitude=Longitude(lon_radians, unit=u.radian)).radian

    return tsr
github scivision / pymap3d / pymap3d / azelradec.py View on Github external
default use astropy. If true, use Vallado algorithm

    Returns
    -------
    ra_deg : "ndarray"
         ecliptic right ascension (degress)
    dec_deg : "ndarray"
         ecliptic declination (degrees)
    """

    if usevallado or Time is None:  # non-AstroPy method, less accurate
        return vazel2radec(az_deg, el_deg, lat_deg, lon_deg, time)

    obs = EarthLocation(lat=lat_deg * u.deg, lon=lon_deg * u.deg)

    direc = AltAz(location=obs, obstime=Time(str2dt(time)), az=az_deg * u.deg, alt=el_deg * u.deg)

    sky = SkyCoord(direc.transform_to(ICRS()))

    return sky.ra.deg, sky.dec.deg