-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #176 from FAIRmat-NFDI/165-merging-of-multiple-files
Introduces a new mapping flag and auto merge of partial NeXus files feature
- Loading branch information
Showing
16 changed files
with
251 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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 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,36 @@ | ||
# JSON Map Reader | ||
|
||
## What is this reader? | ||
|
||
This reader is designed to allow users of pynxtools to convert their existing data with the help of a map file. The map file tells the reader what to pick from your data files and convert them to FAIR NeXus files. The following formats are supported as input files: | ||
* HDF5 (any extension works i.e. h5, hdf5, nxs, etc) | ||
* JSON | ||
* Python Dict Objects Pickled with [pickle](https://docs.python.org/3/library/pickle.html). These can contain [xarray.DataArray](https://docs.xarray.dev/en/stable/generated/xarray.DataArray.html) objects as well as regular Python types and Numpy types. | ||
|
||
It accepts any NXDL file that you like as long as your mapping file contains all the fields. | ||
Please use the --generate-template function of the dataconverter to create a .mapping.json file. | ||
|
||
```console | ||
user@box:~$ dataconverter --nxdl NXmynxdl --generate-template > mynxdl.mapping.json | ||
``` | ||
##### Details on the [mapping.json](/pynxtools/dataconverter/readers/json_map/README.md#the-mappingjson-file) file. | ||
|
||
## How to run these examples? | ||
|
||
### Automatically merge partial NeXus files | ||
```console | ||
user@box:~$ dataconverter --nxdl NXiv_temp --input-file voltage_and_temperature.nxs --input-file current.nxs --output auto_merged.nxs | ||
``` | ||
|
||
### Map and copy over data to new NeXus file | ||
```console | ||
user@box:~$ dataconverter --nxdl NXiv_temp --mapping merge_copied.mapping.json --input-file voltage_and_temperature.nxs --input-file current.nxs --output merged_copied.nxs | ||
``` | ||
|
||
### Map and link over data to new NeXus file | ||
```console | ||
user@box:~$ dataconverter --nxdl NXiv_temp --mapping merge_linked.mapping.json --input-file voltage_and_temperature.nxs --input-file current.nxs --output merged_linked.nxs | ||
``` | ||
|
||
## Contact person in FAIRmat for this reader | ||
Sherjeel Shabih |
Binary file not shown.
Binary file not shown.
This file contains 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,35 @@ | ||
{ | ||
"/@default": "entry", | ||
"/ENTRY[entry]/DATA[data]/current": "/entry/data/current", | ||
"/ENTRY[entry]/DATA[data]/current_295C": "/entry/data/current_295C", | ||
"/ENTRY[entry]/DATA[data]/current_300C": "/entry/data/current_300C", | ||
"/ENTRY[entry]/DATA[data]/current_305C": "/entry/data/current_305C", | ||
"/ENTRY[entry]/DATA[data]/current_310C": "/entry/data/current_310C", | ||
"/ENTRY[entry]/DATA[data]/temperature": "/entry/data/temperature", | ||
"/ENTRY[entry]/DATA[data]/voltage": "/entry/data/voltage", | ||
"/ENTRY[entry]/INSTRUMENT[instrument]/ENVIRONMENT[environment]/voltage_controller/calibration_time": "/entry/instrument/environment/voltage_controller/calibration_time", | ||
"/ENTRY[entry]/INSTRUMENT[instrument]/ENVIRONMENT[environment]/voltage_controller/run_control": "/entry/instrument/environment/voltage_controller/run_control", | ||
"/ENTRY[entry]/INSTRUMENT[instrument]/ENVIRONMENT[environment]/voltage_controller/value": "/entry/instrument/environment/voltage_controller/value", | ||
"/ENTRY[entry]/INSTRUMENT[instrument]/ENVIRONMENT[environment]/temperature_controller/calibration_time": "/entry/instrument/environment/temperature_controller/calibration_time", | ||
"/ENTRY[entry]/INSTRUMENT[instrument]/ENVIRONMENT[environment]/temperature_controller/run_control": "/entry/instrument/environment/temperature_controller/run_control", | ||
"/ENTRY[entry]/INSTRUMENT[instrument]/ENVIRONMENT[environment]/temperature_controller/value": "/entry/instrument/environment/temperature_controller/value", | ||
"/ENTRY[entry]/INSTRUMENT[instrument]/ENVIRONMENT[environment]/current_sensor/calibration_time": "/entry/instrument/environment/current_sensor/calibration_time", | ||
"/ENTRY[entry]/INSTRUMENT[instrument]/ENVIRONMENT[environment]/current_sensor/run_control": "/entry/instrument/environment/current_sensor/run_control", | ||
"/ENTRY[entry]/INSTRUMENT[instrument]/ENVIRONMENT[environment]/current_sensor/value": "/entry/instrument/environment/current_sensor/value", | ||
"/ENTRY[entry]/INSTRUMENT[instrument]/ENVIRONMENT[environment]/independent_controllers": ["voltage_controller", "temperature_control"], | ||
"/ENTRY[entry]/INSTRUMENT[instrument]/ENVIRONMENT[environment]/measurement_sensors": ["current_sensor"], | ||
"/ENTRY[entry]/INSTRUMENT[instrument]/ENVIRONMENT[environment]/NXpid[heating_pid]/description": "/entry/instrument/environment/heating_pid/description", | ||
"/ENTRY[entry]/INSTRUMENT[instrument]/ENVIRONMENT[environment]/NXpid[heating_pid]/setpoint": "/entry/instrument/environment/heating_pid/setpoint", | ||
"/ENTRY[entry]/INSTRUMENT[instrument]/ENVIRONMENT[environment]/NXpid[heating_pid]/K_p_value": "/entry/instrument/environment/heating_pid/K_p_value", | ||
"/ENTRY[entry]/INSTRUMENT[instrument]/ENVIRONMENT[environment]/NXpid[heating_pid]/K_i_value": "/entry/instrument/environment/heating_pid/K_i_value", | ||
"/ENTRY[entry]/INSTRUMENT[instrument]/ENVIRONMENT[environment]/NXpid[heating_pid]/K_d_value": "/entry/instrument/environment/heating_pid/K_d_value", | ||
"/ENTRY[entry]/PROCESS[process]/program": "Bluesky", | ||
"/ENTRY[entry]/PROCESS[process]/program/@version": "1.6.7", | ||
"/ENTRY[entry]/SAMPLE[sample]/name": "super", | ||
"/ENTRY[entry]/SAMPLE[sample]/atom_types": "Si, C", | ||
"/ENTRY[entry]/definition": "NXiv_temp", | ||
"/ENTRY[entry]/definition/@version": "1", | ||
"/ENTRY[entry]/experiment_identifier": "dbdfed37-35ed-4aee-a465-aaa0577205b1", | ||
"/ENTRY[entry]/experiment_description": "A simple IV temperature experiment.", | ||
"/ENTRY[entry]/start_time": "2022-05-30T16:37:03.909201+02:00" | ||
} |
This file contains 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,25 @@ | ||
{ | ||
"/@default": "entry", | ||
"/ENTRY[entry]/DATA[data]/current": {"link": "current.nxs:/entry/data/current"}, | ||
"/ENTRY[entry]/DATA[data]/current_295C": {"link": "current.nxs:/entry/data/current_295C"}, | ||
"/ENTRY[entry]/DATA[data]/current_300C": {"link": "current.nxs:/entry/data/current_300C"}, | ||
"/ENTRY[entry]/DATA[data]/current_305C": {"link": "current.nxs:/entry/data/current_305C"}, | ||
"/ENTRY[entry]/DATA[data]/current_310C": {"link": "current.nxs:/entry/data/current_310C"}, | ||
"/ENTRY[entry]/DATA[data]/temperature": {"link": "voltage_and_temperature.nxs:/entry/data/temperature"}, | ||
"/ENTRY[entry]/DATA[data]/voltage": {"link": "voltage_and_temperature.nxs:/entry/data/voltage"}, | ||
"/ENTRY[entry]/INSTRUMENT[instrument]/ENVIRONMENT[environment]/voltage_controller": {"link": "voltage_and_temperature.nxs:/entry/instrument/environment/voltage_controller"}, | ||
"/ENTRY[entry]/INSTRUMENT[instrument]/ENVIRONMENT[environment]/temperature_controller": {"link": "voltage_and_temperature.nxs:/entry/instrument/environment/temperature_controller"}, | ||
"/ENTRY[entry]/INSTRUMENT[instrument]/ENVIRONMENT[environment]/current_sensor": {"link": "current.nxs:/entry/instrument/environment/current_sensor"}, | ||
"/ENTRY[entry]/INSTRUMENT[instrument]/ENVIRONMENT[environment]/independent_controllers": ["voltage_controller", "temperature_control"], | ||
"/ENTRY[entry]/INSTRUMENT[instrument]/ENVIRONMENT[environment]/measurement_sensors": ["current_sensor"], | ||
"/ENTRY[entry]/INSTRUMENT[instrument]/ENVIRONMENT[environment]/NXpid[heating_pid]": {"link": "voltage_and_temperature.nxs:/entry/instrument/environment/heating_pid"}, | ||
"/ENTRY[entry]/PROCESS[process]/program": "Bluesky", | ||
"/ENTRY[entry]/PROCESS[process]/program/@version": "1.6.7", | ||
"/ENTRY[entry]/SAMPLE[sample]/name": "super", | ||
"/ENTRY[entry]/SAMPLE[sample]/atom_types": "Si, C", | ||
"/ENTRY[entry]/definition": "NXiv_temp", | ||
"/ENTRY[entry]/definition/@version": "1", | ||
"/ENTRY[entry]/experiment_identifier": "dbdfed37-35ed-4aee-a465-aaa0577205b1", | ||
"/ENTRY[entry]/experiment_description": "A simple IV temperature experiment.", | ||
"/ENTRY[entry]/start_time": "2022-05-30T16:37:03.909201+02:00" | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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 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 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 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,24 +1,63 @@ | ||
# JSON Map Reader | ||
|
||
This reader allows you to convert either data from a .json file or an xarray exported as a .pickle using a flat .mapping.json file. | ||
## What is this reader? | ||
|
||
This reader is designed to allow users of pynxtools to convert their existing data with the help of a map file. The map file tells the reader what to pick from your data files and convert them to FAIR NeXus files. The following formats are supported as input files: | ||
* HDF5 (any extension works i.e. h5, hdf5, nxs, etc) | ||
* JSON | ||
* Python Dict Objects Pickled with [pickle](https://docs.python.org/3/library/pickle.html). These can contain [xarray.DataArray](https://docs.xarray.dev/en/stable/generated/xarray.DataArray.html) objects as well as regular Python types and Numpy types. | ||
|
||
It accepts any NXDL file that you like as long as your mapping file contains all the fields. | ||
Please use the --generate-template function of the dataconverter to create a .mapping.json file. | ||
|
||
```console | ||
user@box:~$ python convert.py --nxdl NXmynxdl --generate-template > mynxdl.mapping.json | ||
user@box:~$ dataconverter --nxdl NXmynxdl --generate-template > mynxdl.mapping.json | ||
``` | ||
|
||
There are some example files you can use: | ||
|
||
[data.mapping.json](/tests/data/dataconverter/readers/json_map/data.mapping.json) | ||
|
||
[data.mapping.json](/tests/data/tools/dataconverter/readers/json_map/data.mapping.json) | ||
|
||
[data.json](/tests/data/tools/dataconverter/readers/json_map/data.json) | ||
[data.json](/tests/data/dataconverter/readers/json_map/data.json) | ||
|
||
```console | ||
user@box:~$ python convert.py --nxdl NXtest --input-file data.json --input-file data.mapping.json --reader json_map | ||
user@box:~$ dataconverter --nxdl NXtest --input-file data.json --mapping data.mapping.json | ||
``` | ||
|
||
##### [Example](/examples/json_map/) with HDF5 files. | ||
|
||
## The mapping.json file | ||
|
||
This file is designed to let you fill in the requirements of a NeXus Application Definition without writing any code. If you already have data in the formats listed above, you just need to use this mapping file to help the dataconverter pick your data correctly. | ||
|
||
The mapping files will always be based on the Template the dataconverter generates. See above on how to generate a mapping file. | ||
The right hand side values of the Template keys are what you can modify. | ||
|
||
Here are the three different ways you can fill the right hand side of the Template keys: | ||
* Write the nested path in your datafile. This is indicated by a leading `/` before the word `entry` to make `/entry/data/current_295C` below. | ||
Example: | ||
|
||
```json | ||
"/ENTRY[entry]/DATA[data]/current_295C": "/entry/data/current_295C", | ||
"/ENTRY[entry]/NXODD_name/posint_value": "/a_level_down/another_level_down/posint_value", | ||
``` | ||
|
||
* Write the values directly in the mapping file for missing data from your data file. | ||
|
||
```json | ||
|
||
"/ENTRY[entry]/PROCESS[process]/program": "Bluesky", | ||
"/ENTRY[entry]/PROCESS[process]/program/@version": "1.6.7" | ||
``` | ||
|
||
* Write JSON objects with a link key. This follows the same link mechanism that the dataconverter implements. In the context of this reader, you can only use external links to your data files. In the example below, `current.nxs` is an already existing HDF5 file that we link to in our new NeXus file without copying over the data. The format is as follows: | ||
`"link": "<filename>:<path_in_file>"` | ||
Note: This only works for HDF5 files currently. | ||
|
||
```json | ||
"/ENTRY[entry]/DATA[data]/current_295C": {"link": "current.nxs:/entry/data/current_295C"}, | ||
"/ENTRY[entry]/DATA[data]/current_300C": {"link": "current.nxs:/entry/data/current_300C"}, | ||
``` | ||
|
||
## Contact person in FAIRmat for this reader | ||
Sherjeel Shabih | ||
Sherjeel Shabih |
Oops, something went wrong.