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-41811: Add pre-commit and update doc build #7

Merged
merged 7 commits into from
Jan 3, 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
31 changes: 31 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
default_language_version:
python: python3

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.3.0
hooks:
- id: black
# It is recommended to specify the latest version of Python
# supported by your project here, or alternatively use
# pre-commit's default_language_version, see
# https://pre-commit.com/#top_level-default_language_version
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.8
hooks:
- id: ruff
- repo: https://github.com/numpy/numpydoc
rev: "v1.6.0"
hooks:
- id: numpydoc-validation
22 changes: 17 additions & 5 deletions doc/lsst.meas.extensions.multiprofit/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ lsst.meas.extensions.multiprofit
.. Using lsst.meas.extensions.multiprofit
.. ======================================

There is currently one master task, which is a subtask of a generic multiband
fitting ``lsst.pipe.tasks.PipelineTask`` (``lsst.pipe.tasks.fit_multiband.MultibandFitTask``); future tasks will likely follow this pattern.
``lsst.meas.extensions.multiprofit`` implements separate tasks for PSF and source model fitting
using ``lsst.multiprofit``. The tasks depend on more generic ``lsst.pipe.tasks.PipelineTask``
classes defined in ``lsst.pipe.tasks.fit_coadd_psf`` and ``lsst.pipe.tasks.fit_coadd_multiband``.
Note that as implied by the names, the PSF fitting task is single-band only.

Because these tasks produce patch-based Arrow/Astropy tables, a generic task to consolidate
the results into a single multiband tract-based table is also provided. It is anticipated that
this functionality will be folded into the tasks producing objectTable_tract instances in
``lsst.pipe.tasks.postprocess``.

.. toctree linking to topics related to using the module's APIs.

Expand All @@ -28,7 +35,7 @@ Contributing
============

``lsst.meas.extensions.multiprofit`` is developed at https://github.com/lsst-dm/meas_extensions_multiprofit.
You can find Jira issues for this module under the `meas_extensions_multiprofit <https://jira.lsstcorp.org/issues/?jql=project%20%3D%20DM%20AND%20component%20%3D%20meas_extensions_multiprofit>`_ component.
You can find Jira issues for multiprofit through `search <https://jira.lsstcorp.org/issues/?jql=text%20~%20%22multiprofit%22>`_.

.. If there are topics related to developing this module (rather than using it), link to this from a toctree placed here.

Expand Down Expand Up @@ -89,6 +96,11 @@ Configurations
Python API reference
====================

.. automodapi:: lsst.meas.extensions.multiprofit
:no-main-docstr:
.. automodapi:: lsst.meas.extensions.multiprofit.consolidate_astropy_table
:no-inheritance-diagram:

.. automodapi:: lsst.meas.extensions.multiprofit.fit_coadd_multiband
:no-inheritance-diagram:

.. automodapi:: lsst.meas.extensions.multiprofit.fit_coadd_psf
:no-inheritance-diagram:
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,18 @@ max-doc-length = 79

[tool.ruff.pydocstyle]
convention = "numpy"

[tool.numpydoc_validation]
checks = [
"all", # All except the rules listed below.
"ES01", # No extended summary required.
"EX01", # Example section.
"GL01", # Summary text can start on same line as """
"GL08", # Do not require docstring.
"PR04", # numpydoc parameter types are redundant with type hints
"RT01", # Unfortunately our @property trigger this.
"RT02", # Does not want named return value. DM style says we do.
"SA01", # See Also section.
"SS05", # pydocstyle is better at finding infinitive verb.
"SS06", # Summary can go into second line.
]
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
# 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 collections import defaultdict

import astropy.table as apTab
import lsst.pex.config as pexConfig
from lsst.pex.config.configurableActions import ConfigurableAction, ConfigurableActionField
import lsst.pipe.base as pipeBase
import lsst.pipe.base.connectionTypes as connectionTypes

import astropy.table as apTab
from collections import defaultdict
import numpy as np
from lsst.pex.config.configurableActions import ConfigurableAction, ConfigurableActionField


class CatalogAction(ConfigurableAction):
Expand Down Expand Up @@ -90,7 +90,7 @@ def __call__(self, data, **kwargs):


class InputConfig(pexConfig.Config):
"""Config for inputs to ConsolidateAstropyTableTask"""
"""Config for inputs to ConsolidateAstropyTableTask."""

