Self-contained triple-axis spectrometer reduction toolkit.
# optional: create conda env (requires writeable pkgs/envs dirs)
CONDA_ENVS_PATH=$PWD/conda-envs \
CONDA_PKGS_DIRS=$PWD/conda-pkgs \
conda create -y -n tasreduction python=3.10 numpyAdd tasreduction to PYTHONPATH or install in editable mode:
python -m pip install -e ./tasreduction
# lattice + geometry helpers
python -m pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org icp-lattice-calculator
# optional resolution calculator (requires the legacy rescalculator source on PYTHONPATH)
# python -m pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org rescalculator
# peak fitting / optimization helpers
python -m pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org bumpsIf the legacy rescalculator package is available on your PYTHONPATH,
tasreduction will use it for resolution-volume calculations. Polarization
corrections are not yet implemented in this port.
- Rich metadata ported from the classic ICE/NICE headers with "distinct" rules
enforced during reductions via
TripleAxisMetadata. - Instrument models capture monochromator/analyzer blades, collimators, filters,
sample environment channels, PSD/single/diffraction/door detectors, and monitor
streams to keep the workflow in sync with
bt7_stuff.txtanddata_abstraction.py. - Translators for classic ASCII
.bt7files and modern.nxs.bt7NeXus files buildTripleAxisScanobjects with spectator channels (temperature, timestamps, live times, etc.) that are kept in register during combinations. - Combination helpers replicate the IDL
simple_combinemonitor normalization and quadrature error propagation so scan sums honour the uncertainty mathematics without relying on theuncertaintiespackage. tasreduction.latticeexposes thin wrappers aroundicp-lattice-calculatorfor hkℓ/angle queries, andtasreduction.resolutionwires those results into the python resolution calculator for Cooper–Nathans style estimates.tasreduction.polarizationsolves the four-channel analyzer equations so finite-efficiency incident/analyzer corrections can be applied toTripleAxisScanobjects.tasreduction.peaksuses Paul Kienzle’sbumpsoptimizer with BIC model selection to smooth, detect, and fit multiple peaks (wavelet-based detectors can be added later if you want more aggressive peak discovery).
from tasreduction import translate_ice_file, translate_nexus_file, ReducePipeline
scan = translate_ice_file("/path/to/file.bt7")
# or load newer NICE/ICE NeXus output (*.nxs.bt7)
nexus_scan = translate_nexus_file("/path/to/scan.nxs.bt7")
scan.normalize_to_monitor()
pipeline = ReducePipeline()
pipeline.add_signal(scan)
combined = pipeline.sum_signals()
combined.record_treatment("custom step")
# polarization correction (requires all four spin states)
from tasreduction import PolarizationConfig, polarization_correct
corrected = polarization_correct(spin_channels, PolarizationConfig(incident_polarization=0.9, analyzer_polarization=0.85))
# automatic multi-peak fitting
from tasreduction.peaks import auto_peak_fit
peak_fit = auto_peak_fit(combined.axis, combined.counts)