Skip to content

COO-256 Multiple image planes in DetImage._data (data, std, count) - #20

Open
Yashvi-Sharma wants to merge 1 commit into
mainfrom
COO-256-imageplanes
Open

Yashvi-Sharma wants to merge 1 commit into
mainfrom
COO-256-imageplanes

Conversation

@Yashvi-Sharma

Copy link
Copy Markdown
Collaborator

Refactored DetImage _data attribute to hold a xarray.Dataset instead of array.DataArray.

  • Dataset stores the main array in 'data' variable, DetImage init and set_data() handle conversion from DataArray to Dataset. But if a Dataset is passed to be set it should contain 'data' variable.

  • all image_utils.py helpers were modified to work with both DataArray and Dataset

  • DetImage.data property behaves the same as before, returns 'data' variable from Dataset

  • DetImage.get_data() can be used to access full Dataset or a specific data_var

  • Output, FocalPlaneImage methods similarly refactored with extra convenience methods.

  • MasterCombine now returns DetImage with three image planes (data, std, count)

…hods to mostly have the same behavior as before so the tasks are not affected.
raise ValueError("Cannot determine shape of DetImage from metadata or outputs.")

def build_full_mask(self):
def build_full_mask(self) -> bool:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the thought for having partial masks with filled with NaN instead of failing?
Could also have a downstream effect when users run show() and the np.ma.masked_array treats any non-zero value as "masked". NaN is considered non-zero, so the entire region belonging to the not-yet-processed output would treated as masked

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, fill_value should be zero. It shouldn't fail though if only some outputs have a certain mask, that could be intentional behavior, for example if one output has vignetting mask (like in DEIMOS).

self.data = xr.DataArray(data=np.zeros(dim_pix, dtype=float), coords=coords, dims=["y", "x"])
# Initialize masks Dataset
mask_keys = self.det_images[0].masks.data_vars.keys() if self.det_images[0].build_full_mask() else []
data_vars = list(self.det_images[0].get_data('all').data_vars)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks at the first DetImage in the list to decide which variables exist (e.g. ['data'], or ['data', 'std', 'count']). This would then assumes every other DetImage in the list has those exact same variables. What happens when we have a mixture?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably shouldn't ever be the case in practice, and I don't think it's a priority to handle it (by handle it I mean do something "best effort"). But I think it should be checked and fail more gracefully than an unexpected KeyError down the line.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes in practice it should never happen as the detimages belonging to a focal plane would probably go through all the same steps and get same data_vars. But if it still needs handling:

Option 1: I move the empty data array assignment inside the loop so any new data_vars not present already are handled. This would create a big dataset for large focal plane and highly heterogeneous mixtures but since we are assuming that is rare it shouldn't be a problem otherwise.

Option 2: I add a warning and skip any missing data_vars in the loop. 'data' data_var is required to be present in all DetImage._data datasets and checking that is already handled at DetImage creation time, so there shouldn't be a case where _data is a XR.Dataset but without any data_vars at all.

Thoughts?

if di.data is None:
didataset = di.get_data('all')
dimasks = di.masks
if di is None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would di ever be None? Since di = self.det_images[I]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

di can't be None since you'd have already thrown an AttributeError from the line immediately above. Maybe you mean if dimasks is None or similar?

@Yashvi-Sharma Yashvi-Sharma Sep 15, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo...should be didataset

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.

3 participants