Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zoom data reduction #50

Merged
merged 28 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d7d1aff
Draft Zoom example
SimonHeybrock Jan 15, 2024
59b9a7b
Begin adding isis module with Mantid loaders
SimonHeybrock Jan 16, 2024
1139da5
Add run loader
SimonHeybrock Jan 16, 2024
fdd5200
Add masking
SimonHeybrock Jan 16, 2024
a574970
Update Zoom notebook draft
SimonHeybrock Jan 16, 2024
1ec5499
Hack to get correct spectrum numbers for masks
SimonHeybrock Jan 16, 2024
c84fedb
Continue work on Zoom notebook
SimonHeybrock Jan 16, 2024
11b88fd
More cleanup
SimonHeybrock Jan 16, 2024
2b2e5e9
Get gravity direction via reference frame
SimonHeybrock Jan 16, 2024
2bf3b34
Cleanup
SimonHeybrock Jan 16, 2024
78d9dd7
Rewrite mantidio using Mantid more directly
SimonHeybrock Jan 17, 2024
644258d
Update todo
SimonHeybrock Jan 17, 2024
cddd003
Minor cleanup
SimonHeybrock Jan 17, 2024
0577a8d
Refactor to read xml directly
SimonHeybrock Jan 18, 2024
ae45bf9
Update docs
SimonHeybrock Jan 18, 2024
1cbcd01
Use Mantid if available, otherwise pooch
SimonHeybrock Jan 18, 2024
c4e0f02
Add Zoom page to docs
SimonHeybrock Jan 18, 2024
a62f630
Unzip if required
SimonHeybrock Jan 18, 2024
3be36c6
Remove now unused suffix
SimonHeybrock Jan 18, 2024
1c0706b
Fix pooch path handling
SimonHeybrock Jan 18, 2024
30ba0cf
Avoid markdown render problem
SimonHeybrock Jan 22, 2024
a52783f
Copyright date
SimonHeybrock Jan 22, 2024
db6cc19
Fix file comment
SimonHeybrock Jan 22, 2024
88ba28c
Path -> FilePath
SimonHeybrock Jan 22, 2024
ec3d713
Extend file description
SimonHeybrock Jan 23, 2024
a541769
Add simply 2-D instrument view
SimonHeybrock Jan 23, 2024
7f945d4
Move args to notebook
SimonHeybrock Jan 23, 2024
818bf47
Improve function naming and docstring
SimonHeybrock Jan 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions docs/examples/zoom.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
"source": [
"import scipp as sc\n",
"import sciline\n",
"import scippneutron as scn\n",
"import plopp\n",
"import esssans as sans\n",
"import esssans.isis\n",
"from esssans.types import *"
Expand Down Expand Up @@ -242,14 +240,7 @@
"\n",
"display(sc.plot({str(key): results[key] for key in monitors}, norm='log'))\n",
"\n",
"display(\n",
" scn.instrument_view(\n",
" results[MaskedData[SampleRun]].hist(),\n",
" pixel_size=0.0075,\n",
" norm='log',\n",
" camera=plopp.graphics.Camera(position=(0, 0, 22)),\n",
" )\n",
")\n",
"display(sans.isis.plot_instrument(results[MaskedData[SampleRun]]))\n",
"\n",
"parts = {str(key): results[key] for key in parts}\n",
"parts = {key: val if val.bins is None else val.hist() for key, val in parts.items()}\n",
Expand Down
2 changes: 2 additions & 0 deletions src/esssans/isis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .common import transmission_from_background_run, transmission_from_sample_run
from .io import CalibrationFilename, DataFolder, Filename, PixelMaskFilename
from .masking import PixelMask
from .visualization import plot_instrument

providers = (
(
Expand Down Expand Up @@ -40,4 +41,5 @@
'providers',
'transmission_from_background_run',
'transmission_from_sample_run',
'plot_instrument',
]
2 changes: 1 addition & 1 deletion src/esssans/isis/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
'ModeratorStdDev_TS2_SANS_LETexptl_07Aug2015.txt': 'md5:5fc389340d453b9095a5dfcc33608dae', # noqa: E501
# ISIS user file configuring the data reduction
'USER_ZOOM_Cabral_4m_TJump_233G_8x8mm_Small_BEAMSTOP_v1_M5.toml': 'md5:4423ecb7d924c79711aba5b0a30a23e7', # noqa: E501
# Mask files
# 7 pixel mask files for the ZOOM00034786.nxs run
'andru_test.xml': 'md5:c59e0c4a80640a387df7beca4857e66f',
'left_beg_18_2.xml': 'md5:5b24a8954d4d8a291f59f5392cd61681',
'right_beg_18_2.xml': 'md5:fae95a5056e5f5ba4996c8dff83ec109',
Expand Down
43 changes: 43 additions & 0 deletions src/esssans/isis/visualization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp)
"""
Plotting functions for ISIS data.
"""
from typing import Any

import scipp as sc


def plot_instrument(da: sc.DataArray, pixels_per_tube: int = 512, **kwargs: Any) -> Any:
Copy link
Member

Choose a reason for hiding this comment

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

Are you thinking this is generic enough that it can be used for other isis instruments? I guess it would work for sans2d as well. But then it should also work for other flat panels, not just isis panels?
Should we call it something else that implies it is plotting a flat panel? As it wouldn't work for something else.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are there any ISIS SANS instruments that do not have tubes that we have to worry about?

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 renamed it.

"""
Plot a 2-D instrument view of a data array.

This is an alternative to the `scn.instrument_view` function, avoiding the 3-D
rendering of the instrument. The exact X and Y coordinates of the pixels are
used for the 2-D plot.

Parameters
----------
da:
The data array to plot. Must have a 'position' coord and a single dimension.
Copy link
Member

Choose a reason for hiding this comment

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

Is it not possible to flatten if there are more than one dimension?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, but this is for ISIS data, which has been loaded with Mantid, so why complicate things? It can be extended once/if required?

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 had considered doing this, but then it would complicate since we would need to maybe support summing some dims but flattening others, I didn't think it was worth it at this point. After all, this is not an ESS instrument.

pixels_per_tube:
The number of pixels per tube. Defaults to 512.
kwargs:
Additional arguments passed to `sc.plot`.
"""
if da.bins is not None:
da = da.hist()
da.coords['x'] = da.coords['position'].fields.x.copy()
da.coords['y'] = da.coords['position'].fields.y.copy()
folded = da.fold(da.dim, sizes={'y': -1, 'x': pixels_per_tube})
y = folded.coords['y']
if sc.all(y.min('x') == y.max('x')):
folded.coords['y'] = y.min('x')
else:
raise ValueError(
'Cannot plot 2-D instrument view of data array with non-constant '
Copy link
Member

Choose a reason for hiding this comment

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

Do we really have to raise or would it just make a ragged detector panel, like the other plots we have with 2d coords?

Copy link
Member

Choose a reason for hiding this comment

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

Ah maybe it's because the x coord is already 2d?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, Scipp (and plotting, I guess?) do not support multiple 2-D coords. Or is Plopp supporting this?

Copy link
Member

Choose a reason for hiding this comment

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

Or is Plopp supporting this?

No, we are not.

'y coordinate along tubes. Use scippneutron.instrument_view instead.'
)
plot_kwargs = dict(aspect='equal', norm='log', figsize=(6, 10))
Copy link
Member

Choose a reason for hiding this comment

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

I think the aspect='equal' make sense for this, but I find it a little strange that it has log as a default, and also changes the figsize? This size would not work e.g. for the sans2d panel.

plot_kwargs.update(kwargs)
return folded.plot(**plot_kwargs)