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

Error in obtaining twilight time for site #608

Open
simontorres opened this issue Dec 17, 2024 · 1 comment
Open

Error in obtaining twilight time for site #608

simontorres opened this issue Dec 17, 2024 · 1 comment

Comments

@simontorres
Copy link

I've found that issues #464 and #533 present a similar problem.
I'm using astroplan version 0.10.1
I'm running the following code for testing:

import astropy.units as u
from astropy.time import Time
from astropy.coordinates import EarthLocation
from astroplan import Observer

observatory = 'SOAR Telescope'

geodetic_location = ['-70d44m01.11s', '-30d14m16.41s', 2748]

longitude = geodetic_location[0]
latitude = geodetic_location[1]
elevation = geodetic_location[2]

timezone = 'UTC'

description = 'Soar Telescope on Cerro Pachon, Chile'


soar_loc = EarthLocation.from_geodetic(
    longitude,
    latitude,
    elevation * u.m,
    ellipsoid='WGS84')

soar = Observer(name=observatory,
                location=soar_loc,
                timezone=timezone,
                description=description)

date_obs = [
    '2024-12-08T19:12:58.281',
    '2024-12-08T19:14:00.814',
    '2024-12-08T19:14:13.016',
    '2024-12-08T19:14:25.218',
    '2024-12-08T19:14:37.423',
    '2024-12-08T19:14:49.627',
    '2024-12-08T19:15:01.826',
    '2024-12-08T19:15:14.025',
    '2024-12-08T19:15:26.223',
    '2024-12-08T19:15:38.421',
    '2024-12-08T19:15:50.620',
    '2024-12-08T19:16:02.819',
    '2024-12-08T19:26:51.024',
    '2024-12-08T19:27:01.016',
    '2024-12-08T19:27:10.980',
    '2024-12-08T19:27:20.945',
    '2024-12-08T19:27:30.939',
    '2024-12-08T19:27:40.904',
    '2024-12-08T19:27:50.873',
    '2024-12-08T19:28:00.841',
    '2024-12-08T19:28:10.807',
    '2024-12-08T19:28:20.773',
    '2024-12-08T19:31:11.133',
    '2024-12-08T19:32:03.088',
    '2024-12-08T19:32:14.580',
    '2024-12-08T19:32:26.074',
    '2024-12-08T19:32:37.592',
    '2024-12-08T19:32:49.092',
    '2024-12-08T19:33:00.585',
    '2024-12-08T19:33:12.073',
    '2024-12-08T19:33:23.569',
    '2024-12-08T19:33:35.067',
    '2024-12-08T19:35:16.249',
    '2024-12-08T19:37:07.451',
    '2024-12-08T19:39:44.707',
    '2024-12-08T19:41:30.004',
    '2024-12-08T19:41:55.606',
    '2024-12-08T19:44:42.483',
    '2024-12-08T19:45:43.977',
    '2024-12-08T19:45:59.987',
    '2024-12-08T19:46:15.949',
    '2024-12-08T19:46:31.938',
    '2024-12-08T19:46:47.928',
    '2024-12-08T19:47:03.930',
    '2024-12-08T19:47:19.913',
    '2024-12-08T19:47:35.907',
    '2024-12-08T19:47:51.902',
    '2024-12-08T19:48:07.926',
    '2024-12-09T00:36:05.258',
    '2024-12-09T00:42:48.890',
    '2024-12-09T00:45:59.575',
    '2024-12-09T00:49:47.609',
    '2024-12-09T00:51:15.288',
    '2024-12-09T00:54:38.605',
    '2024-12-09T01:02:21.778',
    '2024-12-09T01:13:07.968',
    '2024-12-09T01:23:34.241',
    '2024-12-09T01:35:06.785',
    '2024-12-09T01:43:37.992',
    '2024-12-09T01:45:02.019',
    '2024-12-09T02:04:56.958',
    '2024-12-09T02:15:06.920',
    '2024-12-09T02:26:06.814',
    '2024-12-09T02:32:23.438',
    '2024-12-09T02:42:33.399',
    '2024-12-09T02:52:43.364',
    '2024-12-09T03:03:35.575',
    '2024-12-09T03:09:17.902',
    '2024-12-09T03:15:02.153',
    '2024-12-09T03:20:44.887',
    '2024-12-09T03:32:59.756',
    '2024-12-09T03:38:22.151',
    '2024-12-09T03:44:21.035',
    '2024-12-09T03:50:33.126',
    '2024-12-09T03:55:54.897',
    '2024-12-09T04:01:39.901',
    '2024-12-09T04:07:31.277',
    '2024-12-09T04:17:57.604',
    '2024-12-09T04:19:47.582',
    '2024-12-09T04:22:57.544',
    '2024-12-09T04:31:11.036',
    '2024-12-09T04:41:21.359',
    '2024-12-09T04:51:37.185',
    '2024-12-09T05:02:19.628',
    '2024-12-09T05:08:44.461',
    '2024-12-09T05:18:54.425',
    '2024-12-09T05:29:43.797',
    '2024-12-09T05:35:50.238',
    '2024-12-09T05:46:00.214',
    '2024-12-09T05:56:16.908',
    '2024-12-09T06:07:08.788',
    '2024-12-09T06:10:44.439',
    '2024-12-09T06:11:54.360',
    '2024-12-09T06:12:44.865',
    '2024-12-09T06:21:21.403',
    '2024-12-09T06:26:31.429',
    '2024-12-09T06:32:43.745',
    '2024-12-09T06:38:25.124',
    '2024-12-09T06:43:51.164',
    '2024-12-09T06:49:01.142',
    '2024-12-09T06:54:58.791',
    '2024-12-09T07:03:49.460',
    '2024-12-09T07:08:59.467',
    '2024-12-09T07:14:41.059',
    '2024-12-09T07:25:59.400',
    '2024-12-09T07:36:09.377',
    '2024-12-09T07:46:19.382',
    '2024-12-09T07:58:00.468',
    '2024-12-09T07:59:00.468']

