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

Bring in NOMAD examples #32

Merged
merged 32 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a152626
Add examples and test stage
domna Dec 1, 2023
ec478db
Updates example files to work with new NXmpes definitions
domna Jan 23, 2024
4684d61
Updates config file
domna Feb 13, 2024
88f8669
Add k-space conversion and sed postprocessing example
domna Oct 8, 2024
ad5b64d
add entrypoint for NOMAD example
lukaspie Oct 11, 2024
580bc50
test for NOMAD example entry point
lukaspie Oct 11, 2024
a2484ab
remove unneeded imports
lukaspie Oct 11, 2024
4959f28
linitng
lukaspie Oct 11, 2024
9d3c333
install nomad in tests
lukaspie Oct 11, 2024
b628c24
import from pynxtools testing
lukaspie Oct 11, 2024
2df4068
rename test functions
lukaspie Oct 11, 2024
d57193d
use entrypoint directly in test
lukaspie Oct 11, 2024
882f963
fix example
lukaspie Oct 14, 2024
3c9c449
update examples path in docs
lukaspie Oct 14, 2024
f86b51b
update tests
lukaspie Oct 14, 2024
639bd1c
rename test file
lukaspie Oct 14, 2024
9d2ce27
return archive dict in testing function
lukaspie Oct 14, 2024
7209198
update nomad example test
lukaspie Oct 14, 2024
cfb4558
use relative path for test
lukaspie Oct 15, 2024
b167dad
linting
lukaspie Oct 15, 2024
a7ec628
reactivate nomad check in test
lukaspie Oct 15, 2024
373edb6
update mpes example from nomad-distro
lukaspie Nov 25, 2024
262ab49
use resource in ExampleUploadEntryPoint
lukaspie Nov 26, 2024
82870ab
linting
lukaspie Nov 26, 2024
fdfa69e
bump ruff in pre-commit
lukaspie Nov 26, 2024
40cadd6
update nomad exmaple tests
lukaspie Nov 26, 2024
aa543d4
move some test functionality to pynxtools
lukaspie Nov 26, 2024
24ce270
update MANIFEST
lukaspie Nov 27, 2024
7cdfbf7
bring in examples from north
lukaspie Nov 27, 2024
6199d7f
clarify there are 4 examples
lukaspie Nov 27, 2024
8f55e64
allow nomad test for python 3.12
lukaspie Nov 29, 2024
af4c893
install nomad with infrastructure extra in CI/CD
lukaspie Nov 29, 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
8 changes: 7 additions & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python_version }}
- name: Install package
- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Install nomad
if: "${{ matrix.python_version != '3.8' && matrix.python_version != '3.12'}}"
run: |
uv pip install nomad-lab@git+https://gitlab.mpcdf.mpg.de/nomad-lab/nomad-FAIR.git
- name: Install package
run: |
uv pip install ".[dev]"
- name: Test with pytest
lukaspie marked this conversation as resolved.
Show resolved Hide resolved
run: |
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.7.0
rev: v0.8.0
hooks:
# Run the linter.
- id: ruff
Expand Down
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
prune *
exclude *
recursive-include src/pynxtools_mpes *.py
include pyproject.toml README.md dev-requirements.txt
include pyproject.toml README.md dev-requirements.txt
graft src/pynxtools_mpes/nomad/examples
2 changes: 1 addition & 1 deletion docs/tutorial/standalone.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ $<eln-file path> \

### Examples

