Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
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()
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()
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()
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()
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
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
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