Metadata-Version: 2.4
Name: passive-shimming
Version: 0.0.1
Summary: Tools for passive MRI shimming, shim-field simulation, optimization, and fabrication.
Author: Sairam Geethanath
License-Expression: MIT
Project-URL: Homepage, https://github.com/imr-framework/passive_shimming
Project-URL: Repository, https://github.com/imr-framework/passive_shimming
Project-URL: Issues, https://github.com/imr-framework/passive_shimming/issues
Keywords: MRI,magnetic resonance imaging,passive shimming,low-field MRI,magpylib,shim optimization,3D printing
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Education
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Physics
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=2.0
Requires-Dist: scipy>=1.13
Requires-Dist: matplotlib>=3.9
Requires-Dist: plotly>=5.24
Requires-Dist: magpylib>=5.0
Requires-Dist: pymoo<0.7,>=0.6.1.3
Requires-Dist: trimesh>=4.4
Requires-Dist: shapely>=2.0
Requires-Dist: numpy-stl>=3.1
Requires-Dist: manifold3d>=3.0
Provides-Extra: notebook
Requires-Dist: jupyterlab>=4; extra == "notebook"
Requires-Dist: ipykernel>=6; extra == "notebook"
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == "dev"
Requires-Dist: twine>=5; extra == "dev"
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: jupyterlab>=4; extra == "dev"
Requires-Dist: ipykernel>=6; extra == "dev"
Dynamic: license-file

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