[AstroPy] TIme.now() problem

Frederic V. Hessman hessman at astro.physik.uni-goettingen.de
Wed Mar 8 03:26:05 EST 2017


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








More information about the AstroPy mailing list