From 6778a151ac5a1e7c4d41bd9bf2913728d357b24b Mon Sep 17 00:00:00 2001 From: Eric Neilsen Date: Tue, 13 Aug 2024 12:50:04 -0700 Subject: [PATCH 1/4] add missing required column in TeffStacker --- rubin_sim/maf/stackers/teff_stacker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rubin_sim/maf/stackers/teff_stacker.py b/rubin_sim/maf/stackers/teff_stacker.py index a89a2e74..fd4d773c 100644 --- a/rubin_sim/maf/stackers/teff_stacker.py +++ b/rubin_sim/maf/stackers/teff_stacker.py @@ -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) From eac10197db729b91d35e182de2830d3366c2eb51 Mon Sep 17 00:00:00 2001 From: Eric Neilsen Date: Tue, 13 Aug 2024 12:51:11 -0700 Subject: [PATCH 2/4] add AgeMetric --- rubin_sim/maf/metrics/__init__.py | 1 + rubin_sim/maf/metrics/schedview_metrics.py | 39 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 rubin_sim/maf/metrics/schedview_metrics.py diff --git a/rubin_sim/maf/metrics/__init__.py b/rubin_sim/maf/metrics/__init__.py index 9a89ff1b..002b201a 100644 --- a/rubin_sim/maf/metrics/__init__.py +++ b/rubin_sim/maf/metrics/__init__.py @@ -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 * diff --git a/rubin_sim/maf/metrics/schedview_metrics.py b/rubin_sim/maf/metrics/schedview_metrics.py new file mode 100644 index 00000000..6702aa16 --- /dev/null +++ b/rubin_sim/maf/metrics/schedview_metrics.py @@ -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 From 99d2c3c9e0a4bf330e64fd27b44630698ffae16b Mon Sep 17 00:00:00 2001 From: Eric Neilsen Date: Tue, 13 Aug 2024 13:20:06 -0700 Subject: [PATCH 3/4] test for AgeMetric --- tests/maf/test_schedviewmetrics.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/maf/test_schedviewmetrics.py diff --git a/tests/maf/test_schedviewmetrics.py b/tests/maf/test_schedviewmetrics.py new file mode 100644 index 00000000..f53274d6 --- /dev/null +++ b/tests/maf/test_schedviewmetrics.py @@ -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)) From 86819196cd30357323317db12a4fb686f50dd623 Mon Sep 17 00:00:00 2001 From: Eric Neilsen Date: Tue, 13 Aug 2024 14:35:41 -0700 Subject: [PATCH 4/4] do not request unnecessary read access to data in TestSNmetrics --- tests/maf/test_snmetrics_nsn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/maf/test_snmetrics_nsn.py b/tests/maf/test_snmetrics_nsn.py index c16e5a3d..7cd3d095 100644 --- a/tests/maf/test_snmetrics_nsn.py +++ b/tests/maf/test_snmetrics_nsn.py @@ -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("/")