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

Add AOS FWHM metric #69

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 python/lsst/analysis/tools/actions/vector/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .calcFwhmZernikes import *
from .calcRhoStatistics import *
from .calcShapeSize import CalcShapeSize
from .ellipticity import *
Expand Down
97 changes: 97 additions & 0 deletions python/lsst/analysis/tools/actions/vector/calcFwhmZernikes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# 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__ = ("CalcFwhmZernikesBase", "CalcFwhmZernikesLsst", "CalcFwhmZernikesLatiss")

import numpy as np
from lsst.pex.config import Field
from ...interfaces import KeyedData, KeyedDataSchema, Vector, ScalarAction, Scalar


class CalcFwhmZernikesBase(ScalarAction):

vectorKey = Field[str](doc="Vector on which to compute statistics")
# conversion_factors need to be assigned in daughter class
conversion_factors = None

def getInputSchema(self, **kwargs) -> KeyedDataSchema:
return ((self.vectorKey, Vector),)

def __call__(self, data: KeyedData, **kwargs) -> Scalar:

results = np.sqrt(np.sum((data[self.vectorKey] * self.conversion_factors) ** 2.0))

return results


class CalcFwhmZernikesLsst(CalcFwhmZernikesBase):

conversion_factors = np.array(
[
0.751,
0.271,
0.271,
0.819,
0.819,
0.396,
0.396,
1.679,
0.937,
0.937,
0.517,
0.517,
1.755,
1.755,
1.089,
1.089,
0.635,
0.635,
2.810,
]
)


class CalcFwhmZernikesLatiss(CalcFwhmZernikesBase):

conversion_factors = np.array(
[
3.395,
1.969,
1.969,
4.374,
4.374,
2.802,
2.802,
7.592,
5.726,
5.726,
3.620,
3.620,
8.696,
8.696,
7.146,
7.146,
4.434,
4.434,
12.704,
]
)
1 change: 1 addition & 0 deletions python/lsst/analysis/tools/analysisMetrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# 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 .analysisMetrics import *
from .aosMetrics import *
from .apDiaSourceMetrics import *
from .apSsoMetrics import *
from .limitingMagnitudeMetric import *
Expand Down
54 changes: 54 additions & 0 deletions python/lsst/analysis/tools/analysisMetrics/aosMetrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 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__ = ("ZernikesFwhmMetricLsst", "ZernikesFwhmMetricLatiss")

from ..actions.vector import CalcFwhmZernikesLsst, CalcFwhmZernikesLatiss
from ..interfaces import AnalysisMetric


class ZernikesFwhmMetricLsst(AnalysisMetric):
"""Calculate FWHM from Zernikes for LsstCam."""

def setDefaults(self):
super().setDefaults()

# Calculate FWHM from Zernike Coefficients
self.process.calculateActions.ZernikesFwhmMetric = CalcFwhmZernikesLsst(
vectorKey="zernikeEstimateAvg"
)

self.produce.units = {"ZernikesFwhmMetric": "arcsec"}


class ZernikesFwhmMetricLatiss(AnalysisMetric):
"""Calculate FWHM from Zernikes for LAtiss."""

def setDefaults(self):
super().setDefaults()

# Calculate FWHM from Zernike Coefficients
self.process.calculateActions.ZernikesFwhmMetric = CalcFwhmZernikesLatiss(
vectorKey="zernikeEstimateAvg"
)

self.produce.units = {"ZernikesFwhmMetric": "arcsec"}
1 change: 1 addition & 0 deletions python/lsst/analysis/tools/tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .aosAnalysis import *
from .associatedSourcesTractAnalysis import *
from .catalogMatch import *
from .ccdVisitTableAnalysis import *
Expand Down
50 changes: 50 additions & 0 deletions python/lsst/analysis/tools/tasks/aosAnalysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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__ = ("aosAnalysisConnections", "aosAnalysisConfig", "aosAnalysisTask")

from lsst.pipe.base import connectionTypes as ct

from .base import AnalysisBaseConfig, AnalysisBaseConnections, AnalysisPipelineTask


class aosAnalysisConnections(
AnalysisBaseConnections,
dimensions=("visit", "detector", "instrument"),
):
data = ct.Input(
doc="Zernikes from detector.",
name="zernikeEstimateAvg",
storageClass="NumpyArray",
dimensions=("visit", "detector", "instrument"),
deferLoad=True,
)


class aosAnalysisConfig(AnalysisBaseConfig, pipelineConnections=aosAnalysisConnections):
pass


class aosAnalysisTask(AnalysisPipelineTask):

ConfigClass = aosAnalysisConfig
_DefaultName = "aosAnalysis"
10 changes: 9 additions & 1 deletion python/lsst/analysis/tools/tasks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,15 @@ def loadData(self, handle: DeferredDatasetHandle, names: Iterable[str] | None =
"""
if names is None:
names = self.collectInputNames()
return cast(KeyedData, handle.get(parameters={"columns": names}))

# If input data is a numpy array instead of a catalog
# or dataframe, we need to create an object with keys.
if handle.ref.datasetType.storageClass_name == "NumpyArray":
dataLabel = list(names)[0]
dataDict = {dataLabel: handle.get()}
return cast(KeyedData, dataDict)
else:
return cast(KeyedData, handle.get(parameters={"columns": names}))

def collectInputNames(self) -> Iterable[str]:
"""Get the names of the inputs.
Expand Down