Skip to content

Commit

Permalink
Add ability to dispatch metrics to Sasquatch
Browse files Browse the repository at this point in the history
This commit adds the ability to dispatch MetricMeasurementBundles
to the Sasquatch service. This can be done either with the
SasquatchDisaptcher class, or more commonly using a butler
datastore that will automatically dispatch them when put to the
datastore. There are a few other cleanups on this commit that were
made either to support this work, or that were found in the
process of doing this ticket.
  • Loading branch information
natelust committed May 3, 2023
1 parent 56d535e commit 87ab7a8
Show file tree
Hide file tree
Showing 12 changed files with 1,000 additions and 32 deletions.
1 change: 0 additions & 1 deletion python/lsst/analysis/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,5 @@
from the object itself, which allows
"""

from .interfaces import *
from .statistics import *
from .version import * # Generated by sconsUtils
3 changes: 1 addition & 2 deletions python/lsst/analysis/tools/actions/plot/colorColorFitPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@
import matplotlib.patheffects as pathEffects
import matplotlib.pyplot as plt
import numpy as np
from lsst.analysis.tools import PlotAction
from lsst.pex.config import Field, ListField
from matplotlib.figure import Figure
from matplotlib.patches import Rectangle
from sklearn.neighbors import KernelDensity

from ...interfaces import KeyedData, KeyedDataSchema, Scalar, Vector
from ...interfaces import KeyedData, KeyedDataSchema, PlotAction, Scalar, Vector
from ...statistics import sigmaMad
from .plotUtils import addPlotInfo, mkColormap, perpDistance

Expand Down
2 changes: 2 additions & 0 deletions python/lsst/analysis/tools/interfaces/_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"PlotAction",
"JointResults",
"JointAction",
"NoMetric",
"NoPlot",
)

import warnings
Expand Down
16 changes: 0 additions & 16 deletions python/lsst/analysis/tools/interfaces/_analysisTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,6 @@ class AnalysisTool(AnalysisAction):
metric_tags = ListField[str](
doc="List of tags which will be associated with metric measurement(s)", default=[]
)
dataset_identifier = Field[str](doc="An identifier to be associated with output Metrics", optional=True)
reference_package = Field[str](
doc="A package who's version, at the time of metric upload to a "
"time series database, will be converted to a timestamp of when "
"that version was produced",
default="lsst_distrib",
)
timestamp_version = Field[str](
doc="Which time stamp should be used as the reference timestamp for a "
"metric in a time series database, valid values are; "
"reference_package_timestamp, run_timestamp, current_timestamp, "
"and dataset_timestamp",
default="run_timestamp",
check=lambda x: x
in ("reference_package_timestamp", "run_timestamp", "current_timestamp", "dataset_timestamp"),
)

def __init_subclass__(cls: type[AnalysisTool], **kwargs):
super().__init_subclass__(**kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class MetricMeasurementBundle(UserDict[str, list[Measurement]]):
"""

def __init__(self, *args, **kwargs):
self.reference_package: str | None = kwargs.pop("reference_package", None)
self.timestamp_version: str | None = kwargs.pop("timestamp_version", None)
self.dataset_identifier: str | None = kwargs.pop("dataset_identifier", None)
super().__init__(*args, **kwargs)
self.reference_package: str | None = None
self.timestamp_version: str | None = None
self.dataset_identifier: str | None = None

def json(self) -> str:
result = {}
Expand Down
12 changes: 5 additions & 7 deletions python/lsst/analysis/tools/interfaces/_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,6 @@ def freeze(self):
for tool in self.atools:
for tag in self.metric_tags:
tool.metric_tags.insert(-1, tag)
if tool.dataset_identifier is None:
tool.dataset_identifier = self.dataset_identifier
if tool.reference_package == "lsst_distrib":
tool.reference_package = self.reference_package
if tool.timestamp_version == "run_timestamp":
tool.timestamp_version = self.timestamp_version
super().freeze()

def validate(self):
Expand Down Expand Up @@ -245,7 +239,11 @@ class AnalysisPipelineTask(PipelineTask):

def _runTools(self, data: KeyedData, **kwargs) -> Struct:
results = Struct()
results.metrics = MetricMeasurementBundle() # type: ignore
results.metrics = MetricMeasurementBundle(
dataset_identifier=self.config.dataset_identifier,
reference_package=self.config.reference_package,
timestamp_version=self.config.timestamp_version,
)
# copy plot info to be sure each action sees its own copy
plotInfo = kwargs.get("plotInfo")
plotKey = f"{self.config.connections.outputName}_{{name}}"
Expand Down
2 changes: 2 additions & 0 deletions python/lsst/analysis/tools/interfaces/datastore/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from ._dispatcher import *
from ._sasquatchDatastore import *

0 comments on commit 87ab7a8

Please sign in to comment.