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

docs: some fixes after comments from celine #137

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

jokasimr
Copy link
Contributor

No description provided.

@jokasimr jokasimr requested a review from nvaytet March 10, 2025 13:29
Comment on lines 118 to 119
"# and it expects `wavelength` to be the last dimension\n",
"transmission_fraction_mantle = transmission_fraction_mantle.transpose((*(set(transmission_fraction_mantle.dims) - {'wavelength'}), 'wavelength'))\n",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"# and it expects `wavelength` to be the last dimension\n",
"transmission_fraction_mantle = transmission_fraction_mantle.transpose((*(set(transmission_fraction_mantle.dims) - {'wavelength'}), 'wavelength'))\n",

I don't think that's necessary, I think it just works because we have dim='wavelength' below.

Copy link
Contributor Author

@jokasimr jokasimr Mar 10, 2025

Choose a reason for hiding this comment

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

No it's needed if we run method="medium" or method="expensive" instead of method="cheap" . Then the transmission fraction is evaluated piecewise and not for the entire detector at once. This makes the returned value have a different shape. The instrument view requires the wavelength dimension to be the last dimension of the data array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we should make the instrument view automatically transpose the input data it receives if it has the wrong shape.

Copy link
Member

Choose a reason for hiding this comment

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

The instrument view requires the wavelength dimension to be the last dimension of the data array.

Where does it fail? Is it when it tries to flatten the dimensions?

Maybe we should make the instrument view automatically transpose the input data it receives if it has the wrong shape.

Yes, we should. The user should not have to worry about the order of dimensions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where does it fail? Is it when it tries to flatten the dimensions?

Yes exactly.

File [~/work/essdiffraction/src/ess/dream/instrument_view.py:64](http://localhost:8889/lab/tree/docs/user-guide/dream/src/ess/dream/instrument_view.py#line=63), in _pre_process(da, dim)
     62 if dim is not None:
     63     dims.remove(dim)
---> 64 out = da.flatten(dims=dims, to="pixel")
     65 sel = sc.isfinite(out.coords["position"])
     66 return out[sel]

File [~/mambaforge/envs/essdiffraction/lib/python3.10/site-packages/scipp/core/shape.py:363](http://localhost:8889/home/johannes/mambaforge/envs/essdiffraction/lib/python3.10/site-packages/scipp/core/shape.py#line=362), in flatten(x, dims, to)
    357 if to is None:
    358     # Note that this is a result of the fact that we want to support
    359     # calling flatten without kwargs, and that in this case it semantically
    360     # makes more sense for the dims that we want to flatten to come first
    361     # in the argument list.
    362     raise ValueError("The final flattened dimension is required.")
--> 363 return _call_cpp_func(_cpp.flatten, x, dims, to)

File [~/mambaforge/envs/essdiffraction/lib/python3.10/site-packages/scipp/core/_cpp_wrapper_util.py:27](http://localhost:8889/home/johannes/mambaforge/envs/essdiffraction/lib/python3.10/site-packages/scipp/core/_cpp_wrapper_util.py#line=26), in call_func(func, *args, **kwargs)
     25     return data_group_nary(func, *args, **kwargs)
     26 if out is None:
---> 27     return func(*args, **kwargs)
     28 else:
     29     return func(*args, **kwargs, out=out)

DimensionError: Can only flatten a contiguous set of dimensions in the correct order

Copy link
Member

Choose a reason for hiding this comment

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

Will you add the automatic transpose here or in a different PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do it here

" detector_position=dg['endcap_backward'].coords['position']['strip', 0].copy(),\n",
" quadrature_kind='cheap',\n",
")\n",
"\n",
"transmission_fraction_endcap.coords['position'] = transmission_fraction_endcap.coords.pop('detector_position')\n",
"transmission_fraction_endcap = transmission_fraction_endcap.transpose((*(set(transmission_fraction_endcap.dims) - {'wavelength'}), 'wavelength'))\n",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"transmission_fraction_endcap = transmission_fraction_endcap.transpose((*(set(transmission_fraction_endcap.dims) - {'wavelength'}), 'wavelength'))\n",

@jokasimr jokasimr enabled auto-merge (squash) March 11, 2025 11:51
@jokasimr jokasimr requested a review from nvaytet March 11, 2025 13:02
jokasimr and others added 3 commits March 12, 2025 08:02
it becomes too hairy when different entries in the datagroup have
different sets of dimensions
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.

2 participants