-
Notifications
You must be signed in to change notification settings - Fork 2
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-37193: Reorganize vectorActions #108
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
39c39c4
Sort basic vectorActions
taranu b53f53d
Move math vectorActions to mathActions
taranu 389e4aa
Add AddVector and MultiplyVector
taranu e42f2b4
Add Add/MultiplyVector unit tests
taranu 2130f5b
Rename MagColumnNanoJansky to ConvertFluxToMags
taranu 92e6bdc
Add fluxUnit to ConvertFluxToMags
taranu 1dbf72d
Merge SNCalculator and Sn into CalcSn
taranu 40c44e7
Sort vectorActions somewhat logically
taranu File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# TODO: Any way to avoid this causing a circular import? | ||
# from .calcBinnedStats import CalcBinnedStatsAction | ||
from .calcRhoStatistics import * | ||
from .calcShapeSize import CalcShapeSize | ||
from .ellipticity import * | ||
from .mathActions import * | ||
from .selectors import * | ||
from .vectorActions import * |
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
132 changes: 132 additions & 0 deletions
132
python/lsst/analysis/tools/actions/vector/mathActions.py
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,132 @@ | ||
# 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__ = ( | ||
"ConstantValue", | ||
"AddVector", | ||
"SubtractVector", | ||
"DivideVector", | ||
"MultiplyVector", | ||
"FractionalDifference", | ||
) | ||
|
||
import logging | ||
|
||
import numpy as np | ||
from lsst.pex.config import Field | ||
from lsst.pex.config.configurableActions import ConfigurableActionField | ||
|
||
from ...interfaces import KeyedData, KeyedDataSchema, Vector, VectorAction | ||
|
||
_LOG = logging.getLogger(__name__) | ||
|
||
|
||
class ConstantValue(VectorAction): | ||
"""Return a constant scalar value.""" | ||
|
||
value = Field[float](doc="A single constant value", optional=False) | ||
|
||
def getInputSchema(self) -> KeyedDataSchema: | ||
return () | ||
|
||
def __call__(self, data: KeyedData, **kwargs) -> Vector: | ||
return np.array([self.value]) | ||
|
||
|
||
class AddVector(VectorAction): | ||
"""Calculate (A+B).""" | ||
|
||
actionA = ConfigurableActionField[VectorAction](doc="Action which supplies vector A") | ||
actionB = ConfigurableActionField[VectorAction](doc="Action which supplies vector B") | ||
|
||
def getInputSchema(self) -> KeyedDataSchema: | ||
yield from self.actionA.getInputSchema() # type: ignore | ||
yield from self.actionB.getInputSchema() # type: ignore | ||
|
||
def __call__(self, data: KeyedData, **kwargs) -> Vector: | ||
vecA = self.actionA(data, **kwargs) # type: ignore | ||
vecB = self.actionB(data, **kwargs) # type: ignore | ||
return vecA + vecB | ||
|
||
|
||
class SubtractVector(VectorAction): | ||
"""Calculate (A-B).""" | ||
|
||
actionA = ConfigurableActionField[VectorAction](doc="Action which supplies vector A") | ||
actionB = ConfigurableActionField[VectorAction](doc="Action which supplies vector B") | ||
|
||
def getInputSchema(self) -> KeyedDataSchema: | ||
yield from self.actionA.getInputSchema() # type: ignore | ||
yield from self.actionB.getInputSchema() # type: ignore | ||
|
||
def __call__(self, data: KeyedData, **kwargs) -> Vector: | ||
vecA = self.actionA(data, **kwargs) # type: ignore | ||
vecB = self.actionB(data, **kwargs) # type: ignore | ||
return vecA - vecB | ||
|
||
|
||
class MultiplyVector(VectorAction): | ||
"""Calculate (A*B)""" | ||
|
||
actionA = ConfigurableActionField[VectorAction](doc="Action which supplies vector A") | ||
actionB = ConfigurableActionField[VectorAction](doc="Action which supplies vector B") | ||
|
||
def getInputSchema(self) -> KeyedDataSchema: | ||
yield from self.actionA.getInputSchema() # type: ignore | ||
yield from self.actionB.getInputSchema() # type: ignore | ||
|
||
def __call__(self, data: KeyedData, **kwargs) -> Vector: | ||
vecA = self.actionA(data, **kwargs) # type: ignore | ||
vecB = self.actionB(data, **kwargs) # type: ignore | ||
return vecA * vecB | ||
|
||
|
||
class DivideVector(VectorAction): | ||
"""Calculate (A/B)""" | ||
|
||
actionA = ConfigurableActionField[VectorAction](doc="Action which supplies vector A") | ||
actionB = ConfigurableActionField[VectorAction](doc="Action which supplies vector B") | ||
|
||
def getInputSchema(self) -> KeyedDataSchema: | ||
yield from self.actionA.getInputSchema() # type: ignore | ||
yield from self.actionB.getInputSchema() # type: ignore | ||
|
||
def __call__(self, data: KeyedData, **kwargs) -> Vector: | ||
vecA = self.actionA(data, **kwargs) # type: ignore | ||
vecB = self.actionB(data, **kwargs) # type: ignore | ||
return vecA / vecB | ||
|
||
|
||
class FractionalDifference(VectorAction): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most vector actions in the |
||
"""Calculate (A-B)/B.""" | ||
|
||
actionA = ConfigurableActionField[VectorAction](doc="Action which supplies vector A") | ||
actionB = ConfigurableActionField[VectorAction](doc="Action which supplies vector B") | ||
|
||
def getInputSchema(self) -> KeyedDataSchema: | ||
yield from self.actionA.getInputSchema() # type: ignore | ||
yield from self.actionB.getInputSchema() # type: ignore | ||
|
||
def __call__(self, data: KeyedData, **kwargs) -> Vector: | ||
vecA = self.actionA(data, **kwargs) # type: ignore | ||
vecB = self.actionB(data, **kwargs) # type: ignore | ||
return (vecA - vecB) / vecB |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most vector actions in the
mathActions
file end with the suffixVector
(all except here andFractionalDifference
). Is it worth considering making that consistent here too? E.g.,ConstantVector
?ConstantValueVector
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was actually considering renaming it to
Scalar
something rather thanConstant
something, but decided against it.But to the extent that there is a naming scheme, the
Vector
-suffixed actions all begin with verbs (see alsoLoadVector
andDownselectVector
invectorActions.py
), whereas the unsuffixed actions are nouns (ConstantValue
,MagDiff
as short forMagnitudeDifference
, etc). In principle you could verbify the variousDiff(erence)
actions since difference is a verb too, but I don't think the names would be any clearer. ForConstantValue
, I can't think of a good way to verbify it at all.ReturnScalar
? Actually,LoadScalar
would be consistent withLoadVector
, even though it's not really loading anything.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. In which case, I suggest leaving this (and the other non-conformant action here) as-is for the time being. Further changes can be punted to a future ticket, if desired.