Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LocalTimeConstraint does not consider local time-zone #466

Open
Lagrang3 opened this issue Aug 21, 2020 · 9 comments
Open

LocalTimeConstraint does not consider local time-zone #466

Lagrang3 opened this issue Aug 21, 2020 · 9 comments

Comments

@Lagrang3
Copy link
Contributor

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 
@Lagrang3
Copy link
Contributor Author

Lagrang3 commented Aug 21, 2020

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.

@Lagrang3
Copy link
Contributor Author

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.

@wtgee
Copy link
Collaborator

wtgee commented Aug 21, 2020

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.

@Lagrang3
Copy link
Contributor Author

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.

@Lagrang3
Copy link
Contributor Author

Lagrang3 commented Aug 21, 2020

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.

@Lagrang3
Copy link
Contributor Author

Lagrang3 commented Aug 21, 2020

In fact in the code the timezome is copied from the observer but then it is not used at all.

@wtgee
Copy link
Collaborator

wtgee commented Aug 21, 2020

I don't use the LocalTimeConstraint, but it's odd that the timezone is ignored here @bmorris3

timezone = observer.timezone

@wtgee
Copy link
Collaborator

wtgee commented Aug 21, 2020

In fact in the code the timezome is copied from the observer but then it is not used at all.

You beat me to it. ;)

@Lagrang3
Copy link
Contributor Author

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]

@Lagrang3 Lagrang3 changed the title AltitudeConstraint does not consider DST? LocalTimeConstraint does not consider local time-zone Aug 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants