Skip to content

Weights are not properly applied for masked and clipped arrays in combine() #893

@monodera

Description

@monodera

I'm trying to combine images with ccdproc.combine().

The following is an example to show the issue. Note that I set the mask = [[1, 0, 0], [0, 0, 0]] for the first image.

import numpy as np
from astropy.nddata import CCDData
from ccdproc import combine

ccd1 = CCDData([[1, 1, 1], [2, 2, 2]], mask=[[1, 0, 0], [0, 0, 0]], unit="adu")
ccd2 = CCDData([[1, 1, 1], [2, 2, 2]], unit="adu")

weights = np.array([1, 1])
weights = None

combined_ccd = combine(
    [ccd1, ccd2],
    method="average",
    weights=weights,
)

print(combined_ccd.data)

With weights = None, the result is [[1., 1., 1.], [2., 2., 2.]] as expected.

On the other hand, with weights = np.array([1, 1]), the result becomes [[0.5 1. 1. ], [2., 2., 2.]], while I still expect the result is [[1, 1, 1], [2, 2, 2]].

I think that the combine() does not remove the masked elements from the weights array, so smaller value are returned.

A similar behavior is also seen in the clipped arrays.

My Python environment is the following:

  • Python 3.11.12
  • ccdproc 2.4.3
  • Numpy 2.2.5
  • Astropy 7.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions