Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tickets/PREOPS-5360: clean up the nightsum and prenight Times Square notebooks by updating schedview to support them better #418

Merged
merged 4 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading