From 868daa1a061d45a3744d3352ef3b162561eef7c8 Mon Sep 17 00:00:00 2001 From: Merlin Fisher-Levine Date: Sun, 1 Dec 2024 19:34:16 -0800 Subject: [PATCH] Add SOAR seeing scraping and plotting --- python/lsst/rubintv/production/soarSeeing.py | 74 ++++++++++++++++++++ scripts/summit/misc/runSoarSeeingScraper.py | 26 +++++++ scripts/summit/misc/runSoarSeeingUploader.py | 27 +++++++ 3 files changed, 127 insertions(+) create mode 100644 python/lsst/rubintv/production/soarSeeing.py create mode 100644 scripts/summit/misc/runSoarSeeingScraper.py create mode 100644 scripts/summit/misc/runSoarSeeingUploader.py diff --git a/python/lsst/rubintv/production/soarSeeing.py b/python/lsst/rubintv/production/soarSeeing.py new file mode 100644 index 000000000..ed438329e --- /dev/null +++ b/python/lsst/rubintv/production/soarSeeing.py @@ -0,0 +1,74 @@ +# This file is part of rubintv_production. +# +# Developed for the LSST Data Management System. +# This product includes software developed by the LSST Project +# (https://www.lsst.org). +# See the COPYRIGHT file at the top-level directory of this distribution +# for details of code ownership. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +from __future__ import annotations + +__all__ = [ + "SoarUploader", +] + +import logging +import tempfile +from time import sleep + +import matplotlib.pyplot as plt +from astropy.time import Time + +from lsst.rubintv.production.uploaders import MultiUploader +from lsst.rubintv.production.utils import getRubinTvInstrumentName, raiseIf +from lsst.summit.extras.soarSeeing import SoarSeeingMonitor +from lsst.summit.utils.utils import getCurrentDayObs_int + + +class SoarUploader: + def __init__(self, doRaise: bool) -> None: + self.soar = SoarSeeingMonitor() + self.instrument = "LSSTComCam" # change to LSSTCam when we switch instruments + self.doRaise = doRaise + self.figure = plt.figure(figsize=(18, 10)) + self.uploader = MultiUploader() + self._lastUpdated = Time.now() + self.log = logging.getLogger(__name__) + + def newData(self) -> bool: + return self._lastUpdated != self.soar.getMostRecentTimestamp() + + def run(self) -> None: + while True: + dayObs = getCurrentDayObs_int() + try: + if not self.newData(): + sleep(15) + continue + + self._lastUpdated = self.soar.getMostRecentTimestamp() + self.figure = self.soar.plotSeeingForDayObs(dayObs, addMostRecentBox=False, fig=self.figure) + with tempfile.NamedTemporaryFile(suffix=".png") as f: + self.log.info(f"Uploading SOAR seeing to night report for {dayObs}") + self.figure.savefig(f.name) + self.uploader.uploadNightReportData( + getRubinTvInstrumentName(self.instrument), dayObs, f.name, "SoarSeeingMonitor" + ) + self.log.info("Done") + self.figure.clear() + + except Exception as e: + logging.error(f"Error: {e}") + raiseIf(self.doRaise, e, self.log) diff --git a/scripts/summit/misc/runSoarSeeingScraper.py b/scripts/summit/misc/runSoarSeeingScraper.py new file mode 100644 index 000000000..22166188b --- /dev/null +++ b/scripts/summit/misc/runSoarSeeingScraper.py @@ -0,0 +1,26 @@ +# This file is part of rubintv_production. +# +# Developed for the LSST Data Management System. +# This product includes software developed by the LSST Project +# (https://www.lsst.org). +# See the COPYRIGHT file at the top-level directory of this distribution +# for details of code ownership. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from lsst.summit.extras.soarSeeing import SoarDatabaseBuiler + +scraper = SoarDatabaseBuiler() + +scraper.run() diff --git a/scripts/summit/misc/runSoarSeeingUploader.py b/scripts/summit/misc/runSoarSeeingUploader.py new file mode 100644 index 000000000..62088c6e9 --- /dev/null +++ b/scripts/summit/misc/runSoarSeeingUploader.py @@ -0,0 +1,27 @@ +# This file is part of rubintv_production. +# +# Developed for the LSST Data Management System. +# This product includes software developed by the LSST Project +# (https://www.lsst.org). +# See the COPYRIGHT file at the top-level directory of this distribution +# for details of code ownership. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from lsst.rubintv.production.soarSeeing import SoarUploader +from lsst.rubintv.production.utils import getDoRaise + +uploader = SoarUploader(doRaise=getDoRaise()) + +uploader.run()