[AstroPy] TIme.now() problem

Stuart P Littlefair s.littlefair at sheffield.ac.uk
Wed Mar 8 03:34:37 EST 2017


Hi Rick

You've two options; either pass the longitude to the sidereal_time call, e.g

from astropy.time import Time
from astropy import units as u

now = Time.now()
now.sidereal_time('mean', longitude=20*u.deg)

Or you can add the location post-hoc, e.g

now.location = loc
now.sidereal_time('mean')


Stuart Littlefair
Dept. of Physics & Astronomy
Univ. of Sheffield, Sheffield, S3 7RH

email: s.littlefair at shef.ac.uk
Phone: +44 114 2224525
Sent from my iPhone

> On 8 Mar 2017, at 08:26, Frederic V. Hessman <hessman at astro.physik.uni-goettingen.de> wrote:
>
> I’ve probably got a mental block after reading lots of documentation: how does one handle Time.now() and Time.sidereal_time() ?
>
> The examples given are always things like
>
>    from astropy.time import Time
>    from astropy.coordinates import EarthLocation
>    loc = EarthLocation.of_site ('McDonald Observatory’)
>    t = Time ('2016-03-08T12:34:56.7', format='isot', location=loc)
>    lst = t.sidereal_time (‘mean’)
>
> but if I want to use the current time, the logical thing to do would be
>
>    tnow = Time(None,location=loc).now()    # USE None BECAUSE I HAVE TO USE SOMETHING BUT DON’T KNOW THE TIME
>
> but this doesn’t work:
>
>    Traceback (most recent call last):
>        tnow = Time(None,location=loc).now()
>      File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/astropy/time/core.py", line 253, in __init__
>        precision, in_subfmt, out_subfmt)
>      File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/astropy/time/core.py", line 303, in _init_from_vals
>        precision, in_subfmt, out_subfmt)
>      File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/astropy/time/core.py", line 347, in _get_time_fmt
>        raise ValueError('Input values did not match {0}'.format(err_msg))
>    ValueError: Input values did not match any of the formats where the format keyword is optional ['datetime', 'iso', 'isot', 'yday', 'fits', 'byear_str', 'jyear_str’]
>
> and it doesn’t  help to give a format.  Ok, so Time() wants some concrete, if dummy value/object.  If I simply use the old t to create a tnow
>
>    tnow = t.now()
>
> things are fine but when I use it to get the LST,
>
>    lstnow = tnow.sideral_time (‘mean’)
>
> I get a location error:
>
>    Traceback (most recent call last):
>        lstnow = tnow.sidereal_time ('mean')
>      File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/astropy/time/core.py", line 715, in sidereal_time
>        raise ValueError('No longitude is given but the location for '
>    ValueError: No longitude is given but the location for the Time object is not set.
>
> which is wrong, since t had the location and tnow was derived directly from t.  Changing things to
>
>    tnow = Time(t,location=loc).now()
>
> doesn’t help and something like
>
>    tnow = t.now (location=loc)
>
> which would have passed on the location to the dumb time object isn’t supported.
>
> Any hints?   python 3.4.5, astropy 1.3, OSX
>
> Rick
>
>
>
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> https://mail.scipy.org/mailman/listinfo/astropy



More information about the AstroPy mailing list