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

Adding nexus in ref #150

Merged
merged 8 commits into from
Dec 20, 2024
Merged

Adding nexus in ref #150

merged 8 commits into from
Dec 20, 2024

Conversation

RubelMozumder
Copy link
Contributor

@RubelMozumder RubelMozumder commented Dec 20, 2024

Implement Nexus file generation for XRD measurements.

PR #116 handled in #118 and #150.

Copy link

sourcery-ai bot commented Dec 20, 2024

Reviewer's Guide by Sourcery

This pull request implements NeXus support for XRD measurements. It introduces a new schema for storing NeXus references and populates it during normalization. Additionally, it includes functions to traverse archive data, map archive data to NeXus, and write NeXus files.

Sequence diagram for NeXus file generation process

sequenceDiagram
    participant Archive
    participant HDF5Handler
    participant Template
    participant Writer

    Archive->>HDF5Handler: write_nx_file()
    HDF5Handler->>Template: generate_template_from_nxdl()
    HDF5Handler->>HDF5Handler: populate_nx_dataset_and_attribute()
    loop For each dataset
        HDF5Handler->>Template: Add dataset to template
    end
    loop For each attribute
        HDF5Handler->>Template: Add attribute to template
    end
    HDF5Handler->>Writer: write(template)
    Writer-->>HDF5Handler: Return success
    HDF5Handler->>Archive: Update reference
Loading

Class diagram for NeXus implementation

classDiagram
    class ELNXRayDiffraction {
        +nexus_results: ArchiveSection
        +normalize(archive, logger)
        +get_read_write_functions()
    }

    class HDF5Handler {
        +write_nx_file()
        -_write_hdf5_file()
        -_remove_nexus_annotations()
    }

    class DatasetModel {
        +data: Any
    }

    ELNXRayDiffraction --> HDF5Handler
    HDF5Handler --> DatasetModel

    note for ELNXRayDiffraction "Added nexus_results field"
    note for HDF5Handler "Implemented NeXus file generation"
Loading

File-Level Changes

Change Details Files
Added support for NeXus in the XRD schema and data processing.
  • Introduced a new nexus_results field in the ELNXRayDiffraction schema to store references to NeXus entries.
  • Added functions to traverse the archive data structure and map archive data to the corresponding NeXus datasets and attributes.
  • Implemented a write_nx_file method in the HDF5Handler class to generate NeXus files.
  • Included functions to populate NeXus datasets and attributes from the archive data.
  • Added logic to populate the nexus_results field during normalization if a NeXus file exists and ends with '.nxs'.
src/nomad_measurements/xrd/schema.py
src/nomad_measurements/xrd/nx.py
src/nomad_measurements/utils.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @RubelMozumder - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

if not entry_list:
self.archive.m_context.process_updated_raw_file(self.data_file)

except NXFileGenerationError as exc:
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Error handling could mask original exception when cleanup fails

Consider handling file deletion errors separately to preserve the original exception context and ensure proper cleanup.

@RubelMozumder RubelMozumder self-assigned this Dec 20, 2024
src/nomad_measurements/xrd/nx.py Outdated Show resolved Hide resolved
src/nomad_measurements/xrd/nx.py Outdated Show resolved Hide resolved
src/nomad_measurements/xrd/schema.py Outdated Show resolved Hide resolved
@ka-sarthak ka-sarthak self-requested a review December 20, 2024 13:26
Copy link
Collaborator

@ka-sarthak ka-sarthak left a comment

Choose a reason for hiding this comment

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

Looks great!

@RubelMozumder RubelMozumder merged commit 90d07a1 into write-nexus-section Dec 20, 2024
5 checks passed
@RubelMozumder RubelMozumder deleted the Adding_nexus_in_ref branch December 20, 2024 13:33
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