Skip to content

[WIP] Htt magspec image stitching algorithm#277

Merged
skbarber merged 24 commits intomasterfrom
HTT-Magspec-image-stitching-algorithm
Mar 26, 2026
Merged

[WIP] Htt magspec image stitching algorithm#277
skbarber merged 24 commits intomasterfrom
HTT-Magspec-image-stitching-algorithm

Conversation

@skbarber
Copy link
Copy Markdown
Collaborator

@skbarber skbarber commented Mar 9, 2026

Porting original MATLAB code for mag spec analysis into python. Still more to do, but some core functionality is implemented

Original workflow for matlab analysis:

  • load image
  • subtract background
  • apply vignette correction
  • low pass filter
  • charge calibration
  • energy axis calibration and interpolation (based off calibration files)

Much of this original work flow is already covered by existing functionalities in ImageAnalysis. And, the existing magspec_manual_calib_analyzer already had energy axis interpolation embedded.

Vignette correction was added as a new processing type available to all image analyzers. Charge calibration was defined in the scope of magspec_manual_calib_analyzer. And a specific energy axis calibration was implemented for "dnn' magnet.

No angle calibration has been implemented yet. Rigorous benchmarking needed still.

The code and new features are currently very specific to implementing the original MATLAB code. Once things are verified working, we should improve organziation/generaliry

skbarber added 11 commits March 4, 2026 20:50
Allow ImageAnalyzer methods to accept lists for multi-device workflows: analyze_image now accepts a single array or a list of arrays, analyze_image_file accepts a Path or list[Path], and load_image accepts a Path or list[Path] and returns an array or list of arrays. Type hints and docstrings were updated to document multi-device usage. load_image handles list inputs by recursively calling itself (preserving subclass overrides for custom formats), and analyze_image_file loads path(s) via load_image then delegates to analyze_image, preserving single-file behavior.
Replace ad-hoc calibration logic with a pluggable EnergyCalibration hierarchy and runtime config parsing. Adds PolynomialCalibration, ArrayCalibration, CallableCalibration and DnnAxisCalibration (loads MATLAB-style DNN camera+trajectory tables via tab-delimited files, uses CubicSpline) plus AxisResampler for uniform energy resampling. Introduces MagSpecAnalyzerConfig (pydantic) to parse camera_config.analysis or provide presets, and converts to the runtime MagSpecConfig; MagSpecConfig.calibration now uses EnergyCalibration. Integrates these into MagSpecManualCalibAnalyzer (uses calibration.build_axis and resampler) and improves validation/error messages and file resolution. Overall this centralizes calibration strategies, adds DNN axis support, and simplifies axis interpolation/resampling.
vignette correction was implemented by Kei in magspec analysis. It's a generally useful correction taht could be abpplied to all ImageAnalyzers in teh processing pipeline. Right now, all of the vignette correction is very specific to Kei's implementation and could reasonably be made more general. but the goal for now is to preserve the magspec implementation as directly as possible
skbarber added 13 commits March 9, 2026 21:50
Organziation of code after simple 'making it work' mode.
…arg in analyze_image method. Overwrite default from config
Call _save_calibrated_outputs from analyze_image when auxiliary_data contains file_path; add method to write a 16-bit PNG of the calibrated image and a two-column TSV spectrum alongside the source data. Creates sibling dirs {camera_name}-interp (uint16 PNG, image scaled by 1000 and clipped to 0..65535) and {camera_name}-interpSpec (TSV with Energy [MeV] and Charge Density [pC/MeV]). Adds import of pypng (png) and logs failures when saving.
Replace the previous hardcoded 'magnetic_field_t' lookup with an explicit BField_key set to 'HTT-MagTeslameter-DTM141 Field' and use it when reading auxiliary magnetic field data. This clarifies the key being used for override and preserves the existing behavior of letting auxiliary data override DNN calibration when present.
@skbarber skbarber merged commit 5ce1191 into master Mar 26, 2026
2 checks passed
@skbarber skbarber mentioned this pull request Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant