-
Notifications
You must be signed in to change notification settings - Fork 3
Add esrf bm16 data #17
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d62fbf3
remove module copied from xraylarch
woutdenolf 95960c0
flake8
woutdenolf cb7a88b
incorporate conversion_examples in docs and CONTRIBUTING description
woutdenolf 5ca6add
adapt conversion_examples to NXxas changes
woutdenolf 690f57b
default NXentry
woutdenolf 89c966c
fix filenames and dirs
woutdenolf 351b48c
add example: transmission + reference + multi-detector fluorescence
woutdenolf b5e163c
build docs only on linux
woutdenolf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,44 @@ | ||
| <a href="https://gitlab.esrf.fr/workflow/ewoksadmin/ewoksci/-/blob/main/CONTRIBUTING.md" target="_blank">CONTRIBUTING.md</a> | ||
| ## Getting started | ||
|
|
||
| Requirements are listed in `setup.cfg` and can be installed with | ||
|
|
||
| ```bash | ||
| pip install [--user] .[dev] | ||
| ``` | ||
|
|
||
| ## Make a contribution | ||
|
|
||
| Before making a merge request make sure the following is done on your branch | ||
|
|
||
| 1. Update HDF5 repository examples | ||
| 2. Linting | ||
| 3. Testing | ||
|
|
||
| ### Update HDF5 repository examples | ||
|
|
||
| To be sure all HDF5 files are compliant with the latest standard | ||
|
|
||
| ```bash | ||
| pip install -e .[dev] | ||
| ./converted/generate.sh | ||
| ``` | ||
|
|
||
| ### Linting | ||
|
|
||
| The configuration for [black](https://black.readthedocs.io/en/stable/) and [flake8](https://flake8.pycqa.org/en/latest/index.html) can be modified in `setup.cfg`. | ||
|
|
||
| Comment lines with `# noqa: E123` to ignore certain linting errors. | ||
|
|
||
| ### Testing | ||
|
|
||
| Tests make use [pytest](https://docs.pytest.org/en/stable/index.html) and can be run as follows | ||
|
|
||
| ```bash | ||
| pytest . | ||
| ``` | ||
|
|
||
| Testing an installed project is done like this | ||
|
|
||
| ```bash | ||
| pytest --pyargs <project_name> | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| from pathlib import Path | ||
|
|
||
| import h5py | ||
| import numpy | ||
|
|
||
| THIS_DIRECTORY = Path(__file__).parent | ||
|
|
||
|
|
||
| def bliss2nexus(nxentry_in, expressions, metadata, nxroot_out, entry_name): | ||
| root = create_nxclass(nxroot_out, entry_name, "NXentry") | ||
| nxroot_out.attrs["default"] = entry_name | ||
|
|
||
| inst = create_nxclass(root, "instrument", "NXinstrument") | ||
|
|
||
| source = create_nxclass(inst, "source", "NXsource") | ||
| source["type"] = "Synchrotron X-ray Source" | ||
| source["probe"] = "x-ray" | ||
|
|
||
| monochromator = create_nxclass(inst, "monochromator", "NXmonochromator") | ||
| nxinstrument_input = nxentry_in["instrument"] | ||
| dset = nxinstrument_input[metadata["energy"]]["data"] | ||
| monochromator["energy"] = dset[()] | ||
| energy_units = dset.attrs.get("units", "keV") | ||
| monochromator.attrs["units"] = energy_units | ||
|
|
||
| for name, expression in expressions.items(): | ||
| subroot = create_nxclass(root, name, "NXsubentry", default="plot") | ||
| root.attrs["default"] = name | ||
| subroot["definition"] = "NXxas" | ||
|
|
||
| mode = expression["mode"] | ||
| subroot["mode"] = mode | ||
|
|
||
| subroot["energy"] = h5py.SoftLink(monochromator["energy"].name) | ||
|
|
||
| if mode == "transmission": | ||
| I0 = nxinstrument_input[expression["I0"]]["data"][()] | ||
| It = nxinstrument_input[expression["It"]]["data"][()] | ||
| subroot["intensity"] = numpy.log(I0 / It) | ||
| elif mode == "fluorescence": | ||
| I0 = nxinstrument_input[expression["I0"]]["data"][()] | ||
| mca = nxinstrument_input[expression["mca"]] | ||
| Ifluo = mca[expression["Ifluo"]][()] | ||
| Lt = mca[expression["Lt"]][()] | ||
| subroot["intensity"] = numpy.log(Ifluo / (I0 * Lt)) | ||
| else: | ||
| raise NotImplementedError(mode) | ||
|
|
||
| element = create_nxclass(subroot, "element", "NXelement") | ||
| element["symbol"] = metadata["element"] | ||
|
|
||
| edge = create_nxclass(subroot, "edge", "NXedge") | ||
| edge["name"] = metadata["edge"] | ||
|
|
||
| plot = create_nxclass( | ||
| subroot, "plot", "NXdata", signal="intensity", axes="energy" | ||
| ) | ||
| plot["title"] = expression.get("title", name) | ||
| plot["energy"] = h5py.SoftLink(subroot["energy"].name) | ||
| plot["intensity"] = h5py.SoftLink(subroot["intensity"].name) | ||
| plot["energy"].attrs["long_name"] = f"Energy ({energy_units})" | ||
| plot["intensity"].attrs["long_name"] = "Normalized mu(E)" | ||
|
|
||
|
|
||
| def create_nxclass(root, name, nx_class, **attrs): | ||
| """Create NeXus class instance with attributes.""" | ||
| child = root.create_group(name, track_order=True) | ||
| child.attrs["NX_class"] = nx_class | ||
| for name, value in attrs.items(): | ||
| child.attrs[name] = value | ||
| return child | ||
|
|
||
|
|
||
| def main(output_filename): | ||
| with h5py.File(output_filename, "w", track_order=True) as nxroot_out: | ||
|
|
||
| input_filename = THIS_DIRECTORY / "test_Assolution_Mauro_0001.h5" | ||
|
|
||
| expressions = { | ||
| "itrans": { | ||
| "mode": "transmission", | ||
| "I0": "p201_1_bkg_sub", | ||
| "It": "p201_3_bkg_sub", | ||
| "title": "Transmission", | ||
| }, | ||
| "iref": { | ||
| "mode": "transmission", | ||
| "I0": "p201_3_bkg_sub", | ||
| "It": "p201_5_bkg_sub", | ||
| "title": "Standard", | ||
| }, | ||
| } | ||
| for mca_nr in range(16): | ||
| expressions[f"fluo{mca_nr}"] = { | ||
| "mode": "fluorescence", | ||
| "I0": "p201_1_bkg_sub", | ||
| "mca": f"xmapd16_det{mca_nr}", | ||
| "Ifluo": "roi1", | ||
| "Lt": "live_time", # effective measurement time | ||
| "title": f"Fluorescence #{mca_nr}", | ||
| } | ||
| metadata = {"element": "As", "edge": "K", "energy": "energy_enc"} | ||
|
|
||
| with h5py.File(input_filename, "r") as nxroot_in: | ||
| for entry_name in nxroot_in: | ||
| if entry_name.endswith(".1"): | ||
| nxentry_in = nxroot_in[entry_name] | ||
| bliss2nexus( | ||
| nxentry_in, expressions, metadata, nxroot_out, entry_name | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main(THIS_DIRECTORY / ".." / ".." / "nxxas_examples" / f"{THIS_DIRECTORY.name}.h5") | ||
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They recommend to import as
import numpy as np. Not critical, though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a favor for the same reason I'm not in favor of single letter variable names.