An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

[![PyPI](https://img.shields.io/pypi/v/dls-dodal.svg)](https://pypi.org/project/mmg_toolbox)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![](https://img.shields.io/github/forks/DiamondLightSource/mmg_toolbox?label=GitHub%20Repo&style=social)](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.
![mmg_dataviewer](docs/images/mmg_dataviewer.png)

## 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!