Skip to content

Avoid mapping CCDData uncertainty twice - #487

Open
timbeccue wants to merge 1 commit into
mainfrom
fix/uncertainty-double-mapping
Open

timbeccue wants to merge 1 commit into
mainfrom
fix/uncertainty-double-mapping

Conversation

@timbeccue

@timbeccue timbeccue commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Creating a memory-mapped CCDData currently copies its uncertainty array into two temporary files: once in the constructor and again in the uncertainty setter. Only the second mapping is kept as the uncertainty array, so every construction does an unnecessary full-image allocation and copy.

The original CCDData.__init__ in data.py calls _init_array() before assigning the result to self.uncertainty:

self.uncertainty = self._init_array(uncertainty)

That assignment invokes the uncertainty setter, which calls _init_array() again on the already mapped array:

@uncertainty.setter
def uncertainty(self, value: np.array):
    self._validate_array(value)
    self._uncertainty = self._init_array(value)

With memory mapping enabled, each _init_array() call creates a temporary file and copies the array into a new memory map. The constructor therefore creates two copies of the same uncertainty image.

Pass the original array directly to the setter:

- self.uncertainty = self._init_array(uncertainty)
+ self.uncertainty = uncertainty

The setter still validates the shape and creates the memory map, now only once. This removes one temporary file and one full-image copy per CCDData construction while preserving the uncertainty values.

@timbeccue
timbeccue requested a review from cmccully September 15, 2026 23:22

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant