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-41362: Add black+isort #32

Merged
merged 7 commits into from
Oct 27, 2023
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
7 changes: 7 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Run this command to always ignore formatting commits in `git blame`
# git config blame.ignoreRevsFile .git-blame-ignore-revs

# Changes to be compliant with black
929500d35832c1d3925e8a91aaca136b59652824
# Changes to be compliant with isort
f30c70860a3b9b1b8a87d83093c95bd3c837e29a
11 changes: 11 additions & 0 deletions .github/workflows/formatting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: check Python formatting

on:
push:
branches:
- main
pull_request: null

jobs:
call-workflow:
uses: lsst/rubin_workflows/.github/workflows/formatting.yaml@main
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.10.1
hooks:
- id: black
language_version: python3.11
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
1 change: 0 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from documenteer.conf.pipelinespkg import *


project = "drp_tasks"
html_theme_options["logotext"] = project
html_title = project
Expand Down
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[tool.isort]
profile = "black"
line_length = 110

[tool.black]
line_length = 110

[tool.lsst_versions]
write_to = "python/lsst/drp_tasks/version.py"
1 change: 1 addition & 0 deletions python/lsst/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import pkgutil

__path__ = pkgutil.extend_path(__path__, __name__)
1 change: 1 addition & 0 deletions python/lsst/drp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import pkgutil

__path__ = pkgutil.extend_path(__path__, __name__)
3 changes: 1 addition & 2 deletions python/lsst/drp/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@
# 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 .version import * # Generated by sconsUtils

from .forcedPhotCoadd import *
from .version import * # Generated by sconsUtils
48 changes: 21 additions & 27 deletions python/lsst/drp/tasks/assemble_chi2_coadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@


import logging
import numpy as np

from lsst.afw.detection import Psf
import lsst.afw.math as afwMath
import lsst.afw.image as afwImage
import lsst.afw.math as afwMath
import lsst.afw.table as afwTable
from lsst.meas.algorithms import SourceDetectionTask
from lsst.meas.base import SkyMapIdGeneratorConfig
import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase
import lsst.pipe.base.connectionTypes as cT

import numpy as np
from lsst.afw.detection import Psf
from lsst.meas.algorithms import SourceDetectionTask
from lsst.meas.base import SkyMapIdGeneratorConfig

log = logging.getLogger(__name__)

Expand All @@ -55,7 +54,7 @@ def calculateKernelSize(sigma: float, nSigmaForKernel: float = 7) -> int:
size:
Size of the smoothing kernel.
"""
return (int(sigma * nSigmaForKernel + 0.5)//2)*2 + 1 # make sure it is odd
return (int(sigma * nSigmaForKernel + 0.5) // 2) * 2 + 1 # make sure it is odd


def convolveImage(image: afwImage.Image, psf: Psf) -> afwImage.Image:
Expand Down Expand Up @@ -97,16 +96,17 @@ def convolveImage(image: afwImage.Image, psf: Psf) -> afwImage.Image:
return convolvedImage.Factory(convolvedImage, bbox, afwImage.PARENT, False)


class AssembleChi2CoaddConnections(pipeBase.PipelineTaskConnections,
dimensions=("tract", "patch", "skymap"),
defaultTemplates={"inputCoaddName": "deep",
"outputCoaddName": "deepChi2"}):
class AssembleChi2CoaddConnections(
pipeBase.PipelineTaskConnections,
dimensions=("tract", "patch", "skymap"),
defaultTemplates={"inputCoaddName": "deep", "outputCoaddName": "deepChi2"},
):
inputCoadds = cT.Input(
doc="Exposure on which to run deblending",
name="{inputCoaddName}Coadd_calexp",
storageClass="ExposureF",
multiple=True,
dimensions=("tract", "patch", "band", "skymap")
dimensions=("tract", "patch", "band", "skymap"),
)
chi2Coadd = cT.Output(
doc="Chi^2 exposure, produced by merging multiband coadds",
Expand All @@ -116,21 +116,20 @@ class AssembleChi2CoaddConnections(pipeBase.PipelineTaskConnections,
)


class AssembleChi2CoaddConfig(pipeBase.PipelineTaskConfig,
pipelineConnections=AssembleChi2CoaddConnections):
class AssembleChi2CoaddConfig(pipeBase.PipelineTaskConfig, pipelineConnections=AssembleChi2CoaddConnections):
outputPixelatedVariance = pexConfig.Field(
dtype=bool,
default=False,
doc="Whether to output a pixelated variance map for the generated "
"chi^2 coadd, or to have a flat variance map defined by combining "
"the inverse variance maps of the coadds that were combined."
"chi^2 coadd, or to have a flat variance map defined by combining "
"the inverse variance maps of the coadds that were combined.",
)

useUnionForMask = pexConfig.Field(
dtype=bool,
default=True,
doc="Whether to calculate the union of the mask plane in each band, "
"or the intersection of the mask plane in each band."
"or the intersection of the mask plane in each band.",
)


Expand All @@ -151,6 +150,7 @@ class AssembleChi2CoaddTask(pipeBase.PipelineTask):

.. [4] https://project.lsst.org/meetings/law/sites/lsst.org.meetings.law/files/Building%20and%20using%20coadds.pdf # noqa: E501, W505
"""

ConfigClass = AssembleChi2CoaddConfig
_DefaultName = "assembleChi2Coadd"

Expand Down Expand Up @@ -224,10 +224,10 @@ def run(self, inputCoadds: list[afwImage.Exposure]) -> pipeBase.Struct:
variance = refExp.variance.Factory(bbox)
if self.config.outputPixelatedVariance:
# Write the per pixel variance to the output coadd
variance.array[:] = np.sum([1/coadd.variance for coadd in inputCoadds], axis=0)
variance.array[:] = np.sum([1 / coadd.variance for coadd in inputCoadds], axis=0)
else:
# Use a flat variance in each band
variance.array[:] = np.sum(1/np.array(variance_list))
variance.array[:] = np.sum(1 / np.array(variance_list))
# Combine the masks planes to calculate the mask plae of the new coadd
mask = self.combinedMasks([coadd.mask for coadd in inputCoadds])
# Create the exposure
Expand All @@ -240,10 +240,7 @@ def run(self, inputCoadds: list[afwImage.Exposure]) -> pipeBase.Struct:
class DetectChi2SourcesConnections(
pipeBase.PipelineTaskConnections,
dimensions=("tract", "patch", "skymap"),
defaultTemplates={
"inputCoaddName": "deepChi2",
"outputCoaddName": "deepChi2"
}
defaultTemplates={"inputCoaddName": "deepChi2", "outputCoaddName": "deepChi2"},
):
detectionSchema = cT.InitOutput(
doc="Schema of the detection catalog",
Expand All @@ -265,10 +262,7 @@ class DetectChi2SourcesConnections(


class DetectChi2SourcesConfig(pipeBase.PipelineTaskConfig, pipelineConnections=DetectChi2SourcesConnections):
detection = pexConfig.ConfigurableField(
target=SourceDetectionTask,
doc="Detect sources in chi2 coadd"
)
detection = pexConfig.ConfigurableField(target=SourceDetectionTask, doc="Detect sources in chi2 coadd")

idGenerator = SkyMapIdGeneratorConfig.make_field()

Expand Down
Loading