pynxtools-igor 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -0,0 +1,17 @@
1
+ """
2
+ MKdocs macros for the documentation
3
+ """
4
+
5
+
6
+ def define_env(env):
7
+ """
8
+ This is the hook for defining variables, macros and filters
9
+
10
+ - variables: the dictionary that contains the environment variables
11
+ - macro: a decorator function, to declare a macro.
12
+ - filter: a function with one of more arguments,
13
+ used to perform a transformation
14
+ """
15
+
16
+ # add to the dictionary of variables available to markdown pages:
17
+ env.variables["version"] = "2023.10" # Figure out from setuptools-scm eventually
@@ -0,0 +1,35 @@
1
+ #
2
+ # Copyright The NOMAD Authors.
3
+ #
4
+ # This file is part of NOMAD. See https://nomad-lab.eu for further info.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ """Entry points for igor examples."""
19
+
20
+ try:
21
+ from nomad.config.models.plugins import ExampleUploadEntryPoint
22
+ except ImportError as exc:
23
+ raise ImportError(
24
+ "Could not import nomad package. Please install the package 'nomad-lab'.",
25
+ ) from exc
26
+
27
+ igor_example = ExampleUploadEntryPoint(
28
+ title="Igor Reader",
29
+ category="FAIRmat examples",
30
+ description="""
31
+ Description tbd
32
+ """,
33
+ plugin_package="pynxtools_igor",
34
+ resources=["nomad/examples/*"],
35
+ )
@@ -0,0 +1,224 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# Example for using the Igor reader\n",
8
+ "The igor reader allows reading data from Wavemetrics Igor Pro .ibw \"binary wave\" files and .pxp \"packed experiment\" files. These two modes of operation are mutually exclusive, i.e. you can either pass one or multiple ibw files, or one pxp file. The behavior of the reader is controlled via two config files: ``config.json`` defines the assignment to nexus class paths, whereas ``entries.yaml.entry`` defines which data to read from the source file(s). This notebook showcases several examples how to use the reader. A more complete example and template how to convert complete datasets can be found in another example notebook. These examples convert to the nexus class ``NXroot``, the most generic Nexus class."
9
+ ]
10
+ },
11
+ {
12
+ "cell_type": "code",
13
+ "execution_count": null,
14
+ "metadata": {},
15
+ "outputs": [],
16
+ "source": [
17
+ "%load_ext autoreload\n",
18
+ "%autoreload 2\n",
19
+ "from pynxtools.dataconverter.convert import convert\n",
20
+ "import yaml"
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "markdown",
25
+ "metadata": {},
26
+ "source": [
27
+ "## Convert from ``.ibw`` Igor binary wave files"
28
+ ]
29
+ },
30
+ {
31
+ "cell_type": "markdown",
32
+ "metadata": {},
33
+ "source": [
34
+ "### Conversion without entry definition\n",
35
+ "The conversion from ``.ibw`` files does not require the definition of an entry file. In that case, each ibw file generates an entry with the filename (excluding \".ibw\") as entry name. Axis data as well as units are read from the ibw wave information (internal wave scaling), and named ``axis0`` to ``axis3``. These are available via the ``@data`` mechanism. Wave notes are parsed and split according to a ``key=value\\\\n`` schema, and are available vie the ``@attrs`` mechanism."
36
+ ]
37
+ },
38
+ {
39
+ "cell_type": "code",
40
+ "execution_count": null,
41
+ "metadata": {},
42
+ "outputs": [],
43
+ "source": [
44
+ "convert(\n",
45
+ " input_file=[\"config_file.json\", \"Norm_0057.ibw\", \"Norm_0059.ibw\"],\n",
46
+ " reader=\"igor\",\n",
47
+ " nxdl=\"NXroot\",\n",
48
+ " output=\"example_ibw.nxs\",\n",
49
+ ")"
50
+ ]
51
+ },
52
+ {
53
+ "cell_type": "markdown",
54
+ "metadata": {},
55
+ "source": [
56
+ "### Conversion with entry definition\n",
57
+ "Alternatively, an entry definition can be passed in addition, which contains a dictionary of entries, where each entry key generates an entry of that name. The dict entries are expected to be dicts as well, containing at least the key ``data`` with the filename of the respective ibw file to use as data for this entry. Additionally, ``axisN_name`` keys can be passed to rename the axis entries from the default ``axis0`` to ``axis3``. Similarly, ``axisN_units`` and ``data_units`` can be passed to overwrite respective information read from the ibw files. ibw files for which no entry has been defined will generate an entry according to their filename as before. Additionally, each entry can contain a ``metadata`` dict with additional metadata specific to this entry.\n",
58
+ "\n",
59
+ "This entry dict can be passed as an object, in which case it is expected as sole and single object in the objects tuple."
60
+ ]
61
+ },
62
+ {
63
+ "cell_type": "code",
64
+ "execution_count": null,
65
+ "metadata": {},
66
+ "outputs": [],
67
+ "source": [
68
+ "entry_dict = {\n",
69
+ " \"Scan57\": {\n",
70
+ " \"data\": \"Norm_0057.ibw\",\n",
71
+ " \"data_units\": \"counts/monitor\",\n",
72
+ " \"axis0_name\": \"theta\",\n",
73
+ " \"axis0_units\": \"degree\",\n",
74
+ " },\n",
75
+ "}\n",
76
+ "convert(\n",
77
+ " input_file=[\"config_file.json\", \"Norm_0057.ibw\", \"Norm_0059.ibw\"],\n",
78
+ " reader=\"igor\",\n",
79
+ " nxdl=\"NXroot\",\n",
80
+ " output=\"example_ibw_entry.nxs\",\n",
81
+ " objects=(entry_dict,),\n",
82
+ ")"
83
+ ]
84
+ },
85
+ {
86
+ "cell_type": "markdown",
87
+ "metadata": {},
88
+ "source": [
89
+ "The ``entry`` dict can also be passed as yaml file with extension ``.entry``"
90
+ ]
91
+ },
92
+ {
93
+ "cell_type": "code",
94
+ "execution_count": null,
95
+ "metadata": {},
96
+ "outputs": [],
97
+ "source": [
98
+ "with open(\"Norm57.yaml.entry\", \"w\") as f:\n",
99
+ " yaml.dump(entry_dict, f)\n",
100
+ "convert(\n",
101
+ " input_file=[\n",
102
+ " \"config_file.json\",\n",
103
+ " \"Norm_0057.ibw\",\n",
104
+ " \"Norm_0059.ibw\",\n",
105
+ " \"Norm57.yaml.entry\",\n",
106
+ " ],\n",
107
+ " reader=\"igor\",\n",
108
+ " nxdl=\"NXroot\",\n",
109
+ " output=\"example_ibw_entry.nxs\",\n",
110
+ ")"
111
+ ]
112
+ },
113
+ {
114
+ "cell_type": "markdown",
115
+ "metadata": {},
116
+ "source": [
117
+ "## Conversion from Igor packed experiment files\n",
118
+ "Conversion from ``.pxp`` files requires definition of an entry dict. Here also, each key/value defines one entry to generate in the Nexus file. the ``data`` entry contains here the ibw-path to the wave to use as main data entry. Axis information can be either read from the wave scaling, or be provided via an ``axisN`` entry, pointing to a wave containing axis information. Similarly, a ``data_errors`` key can be defined, pointing to a wave containing data uncertainties."
119
+ ]
120
+ },
121
+ {
122
+ "cell_type": "code",
123
+ "execution_count": null,
124
+ "metadata": {},
125
+ "outputs": [],
126
+ "source": [
127
+ "# pxp test\n",
128
+ "entry_dict = {\n",
129
+ " \"Scan57\": {\n",
130
+ " \"data\": \"root/Norm_0057\",\n",
131
+ " \"data_units\": \"counts/monitor\",\n",
132
+ " \"axis0\": \"root/Raw/SPECScan_0057/QWave\",\n",
133
+ " \"axis0_name\": \"l\",\n",
134
+ " \"axis0_units\": \"r.l.u.\",\n",
135
+ " \"metadata\": {\"entry_title\": \"Scan at 16 K\"},\n",
136
+ " },\n",
137
+ " \"Scan59\": {\n",
138
+ " \"data\": \"root/Norm_0059\",\n",
139
+ " \"data_units\": \"counts/monitor\",\n",
140
+ " \"axis0\": \"root/Raw/SPECScan_0059/QWave\",\n",
141
+ " \"axis0_name\": \"l\",\n",
142
+ " \"axis0_units\": \"r.l.u.\",\n",
143
+ " \"metadata\": {\"entry_title\": \"Scan at 18 K\"},\n",
144
+ " },\n",
145
+ "}\n",
146
+ "convert(\n",
147
+ " input_file=[\"config_file.json\", \"Fig2a.pxp\"],\n",
148
+ " reader=\"igor\",\n",
149
+ " nxdl=\"NXroot\",\n",
150
+ " output=\"example_pxp.nxs\",\n",
151
+ " objects=(entry_dict,),\n",
152
+ ")"
153
+ ]
154
+ },
155
+ {
156
+ "cell_type": "markdown",
157
+ "metadata": {},
158
+ "source": [
159
+ "This method also can be invoked using a ``.entry`` yaml file"
160
+ ]
161
+ },
162
+ {
163
+ "cell_type": "code",
164
+ "execution_count": null,
165
+ "metadata": {},
166
+ "outputs": [],
167
+ "source": [
168
+ "with open(\"Scan57_59.yaml.entry\", \"w\") as f:\n",
169
+ " yaml.dump(entry_dict, f)\n",
170
+ "convert(\n",
171
+ " input_file=[\"config_file.json\", \"Fig2a.pxp\", \"Scan57_59.yaml.entry\"],\n",
172
+ " reader=\"igor\",\n",
173
+ " nxdl=\"NXroot\",\n",
174
+ " output=\"example_pxp.nxs\",\n",
175
+ ")"
176
+ ]
177
+ },
178
+ {
179
+ "cell_type": "markdown",
180
+ "metadata": {},
181
+ "source": [
182
+ "## Invoking from command line\n",
183
+ "Off course, the dataconverter can also be called from the command line"
184
+ ]
185
+ },
186
+ {
187
+ "cell_type": "code",
188
+ "execution_count": null,
189
+ "metadata": {},
190
+ "outputs": [],
191
+ "source": [
192
+ "!dataconverter --reader igor --nxdl NXroot --output example_pxp.nxs config_file.json Fig2a.pxp Scan57_59.yaml.entry"
193
+ ]
194
+ },
195
+ {
196
+ "cell_type": "code",
197
+ "execution_count": null,
198
+ "metadata": {},
199
+ "outputs": [],
200
+ "source": []
201
+ }
202
+ ],
203
+ "metadata": {
204
+ "kernelspec": {
205
+ "display_name": ".pyenv",
206
+ "language": "python",
207
+ "name": "python3"
208
+ },
209
+ "language_info": {
210
+ "codemirror_mode": {
211
+ "name": "ipython",
212
+ "version": 3
213
+ },
214
+ "file_extension": ".py",
215
+ "mimetype": "text/x-python",
216
+ "name": "python",
217
+ "nbconvert_exporter": "python",
218
+ "pygments_lexer": "ipython3",
219
+ "version": "3.8.0"
220
+ }
221
+ },
222
+ "nbformat": 4,
223
+ "nbformat_minor": 2
224
+ }