Skip to content

imr-framework/passive_shimming

Repository files navigation

Overview

This script performs passive magnetic shimming to improve the homogeneity of a magnetic field. Below is a breakdown of the code:

1. Reading Magnetic Field Data

  • The script loads magnetic field data from a .npy file.
  • Converts the field and position data into meters and filters the data within a defined spherical region (DSV - Diameter Spherical Volume).
  • The magnetic field data is visualized in 3D scatter plots.

2. Defining Shim Geometry

  • Specifies the geometry of the shim array, including magnet dimensions, diameter, and magnetization.
  • Creates shim ring templates using the make_shim_ring_template function.
  • Saves the initial shim tray arrangement as an STL file for visualization.

3. Field Computation

  • Computes the magnetic field generated by the shim tray template.
  • Visualizes the computed field and its combination with the measured field.

4. Optimization for Homogeneity

  • Defines an optimization problem using the shimming_problem function to minimize field inhomogeneity.
  • Uses the MixedVariableGA algorithm from the pymoo library to solve the optimization problem.
  • Outputs the optimized shim tray configuration.

5. Generating Optimized Shim Tray

  • Creates an optimized shim tray based on the optimization results.
  • Saves the optimized shim tray as an STL file and visualizes the shimmed magnetic field.

6. Saving and Loading Shim Tray

  • Saves the optimized shim tray configuration to a .pkl file.
  • Demonstrates how to reload and visualize the saved shim tray.

Key Functions and Libraries

  • magpylib: Used for magnetic field computations and visualization.
  • pymoo: Provides optimization algorithms for solving the shimming problem.
  • Custom Functions:
    • get_field_pos, filter_dsv: Process and filter magnetic field data.
    • make_shim_ring_template: Creates shim tray templates.
    • cost_fn: Evaluates the field homogeneity.
    • write2stl: Exports shim tray configurations to STL files.

Outputs

  • Visualizations of the magnetic field before and after shimming.
  • STL files for initial and optimized shim tray configurations.
  • A .pkl file containing the optimized shim tray for future use.

This script automates the process of designing and optimizing passive shim trays for magnetic field correction.

About

Provides passive shimming software and shim tray design outputs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages