Skip to content

Commit

Permalink
Add SOAR seeing scraping and plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
mfisherlevine committed Dec 2, 2024
1 parent 12edf95 commit 868daa1
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 0 deletions.
74 changes: 74 additions & 0 deletions python/lsst/rubintv/production/soarSeeing.py
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
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)
26 changes: 26 additions & 0 deletions scripts/summit/misc/runSoarSeeingScraper.py
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

from lsst.summit.extras.soarSeeing import SoarDatabaseBuiler

scraper = SoarDatabaseBuiler()

scraper.run()
27 changes: 27 additions & 0 deletions scripts/summit/misc/runSoarSeeingUploader.py
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

from lsst.rubintv.production.soarSeeing import SoarUploader
from lsst.rubintv.production.utils import getDoRaise

uploader = SoarUploader(doRaise=getDoRaise())

uploader.run()

0 comments on commit 868daa1

Please sign in to comment.