Skip to content

Conversation

@jl-wynen
Copy link
Member

Fixes #35

This obviously needs a lot of work. But it is meant as a skeleton to add the rest of the milestone.

The data is currently private. I'm waiting for an ok from the instrument team before publishing it.

@jl-wynen jl-wynen changed the base branch from main to dream-instrument-view March 12, 2024 15:42
Comment on lines 9 to 12
def flatten_detector_dimensions(
data: RawDetectorData[RunType],
) -> FlatDetectorData[RunType]:
"""Flatten logical detector dimensions to a single ``spectrum``.
Copy link
Member

Choose a reason for hiding this comment

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

Isn't RawDetectorData (from ESSreduce) flat already?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it's shaped like the logical dims. At least this is what the GEANT4 loader produces. Would you rather we load a flat array and have a separate step for folding afterwards?

Copy link
Member

Choose a reason for hiding this comment

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

My question is why you flatten it. We want to fold the flat version we get from ESSreduce, that is what also ESSsans will do.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed flattening

Comment on lines 23 to 27
Flattened detector data with a ``spectrum`` dimension.
"""
logical_dims = {'module', 'segment', 'counter', 'wire', 'strip', 'sector'}
actual_dims = tuple(dim for dim in data.dims if dim in logical_dims)
return FlatDetectorData[RunType](data.flatten(dims=actual_dims, to='spectrum'))
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Some providers didn't work. In particular, the focussing step needs a spectrum dim. Should I make that instrument-specific so that it can use the logical dimensions?

Also, isn't there a massive performance penalty when binning in an additional dim like tof?

Copy link
Member

Choose a reason for hiding this comment

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

The steps should be fixed to work with any dims. If this is too much work, we should look into it.

def _to_dspacing_impl(
data: sc.DataArray, base_graph: dict[str, Callable[..., Any]]
) -> sc.DataArray:
out = _restore_tof_if_in_wavelength(data)
Copy link
Member

Choose a reason for hiding this comment

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

Seems to contradict the "Attention" section in the docstring above?

Copy link
Member Author

Choose a reason for hiding this comment

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

No. _restore_tof_if_in_wavelength is a bit funky, but it removes the wavelength and makes tof aligned. The latter part is no longer needed, this code is a leftover from when we used attrs. So I guess we can just delete the wavelength coord instead.


out = out.transform_coords('dspacing', graph=graph, keep_intermediate=False)
out = data.transform_coords('dspacing', graph=graph, keep_intermediate=False)
out.coords.pop('_tag_positions_consumed', None)
Copy link
Member

Choose a reason for hiding this comment

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

What exactly do you ensure with this mechanism? That a conversion actually happens?

Copy link
Member Author

Choose a reason for hiding this comment

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

It ensures that positions in the output are unaligned. The conversion with calibration doesn't use positions directly but conceptually, d is derived from positions.

Copy link
Member

Choose a reason for hiding this comment

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

Can you explain this in a comment please?

Copy link
Member

Choose a reason for hiding this comment

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

@jl-wynen Has this been addressed somewhere? Can't see in the diff.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done now. I actually simplified the conversion with positions because it doesn't need this mechanism.

Comment on lines 99 to 100
class FlatDetectorData(sciline.Scope[RunType, sc.DataArray], sc.DataArray):
"""Data (events / histogram) of a RawDetector flattened to ``detector_number``."""
Copy link
Member

Choose a reason for hiding this comment

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

See above, not sure why this is needed.

Base automatically changed from dream-instrument-view to main March 14, 2024 11:53
@jl-wynen jl-wynen force-pushed the basic-dream-workflow branch from a0a3466 to 1acddf9 Compare March 14, 2024 16:04
@jl-wynen jl-wynen force-pushed the basic-dream-workflow branch from 1acddf9 to 2d97220 Compare March 15, 2024 08:27
Comment on lines 22 to 24
base = ('module', 'segment', 'counter', 'wire', 'strip')
if detector_name == DetectorName.high_resolution:
return DetectorDimensions(base + ('sector',))
Copy link
Member

Choose a reason for hiding this comment

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

Can you double check if this is actually correct? I remember that at least one detector was not prepresentable with these base dims.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have not encountered this. But I only have simulated data. Do you have a NeXus file where it doesn't work? If so, we need to update the csv loader.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

The endcap detectors have a irregular structure that cannot be fully folded.
This is not a problem but note again that the counter may be reversed. It is
currently not clear if this is a bug in the file.

What do I do with this information? Do I just not fold the endcaps? Or do I only fold part of them, which part?
Or Do we just wait because it seems to be unclear whether real files will be like this?

Copy link
Member

Choose a reason for hiding this comment

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

I do not think it is unclear. Real file are (and will be) like this. It is impossible to (fully) fold. I guess we should do what is done in the linked file?

Copy link
Member Author

Choose a reason for hiding this comment

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

Comparing geant4 and ICD names and sizes (https://confluence.esss.lu.se/pages/viewpage.action?pageId=462000005), I don't think we can really represent both simulated and measured data in the same way. Some names are different as well as some sizes. And out test data doesn't even conform to the specs on the confluence page (e.g., the mantle has 7 modules where the pages says there should be 5).

So I would say we just live with the discrepancy. I can change the provider you commented on to check which dims exist in the data and return either the current set or the dims produced by the nexus loader. Got any better idea?

Copy link
Member

@SimonHeybrock SimonHeybrock Mar 18, 2024

Choose a reason for hiding this comment

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

I am fine with any discrepancy, provided that this code is ensured to be Geant-4 specific.

Comment on lines +48 to +69
"""Path to a GEANT4 CSV file for a diamond sample.
**Sample**:
- Diamond powder
- radius=0.0059 m
- yheight=0.05-1e-9 m
- material
reflections of powder from "C_Diamond.laz" (McStas file)
incoherent process with sigma=0.001 barns, packing_factor=1,
unit cell volume=45.39 angstrom^3
absorption of 0.062 1/m
**Container**:
- radius=0.006 m
- yheight=0.05 m
- material
reflections of powder from "V.laz" (McStas file)
incoherent process with sigma=4.935 barns, packing factor=1,
unit cell volume=27.66 angstrom^3
absorption of 36.73 1/m
Copy link
Member

Choose a reason for hiding this comment

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

Great idea to include this info in the docstrings, this makes the data module much more useful.

'counter',
'strip',
'sector',
'sumo_cass_cst',
Copy link
Member

Choose a reason for hiding this comment

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

Typo? See

'sumo_cass_ctr': -1, # sumo*cassette*counter, irregular, cannot fold

@jl-wynen jl-wynen force-pushed the basic-dream-workflow branch from 5151940 to a5415e1 Compare March 18, 2024 14:54
@jl-wynen
Copy link
Member Author

Any more comments?

@jl-wynen jl-wynen enabled auto-merge March 20, 2024 13:01
@jl-wynen jl-wynen merged commit 465ecfa into main Mar 20, 2024
@jl-wynen jl-wynen deleted the basic-dream-workflow branch March 20, 2024 13:08
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.

Basic powder workflow for DREAM

3 participants