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

Add a CIF writer #89

Merged
merged 13 commits into from
Sep 19, 2024
Merged

Add a CIF writer #89

merged 13 commits into from
Sep 19, 2024

Conversation

jl-wynen
Copy link
Member

@jl-wynen jl-wynen commented Sep 5, 2024

Fixes #38

This depends on scipp/scippneutron#548.

I was a bit unsure about the interface. I also tried

def save_reduced_dspacing(
    da: IofDspacing, *, filename: OutFilename, authors: CIFAuthors
) -> IofDspacing:
    # save data
    return da

result = workflow.bind_and_call(dream.io.save_reduced_dspacing)

This is quite concise and gives the user access to the reduced data in the notebook, not just via the file. But I prefer the current solution which gives the user more control over how and when the file is saved. See commit 3248368 for the transition to the current solution.

Note that this is not a complete solution. We will have to save additional data such as a calibration table. Also, this PR saves the data in d-spacing. The analysis team have been asking for data in tof. However, it is still unclear how to convert reduced data back to tof.

For reference, the file written in the DREAm workflow begins with

#\#CIF_1.1
# This file was generated with the DREAM data reduction user guide
# in the documentation of ESSdiffraction.
# See https://scipp.github.io/essdiffraction/
data_reduced_dspacing

loop_
_audit_conform.dict_name
_audit_conform.dict_version
_audit_conform.dict_location
coreCIF 3.3.0 https://github.com/COMCIFS/cif_core/blob/fc3d75a298fd7c0c3cde43633f2a8616e826bfd5/cif_core.dic
pdCIF 2.5.0 https://github.com/COMCIFS/Powder_Dictionary/blob/7608b92165f58f968f054344e67662e01d4b401a/cif_pow.dic

_audit.creation_date 2024-09-05T14:29:48+00:00
_audit.creation_method 'Written by scippneutron v24.8.1.dev31+gb2d36553'
_computing.diffrn_reduction 'ess.dream v0.0.0'

_audit_contact_author.name 'Jane Doe'
_audit_contact_author.email [email protected]
_audit_contact_author.id_orcid 0000-0000-0000-0001
_audit_contact_author.id 1

loop_
_audit_author_role.id
_audit_author_role.role
1 measurement

_diffrn_radiation.probe neutron
_diffrn_source.beamline DREAM
_diffrn_source.facility ESS
_diffrn_source.device spallation

loop_
_pd_proc.d_spacing
_pd_proc.intensity_net
_pd_proc.intensity_net_su
0.0058585 0.0 0.0
0.0175755 0.0 0.0
0.0292925 0.0 0.0
...

@jl-wynen
Copy link
Member Author

Can be merged now after a review.

Copy link
Member

@YooSunYoung YooSunYoung left a comment

Choose a reason for hiding this comment

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

Just couple of minor comments.

@@ -57,8 +58,8 @@
WavelengthMask: None,
CIFAuthors: CIFAuthors(
[
CIFAuthor(
name="Jane Doe", email="[email protected]", id_orcid="0000-0000-0000-0001"
Author(
Copy link
Member

Choose a reason for hiding this comment

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

Would it be better to add one more Author for testing since it's CIFAuthors...?

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 don't think this is so important. The tests here are mainly about checking that the workflow routes the correct data to the writer. The writer itself is tested in ScippNeutron.

Using multiple authors here makes testing harder because then we have a loop over authors in the file. And I already find the string-based tests brittle. So I would like to avoid testing a multi line string for a loop.

@@ -188,3 +182,14 @@ def _assert_contains_source_info(cif_content: str) -> None:
def _assert_contains_author_info(cif_content: str) -> None:
assert "audit_contact_author.name 'Jane Doe'" in cif_content
assert 'audit_contact_author.email [email protected]' in cif_content
Copy link
Member

Choose a reason for hiding this comment

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

Orcid ID could be tested as well.

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 didn't want to replicate all tests from ScippNeutron. But I can add this.

Copy link
Member

Choose a reason for hiding this comment

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

Ah ha, right it's essdiffraction specific test...

@jl-wynen jl-wynen merged commit 7772e69 into main Sep 19, 2024
4 checks passed
@jl-wynen jl-wynen deleted the write-cif branch September 19, 2024 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Write CIF files
2 participants