How mazinlab/momospecsim works
Project type and purpose
• This is a scientific simulation and data-reduction pipeline for the Multi-Object MKID Optical Spectrometer (MOMOS).
• It provides two main command-line entrypoints:
• simulate.py – generates a photon table by propagating a model spectrum through an optical path.
• reduce.py – ingests three photon tables (continuum, lamp, observation) and produces a calibrated spectrum via four sub-steps (MSF, order-sorting, wavecal, extraction).
File structure
• Top level:
• benchdesign/ – auxiliary scripts for grating design, plotting, edge cases.
• filterphot.pyx – Cython module for fast photon filtering/throughput.
• momospecsim/ – core Python package (modules for detector, optics, engine, MSF, simulation settings, spectra, linelists, simfiles, reduction steps, general utilities).
• scripts/ – thin wrappers (simulate.py, reduce.py) plus their argument templates.
• requirements.txt, setup.py – dependency and packaging metadata.
• Configuration/data:
• momospecsim/linelists/*.csv – reference spectral lines for calibration.
• momospecsim/simfiles/ – data files for atmosphere transmission, sky emission, fridge throughput.
• benchdesign/*.txt – master grating specifications.
README for additional insights
• Describes the two core scripts and the four reduction steps.
• Points to a user manual and an AAS paper for detailed algorithmic background.
a. Main components
• CLI Layer: simulate.py, reduce.py
• Simulation Engine: momospecsim.engine, optics, detector, spectra, simsettings
• Data Sources: linelists, simfiles (atmosphere, fridge, sky)
• Reduction Pipeline: momospecsim.steps submodules (fitmsf, ordersort, wavecal, extract)
• Bench-design Tools: benchdesign module (optional pre-processing)
• Cython Module: filterphot for throughput calculations
• Utilities: momospecsim.utils
• External Dependencies: numpy, scipy, Cython, etc.
b. Relationships and data flow
1. simulate.py → parses arguments → calls Simulation Engine
2. Engine reads simsettings, linelists, simfiles → applies optics & detector logic → uses filterphot where needed → outputs photon table
3. reduce.py → loads continuum lamp and observation photon tables
• Step 1 (MSF): uses fitmsf → generates spread function model
• Step 2 (Order-sort): uses ordersort with MSF → sorts lamp & obs photons into orders
• Step 3 (Wavecal): uses wavecal → matches sorted lamp photons to linelist → finds wavelength solution
• Step 4 (Extract): uses extract → applies wavecal to obs photons → produces final spectrum
4. Output spectra and diagnostic plots are written to disk.
c. Architectural patterns / design principles
• Modular package structure: separate core simulation logic vs. pipeline steps.
• Data-driven design: heavy use of CSV/dat files for inputs.
• CLI orchestration: thin script wrappers that invoke library code.
• High-performance Cython for critical loops (filterphot.pyx).
d. Key technologies / frameworks
• Python 3.x, numpy, scipy, Cython
• Custom modules: momospecsim.*
• Scripts: plain argparse or config-file–driven CLIs.
Detail
• Data artifacts (Photon Table, Calibrated Spectrum) as distinct nodes.
• External inputs (linelist CSVs, transmission DAT files) so nothing is lost.