https://github.com/diamondlightsource/mmg_toolbox
Repository for useful python data analysis functions for the Diamond Magnetic Materials Group
https://github.com/diamondlightsource/mmg_toolbox
Last synced: 23 days ago
JSON representation
Repository for useful python data analysis functions for the Diamond Magnetic Materials Group
- Host: GitHub
- URL: https://github.com/diamondlightsource/mmg_toolbox
- Owner: DiamondLightSource
- License: apache-2.0
- Created: 2024-10-16T11:29:46.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2026-03-11T16:11:38.000Z (25 days ago)
- Last Synced: 2026-03-11T17:04:54.393Z (25 days ago)
- Language: Python
- Size: 1.92 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://pypi.org/project/mmg_toolbox)
[](https://opensource.org/licenses/Apache-2.0)
[](https://github.com/DiamondLightSource/mmg_toolbox)
# mmg_toolbox
Repository for useful python data analysis functions for the Diamond Magnetic Materials Group
Source |
:---: | :---:
PyPI | `pip install mmg_toolbox`
Documentation |
Releases |
### Installation
*Requires:* Python >=3.10, Numpy, h5py, matplotlib, hdfmap, nexus2srs
```bash
python -m pip install mmg_toolbox
```
### @DLS
mmg_toolbox is available via the module system:
```bash
$ module load mmg
(python)$ dataviewer
# OR
(python)$ create_notebooks
```
### Usage - Read a NeXus scan file
Read data from a NeXus scan file in a python prompt or script
```python
from mmg_toolbox import data_file_reader
scan = data_file_reader('12345.nxs', beamline='i16')
print(scan) # print a metadata string
scan.plot.plot() # plot defaults
scan.plot.show()
```
### Usage - DataViewer
Start the dataviewer from a terminal
```bash
$ dataviewer
```
Or, to open the data viewer in the current folder:
```bash
$ dataviewer .
```
Or, to open the file viewer for a specific file:
```bash
dataviewer path/to/file.nxs
```
### Usage - Scripting
mmg_toolbox contains many useful tools for data analysis in python scripts, for example:
```python
import matplotlib.pyplot as plt
from mmg_toolbox import Experiment
exp = Experiment('/path/to/files')
# list scans
all_scans = exp.all_scan_numbers() # {scan_number: filename}
print('\n'.join(exp.scans_str(*all_scans)))
exp.plot(1108746, 1108747, 1108748)
scans = exp.scans(*range(-10, 0))
for scan in scans:
scan.plot()
axes, signal = scan.eval('axes, signal')
```
### create_notebooks
the *create_notebooks* script is included as a simple way to get started and create some default scripts in your
working directory. By default you will be prompted to provide a beamline and a directory or visit ID. The
script can then start a Jupyter Lab instance in that directory.
| command | |
|---------------------------------|--------------------------------------------------------|
| `$ create_notebooks` | interactively create scripts and start jupyter |
| `$ create_notebooks -b i10-1 .` | create i10-1 specific scripts in the current directory |
| `$ create_notebooks --help` | additional options |
### Dataviewer
mmg_toolbox contains a tkinter based dataviewer for viewing data in NeXus files. Various plotting and processing
capabilities are available.

## Feedback
mmg_toolbox is still under development, so if you have any feedback, found any bugs or have any feature requests -
please do let me know!