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-47990: Create a new action group dedicated to HealSparse maps and relocate LoadHealSparseMap() from tools to actions #342

Merged
merged 1 commit into from
Feb 6, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .healSparseMapActions import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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__ = ("LoadHealSparseMap",)

from typing import cast

from healsparse.healSparseMap import HealSparseMap
from lsst.pex.config import Field

from ...interfaces import HealSparseMapAction, KeyedData, KeyedDataSchema


class LoadHealSparseMap(HealSparseMapAction):
"""Load and return a HealSparseMap from KeyedData."""

mapKey = Field[str](doc="Key of map which should be loaded.")

def getInputSchema(self) -> KeyedDataSchema:
return ((self.mapKey, HealSparseMap),)

def __call__(self, data: KeyedData, **kwargs) -> HealSparseMap:
return cast(HealSparseMap, data[self.mapKey])
18 changes: 2 additions & 16 deletions python/lsst/analysis/tools/atools/healSparsePropertyMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,11 @@
"SurveyWidePropertyMapTool",
)

from typing import cast

from healsparse.healSparseMap import HealSparseMap
from lsst.pex.config import Field

from ..actions.healSparseMap.healSparseMapActions import LoadHealSparseMap
from ..actions.plot.propertyMapPlot import PerTractPropertyMapPlot, SurveyWidePropertyMapPlot
from ..interfaces import AnalysisAction, AnalysisTool, KeyedData, KeyedDataSchema


class LoadHealSparseMap(AnalysisAction):
"""Load and return a HealSparseMap from KeyedData."""

mapKey = Field[str](doc="Key of map which should be loaded.")

def getInputSchema(self) -> KeyedDataSchema:
return ((self.mapKey, HealSparseMap),)

def __call__(self, data: KeyedData, **kwargs) -> HealSparseMap:
return cast(HealSparseMap, data[self.mapKey])
from ..interfaces import AnalysisTool


class PerTractPropertyMapTool(AnalysisTool):
Expand Down
12 changes: 12 additions & 0 deletions python/lsst/analysis/tools/interfaces/_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

__all__ = (
"AnalysisAction",
"HealSparseMapAction",
"KeyedDataAction",
"VectorAction",
"ScalarAction",
Expand All @@ -43,6 +44,7 @@
from typing import TYPE_CHECKING, Iterable

import lsst.pex.config as pexConfig
from healsparse.healSparseMap import HealSparseMap
from lsst.pex.config.configurableActions import ConfigurableAction, ConfigurableActionField

from ..contexts import ContextApplier
Expand Down Expand Up @@ -139,6 +141,16 @@ def addInputSchema(self, inputSchema: KeyedDataSchema) -> None:
)


class HealSparseMapAction(AnalysisAction):
"""A `HealSparseMapAction` is an `AnalysisAction` that returns a
`HealSparseMap` when called.
"""

@abstractmethod
def __call__(self, data: KeyedData, **kwargs) -> HealSparseMap:
raise NotImplementedError("This is not implemented on the base class")


class KeyedDataAction(AnalysisAction):
"""A `KeyedDataAction` is an `AnalysisAction` that returns `KeyedData` when
called.
Expand Down
Loading