-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #418 from lsst/tickets/PREOPS-5360
tickets/PREOPS-5360: clean up the nightsum and prenight Times Square notebooks by updating schedview to support them better
- Loading branch information
Showing
5 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters