astroplan
astroplan copied to clipboard
LocalTimeConstraint does not consider local time-zone
AltitudeConstraint
does not consider DST (daylight saving time).
For instance consider the following code:
#!/usr/bin/env python3
import astroplan, astropy.time
import astropy.units as u
import pytz,datetime
polse=astroplan.Observer(
latitude=
46+(28+9.1/60)/60,
longitude=
13+(0+42.6/60)/60,
elevation=
750*u.meter,
timezone=
pytz.timezone('Europe/Rome'))
target = astroplan.FixedTarget.from_name('Aldebaran')
constraint = astroplan.AltitudeConstraint(min=20*u.deg)
print(constraint(polse,target,times=astropy.time.Time('2020-04-10 21:00',
location=polse.location)))
It determines whether Aldebaran is visible above 20 deg. on the evening of 2020-04-10.
In Stellarium at that time the star is above 25 deg. and at 22:00 the star is below the 20 deg.
However the code returns False
after 20:00. When it should be True
until 21:00.
I am running anaconda on Linux:
astroplan 0.6
astropy 4.0.1.post1
This snippet
T = astropy.time.Time('2020-04-10 20:00',location=polse.location)
print(polse.altaz(T,target).alt)
prints 16d30m12.0672s
, which corresponds to the actual altitude at 22:00.
Uh... At 20:00 astropy.time says it corresponds to Julian Day 2458950.3333333335
, when
actually it should be 2458950.41667
. I see the astropy.time object is giving back a time point
corresponding to 20:00 utc
, not the local time at the location polse
.
Hi @Lagrang3 , see the astropy time notes about location. Basically the timezones only work in certain situations and when converting between different scales.
We choose to just always use UTC for working with any dates or times and only convert it to a local time for final display purposes or initial input.
Hi @wtgee, thank you for the clarification. Then I must assume that the T
:
T = astropy.time.Time('2020-04-10 20:00',location=polse.location)
is meant UTC. Then what do you make up of this:
constraint = astroplan.LocalTimeConstraint(min=datetime.time(19,30),max=datetime.time(20,30))
print(constraint(polse,target,times=T))
printing True
when polse
is an observer at UTC+2.
In my opinion some of the constraint classes are interpreting the time in the input with respect to UTC while other are assuming them as relative to the observer.
In fact in the code the timezome
is copied from the observer
but then it is not used at all.
I don't use the LocalTimeConstraint, but it's odd that the timezone
is ignored here @bmorris3
https://github.com/astropy/astroplan/blob/7a894acdfb850f560b9d968236a959279f331518/astroplan/constraints.py#L762
In fact in the code the
timezome
is copied from theobserver
but then it is not used at all.
You beat me to it. ;)
Here's a full example.
#!/usr/bin/env python3
import astroplan, astropy.time
import astropy.units as u
import datetime, pytz
polse=astroplan.Observer(
latitude=
46+(28+9.1/60)/60,
longitude=
13+(0+42.6/60)/60,
elevation=
750*u.meter,
timezone=
pytz.timezone('Europe/Rome'))
target = astroplan.FixedTarget.from_name('Aldebaran')
T = astropy.time.Time( [ '2020-04-10 19:05', '2020-04-10 20:05' ],location=polse.location)
altC = astroplan.AltitudeConstraint(min=20*u.deg)
timeC = astroplan.LocalTimeConstraint(min=datetime.time(21,0),max=datetime.time(21,30))
print(altC(polse,target,times=T))
print(timeC(polse,target,times=T))
it should print
[ True False]
[ True False]