for _t in date_obs:
    print(f"{Time(_t)} Evening: {soar.twilight_evening_astronomical(Time(_t), which='nearest').isot} Morning: {soar.twilight_morning_astronomical(Time(_t), which='nearest').isot}")

And I obtain the following output, I removed some of them for brevity:

2024-12-08T19:12:58.281 Evening: 2024-12-09T01:12:33.691 Morning: 2024-12-08T07:57:58.333
2024-12-08T19:14:00.814 Evening: 2024-12-09T01:12:33.739 Morning: 2024-12-08T07:57:58.146
...
...
2024-12-09T00:51:15.288 Evening: 2024-12-09T01:12:33.764 Morning: 2024-12-09T07:57:59.287
2024-12-09T00:54:38.605 Evening: 2024-12-09T01:12:33.682 Morning: 2024-12-09T07:57:59.567
2024-12-09T01:02:21.778 Evening: 2024-12-09T01:12:33.505 Morning: 2024-12-09T07:57:59.343
2024-12-09T01:13:07.968 Evening:                     ——— Morning: 2024-12-09T07:57:59.620
2024-12-09T01:23:34.241 Evening: 2024-12-09T01:12:33.691 Morning: 2024-12-09T07:57:59.560
2024-12-09T01:35:06.785 Evening: 2024-12-09T01:12:33.718 Morning: 2024-12-09T07:57:59.270
2024-12-09T01:43:37.992 Evening: 2024-12-09T01:12:33.774 Morning: 2024-12-09T07:57:59.368
2024-12-09T01:45:02.019 Evening: 2024-12-09T01:12:33.672 Morning: 2024-12-09T07:57:59.278
...
...
2024-12-09T07:36:09.377 Evening: 2024-12-09T01:12:33.771 Morning: 2024-12-09T07:57:59.298
2024-12-09T07:46:19.382 Evening: 2024-12-09T01:12:33.689 Morning: 2024-12-09T07:57:59.309
2024-12-09T07:58:00.468 Evening: 2024-12-09T01:12:33.629 Morning:                     ———
2024-12-09T07:59:00.468 Evening: 2024-12-09T01:12:33.791 Morning: 2024-12-09T07:57:59.451

There are these two points where the output is not correct, they seem to be random, in my application I use the first and the last value to get the corresponding twilight for evening and morning. In this case the last value was failing so I just copied it and added one minute and a a proper value is obtained.

Thanks in advance!

@pavolgaj
Copy link

The problem is probably caused by the fact that for these times the Sun's altitude is very close to -18deg (the limit for astronomical twilight).

Running soar.sun_altaz(Time('2024-12-09T07:58:00.468')).alt gives altitude of -17.998091718201977 deg.

However, soar.twilight_morning_astronomical(Time('2024-12-09T07:58:00.468'),which='previous').isot works fine. But, which='next' fails. In the case of which='nearest', both values are calculated and compared according to the given time.

Due to the change in the day length, the next morning twilight is 2024-12-10T07:58:01.967 which is 24 hours + 1.5 seconds later. Also, this warning tells something similar:

WARNING: TargetNeverUpWarning: Target with index 0 does not cross horizon=-18.0 deg within 24 hours

The issue can be fixed using the only values not masked in comparison - soar.twilight_morning_astronomical(Time('2024-12-09T07:58:00.468'),which='next').masked is True. Probably here in astroplan code:

if which == 'nearest':
.

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