diff --git a/Mag_Field_Sweep_2024_10_21.py b/Mag_Field_Sweep_2024_10_21.py index 108e822..f75e83b 100644 --- a/Mag_Field_Sweep_2024_10_21.py +++ b/Mag_Field_Sweep_2024_10_21.py @@ -2,7 +2,7 @@ """ Created on Fri Dec 22 15:10:10 2023 Lightfield + Positioner -@author: Serdar, adjusted by Lukas +@author: Serdar, adjusted by Lukas and Ryan """ ############################################ # Packages from Ryan diff --git a/README.md b/README.md new file mode 100644 index 0000000..600b40f --- /dev/null +++ b/README.md @@ -0,0 +1,127 @@ + +# Magnetic Field Sweep and Spatial Mapping Automation + +**Author:** Serdar (adjusted by Lukas and Ryan) +**Last Updated:** April 2025 +**Filename:** `Mag_Field_Sweep_2024_10_21.py` + +## Overview + +This script automates spectral acquisition in a magneto-optical experiment using: + +- **LightField** for spectrometer control (Princeton Instruments) +- **AMC Positioner** for precise spatial scanning +- **Attocube APS100** power supplies for magnetic field control + +It enables: +- Magnetic field sweeps along selected axes +- Spatial scans across X-Y positions +- B-field vector rotations with spectral capture +- Live spectrum acquisition and intensity mapping + +## Features + +- **2D Spatial Scan:** Raster-scan across a surface using AMC positioners, capturing spectra at each coordinate. +- **Magnetic Field Sweep:** Vary B-fields in controlled steps along x/y/z, measure spectra at each step. +- **Field Rotation:** Circular B-field rotation (in-plane) with angle-defined steps. +- **Automated File Handling:** Acquires `.spe` files, extracts and saves intensity/wavelengths, deletes intermediates. +- **Flexible Configuration:** Resolution, range, exposure, filters, filenames and scan directions are all customizable. + +## Prerequisites + +### Hardware +- AMC100/AMC300 positioner +- Attocube APS100 single/dual-channel magnet power supplies +- Spectrometer compatible with Princeton Instruments LightField + +### Software & Libraries +- **Python 3.8+** +- Packages: `pyvisa`, `numpy`, `matplotlib`, `pandas`, `clr`, `spe2py`, `spe_loader`, `AMC` module +- .NET integration via `pythonnet` +- LightField SDK: Princeton Instruments (with DLLs loaded via `clr`) + +> Note: Ensure `LIGHTFIELD_ROOT` environment variable is set. + +## Setup + +1. **Install dependencies** + ```bash + pip install pyvisa pandas numpy matplotlib pythonnet + ``` + +2. **Ensure required DLLs** are present in: + ``` + C:\Program Files\Princeton Instruments\LightField\ + ``` + +3. **Set up device IPs** + ```python + IP_AMC100 = "192.168.71.100" # or AMC300 + ``` + +4. **Edit scan parameters in main block:** + ```python + range_x = 20000 + range_y = 20000 + resolution = 1000 # nanometers + + set_llim_bval = -0.3 + set_ulim_bval = 0.3 + set_res_bval = 0.003 # Tesla + ``` + +## Main Functions + +### `move_scan_xy(range_x, range_y, resolution, Settings, baseFileName)` +Performs a 2D XY raster scan of the probe. Acquires spectra and saves results. + +### `sweep_b_val(instr, min_bval, max_bval, res, axis, Settings, base_file_name)` +Sweeps magnetic field (in T) along the specified axis, collecting spectra at each field. + +### `ramp_b_val(instr, bval, magnet_coil)` +Smooth ramping of B-field to target value. + +### `b_field_rotation(instr1, instr2, Babs, startangle, endangle, step, Settings)` +Rotates the in-plane magnetic field by vector combination of Bx and By components. + +## File Saving + +- `.txt`: Intensity data and wavelength arrays saved to timestamped folders +- Folder names include experiment metadata +- `.spe` files are deleted after processing to conserve space + +## Usage Example + +To sweep B-field along the **Y-axis**: + +```python +sweep_b_val( + instr=powerbox_singlesupply, + min_bval=-0.3, + max_bval=0.3, + res=0.003, + magnet_coil='y-axis', + Settings='experiment_config', + base_file_name='scan_name', + zerowhenfin_bool=True, + reversescan_bool=False, + loopscan_bool=True +) +``` + +## Notes + +- Always close power supply connections with `.close()` +- Make sure `.spe` files are not locked by LightField before running +- The AMC section is currently commented — uncomment if positioner control is needed +- Ensure `experiment.Load(...)` points to the correct `.lfe` config + +## Troubleshooting + +- **DLL loading issues?** Confirm path via `sys.path.append(...)` and DLL names. +- **Communication errors?** Check serial port resource names via `pyvisa.ResourceManager().list_resources()` +- **No spectra saved?** Ensure LightField is licensed and experiment file is valid. + +## License + +Internal use only – please contact the authors before distribution or reuse.