Skip to content

[ESSDIFFRACTION] Fix multiplication with mask - #674

Merged
jl-wynen merged 3 commits into
mainfrom
fix-mask-application
Aug 6, 2026
Merged

[ESSDIFFRACTION] Fix multiplication with mask#674
jl-wynen merged 3 commits into
mainfrom
fix-mask-application

Conversation

@jl-wynen

@jl-wynen jl-wynen commented Jul 24, 2026

Copy link
Copy Markdown
Member

I messed this up in #673

  • Zero out masked elements, not unmasked ones keep unmasked elements
  • Apply mask to variances
  • use sc.where instead of multiplication because the latter does not work when the data is Inf or NaN.
  • Add test to check written data

Update: analysis team suggested that masked values should simply be removed from the file written to disk, instead of replacing with zeros or NaNs.
This has the advantage of circumventing the issue with what to do with the variances.

@jl-wynen
jl-wynen requested a review from nvaytet July 24, 2026 09:32
@jl-wynen
jl-wynen enabled auto-merge July 24, 2026 09:32
@github-actions github-actions Bot added the essdiffraction Issues for essdiffraction. label Jul 24, 2026
@github-actions github-actions Bot changed the title Fix multiplication with mask [ESSDIFFRACTION] Fix multiplication with mask Jul 24, 2026
Multiplication does not work with inf and nan.
hist.data = hist.data.copy()
hist.values *= irreducible_mask(hist.masks, hist.dim).values
if hist.variances is not None:
replacement = sc.scalar(0.0, variance=0.0, unit=hist.unit, dtype=hist.dtype)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess this is the usual question: should the variance be 0, and thus being a very tight constraint on fits?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think I would nan the masked values instead of 0. Makes them easier to distinguish from real zeros

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point. I tried that and easydiffraction doesn't like it. It raises

TypeError: Value mismatch for <reduced_tof.data.1.intensity_meas>. Provided nan outside [0, inf]. Keeping current 0.0.

Judging by that error message, inf would be valid.

@AndrewSazonov How do we best encode masked data? In this case, it is masked because the vanadium measurement has a 0 in a bin.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Inf feels like it would just be a workaround/hack. Would make more sense if NaN was accepted downstream.

@jl-wynen
jl-wynen added this pull request to the merge queue Aug 6, 2026
Merged via the queue into main with commit c271142 Aug 6, 2026
6 checks passed
@jl-wynen
jl-wynen deleted the fix-mask-application branch August 6, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

essdiffraction Issues for essdiffraction.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants