Skip to main content

Python wrapper for OpenMagnetics

Project description

PyOpenMagnetics - Python Wrapper for OpenMagnetics

Python License: MIT

PyOpenMagnetics is a Python wrapper for MKF (Magnetics Knowledge Foundation), the simulation engine of OpenMagnetics, providing a comprehensive toolkit for designing and analyzing magnetic components such as transformers and inductors.

Features

  • 🧲 Core Database: Access to extensive database of core shapes, materials, and manufacturers
  • 🔌 Winding Design: Automatic winding calculations with support for various wire types (round, litz, rectangular, planar)
  • 📊 Loss Calculations: Core losses (Steinmetz), winding losses (DC, skin effect, proximity effect)
  • 🎯 Design Adviser: Automated recommendations for optimal magnetic designs
  • 📈 Signal Processing: Harmonic analysis, waveform processing
  • 🖼️ Visualization: SVG plotting of cores, windings, magnetic fields
  • 🔧 SPICE Export: Export magnetic components as SPICE subcircuits

Installation

From PyPI (recommended)

pip install PyOpenMagnetics

From Source

git clone https://github.com/OpenMagnetics/PyOpenMagnetics.git
cd PyOpenMagnetics
pip install .

Quick Start

Basic Example: Creating a Core

import PyOpenMagnetics

# Find a core shape by name
shape = PyOpenMagnetics.find_core_shape_by_name("E 42/21/15")

# Find a core material by name
material = PyOpenMagnetics.find_core_material_by_name("3C95")

# Create a core with gapping
core_data = {
    "functionalDescription": {
        "shape": shape,
        "material": material,
        "gapping": [{"type": "subtractive", "length": 0.001}],  # 1mm gap
        "numberStacks": 1
    }
}

# Calculate complete core data
core = PyOpenMagnetics.calculate_core_data(core_data, False)
print(f"Effective area: {core['processedDescription']['effectiveParameters']['effectiveArea']} m²")

Design Adviser: Get Magnetic Recommendations

import PyOpenMagnetics

# Define design requirements
inputs = {
    "designRequirements": {
        "magnetizingInductance": {
            "minimum": 100e-6,  # 100 µH minimum
            "nominal": 110e-6   # 110 µH nominal
        },
        "turnsRatios": [{"nominal": 5.0}]  # 5:1 turns ratio
    },
    "operatingPoints": [
        {
            "name": "Nominal",
            "conditions": {"ambientTemperature": 25},
            "excitationsPerWinding": [
                {
                    "name": "Primary",
                    "frequency": 100000,  # 100 kHz
                    "current": {
                        "waveform": {
                            "data": [0, 1.0, 0],
                            "time": [0, 5e-6, 10e-6]
                        }
                    },
                    "voltage": {
                        "waveform": {
                            "data": [50, 50, -50, -50],
                            "time": [0, 5e-6, 5e-6, 10e-6]
                        }
                    }
                }
            ]
        }
    ]
}

# Process inputs (adds harmonics and validation)
processed_inputs = PyOpenMagnetics.process_inputs(inputs)

# Get magnetic recommendations
# core_mode: "available cores" (stock cores) or "standard cores" (all standard shapes)
result = PyOpenMagnetics.calculate_advised_magnetics(processed_inputs, 5, "standard cores")

# Result format: {"data": [{"mas": {...}, "scoring": float, "scoringPerFilter": {...}}, ...]}
for i, item in enumerate(result["data"]):
    mag = item["mas"]["magnetic"]
    core = mag["core"]["functionalDescription"]
    print(f"{i+1}. {core['shape']['name']} - {core['material']['name']} (score: {item['scoring']:.3f})")

Calculate Core Losses

import PyOpenMagnetics

# Define core and operating point
core_data = {...}  # Your core definition
operating_point = {
    "name": "Nominal",
    "conditions": {"ambientTemperature": 25},
    "excitationsPerWinding": [
        {
            "frequency": 100000,
            "magneticFluxDensity": {
                "processed": {
                    "peakToPeak": 0.2,  # 200 mT peak-to-peak
                    "offset": 0
                }
            }
        }
    ]
}

losses = PyOpenMagnetics.calculate_core_losses(core_data, operating_point, "IGSE")
print(f"Core losses: {losses['coreLosses']} W")

Winding a Coil

import PyOpenMagnetics

# Define coil requirements
coil_functional_description = [
    {
        "name": "Primary",
        "numberTurns": 50,
        "numberParallels": 1,
        "wire": "Round 0.5 - Grade 1"
    },
    {
        "name": "Secondary",
        "numberTurns": 10,
        "numberParallels": 3,
        "wire": "Round 1.0 - Grade 1"
    }
]

# Wind the coil on the core
result = PyOpenMagnetics.wind(core_data, coil_functional_description, bobbin_data, [1, 1], [])
print(f"Winding successful: {result.get('windingResult', 'unknown')}")

Flyback Converter Wizard

PyOpenMagnetics includes a complete flyback converter design wizard. See flyback.py for a full example:

from flyback import design_flyback, create_mas_inputs, get_advised_magnetics

# Define flyback specifications
specs = {
    "input_voltage_min": 90,
    "input_voltage_max": 375,
    "outputs": [{"voltage": 12, "current": 2, "diode_drop": 0.5}],
    "switching_frequency": 100000,
    "max_duty_cycle": 0.45,
    "efficiency": 0.85,
    "current_ripple_ratio": 0.4,
    "force_dcm": False,
    "safety_margin": 0.85,
    "ambient_temperature": 40,
    "max_drain_source_voltage": None,
}

# Calculate magnetic requirements
design = design_flyback(specs)
print(f"Required inductance: {design['min_inductance']*1e6:.1f} µH")
print(f"Turns ratio: {design['turns_ratios'][0]:.2f}")

# Create inputs for PyOpenMagnetics
inputs = create_mas_inputs(specs, design)

# Get recommended magnetics
magnetics = get_advised_magnetics(inputs, max_results=5)

API Reference

Database Access

Function Description
get_core_materials() Get all available core materials
get_core_shapes() Get all available core shapes
get_wires() Get all available wires
get_bobbins() Get all available bobbins
find_core_material_by_name(name) Find core material by name
find_core_shape_by_name(name) Find core shape by name
find_wire_by_name(name) Find wire by name

Core Calculations

Function Description
calculate_core_data(core, process) Calculate complete core data
calculate_core_gapping(core, gapping) Calculate gapping configuration
calculate_inductance_from_number_turns_and_gapping(...) Calculate inductance
calculate_core_losses(core, operating_point, model) Calculate core losses

Winding Functions

Function Description
wind(core, coil, bobbin, pattern, layers) Wind coils on a core
calculate_winding_losses(...) Calculate total winding losses
calculate_ohmic_losses(...) Calculate DC losses
calculate_skin_effect_losses(...) Calculate skin effect losses
calculate_proximity_effect_losses(...) Calculate proximity effect losses

Design Adviser

Function Description
calculate_advised_cores(inputs, max_results) Get recommended cores
calculate_advised_magnetics(inputs, max, mode) Get complete designs
process_inputs(inputs) Process and validate inputs

Visualization

Function Description
plot_core(core, ...) Generate SVG of core
plot_sections(magnetic, ...) Plot winding sections
plot_layers(magnetic, ...) Plot winding layers
plot_turns(magnetic, ...) Plot individual turns
plot_field(magnetic, ...) Plot magnetic field

Settings

Function Description
get_settings() Get current settings
set_settings(settings) Configure settings
reset_settings() Reset to defaults

SPICE Export

Function Description
export_magnetic_as_subcircuit(magnetic, ...) Export as SPICE model

Core Materials

PyOpenMagnetics includes materials from major manufacturers:

  • TDK/EPCOS: N27, N49, N87, N95, N97, etc.
  • Ferroxcube: 3C90, 3C94, 3C95, 3F3, 3F4, etc.
  • Fair-Rite: Various ferrite materials
  • Magnetics Inc.: Powder cores (MPP, High Flux, Kool Mu)
  • Micrometals: Iron powder cores

Core Shapes

Supported shape families include:

  • E cores: E, EI, EFD, EQ, ER
  • ETD/EC cores: ETD, EC
  • PQ/PM cores: PQ, PM
  • RM cores: RM, RM/ILP
  • Toroidal: Various sizes
  • Pot cores: P, PT
  • U/UI cores: U, UI, UR
  • Planar: E-LP, EQ-LP, etc.

Wire Types

  • Round enamelled wire: Various AWG and IEC sizes
  • Litz wire: Multiple strand configurations
  • Rectangular wire: For high-current applications
  • Foil: For planar magnetics
  • Planar PCB: For integrated designs

Configuration

Use set_settings() to configure:

settings = PyOpenMagnetics.get_settings()
settings["coilAllowMarginTape"] = True
settings["coilWindEvenIfNotFit"] = False
settings["painterNumberPointsX"] = 50
PyOpenMagnetics.set_settings(settings)

Contributing

Contributions are welcome! Please see the OpenMagnetics organization for contribution guidelines.

Documentation

Quick Start

  • llms.txt - Comprehensive API reference optimized for AI assistants and quick lookup
  • examples/ - Practical example scripts for common design workflows
  • PyOpenMagnetics.pyi - Type stubs for IDE autocompletion

Tutorials

Reference

Validation

License

This project is licensed under the MIT License - see the LICENSE file for details.

Related Projects

References

  • Maniktala, S. "Switching Power Supplies A-Z", 2nd Edition
  • Basso, C. "Switch-Mode Power Supplies", 2nd Edition
  • McLyman, C. "Transformer and Inductor Design Handbook"

Support

For questions and support:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyopenmagnetics-1.2.0.tar.gz (130.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyopenmagnetics-1.2.0-cp313-cp313-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.13Windows x86-64

pyopenmagnetics-1.2.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

pyopenmagnetics-1.2.0-cp313-cp313-macosx_15_0_arm64.whl (5.3 MB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

pyopenmagnetics-1.2.0-cp312-cp312-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.12Windows x86-64

pyopenmagnetics-1.2.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

pyopenmagnetics-1.2.0-cp312-cp312-macosx_15_0_arm64.whl (5.3 MB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

pyopenmagnetics-1.2.0-cp311-cp311-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.11Windows x86-64

pyopenmagnetics-1.2.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

pyopenmagnetics-1.2.0-cp311-cp311-macosx_15_0_arm64.whl (5.3 MB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

pyopenmagnetics-1.2.0-cp310-cp310-win_amd64.whl (3.8 MB view details)

Uploaded CPython 3.10Windows x86-64

pyopenmagnetics-1.2.0-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

pyopenmagnetics-1.2.0-cp310-cp310-macosx_15_0_arm64.whl (5.3 MB view details)

Uploaded CPython 3.10macOS 15.0+ ARM64

File details

Details for the file pyopenmagnetics-1.2.0.tar.gz.

File metadata

  • Download URL: pyopenmagnetics-1.2.0.tar.gz
  • Upload date:
  • Size: 130.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyopenmagnetics-1.2.0.tar.gz
Algorithm Hash digest
SHA256 72ca76ba5980da2d4058c235ca1687050369eed2e0215e7638b3922f77fc0147
MD5 478636fecc69a321bf4dbd8070a50bd9
BLAKE2b-256 a63ddd4ae7fdc09576af4f7575b8f6ab2404cc6b5cac117ec7c6e6e8b5ef9bcf

See more details on using hashes here.

File details

Details for the file pyopenmagnetics-1.2.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for pyopenmagnetics-1.2.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 569f637adc4648515281d1e70be633269d85989ab747e1625f996c190b457d6a
MD5 3037551a11b2e2bf433d4ad91e7b4dad
BLAKE2b-256 2394b701662d1bc75b88a9797a77b4fc600deb33ecb31e2f19b0bf9e7fbd084f

See more details on using hashes here.

File details

Details for the file pyopenmagnetics-1.2.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyopenmagnetics-1.2.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c9451ce8ec3148826d3ddb8e7bd2c56d2d88243b5ac3561c026b4e67a6fb2acc
MD5 a6e901bb1075677b62ad364927073d4b
BLAKE2b-256 76e96126e8b7fe450612b20e5816d2d5fba56ce84bf770f086145395b1003988

See more details on using hashes here.

File details

Details for the file pyopenmagnetics-1.2.0-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pyopenmagnetics-1.2.0-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 4397e3a88b7e7ef980f177f0cb3778f41b7c1f5d9825ac54039d3b4ee6b0d836
MD5 9cc00151497b5248d0841520f86bac24
BLAKE2b-256 7e2a864d5e1785b0b4cb9f4ab5d89098926fef131cc8dc11370f4bb2f659af42

See more details on using hashes here.

File details

Details for the file pyopenmagnetics-1.2.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for pyopenmagnetics-1.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e52aa13dec7de7acd9bb11e6361f31e59327584a75b3e64bfc7e259f76bed1e0
MD5 a1ad6e389de0a03a1626a0a4c31d8115
BLAKE2b-256 3098b8e036441f5e8f164b4c30dadd52812b9548aa34fdd4689be5888f7f5f5f

See more details on using hashes here.

File details

Details for the file pyopenmagnetics-1.2.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyopenmagnetics-1.2.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 efa77bed7ee9531426ac75f461d677bee565ab45bc329ff1931cbd14803ce3af
MD5 840e8fd90a22439512a4b03abf286d4c
BLAKE2b-256 47e2c5234024c738bb89511bc03f2c6ff1500b6c484f03de8b3112edc8ab3823

See more details on using hashes here.

File details

Details for the file pyopenmagnetics-1.2.0-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pyopenmagnetics-1.2.0-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 80ba5260cbfa8f40bbc68e570b8222282a1e3b5a0ba1c5876bd4588b19ccbcb8
MD5 aee278295dc1f5ff84ff8cad1ff70b03
BLAKE2b-256 3b3d13c49f50f9ff14b2b11da0bd0958afa642cc862a485cce889a0fdc91dc95

See more details on using hashes here.

File details

Details for the file pyopenmagnetics-1.2.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for pyopenmagnetics-1.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 eccb6b6288aeecb0ccb45b18e02cdde18724cad3110e2996d295bb2bfb2b46a7
MD5 0c66205d6aa6aa6a84fac0986d7f6ff8
BLAKE2b-256 9f6ade2d1a5b8b55e303137ee5feefbb5fdfc5959cb74fd20d5459f1d83fc7d6

See more details on using hashes here.

File details

Details for the file pyopenmagnetics-1.2.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyopenmagnetics-1.2.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 62b877a908165c98c8a6b521cdbd3c2ad96808d4c20dda35f07cf59ec4e97253
MD5 118bb1629238078b698409bfeccca551
BLAKE2b-256 91b0891bac444ca379f852f93f61891e6ecc480d46374e35488a25eee445c7dd

See more details on using hashes here.

File details

Details for the file pyopenmagnetics-1.2.0-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pyopenmagnetics-1.2.0-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 c0ce00f16af2fdde608817b9407cba3b39aadccddc4508e60ee9896f964e6c73
MD5 ac75527f1cdf482587f52c9912f62335
BLAKE2b-256 6bb22075e058182280d2af741ecd87e577a2ca5ddc898c6e57c60ae31d9dddaf

See more details on using hashes here.

File details

Details for the file pyopenmagnetics-1.2.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pyopenmagnetics-1.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 1ad9708398eb89d4d3b0133e77fae666db7e36af40bd98a4732b93412d439d99
MD5 0080db95782f46506cf37fefbd98a064
BLAKE2b-256 fb1b4c246d9876153abb49bd4a79f9729af185ad2fbcc5253c9f80a0dab6cfda

See more details on using hashes here.

File details

Details for the file pyopenmagnetics-1.2.0-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyopenmagnetics-1.2.0-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 73ce698f76f457371250f730aad87fd09474a679c895581db45bbe69d33785ea
MD5 70a6a7ee732232ce88fde77f91435ada
BLAKE2b-256 8b8be6b0f4a1125031f90bfc0b50dca892f32e2b0ae6f06beba08236af0b6182

See more details on using hashes here.

File details

Details for the file pyopenmagnetics-1.2.0-cp310-cp310-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pyopenmagnetics-1.2.0-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 f6e7aed4bb0eddc8f611a446be90192fc383e7b586641b7791724e2ea892186f
MD5 8e42c336874976b30f85ccbcbab2ff4b
BLAKE2b-256 cc8f3a0e4ec31fd8771aada8e466b19562de172f3ec719ebc8f44ee7f1983e3f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page