Skip to content

Commit

Permalink
Merge pull request #92 from lsst-sitcom/tickets/DM-43213
Browse files Browse the repository at this point in the history
DM-43213: Patch StarTracker headers to pick up pressure
  • Loading branch information
mfisherlevine committed Mar 7, 2024
2 parents 9c53239 + 8e795f2 commit f7cef97
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
19 changes: 17 additions & 2 deletions python/lsst/summit/utils/astrometry/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import copy
import logging

import astropy.units as u
import matplotlib.pyplot as plt
Expand All @@ -33,7 +34,9 @@
# TODO: Add some of Craig's nice overlay stuff here


def plot(exp, icSrc=None, filteredSources=None, saveAs=None, clipMin=1, clipMax=1000000, doSmooth=True):
def plot(
exp, icSrc=None, filteredSources=None, saveAs=None, clipMin=1, clipMax=1000000, doSmooth=True, fig=None
):
"""Plot an exposure, overlaying the selected sources and compass arrows.
Plots the exposure on a logNorm scale, with the brightest sources, as
Expand All @@ -58,8 +61,20 @@ def plot(exp, icSrc=None, filteredSources=None, saveAs=None, clipMin=1, clipMax=
Clip values in the image above this value to ``clipMax``.
doSmooth : `bool`, optional
Smooth the image slightly to improve the visability of low SNR sources?
fig : `matplotlib.figure.Figure`, optional
The figure to plot on. If not supplied, a new figure is created.
"""
fig = plt.figure(figsize=(16, 16))
if fig is None:
log = logging.getLogger(__name__)
log.warning(
"No figure supplied, creating a new one -"
" if you see this in a loop you're going to have a bad time"
)
fig = plt.figure(figsize=(16, 16))
fig.clear()
ax = fig.gca()
ax.clear()

data = copy.deepcopy(exp.image.array)
data = np.clip(data, clipMin, clipMax)
if doSmooth:
Expand Down
22 changes: 20 additions & 2 deletions python/lsst/summit/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import lsst.geom as geom
import lsst.pipe.base as pipeBase
import lsst.utils.packages as packageUtils
from lsst.afw.coord import Weather
from lsst.afw.detection import Footprint, FootprintSet
from lsst.daf.butler.cli.cliLog import CliLog
from lsst.obs.lsst.translators.latiss import AUXTEL_LOCATION
Expand Down Expand Up @@ -821,14 +822,31 @@ def starTrackerFileToExposure(filename, logger=None):
# stripped out and somehow not set (plus it doesn't give the midpoint
# of the exposure), so set it manually from the midpoint here
try:
newArgs = {} # dict to unpack into visitInfo.copyWith - fill it with whatever needs to be replaced
md = exp.getMetadata()

begin = datetime.datetime.fromisoformat(md["DATE-BEG"])
end = datetime.datetime.fromisoformat(md["DATE-END"])
duration = end - begin
mid = begin + duration / 2
newTime = dafBase.DateTime(mid.isoformat(), dafBase.DateTime.Timescale.TAI)
newVi = exp.visitInfo.copyWith(date=newTime)
exp.info.setVisitInfo(newVi)
newArgs["date"] = newTime

# AIRPRESS is being set as PRESSURE so afw doesn't pick it up
# once we're using the butler for data we will just set it to take
# PRESSURE in the translator instead of this
weather = exp.visitInfo.getWeather()
oldPressure = weather.getAirPressure()
if not np.isfinite(oldPressure):
pressure = md.get("PRESSURE")
if pressure is not None:
logger.info("Patching the weather info using the PRESSURE header keyword")
newWeather = Weather(weather.getAirTemperature(), pressure, weather.getHumidity())
newArgs["weather"] = newWeather

if newArgs:
newVi = exp.visitInfo.copyWith(**newArgs)
exp.info.setVisitInfo(newVi)
except Exception as e:
logger.warning(f"Failed to set date from header: {e}")

Expand Down

0 comments on commit f7cef97

Please sign in to comment.