You can find exhaustive examples how to use `pynxtools-mpes` for your ARPES research data pipeline [here](https://gitlab.mpcdf.mpg.de/nomad-lab/nomad-remote-tools-hub/-/tree/develop/docker/mpes).
You can find exhaustive examples how to use `pynxtools-mpes` for your ARPES research data pipeline in [`src/pynxtools-mpes/nomad/examples`](../../src/pynxtools_mpes/nomad/examples/). These are designed for working with [`NOMAD`](https://nomad-lab.eu/) and its [`NOMAD Remote Tools Hub (NORTH)`](https://nomad-lab.eu/prod/v1/gui/analyze/north).

There are also small example files for using the `pynxtools` dataconverter with the `mpes` reader and the `NXmpes` application definition in [`tests/data`](https://github.com/FAIRmat-NFDI/pynxtools.mpes/tree/main/tests/data).

Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
lukaspie marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ docs = [
[project.entry-points."pynxtools.reader"]
mpes = "pynxtools_mpes.reader:MPESReader"

[project.entry-points.'nomad.plugin']
lukaspie marked this conversation as resolved.
Show resolved Hide resolved
mpes_example = "pynxtools_mpes.nomad.entrypoints:mpes_example"

[tool.setuptools.packages.find]
where = [
"src",
Expand Down
41 changes: 41 additions & 0 deletions src/pynxtools_mpes/nomad/entrypoints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Entry points for mpes examples."""

try:
from nomad.config.models.plugins import ExampleUploadEntryPoint
except ImportError as exc:
raise ImportError(
"Could not import nomad package. Please install the package 'nomad-lab'."
) from exc

mpes_example = ExampleUploadEntryPoint(
title="Multidimensional photoemission spectroscopy (MPES)",
category="FAIRmat examples",
description="""
This example presents the capabilities of the NOMAD platform to store and standardize multidimensional photoemission spectroscopy (MPES) experimental data. It contains four major examples:

- Taking a pre-binned file, here stored in a h5 file, and converting it into the standardized MPES NeXus format.
There exists a [NeXus application definition for MPES](https://manual.nexusformat.org/classes/contributed_definitions/NXmpes.html#nxmpes) which details the internal structure of such a file.
- Binning of raw data (see [here](https://www.nature.com/articles/s41597-020-00769-8) for additional resources) into a h5 file and consecutively generating a NeXus file from it.
- An analysis example using data in the NeXus format and employing the [pyARPES](https://github.com/chstan/arpes) analysis tool to reproduce the main findings of [this paper](https://arxiv.org/pdf/2107.07158.pdf).
- Importing angle-resolved data stored in NXmpes_arpes, and convert these into momentum space coordinates using tools in pyARPES.
""",
lukaspie marked this conversation as resolved.
Show resolved Hide resolved
plugin_package="pynxtools_mpes",
resources=["nomad/examples/*"],
)
161 changes: 161 additions & 0 deletions src/pynxtools_mpes/nomad/examples/E1 Convert to NeXus.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Converting Multidimensional Photoemission Spectroscopy (MPES) data into the NeXus format"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This example shows how to convert x-array based h5 measurement files as generated by the [preprocessing output](https://www.nature.com/articles/s41597-020-00769-8) of the software used at the Fritz-Haber Institute into the [MPES NeXus format](https://manual.nexusformat.org/classes/contributed_definitions/NXmpes.html#nxmpes).\n",
"For an example on how to generate such a h5 measurement file please refer to the [postprocessing example](./E2%20ARPES%20postprocessing.ipynb)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Download the data\n",
"Since the provided datafile is comparably large (~200MB) it is not directly provided with the example.\n",
"You can [download](https://zenodo.org/record/7573825/files/MoTe2.h5?download=1) it from zenodo. Place the file in the directory of this notebook afterwards. Under Linux, macOS and in a NORTH container you can directly use the cell below to download the file with curl."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"skip-execution"
]
},
"outputs": [],
"source": [
"! curl -o MoTe2.h5 \"https://zenodo.org/records/7573825/files/MoTe2.h5?download=1\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Convert the file to NeXus\n",
"To convert the available files to the NeXus format we use the convert function readily supplied by pynxtools.\n",
"It uses the downloaded measurement file, a json config file and optionally an electronic lab notebook (ELN) yaml file that is used in the [binning of WSe2 example](./E2%20Binning%20of%20WSe2.ipynb).\n",
"The json config file maps specific metadata from the h5 measurement file to the nxs file, i.e. a pressure reading which automatically gets collected during measurement.\n",
"The ELN is a file which supplies additional metadata which is written into the NeXus file.\n",
"This is data which is not collected automatically, such as the person conducting the experiment.\n",
"It can be written manually or generated, e.g. by the NOMAD ELN functionality.\n",
"\n",
"The convert command may also be executed in the command line with the command `dataconverter`:\n",
"```\n",
"dataconverter \\\n",
" --reader mpes \\\n",
" --nxdl NXmpes \\\n",
" --output MoTe2.mpes.nxs \\\n",
" MoTe2.h5 \\\n",
" config_file.json\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from pynxtools.dataconverter.convert import convert"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The input parameters are defined as follows:\n",
"\n",
"**reader**: The specific reader which gets called inside pynxtools. This is supplied in the pynxtools python code. If you create a specific reader for your measurement file it gets selecetd here. If you use the binning procedure from FHI to generate a xarray h5 file you should use the reader called `mpes`.\n",
"\n",
"**nxdl**: The specific nxdl file to be used. For MPES this should always be `NXmpes` or one of its subdefinitions of the form `NXmpes_<name>`.\n",
" \n",
"**output**: The output filename of the NeXus file."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"convert(input_file=[\"MoTe2.h5\", \"config_file.json\"],\n",
" reader='mpes',\n",
" nxdl='NXmpes',\n",
" output='MoTe2.mpes.nxs')"
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"## View the data with H5Web\n",
"H5Web is a tool for visualizing any data in the h5 data format. Since the NeXus format builds opon h5 it can be used to view this data as well. We just import the package and call H5Web with the output filename from the convert command above. For an analysis on NeXus data files please refer to [analysis example](./E3%20pyARPES%20analysis.ipynb).\n",
"\n",
"You can also view this data with the H5Viewer or other tools from your local filesystem."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from jupyterlab_h5web import H5Web"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"H5Web('MoTe2.mpes.nxs')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.12"
},
"vscode": {
"interpreter": {
"hash": "982c6a11128e6710069266786b6cc2519a098e817123fe996210f6bb9a67eb40"
}
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading
Loading