From d3fb576222e325b23a476730493edf17bec48a03 Mon Sep 17 00:00:00 2001 From: WGolay Date: Tue, 14 Nov 2023 13:36:18 -0500 Subject: [PATCH] Fix to t0 in schedtel and exoplanet_transits --- pyscope/telrun/exoplanet_transits.py | 35 +++++++++++----------------- pyscope/telrun/schedtel.py | 29 ++++++++++------------- 2 files changed, 26 insertions(+), 38 deletions(-) diff --git a/pyscope/telrun/exoplanet_transits.py b/pyscope/telrun/exoplanet_transits.py index a8beeeb6..7de5c7e0 100644 --- a/pyscope/telrun/exoplanet_transits.py +++ b/pyscope/telrun/exoplanet_transits.py @@ -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 diff --git a/pyscope/telrun/schedtel.py b/pyscope/telrun/schedtel.py index a0c6c223..36cc3917 100644 --- a/pyscope/telrun/schedtel.py +++ b/pyscope/telrun/schedtel.py @@ -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))