Skip to content

jdranczewski/Magic2

Repository files navigation

Magic2

A rewrite of the original Magic by George Swadling, done by Jakub Dranczewski during a UROP in 2018.

The purpose of Magic2 is to interpolate and help in the analysis of traced out interferograms, mostly for the purpose of plasma physics research. It also has many functions assisting in the processing and inspection of the obtained data. It is also a fully independent Python library that can be used with other code in headless mode (no GUI).

Getting help

help.html in the main catalogue of this project contains all the information you should need to use the GUI of Magic2.

All of the code is heavily commented, so it shouldn't be very hard to understand.

Preparing the python environment

Magic2 has been tested with:

Python 3.14.0 environment with Package Version


contourpy 1.3.3 cycler 0.12.1 fonttools 4.63.0 imageio 2.37.3 kiwisolver 1.5.0 lazy-loader 0.5 matplotlib 3.11.0 networkx 3.6.1 numpy 2.5.0 packaging 26.2 pillow 12.2.0 pyparsing 3.3.2 python-dateutil 2.9.0.post0 scikit-image 0.26.0 scipy 1.18.0 six 1.17.0 tifffile 2026.6.1

Errors with Magic2 can occur as these packages updated and change their syntax. We recommend you use a virtual environmenet, such as uv or conda, to install compatible packages. For example, after creating a venv with uv, you can use

uv pip install numpy, scipy, matplotlib, scikit-image

to install the relevant packages. If you find incompatibilities with the latest packages, please submit an issue in github, or if you are able to fix it, please submit a pull request.

Running the software

Run main.py in the Python distribution of your choice or double click Magic2.bat in Windows.

What's the difference between Magic2 and Magic?

  • Magic2 is the sequel written in Python instead of Matlab, which means it doesn't require proprietary software to run.
  • It's faster - both in normal operation and interpolation.
  • It's more streamlined - with a few user interface improvements that should speed up your workflow.
  • It's got better lineouts - they're really cool, try them!
  • It's got its own file format, which allows you to store all the important data for a shot in around 200KB for easy safekeeping and circulation.
  • It's got a few new functions, and most of the old ones.

The structure of this repository

There are two main branches: master is the stable branch, you can always grab the most recent release from here. The release history can also be found here. dev is used for development, features, and fixes that are being built live there - it's often unstable. docs is a long forgotten branch that was used to kickstart the documentation.

Using Magic2 as a library

Magic2 is capable of running in headless mode (without GUI). See main_old.py for reference, it contains the entire flow of the programme without putting it all in a window. To import a Magic2 module, use the normal Python import syntax:

import magic2.triangulate

or, to make referencing easier:

import magic2.triangulate as m2triangulate

You have to have the magic2 folder in a place where Python can find it, either in the same directory as your code, or in a folder that is in your PYTHONPATH.

Bear in mind that while Magic2's functions and classes are general, they will expect the data you provide them with to have a particular structure.

References

  • Swadling, G. F. et al. (2013) ‘Oblique shock structures formed during the ablation phase of aluminium wire array z-pinches’, Physics of Plasmas. American Institute of Physics, 20(2), p. 022705. doi: 10.1063/1.4790520.
  • Swadling, G. F. (2012) ‘An experimental investigation of the azimuthal structures formed during the ablation phase of wire array z-pinches’, Ph.D. dissertation. Imperial College London. Available at: https://spiral.imperial.ac.uk/handle/10044/1/9515.
  • Ware, J. M. (1998) ‘A procedure for automatically correcting invalid flat triangles occurring in triangulated contour data’, Computers & Geosciences. Pergamon, 24(2), pp. 141–150. doi: 10.1016/S0098-3004(97)00088-5.
  • https://codeplea.com/triangular-interpolation

This work was carried out during a UROP with the MAGPIE Group, Department of Physics, Imperial College London and was supported in part by the Engineering and Physical Sciences Research Council (EPSRC) Grant No. EP/N013379/1, by the U.S. Department of Energy (DOE) Awards No. DE-F03-02NA00057 and No. DE-SC- 0001063

About

The new, Python version of the Magic tool

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors