GalCubeCraft is a high-fidelity, easy-to-read pipeline for synthesising IFU-style spectral cubes (velocity × y × x). It is designed for method development: fast generation of controllable, reproducible cubes for denoising, deconvolution, kinematic tests, and ML pretraining. The code emphasises clarity (well-named small functions), sensible defaults, and modularity so you can replace morphology, kinematics or instrument modules with minimal changes.
What it does
- Constructs a 3D flux field per galaxy component using a radial Sérsic-like surface profile (disk plane) combined with an exponential vertical profile.
- Builds a compact analytic rotation-curve model to assign tangential velocities to voxels; supports multiple components (primary + satellites) and simple velocity dispersion models.
- Rotates the 3D flux & velocity fields to an arbitrary viewing geometry (inclination + position angle) and projects emission into line-of-sight velocity bins to form a spectral cube.
- Applies optional instrument effects: per-channel 2D beam convolution (elliptical Gaussian), channel binning / spectral smoothing, and additive noise models. Cubes are saved with accompanying metadata for reproducibility.
Design & architecture
- Core pipeline: small, single-responsibility functions in
src/GalCubeCraft/core.pyorchestrate grid creation, component stacking, kinematics and I/O. - Helpers:
utils.pycontains beam kernels, convolution helpers and spatial transforms;io.pywraps saving/loading with consistent folder layouts. - Visualisation:
visualise.pyexposes moment map and spectrum helpers used by both scripts and the GUI. - GUI: a compact Tkinter-based GUI (see below) designed for interactive exploration without blocking the UI thread.
Quick install & API example
pip install GalCubeCraft
import GalCubeCraft
# create and run quickly from script
g = GalCubeCraft(n_cubes=1, grid_size=125, n_spectral_slices=40, seed=42)
results = g.generate_cubes()
cube, params = results[0]
print('cube shape =', cube.shape)
g.visualise(results, idx=0, save=False)
Files & integration (expanded)
src/GalCubeCraft/core.py— orchestrates grid creation, stacking components and kinematics.src/GalCubeCraft/utils.py— beam kernels, convolution helpers and small numeric utilities.src/GalCubeCraft/visualise.py— moment maps and spectrum plotting helpers used by the GUI and scripts.src/GalCubeCraft/gui.py— the compact Tkinter GUI; see the pseudocode excerpt above for its threading pattern.
GUI - Interactive Usage
- Generates one spectral cube at a time from the parameters you set. This is sufficient for interactive experimentation and previewing the effects of different choices.
- Runs the heavy generation step in a background thread and displays logs in a small Log window so you can follow progress and any printed diagnostics.
- Provides convenience buttons to visualise results using the plotting helpers: Moment-0 (integrated intensity), Moment-1 (intensity-weighted velocity), and the integrated line-of-sight spectrum. These open interactive Matplotlib figures so you can pan/zoom as needed.
- Allows saving the generated spectral cube along with a parameters/metadata dictionary to disk. Both NumPy
.npzarchives and Python.pklpickles are supported by the GUI save dialog.
Controls and parameters
The GUI exposes the following user-adjustable parameters (each control is directly reflected in the generator instance shown in gui.py):
- Number of galaxies (primary + satellites)
- Satellite offset (distance from primary centre, pixels)
- Beam information: minor axis (bmin, px), major axis (bmaj, px), position angle (BPA, degrees)
- Resolution parameter r (controls Re relative to beam size)
- Sérsic index n (profile concentration)
- Scale height h_z (vertical exponential scale, px)
- Central effective flux density S_e (intrinsic scaling)
- Line-of-sight velocity dispersion
σ_v,z(km/s) - Grid size (nx = ny, pixels)
- Number of spectral channels (n_s)
- Inclination angle (rotation about X, degrees)
- Azimuthal / position angle (rotation about Y, degrees)
Launch
# from package (recommended)
python -m GalCubeCraft.gui
# or from the source tree
cd src/GalCubeCraft
python gui.py
Behaviour and UX notes
- Generation is started with the "Generate" button. While a cube is being produced the GUI disables the interactive sliders (to indicate a running state) and the Log window is shown so you can follow output.
- When generation finishes the visualisation buttons (Moment0, Moment1, Spectra) and the Save button become enabled. The "New" button clears the current generator state and re-enables controls so you can start a fresh instance.
- The GUI attempts to render LaTeX-style labels for parameter names (using Matplotlib mathtext). If rendering fails for a label it falls back to a readable plain-text label so controls remain understandable.
Visualisation
- Moment-0: integrated intensity map produced by summing the cube along the spectral axis and optionally saving the figure.
- Moment-1: intensity-weighted velocity map computed from the spectral channels and visualised with an overlaid beam marker.
- Spectrum: integrated flux vs velocity (line-of-sight spectrum).
All visualisation helpers are implemented as small functions in src/GalCubeCraft/visualise.py and are called by the GUI to produce Matplotlib figures. These figures are interactive; you can pan/zoom and save them using Matplotlib's GUI controls.
Saving
The GUI Save flow prefers to save already-generated results (so it does not re-run the expensive generation step). You can save as a compressed NumPy archive (.npz) or as a pickled Python object (.pkl). Saved contents include the spectral cube array and a parameter dictionary with metadata (beam info, pixel scale, average velocities, etc.).
Future features
Planned enhancements for future releases include:
- Artificial noise injection and configurable S/N controls
- Batch generation of multiple cubes and export of training-ready datasets
- More advanced kinematic models and multi-component morphologies
- Small GUI refinements (progress bar for generation, better layout on HiDPI displays)
Authors
- Arnab Lahiry (alahiry@ics.forth.gr)