Skip to content

Commit

Permalink
Merge pull request #81 from WWGolay/t0-fix
Browse files Browse the repository at this point in the history
Fix to t0 in schedtel and exoplanet_transits
  • Loading branch information
WWGolay authored Nov 14, 2023
2 parents 98b26a4 + d3fb576 commit 6e461d1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 38 deletions.
35 changes: 14 additions & 21 deletions pyscope/telrun/exoplanet_transits.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,24 @@ def exoplanet_transits_cli(
if transit_depth_percent is not None:
transit_depth = np.log10(1 + transit_depth_percent / 100) / 0.4

tz = timezonefinder.TimezoneFinder().timezone_at(lng=lon.deg, lat=lat.deg)
tz = zoneinfo.ZoneInfo(tz)
logger.debug(f"tz = {tz}")

if date is None:
logger.info("Using current date at observatory location")
tz = timezonefinder.TimezoneFinder().timezone_at(
lng=observatory.observatory_location.lon.deg,
lat=observatory.observatory_location.lat.deg,
)
date = datetime.datetime.now(pytz.timezone(tz))
logger.debug("Using current date at observatory location")
date = datetime.datetime.now()
else:
date = datetime.datetime.strptime(date, "%Y-%m-%d")
date = datetime.datetime(date.year, date.month, date.day, 12, 0, 0, tzinfo=tz)

t0 = (
astrotime.Time(
datetime.datetime(date.year, date.month, date.day, 12, 0, 0),
format="datetime",
scale="utc",
)
- (
(
astrotime.Time(date, format="datetime", scale="utc")
- astrotime.Time.now()
).day
% 1
)
* u.day
t0 = astrotime.Time(
datetime.datetime(date.year, date.month, date.day, 12, 0, 0, tzinfo=tz),
format="datetime",
)
logger.debug(f"t0 = {t0}")
t1 = t0 + 1 * u.day
logger.info("Searching UT range: %s to %s" % (t0.iso, t1.iso))
logger.debug(f"t1 = {t1}")

min_ra = observatory.lst(t=t0).to(u.deg).value
max_ra = observatory.lst(t=t1).to(u.deg).value
Expand Down
29 changes: 12 additions & 17 deletions pyscope/telrun/schedtel.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,25 +287,20 @@ def schedtel_cli(
)

# Schedule
tz = timezonefinder.TimezoneFinder().timezone_at(lng=lon.deg, lat=lat.deg)
tz = zoneinfo.ZoneInfo(tz)
logger.debug(f"tz = {tz}")

if date is None:
logger.info("Using current date at observatory location")
tz = timezonefinder.TimezoneFinder().timezone_at(lng=obs_long, lat=obs_lat)
date = datetime.datetime.now(pytz.timezone(tz))
logger.debug("Using current date at observatory location")
date = datetime.datetime.now()
else:
date = datetime.datetime.strptime(date, "%Y-%m-%d")
date = datetime.datetime(date.year, date.month, date.day, 12, 0, 0, tzinfo=tz)

t0 = (
astrotime.Time(
datetime.datetime(date.year, date.month, date.day, 12, 0, 0),
format="datetime",
scale="utc",
)
- (
(
astrotime.Time(date, format="datetime", scale="utc")
- astrotime.Time.now()
).day
% 1
)
* u.day
t0 = astrotime.Time(
datetime.datetime(date.year, date.month, date.day, 12, 0, 0, tzinfo=tz),
format="datetime",
)
t1 = t0 + 1 * u.day
logger.info("Schedule time range: %s to %s" % (t0.iso, t1.iso))
Expand Down

0 comments on commit 6e461d1

Please sign in to comment.