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

XYE filewriter #417

Merged
merged 19 commits into from Feb 16, 2023
Merged

XYE filewriter #417

merged 19 commits into from Feb 16, 2023

Conversation

jl-wynen
Copy link
Member

Fixes #413

easyDiffraction can load files written by save_xye.

@@ -41,6 +41,7 @@ Features
~~~~~~~~

* Coordinate transformation kernel for :math:`\vec{Q}` `412 <https://github.com/scipp/scipp/pull/412>`_.
* Added :func:`scippneutron.io.xye.save_xye` and :func:`scippneutron.io.xye.load_xye` `417 <https://github.com/scipp/scipp/pull/417>`_.
Copy link
Member

Choose a reason for hiding this comment

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

The xye module feels like overkill? Will there be more than 2 user-facing functions?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably not. But there may be many functions for different formats. I think it is cleaner to keep them in separate modules.
Note that it is possible to call them with scn.io.save_xye. But Sphinx doesn't want to generate link to that, only to the actual definition of the function.

Copy link
Member

Choose a reason for hiding this comment

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

We have the same problem in Scipp and elsewhere. I think we have to fix that (maybe by not using automodule, but listing contents by hand?).

src/scippneutron/__init__.py Outdated Show resolved Hide resolved
'Cannot save data to XYE file because it is not one-dimensional. '
f'It has dimensions {da.dims}')
if len(da.coords) == 0:
raise ValueError('Cannot save data to XYE file because it has no coordinates.')
Copy link
Member

Choose a reason for hiding this comment

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

Have you considered raising when there are masks? Dropping them is almost always wrong, so it might avoid hours/days of debugging for users.

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 considered several approaches:

  • Raise when there are masks, attrs, other coords and add a flag to ignore this check.
  • Log a message about other metadata.
  • Do nothing.

I went with the last because I was unsure how useful this check would be. But I agree that masks may cause problems. I can add a check for those.

And maybe a log message of the form 'saving data or unit {unit} with coordiante {coord} to XYE file {fname}'?

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 ignoring other coords and attrs is not harmful, but ignoring masks definitely is?

Comment on lines 72 to 77
if coord is None:
if len(da.coords) > 1:
raise ValueError(
'Cannot deduce which coordinate to save because the data has more '
f'than one: {list(da.coords.keys())}')
coord = next(iter(da.coords))
Copy link
Member

Choose a reason for hiding this comment

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

This does not feel very convenient. Why not use da.coords[da.dim] by default?

Copy link
Member Author

Choose a reason for hiding this comment

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

This seemed risky. Since the file doesn't really include metadata, it is hard to tell what it actually contains.

Copy link
Member

Choose a reason for hiding this comment

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

But the dimension-coord should be the most sensible one in 99% of cases?

src/scippneutron/io/xye.py Outdated Show resolved Hide resolved
src/scippneutron/io/xye.py Outdated Show resolved Hide resolved
coord = dim if coord is None else coord
loaded = np.loadtxt(fname, delimiter=' ', unpack=True)
if loaded.ndim == 1:
loaded = loaded[:, np.newaxis]
Copy link
Member

Choose a reason for hiding this comment

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

I presume the header is not standardized, so we can make no attempt to read units and dims from there?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct. Mantid writes a similar header but places the units in separate lines.

@jl-wynen jl-wynen merged commit 4947644 into main Feb 16, 2023
@jl-wynen jl-wynen deleted the xye-filewriter branch February 16, 2023 15:06
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.

GSAS-II file writer
2 participants