Skip to content

Commit

Permalink
catch user error raised by maf when no data is in range
Browse files Browse the repository at this point in the history
  • Loading branch information
ehneilsen committed Feb 27, 2024
1 parent d82e5fc commit 9e266eb
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions schedview/app/prenight/prenight.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,20 @@ def _update_visits(self):
if not ResourcePath(self.opsim_output_fname).exists():
raise FileNotFoundError(f"Resource not found: {self.opsim_output_fname}")

visits = schedview.collect.opsim.read_opsim(
self.opsim_output_fname,
Time(self._almanac_events.loc["sunset", "UTC"]),
Time(self._almanac_events.loc["sunrise", "UTC"]),
)
if len(visits) == 0:
try:
visits = schedview.collect.opsim.read_opsim(
self.opsim_output_fname,
Time(self._almanac_events.loc["sunset", "UTC"]),
Time(self._almanac_events.loc["sunrise", "UTC"]),
)
no_data_found = len(visits) == 0
except UserWarning as user_warning:
if user_warning.args[0].startswith("No data found matching"):
no_data_found = True
else:
raise user_warning

if no_data_found:
self.logger.info("No visits on requested night, looking for a night with visits.")
# read all visits to so we can find a central one
visits = schedview.collect.opsim.read_opsim(self.opsim_output_fname)
Expand Down

0 comments on commit 9e266eb

Please sign in to comment.