Skip to content

Commit

Permalink
Merge pull request #418 from lsst/tickets/PREOPS-5360
Browse files Browse the repository at this point in the history
tickets/PREOPS-5360: clean up the nightsum and prenight Times Square notebooks by updating schedview to support them better
  • Loading branch information
ehneilsen committed Aug 23, 2024
2 parents 071a912 + 8681919 commit 9f3e0c5
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
1 change: 1 addition & 0 deletions rubin_sim/maf/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from .phase_gap_metric import *
from .qso_number_counts_metric import *
from .scaling_metrics import *
from .schedview_metrics import *
from .season_metrics import *
from .simple_metrics import *
from .sky_sat_metric import *
Expand Down
39 changes: 39 additions & 0 deletions rubin_sim/maf/metrics/schedview_metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Metrics for scheduler monitoring and progress."""

__all__ = ["AgeMetric"]

import numpy as np

from .base_metric import BaseMetric


class AgeMetric(BaseMetric):
def __init__(
self, mjd, mjd_col="observationStartMJD", long_limit=30, metric_name="age", mask_val=np.nan, **kwargs
):
"""Metric that shows the time since the previous visit in each slice,
as of a given time
Parameters
----------
mjd : `float`
Reference time for the age.
mjd_col : `str`
Column with the time of visit, by default "observationStartMJD"
long_limit : `int`
The age past which to mask values, by default 30
metric_name : `str`
The metric name, by default 'age'
mask_val : `object`
Name for masked values, by default np.nan
"""
self.mjd = mjd
self.mjd_col = mjd_col
self.long_limit = long_limit
super().__init__(col=[self.mjd_col], metric_name=metric_name, mask_val=mask_val, **kwargs)

def run(self, data_slice, slice_point=None):
age = self.mjd - np.max(data_slice[self.mjd_col])
if age > self.long_limit:
age = self.mask_val
return age
2 changes: 1 addition & 1 deletion rubin_sim/maf/stackers/teff_stacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def __init__(
self.normed = normed
self.fiducial_depth = TEFF_FIDUCIAL_DEPTH if fiducial_depth is None else fiducial_depth
self.fiducial_exptime = TEFF_FIDUCIAL_EXPTIME if fiducial_exptime is None else fiducial_exptime
self.cols_req = [self.m5_col, self.filter_col]
self.cols_req = [self.m5_col, self.filter_col, self.exptime_col]
if self.normed and self.exptime_col not in self.cols_req:
self.cols_req.append(self.exptime_col)

Expand Down
14 changes: 14 additions & 0 deletions tests/maf/test_schedviewmetrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import unittest

import numpy as np

import rubin_sim.maf.metrics as metrics


class TestSchedviewMetrics(unittest.TestCase):
def test_age_metric(self):
data = np.rec.fromrecords([(1, 60000)], names="id,observationStartMJD")

assert metrics.AgeMetric(60002).run(data) == 2
assert metrics.AgeMetric(60002.5).run(data) == 2.5
assert np.isnan(metrics.AgeMetric(70000.0).run(data))
2 changes: 1 addition & 1 deletion tests/maf/test_snmetrics_nsn.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def setUp(self):
if not os.path.isfile(testfile):
raise FileExistsError("%s not found" % testfile)
self.simdata = {}
with pd.HDFStore(testfile) as f:
with pd.HDFStore(testfile, mode="r") as f:
keys = f.keys()
for k in keys:
newkey = k.lstrip("/")
Expand Down

0 comments on commit 9f3e0c5

Please sign in to comment.