-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
148 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from datetime import datetime, date, time, timedelta | ||
import math | ||
from astroplan import Observer | ||
from astropy.time import Time | ||
|
||
class Almanac: | ||
|
||
def __init__(self, *, day_obs=None, site='Rubin'): | ||
if day_obs is None: | ||
astro_day = date.today() - timedelta(days=1) | ||
else: | ||
astro_day = datetime.strptime(str(day_obs), '%Y%m%d').date() | ||
|
||
self.observer = Observer.at_site(site, timezone='Chile/Continental') | ||
self.astro_day = astro_day | ||
self.astro_noon = datetime.combine(self.astro_day,time(12)) | ||
|
||
self.get_moon() | ||
self.get_sun() | ||
|
||
def get_moon(self): | ||
self.moon_rise_time = self.observer.moon_rise_time(self.astro_noon) | ||
self.moon_set_time = self.observer.moon_set_time(self.astro_noon) | ||
|
||
# Percent of moon lit | ||
self.moon_illum = self.observer.moon_illumination(self.astro_noon) | ||
|
||
def get_sun(self): | ||
time = self.observer.datetime_to_astropy_time(self.astro_noon) | ||
|
||
# ast(ronoimical) twilight: -18 degrees) | ||
self.ast_twilight_morning = self.observer.twilight_morning_astronomical( | ||
time) | ||
self.ast_twilight_evening = self.observer.twilight_evening_astronomical( | ||
time) | ||
|
||
# nau(tical) twilight: -12 degrees) | ||
self.nau_twilight_morning = self.observer.twilight_morning_nautical( | ||
time) | ||
self.nau_twilight_evening = self.observer.twilight_evening_nautical( | ||
time) | ||
|
||
# civ(il) twilight: -6 degrees) | ||
self.civ_twilight_morning = self.observer.twilight_morning_civil( | ||
time) | ||
self.civ_twilight_evening = self.observer.twilight_evening_civil( | ||
time) | ||
|
||
self.sun_rise_time = self.observer.sun_rise_time(time) | ||
self.sun_set_time = self.observer.sun_set_time(time) | ||
|
||
@property | ||
def as_dict(self): | ||
data_dict = { | ||
'Moon Rise': self.moon_rise_time.iso, | ||
'Moon Set': self.moon_set_time.iso, | ||
'Moon Illumination': f'{self.moon_illum:.0%}', | ||
'Astronomical Twilight (morning)': self.ast_twilight_morning.iso, | ||
'Astronomical Twilight (evening)': self.ast_twilight_evening.iso, | ||
'Nautical Twilight (morning)': self.nau_twilight_morning.iso, | ||
'Nautical Twilight (evening)': self.nau_twilight_evening.iso, | ||
'Civil Twilight (morning)': self.civ_twilight_morning.iso, | ||
'Civil Twilight (evening)': self.civ_twilight_evening.iso, | ||
} | ||
help_dict = { | ||
'Moon Rise': '', | ||
'Moon Set': '', | ||
'Moon Illumination': '(% lit)', | ||
'Astronomical Twilight (morning)': '(-18 degrees)', | ||
'Astronomical Twilight (evening)': '(-18 degrees)', | ||
'Nautical Twilight (morning)': '(-12 degrees)', | ||
'Nautical Twilight (evening)': '(-12 degrees)', | ||
'Civil Twilight (morning)': '(-6 degrees)', | ||
'Civil Twilight (evening)': '(-6 degrees)', | ||
} | ||
return data_dict, help_dict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
class Dashboard: # TODO Move to its own file (utils.py). | ||
"""Verify that we can get to all the API endpoints and databases we need for | ||
any of our sources. | ||
""" | ||
|
||
envs = dict( | ||
summit = 'https://summit-lsp.lsst.codes', | ||
usdf_dev = 'https://usdf-rsp-dev.slac.stanford.edu', | ||
tucson = 'https://tucson-teststand.lsst.codes', | ||
# Environments not currently used: | ||
# rubin_usdf_dev = '', | ||
# data_lsst_cloud = '', | ||
# usdf = '', | ||
# base_data_facility = '', | ||
# rubin_idf_int = '', | ||
) | ||
adapters = [ExposurelogAdapter, | ||
NarrativelogAdapter, | ||
# NightReportAdapter, # TODO | ||
] | ||
|
||
def report(self, timeout=None): | ||
"""Check our ability to connect to every Source on every Environment. | ||
Report a summary. | ||
RETURN: percentage of good connectons. | ||
""" | ||
url_status = dict() | ||
for env,server in self.envs.items(): | ||
for adapter in self.adapters: | ||
service = adapter(server_url=server) | ||
# url_status[endpoint_url] = http_status_code | ||
url_status.update(service.check_endpoints(timeout=timeout)) | ||
|
||
total_cnt = good_cnt = 0 | ||
good = list() | ||
bad = list() | ||
for url,stat in url_status.items(): | ||
total_cnt += 1 | ||
if stat == 200: | ||
good_cnt += 1 | ||
good.append(url) | ||
else: | ||
bad.append((url,stat)) | ||
|
||
print(f'\nConnected to {good_cnt} out of {total_cnt} endpoints.' | ||
f'({good_cnt/total_cnt:.0%})' | ||
) | ||
goodstr = "\n\t".join(good) | ||
print(f'Successful connects ({good_cnt}): ') | ||
for gurl in good: | ||
print(f'\t{gurl}') | ||
|
||
print(f'Failed connects ({total_cnt - good_cnt}): ') | ||
for burl,stat in bad: | ||
print(f'\t{stat}: {burl}') | ||
|
||
status = dict(num_good=good_cnt, | ||
num_total=total_cnt, | ||
good_urls=good, | ||
bad_ursl=bad, | ||
) | ||
return good_cnt/total_cnt | ||
# END: class Dashboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Generated by setuptools_scm | ||
__all__ = ["__version__"] | ||
__version__ = "0.1.dev49+gb8bd681.d20240913" | ||
__version__ = "0.1.dev53+g1c878ef.d20240914" |