[WIP] Htt magspec image stitching algorithm#277
Merged
Conversation
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.
…mage-stitching-algorithm
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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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