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

DM-46061: Add Metrics to calibrate task metadata #282

Merged
merged 3 commits into from
Oct 6, 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
29 changes: 29 additions & 0 deletions pipelines/calexpMetrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,32 @@ tasks:
config:
atools.calexpSummaryMetrics: CalexpSummaryMetrics
python: from lsst.analysis.tools.atools import *
analyzeCalibrateMetadata:
class: lsst.analysis.tools.tasks.MetadataAnalysisTask
config:
connections.taskName: calibrate
connections.outputName: calibrate_metadata
metadataDimensions: ["instrument", "visit", "detector"]
atools.calexpMetadataMetrics: MetadataMetricTool
atools.calexpMetadataMetrics.taskName: calibrate
atools.calexpMetadataMetrics.metrics:
positive_footprint_count: ct
negative_footprint_count: ct
source_count: ct
sky_footprint_count: ct
saturated_source_count: ct
bad_source_count: ct
bad_mask_fraction: ''
cr_mask_fraction: ''
crosstalk_mask_fraction: ''
edge_mask_fraction: ''
intrp_mask_fraction: ''
no_data_mask_fraction: ''
detected_mask_fraction: ''
detected_negative_mask_fraction: ''
sat_mask_fraction: ''
streak_mask_fraction: ''
suspect_mask_fraction: ''
unmaskednan_mask_fraction: ''
python: |
from lsst.analysis.tools.atools import MetadataMetricTool
1 change: 1 addition & 0 deletions python/lsst/analysis/tools/atools/metadataMetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class MetadataMetricTool(AnalysisTool):
doc="The name of the subtask to extract metadata from. "
"If None, the entire task metadata will be used.",
default=None,
optional=True,
)

metrics = DictField[str, str](
Expand Down
1 change: 1 addition & 0 deletions python/lsst/analysis/tools/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .gatherResourceUsage import *
from .injectedObjectAnalysis import *
from .makeMetricTable import *
from .metadataAnalysis import *
from .metadataExposureDetectorAnalysis import *
from .metricAnalysis import *
from .objectTableSurveyAnalysis import *
Expand Down
91 changes: 91 additions & 0 deletions python/lsst/analysis/tools/tasks/metadataAnalysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# This file is part of analysis_tools.
#
# Developed for the LSST Data Management System.
# This product includes software developed by the LSST Project
# (https://www.lsst.org).
# See the COPYRIGHT file at the top-level directory of this distribution
# for details of code ownership.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from __future__ import annotations

__all__ = ("MetadataAnalysisConfig", "MetadataAnalysisTask")

import lsst.pex.config
from lsst.pipe.base import NoWorkFound, connectionTypes

from ..interfaces import AnalysisBaseConfig, AnalysisBaseConnections, AnalysisPipelineTask


class MetadataAnalysisConnections(
AnalysisBaseConnections,
dimensions={"instrument", "exposure", "detector"},
defaultTemplates={"taskName": "isr"},
):
data = connectionTypes.Input(
doc="Task metadata to load.",
name="{taskName}_metadata",
storageClass="TaskMetadata",
deferLoad=True,
jrmullaney marked this conversation as resolved.
Show resolved Hide resolved
dimensions={"instrument", "exposure", "detector"},
)

def __init__(self, *, config=None):
"""Customize the connections for a specific task's metadata.

Parameters
----------
config : `MetadataMetricConfig`
A config for `MetadataMetricTask` or one of its subclasses.
"""
super().__init__(config=config)
if config and config.metadataDimensions != self.data.dimensions:
self.dimensions.clear()
self.dimensions.update(config.metadataDimensions)
self.data = connectionTypes.Input(
name=self.data.name,
doc=self.data.doc,
storageClass=self.data.storageClass,
deferLoad=self.data.deferLoad,
dimensions=frozenset(config.metadataDimensions),
)


class MetadataAnalysisConfig(
AnalysisBaseConfig,
pipelineConnections=MetadataAnalysisConnections,
):
metadataDimensions = lsst.pex.config.ListField(
# Sort to ensure default order is consistent between runs
default=sorted(MetadataAnalysisConnections.dimensions),
dtype=str,
doc="Override for the dimensions of the input data.",
)


class MetadataAnalysisTask(AnalysisPipelineTask):
ConfigClass = MetadataAnalysisConfig
_DefaultName = "metadataAnalysis"

def runQuantum(self, butlerQC, inputRefs, outputRefs):
dataId = butlerQC.quantum.dataId
inputs = butlerQC.get(inputRefs)
plotInfo = self.parsePlotInfo(inputs, dataId)
metadata = inputs["data"].get().to_dict()
if not metadata:
taskName = inputRefs.data.datasetType.name
taskName = taskName[: taskName.find("_")]
raise NoWorkFound(f"No metadata entries for {taskName}.")
outputs = self.run(data=metadata, plotInfo=plotInfo)
butlerQC.put(outputs, outputRefs)
Loading