doc = pexConfig.Field[str](doc="Doc for connection", optional=False)
action = ConfigurableActionField[CatalogAction](
Expand All @@ -107,7 +107,7 @@ class InputConfig(pexConfig.Config):


class ConsolidateAstropyTableConfigBase(pexConfig.Config):
"""Config for ConsolidateAstropyTableTask"""
"""Config for ConsolidateAstropyTableTask."""

inputs = pexConfig.ConfigDictField(
doc="Mapping of input dataset type config by name",
Expand All @@ -117,8 +117,12 @@ class ConsolidateAstropyTableConfigBase(pexConfig.Config):
)


class ConsolidateAstropyTableConnections(pipeBase.PipelineTaskConnections, dimensions=("tract", "skymap")):
"""Connections for ConsolidateAstropyTableTask"""
class ConsolidateAstropyTableConnections(
# Ignore the undocumented inherited config arg in __init__
pipeBase.PipelineTaskConnections,
dimensions=("tract", "skymap"), # numpydoc ignore=PR01
):
"""Connections for ConsolidateAstropyTableTask."""

cat_output = connectionTypes.Output(
doc="Per-tract horizontal concatenation of the input AstropyTables",
Expand Down Expand Up @@ -154,7 +158,7 @@ class ConsolidateAstropyTableConfig(
ConsolidateAstropyTableConfigBase,
pipelineConnections=ConsolidateAstropyTableConnections,
):
"""PipelineTaskConfig for ConsolidateAstropyTableTask"""
"""PipelineTaskConfig for ConsolidateAstropyTableTask."""


class ConsolidateAstropyTableTask(pipeBase.PipelineTask):
Expand Down
27 changes: 15 additions & 12 deletions python/lsst/meas/extensions/multiprofit/fit_coadd_multiband.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,18 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import math
import numpy as np
import pydantic
from pydantic.dataclasses import dataclass
from typing import Any, Mapping, Sequence
from typing import Any, Mapping, Sequence, Type

import gauss2d as g2
import gauss2d.fit as g2f

from lsst.daf.butler.formatters.parquet import astropy_to_arrow
import lsst.geom as geom
import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase
import lsst.pipe.tasks.fit_coadd_multiband as fitMB
import lsst.utils.timer as utilsTimer

import numpy as np
import pydantic
from lsst.daf.butler.formatters.parquet import astropy_to_arrow
from lsst.multiprofit.config import set_config_from_dict
from lsst.multiprofit.fit_psf import CatalogPsfFitterConfig, PsfRebuildFitFlagError
from lsst.multiprofit.fit_source import (
Expand All @@ -43,19 +40,18 @@
CatalogSourceFitterConfig,
)
from lsst.multiprofit.utils import get_params_uniq

from typing import Type
from pydantic.dataclasses import dataclass

from .utils import get_spanned_image


class NotPrimaryError(RuntimeError):
"""RuntimeError for sources that are not primary and shouldn't be fit"""
"""RuntimeError for sources that are not primary and shouldn't be fit."""


@dataclass(frozen=True, kw_only=True, config=fitMB.CatalogExposureConfig)
class CatalogExposurePsfs(fitMB.CatalogExposureInputs, CatalogExposureSourcesABC):
"""Input data from lsst pipelines, parsed for MultiProFit"""
"""Input data from lsst pipelines, parsed for MultiProFit."""

channel: g2f.Channel = pydantic.Field(title="Channel for the image's band")
config_fit: CatalogSourceFitterConfig = pydantic.Field(title="Channel for the image's band")
Expand Down Expand Up @@ -141,6 +137,11 @@ class MultiProFitSourceTask(CatalogSourceFitterABC, fitMB.CoaddMultibandFitSubTa
prior measurements from single- or merged multiband catalogs for
initialization.

Parameters
----------
**kwargs
Keyword arguments to pass to CoaddMultibandFitSubTask.__init__.

Notes
-----
See https://github.com/lsst-dm/multiprofit for more MultiProFit info.
Expand All @@ -149,7 +150,7 @@ class MultiProFitSourceTask(CatalogSourceFitterABC, fitMB.CoaddMultibandFitSubTa
ConfigClass = MultiProFitSourceConfig
_DefaultName = "multiProFitSource"

def __init__(self, **kwargs):
def __init__(self, **kwargs: Any):
errors_expected = {} if "errors_expected" not in kwargs else kwargs.pop("errors_expected")
if NotPrimaryError not in errors_expected:
errors_expected[NotPrimaryError] = "not_primary_flag"
Expand All @@ -172,6 +173,8 @@ def _init_component(
The component to initialize.
values_init
Initial values to set per parameter type.
limits_init
Initial limits to set per parameter type.
"""
# These aren't necessarily all free - should set cen_x, y
# even if they're fixed, for example
Expand Down
13 changes: 8 additions & 5 deletions python/lsst/meas/extensions/multiprofit/fit_coadd_psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@
# 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 pydantic.dataclasses import dataclass

from lsst.daf.butler.formatters.parquet import astropy_to_arrow
import lsst.pex.config as pexConfig
from lsst.pex.exceptions import InvalidParameterError
import lsst.pipe.base as pipeBase
import lsst.pipe.tasks.fit_coadd_psf as fitCP
import lsst.utils.timer as utilsTimer

from lsst.daf.butler.formatters.parquet import astropy_to_arrow
from lsst.multiprofit.fit_psf import CatalogExposurePsfABC, CatalogPsfFitter, CatalogPsfFitterConfig
from lsst.pex.exceptions import InvalidParameterError
from pydantic.dataclasses import dataclass


@dataclass(frozen=True, kw_only=True, config=fitCP.CatalogExposureConfig)
Expand All @@ -53,6 +51,11 @@ class MultiProFitPsfTask(CatalogPsfFitter, fitCP.CoaddPsfFitSubTask):
evaluated at the centroid of each source in the corresponding
catalog.

Parameters
----------
**kwargs
Keyword arguments to pass to CoaddPsfFitSubTask.__init__.

Notes
-----
See https://github.com/lsst-dm/multiprofit for more MultiProFit info.
Expand Down
Loading