LineStacker 2.0: Python 3 / CASA 6 port¶
Tested with Python 3.13 (requires >= 3.9), NumPy 2.5, SciPy 1.18, astropy 8.0 and CASA 6.7.6
(casatools from PyPI), on the example data in LineStacker/Example
and on the synthetic test suite in tests/ (185 tests; the 12 that need casatools
are skipped without it).
Installing¶
pip install -e .[casa] # with CASA 6 for CASA images
pip install -e . # FITS cubes only
python -m pytest tests # optional: run the tests
To use LineStacker from the CASA prompt (monolithic CASA tarball), install its dependencies with CASA’s own pip, so they match CASA’s NumPy:
PYTHONNOUSERSITE=1 ~/casa-6.7.6-14-py3.12.el9/bin/pip3 install 'astropy>=7.2'
Mixing CASA with packages from another environment (e.g. a venv on
PYTHONPATH) breaks when versions disagree: CASA 6.7.6 bundles NumPy >= 2.4,
which astropy < 7.2 cannot use (module 'numpy' has no attribute 'in1d').
import LineStacker warns when it detects this combination.
CASA is only imported to read or write CASA images (FITS-only use never
starts CASA). When LineStacker starts it, CASA’s log goes to one file,
<temporary dir>/linestacker-casa-<user>.log (appended to), and CASA’s
messages go there instead of the terminal, so no casa-<date>.log piles up
in the working directory. LineStacker.casa_logfile changes this (a path,
None for no log, 'casa' for CASA’s default); a logfile set in
~/.casa/config.py is used, and inside a CASA session (or after importing
casatools/casatasks yourself) CASA’s own settings apply. CASA 5 (Python 2)
is no longer supported.
One stacking module: LineStacker.image¶
line_image and the old continuum module image are merged into a single
LineStacker.image, which does what line_image did, plus continuum
stacking with the same functions:
LineStacker.image.stack(coords, imagenames=names, fEm=fEm) # line stack
LineStacker.image.stack(coords, imagenames=names, continuum=True)
Images without a spectral axis (or with one channel) are stacked as continuum automatically, without warning.
continuum=Trueon cubes with a spectral axis issues a warning and stacks a collapsed version of each cube, made in memory (collapse='sum'default, or'mean','median'; blanked channels are ignored). The output header records it inCOLLAPSE. Only the collapsed arrays are kept, not the full cubes.Coordinates without a spectral value (
readCoords(..., lineON=False)) also select continuum stacking (same warning if cubes get collapsed).Line stacking with an image that has no spectral axis raises an error pointing to
continuum=True.Continuum stacks return the same list as line stacks (the “spectrum” has one channel); FITS output is 2D when the inputs had no spectral axis.
From the old continuum module: weightings
'sigma'(1/σ, mask of two beams by default) and'pb'(squared primary-beam response) are available to all stacks;getFluxis kept.primarybeam=now takes the primary-beam image of each cube (FITS or CASA, e.g. tclean’s.pb; one path, a list in the order ofimagenames, or a dict{cube: pb}), read at each source’s position and line channel, or a functionf(dx, dy, nu)such asLineStacker.image.GaussianPrimaryBeam(dish=12.)(FWHM 1.13 λ/D, as LineStacker.uv). TheLineStacker.pbmodels are gone (see below). Itsnoiseandboot_strapingare covered byanalysisTools.stack_estimatorandbootStraping_Cube, which acceptcontinuum=True. Dropped:psfmode='star',calculate_peak_fluxesandcalculate_flux_weights(.fluximages).import LineStacker.line_imageno longer works: useLineStacker.image(samestackarguments).
What the stacked cube contains¶
Stamps are cut on each cube’s own pixel grid, centred on the source; cubes are not reprojected. The output keeps the first cube’s pixel size and orientation (a rotated grid is written with a PC matrix).
All cubes must have the same kind of spectral axis (FREQ, WAVE, AWAV, VRAD…); stacking frequency with wavelength cubes, or using a non-linear axis (
WAVE-LOG,FREQ-TAB…) in a line stack (anyspectralMethod), is an error. Units are converted to the first cube’s (Hz and GHz cubes stack together);fEm,lEmand observed values are in that unit. DifferentSPECSYSframes, orSPECSYSmissing in some cubes, give a warning: LineStacker does not convert frames.Pixel units (
BUNIT) are compared: scaled units are converted to the first cube’s (mJy/beam to Jy/beam), recognised but physically different units (K and Jy/beam, Jy/pixel and Jy/beam) are an error, and cubes withoutBUNIT, or with units astropy cannot read, give a warning and are stacked without conversion.Cubes on a different grid from the first one (pixel size, orientation, projection, celestial frame, distortions) give a warning; stamps are not reprojected.
BMAJ, BMIN are the mean of the input beams and BPA their axial mean (179° and 1° give 0°), an approximation of the stack’s beam.
Weights must be finite and >= 0 (a negative or NaN weight is an error). Every weighting multiplies the coordinates’ own weights.
1D stacking: Image is now Spectrum¶
The object holding one spectrum to stack is LineStacker.OneD_Stacker.Spectrum
(was Image), with the same arguments and attributes. The 1D functions take
spectra instead of Images/images: Stack(spectra, ...),
bootstraping_OneD(spectra, ...), subsample_OneD(spectra, ...),
rebin_OneD(spectra), regridFromZ1D(spectra, ...). Positional calls are
unchanged; calls passing Images= by keyword need updating.
Velocities are in km/s. A spectrum with velocities and a redshift
(Spectrum(spectrum=..., z=z, fEmLine=f0)) has velocities relative to the
rest frequency f0 (as a CASA spectrum with restfreq=f0); its line is at
v = c z/(1+z) in the radio convention (default, as CASA and LineStacker.uv),
c z with velConvention='optical', or the relativistic velocity with
'relativistic'. velocity_to_frequency and frequency_to_velocity do the
conversions.
Stacking positions: catalogue, arrays or coordinate files¶
LineStacker.readCatalog(catalog): one table for the whole sample, one row per source:ra,dec,z(optional; without it the positions are for continuum stacking),weight(optional) andimage, the cube of each source. Reads CSV, ECSV, FITS tables, VOTable (any astropy table format), an astropyTable, a pandasDataFrameor a dict. Column names are matched case-insensitively, common alternatives are recognised (RAJ2000,DEJ2000,redshift,cube, …), and any name can be given (readCatalog(cat, ra='alpha', z='zspec', image='file')). Positions in degrees (orunit='rad'), with units from the table, or sexagesimal (RA in hours, CASA’s dotted declinations accepted); each value is read on its own, so a column mixing forms is read correctly. Relative cube names are looked up next to the catalogue, then from the working directory (imagedir=overrides).LineStacker.makeCoords(ra, dec, z=..., weight=..., image=...): the same from lists, numpy arrays, astropy quantities or aSkyCoord(notebooks).The cube of a source is never guessed: it comes from the catalogue/
image=, or, when no cube is named, from a single cube given asimagenames. A cube missing fromimagenamesis an error.imagenamescan be omitted when every source names its cube.readCoords(one file per cube) works as before.LineStacker.image.readCube(name)reads a FITS file or CASA image as a numpy array (x, y, stokes, channel), for plots and checks.rebin_CubesSpectra(..., outdir=)writes the rebinned cubes to a folder.
Examples notebook¶
LineStacker/Example/LineStacker_examples.ipynb runs every example (1D
stacking, bootstrapping and subsampling; cube stacking from coordinate files,
a catalogue and arrays; line fits, rebinning and bootstrapping; continuum
stacking and random positions) on the example data in about 30 s, writing to
Example/notebook_outputs/. It is saved with its outputs (figures).
Messages: verbose¶
LineStacker.verbose (default True) makes LineStacker report what it does:
positions read, the full path of every file written (stacked cube, weights,
sub-cubes, rebinned or regridded cubes) and progress bars. Each function that
prints takes verbose=True/False to override it for one call. With verbose
off LineStacker prints nothing; problems (zero-noise stamps, collapsed cubes,
failed fits…) are Python warnings and show either way.
What works now that did not¶
CASA images as input.
line_imagehad been rewritten to read FITS only, so the shipped examples (CASA.imagecubes) failed withIsADirectoryError. All modules now share one reader (LineStacker/_io.py) that takes FITS files or CASA images (exported through casatools; both kinds can be mixed in one stack), in any axis order (RA/Dec swapped, Stokes before or after the spectral axis, no Stokes, 2D images), withCDELTorCDmatrices and frequency or wavelength (FREQ,WAVE,AWAV) axes. Cubes are read once and cached (LineStacker._io.clear_cache()frees them).CASA 6 tools. The shim imported
casalogfromcasatools, which CASA 6 does not export, so it failed on every real CASA 6 installation; its CASA 5 fallback imported itself. Both fixed and checked against casatools 6.7.6.Output cubes.
outfile='x.fits'writes FITS, any other name (e.g.stackResult.image) a CASA image with axes RA, Dec, Stokes, Frequency as before. The header is rebuilt cleanly instead of averaging every keyword of every input header.NumPy 2.
np.NaN,np.float,np.cast,np.rank, list indexing and int-array in-place float maths were removed or brokeOneD_Stacker.Stack,congrid,regridFromZ1D,rebin_OneDand spline regridding. Comparing a weights array with'1/A'raised “truth value is ambiguous”.Modules that used the removed Stacker
CoordListmodel (image(continuum stacking),bootStraping_Cube,stack_estimator,rebin_CubesSpectra, cuberegridFromZ, andrandomCoords/randomizeCoords, which only printed ‘TODO’) are ported toCoord(ra, dec, spec).Coordalso answers tox,y,zfor older scripts.regridFromZ in
line_image.stackwas silently ignored; it now resamples each source to a common rest-frame channel (linear interpolation, fractional line centres), for frequency and wavelength cubes.readCoords: CASA-027.40.59.866declinations, blank/comment lines, delimiter fallback (comma, space, tab),type='pixel'(was ignored). Coordinate files are matched toimagenamesby name, or else by file order.Gaussian fits (
LineStacker.tools.fit) ignore NaN channels and raiseFitError(aRuntimeError) for too few points, constant data or a fit that does not converge; the bootstraps and grades turn those into NaN or 0.DoubleGaussPeakis centred on the middle of its axis (it assumed an axis starting at 0).Input checks with clear messages: empty spectrum or image lists, negative or non-integer
nRandom,minSize/maxSizeofsubsample_OneD,regridMethod, rebinning widths,randomCoordsmargins, empty cube names and non-finitez/weights in catalogues, equatorial frames only (makeCoords(SkyCoord)converts e.g. Galactic positions). Coordinates in different frames (ICRS, FK5…) are each converted.Cached cubes are read again when their file changes (for CASA images, any file of the image directory); the stale copy is dropped.
Smaller crashes:
KeyError: 'freqlen'when a line was near the upper edge of a cube,coord.zin obsSpec mode,returnWeights,plotIt,stampsize=1instack_estimator, non-square images innoise_estimator, float slice indices inrebin_CubesSpectra,freqBinnever rescaled when rebinning 1D spectra,LineStacker.tools.GaussFittypo in the 1D bootstrap.
Changes in results (please check against your expectations)¶
Stack centre moves by one channel for FITS input. The FITS rewrite used the 1-based
CRPIX3where the CASA code used CASA’s 0-based reference pixel. The new code agrees with CASA’s owntopixel.Line centres are rounded half away from zero, as Python 2’s
round()did (Python 3 rounds halves to even).Median stacks ignore channels that fall outside a source’s cube instead of counting them as zeros. Mean stacks already gave those channels zero weight.
bootStraping_Cube‘amp’/’ampAndWidth’/’outflow’ now use the spectrum summed over the stamp, as documented. The code summed axes (1,2,3), i.e. a spatial profile.Weights are computed on copies: the user’s
Coordobjects are not modified, andweighting='sigma2'no longer compounds when the same coordinates are stacked twice.Cubes whose spectral axis runs the other way (positive vs negative CDELT3) are flipped to match the first cube instead of being stacked mirrored.
Channels whose total weight is zero give NaN (blank) instead of ZeroDivisionError; sigma2F channels with zero noise get weight 0 instead of infinity.
Gaussian fits that do not converge are stored as
[nan, nan](with a warning) instead of aborting a whole bootstrap.hduldefaults to'auto'(first HDU with an image: 0 for ALMA/CASA FITS, 1 for MUSE). An explicithdul=1still works.noise_estimator(maskCenter=[x, y])uses x along RA and y along Dec as documented; it no longer blocks onplt.show()(plotIt=Falsedisables the plot).maximizeSNR(the default grade ofsubsample_OneD) returns 0 when the Gaussian fit converges on a line centred outside the spectrum (it can lock onto a stack edge). Its noise was then computed from a negative slice index, i.e. a few channels at the end, giving grades of ~1000 instead of ~4 that dominated the summed grades: the subsampling example no longer singled out the bright spectra. With the fix it does again (with 10 000 iterations already). The fit’s sigma is also used as an absolute value.Random draws are vectorised, so a given
np.random.seedgives different (statistically equivalent) samples than LineStacker 1.x. All Monte-Carlo tools also takeseed=.weighting='sigma2F'multiplies the coordinates’ weights by 1/σ² (it replaced them, so catalogue weights were lost), and σ of each channel uses only the valid pixels outside the mask (masked and blank pixels were counted as zeros, which lowered σ). Unchanged for unit weights, no mask and no blank pixels, as in the examples.weighting='1/A'gives weight 0 (with a warning) to sources whose amplitude is not positive, instead of a negative or infinite weight.Weighted 1D stacks: channels where a spectrum’s flux is NaN no longer count in the sum of weights (they pulled the mean towards 0).
Spectra given as amplitudes only, with an odd number of channels, lost their last channel in ‘full’ stacks (Python 3 rounding of the default velocity axis).
Spectrum(z=..., fEmLine=...)with velocities is centred on the line (velToFreqreturnedfObs v/(v+c), not a frequency).regridFromZ(writing cubes): regridded cubes have a rest-frame spectral axis (CDELT3 was the observed width, so the stack’s CDELT3 was wrong) and keep the sky coordinates of the original cube (CRVAL was set to 0, 0). Its result is stacked as returned, withspectralMethod='z'andfEm.Beam position angles are averaged as axes (BPA changes only when the input angles straddle ±90°).
Cubes in compatible but different intensity units (mJy/beam, Jy/beam) are converted to the first cube’s unit before stacking (they were averaged as raw numbers).
regridFromZ: the coordinates returned for regridded cubes are the sources’ own (fractional) pixels in the stamps, not the integer stamp centre, so their sky positions are exact.1D stacks leave out infinite fluxes, as they do NaN (one infinite channel made the stack infinite).
Blank pixels stay NaN (they were set to 0, as in LineStacker 1.x). Stacks leave them out pixel by pixel; stacked pixels without valid data, and stack channels that no source covers, are NaN instead of 0; pixels that are exactly 0 now count as data in the noise-based weightings and
noise_estimator; collapsed images keep NaN where every channel is blank.readCubereturns NaN for blank pixels. A blank channel blanks only the stack channels interpolated from it (a stack channel that falls exactly on a valid channel keeps its value). Rebinning and regridding never use blank channels: with linear interpolation (rebin_OneD,rebin_CubesSpectra) a new channel interpolated from a blank one is NaN; the cubic spline ofregridFromZ1DandregridFromZruns through each stretch of valid channels separately, so only new channels between a valid and a blank channel are NaN. Blanks thus stay local instead of spreading over the whole spectrum. ThemaximizeSNRgrade measures the noise on valid channels only. 1D stacks also give NaN, instead of 0, for channels without data (no spectrum covers them, or only blank fluxes or zero weights), as cube stacks do.Regridding to a common rest-frame channel width (
regridFromZ1D,Stack(regridFromZ=True),regridFromZ) samples old channel j (1+z_ref)/(1+z) for new channel j, so every source gets exactly the reference channel width (the number of channels was rounded and the width followed it, up to half a channel over the spectrum). New channels beyond the last old channel are NaN; the spline used to give 0 there, and a velocity of 0 at the end of the axis. Spectral axes are interpolated linearly (the spline bent them near the ends), and the channel widths, line centres (rounded, they were truncated), per-channel weights andspectrumarrays follow the new channels. Regridded cubes label their spectral axis with the exact, fractional, channel of the line (it was rounded to a whole channel).rebin_OneDmoves the line centre (centerIndex) with the rebinned channels (it kept the old channel, so line-centre stacks of rebinned spectra were misaligned unlessfit=True), and compares line widths in channels (fitted widths in km/s mixed spectra with different channel widths).The spectral axis of a 1D
Spectrummust be evenly spaced (within 5% of a channel, so rounded values from text files are fine): every channel is located with one channel width, which is now the mean spacing (it was the first spacing, which rounding of the values could make off by a few percent).weights='sigma2'withfit=Trueleft the line in the noise estimate of spectra with decreasing axes. A line centre outside its spectrum is now an error when stacking (it made very long stacks).
On the example data (no blank pixels) all stacks, with every weighting, line and continuum, are bit-identical to the first 2.0 port; items 13-26 change results only for data that hit those cases (the examples do not regrid spectra by redshift).
Speed and parallelism¶
The 1D stacker, the bootstraps and the random-position estimator were vectorised; this matters more than extra cores. Times on the example data, 2-core sandbox (expect better scaling with more cores):
task |
LineStacker 1.x |
2.0 serial |
2.0, 2 cores |
|---|---|---|---|
1D median bootstrap, 50 spectra, 10 000 draws |
263 s |
1.6 s |
0.9 s (threads) |
1D mean bootstrap, 100 000 draws |
~45 min (est.) |
0.8 s |
|
1D bootstrap with Gaussian fits, 20 000 draws |
18.0 s |
10.9 s (processes) |
|
1D subsample (maximizeSNR), 10 000 draws |
~190 s (est.) |
13.7 s |
8.2 s (processes) |
cube stack, 50 CASA cubes (first / cached) |
2.4 s / 0.09 s |
||
continuum stack of the same cubes (collapsed in memory) |
1.6 s / 0.16 s |
||
cube mean bootstrap, 10 000 draws |
broken |
0.2 s |
|
cube median bootstrap, 1 000 draws |
broken |
8.5 s |
4.3 s (threads) |
cube bootstrap with fits, 20 000 draws |
broken |
11.7 s |
6.9 s (processes) |
stack_estimator, 2 000 random stacks |
broken |
0.2 s |
bootstraping_OneD, bootStraping_Cube, subsample_OneD and
stack_estimator take n_jobs (-1 = all cores), backend
('process' or 'thread'; a sensible one is chosen per task) and seed.
Random numbers are drawn before the work is split, so results are identical
for any n_jobs. Worker processes start with spawn (safe with CASA and on
macOS), which costs ~0.7 s, so processes pay off for runs longer than a few
seconds. On macOS/Windows, scripts using processes need an
if __name__ == '__main__': guard (see the examples).
Removed¶
LineStacker.modsubandLineStacker.pb: the uv-domain code of Stacker (it needed the C++libstacker). uv-domain stacking isLineStacker.uv(2.1); primary-beam weighting of image stacks takes primary-beam images or a function (see above).The vendored
intervalpackage (unused).CASA 5 support (
taskinit): CASA 5 runs Python 2.Helpers working on the module state of the last stack:
image.calculate_sigma2_weights,calculate_sigma2_weights_spectral,calculate_amp_weights,myVeryOwnWeightedAverageand the module variables (image.data,skymap,unusedFrequencies…), which kept every cube of the last stack in memory; useweighting=and the valuesstackreturns. AlsoanalysisTools.randomizeSampleandCoord.setWeightToX/setZeroWeightLeft/setZeroWeightRight(unused).The documentation inside the package (
LineStacker/docs): it is built fromdocs/sourceintodocs/(the github.io site).
Review fixes (October 2026)¶
A code review of the 2.0 port led to: the weighting fixes (items 13-15
above), the spectral-unit and axis checks, grid warnings and rotated output
WCS, primary-beam offsets on rotated grids (the cross terms of the pixel
matrix were ignored), the velocity conversion, regridFromZ’s cube labels,
NaN-aware fits, input validation, cache invalidation of modified CASA
images, closing every CASA tool, and per-call isolation of the inputs of
parallel jobs (two jobs in different threads could see each other’s data).
Each fix has a test in tests/test_weights_wcs.py or
tests/test_validation.py.
A second review led to: non-linear spectral axes refused in every line
mode (the stack’s header could not describe them), intensity-unit checks
and conversion, projection/frame/distortion checks, fractional pixels from
regridFromZ, infinite fluxes and one-channel spectra in 1D, FitError
for every fit failure (DoublePeakFit on short inputs, default widths from
valid channels only), the same “at least 2 valid pixels” rule for 'sigma'
and 'sigma2' as for 'sigma2F', integer subsample sizes, one image path
and limit checks in both randomizeCoords, congrid(minusone=True) with a
target size of 1, None/NaN cube names in catalogues, primary-beam cubes on
another spectral axis (an error), LineStacker.cache_check to trust the
cube cache, a lock around the thread variables set for worker processes,
and subprocess tests of CASA’s log settings. Tests:
tests/test_review2.py.
A third round: blank pixels stay NaN (see “Changes in results”, 23), SIP
and lookup-table distortions are compared term by term, the Gaussian
primary beam uses spherical sky offsets, randomCoords(ncoords) and
randomizeCoords(maxTries) must be integers, noise_estimator and
stack_estimator need nRandom >= 1, default fit widths use the median
channel spacing, and spectral axes of spectra must be finite and steadily
increasing or decreasing.
A fourth round finished the NaN handling: exact channels next to a blank
one are no longer blanked (NaN * 0 is NaN) when stamps are cut,
rebinning and regridding share one NaN-aware resampling (blank channels
used by an interpolation blank its result, and nothing else),
rebin_CubesSpectra(regionSize=...) keeps channels blank in the whole
region as NaN for its width fits, maximizeSNR ignores blank channels in
its noise (and gives 0 with fewer than 2 valid ones), spectra with a
one-element velocity or frequency axis raise ValueError, and distortion
signatures with different terms compare as different. regridFromZ with
blanks now also works when it upsamples (it raised an error). Tests:
tests/test_review4.py.
A fifth round and a release review: splines that never use blank channels
(the blank mask approximated the spline’s reach, which its prefilter
extends over the whole spectrum), evenly spaced 1D axes, sigma2
weights of fitted spectra with decreasing axes, NaN for 1D channels without
data, and the resampling fixes of items 24-25 (axes, centres, widths and
weights of rebinned and regridded spectra; exact channel widths and line
labels of regridded cubes). Also: line centres outside a spectrum,
center='zero_vel' without velocities, Gaussian-fit centring of frequency
spectra (it used the velocities), AIPS FELO axes treated as non-linear,
rebin_CubesSpectra(regionSize=...) regions outside the cube (and of the
size asked for: an odd size gave one pixel less, the region is now placed as
the stacker places stamps), a warning and weight 0 for blank primary-beam
responses (beyond the primary-beam cutoff, also for single-plane primary-beam
images, which gave a silent 0), dimension checks in the NaN-aware resampling, NaN-safe
maximizeAmp and 1D bootstrap amplitudes, and the missing docstrings of
congrid, maximizeAmp and maximizeOutflow. Tests: tests/test_review5.py.
LineStacker 2.0.1 (November 2026)¶
Changes since 2.0.0, from two full reviews of the code. Tests:
tests/test_review_201.py, tests/test_review_nov.py,
tests/test_conserve_flux.py.
Files are never deleted
regridFromZ(writeImage=True)no longer emptiesoutdir. It deleted the whole folder first, input cubes kept there included. It now writes its cubes (replacing files of the same name), leaves every other file, and refuses to replace an input cube.An output name that does not end in
.fitsis written as a CASA image, which is a folder. If a folder of that name existed, it was deleted, whatever it held:stack(coords, outfile='results')removed a folderresults. Now only an existing CASA image is replaced; any other folder is an error, raised before the stack is computed.
Results that change
readCoords: on a line with a plain number next to a sexagesimal value, such as53.1475, -27:46:12.4, 6.6, the number was read in hours (RA 77 deg instead of 53 deg). A plain number is now always inunit, as inreadCatalogandmakeCoords. Lines with two numbers, or two sexagesimal values, are read as before.readCoords: an empty field in a comma-separated line,x, y, , w, was dropped, so the weight was read as the redshift. It is now an error for line stacking. Trailing commas and repeated spaces are still accepted.OneD_Stacker.Stack,bootstraping_OneDandsubsample_OneDcentre copies of the spectra, and the spectra keep theircenterIndex. A stack withcenter='fit','center','zero_vel'or a channel number used to overwrite it, as in LineStacker 1.x. Later stacks with the defaultcenter='lineCenterIndex'then used those centres instead of the given ones.OneD_Stacker.set_centers(spectra, 'fit')stores a method’s centres explicitly.Channels made wider are averaged, not sampled (
conserveFlux=True, the new default). This concernsregridFromZ=Truewith'scaleToMax'(the default ofimage.stack),rebin_OneDandrebin_CubesSpectra. A new channel is the mean of the channels it covers. Before, it took the value of the spectrum at its centre, and the channels in between were not used. For a source widened by s:the noise per channel is lower: by 7 % at s = 1.25, 28 % at s = 2 and 49 % at s = 3 on average;
its integrated line flux is kept exactly (sampling overestimated narrow lines);
the line peak is that of the wider channels, a few per cent lower.
conserveFlux=Falsegives the earlier results. Channels made narrower ('scaleToMin') and sources that keep their channels do not change. See the analysis-tools page.OneD_Stacker.StackwithchansStack='full': when spectra given in velocities and spectra given in frequencies were stacked together, the length of the stack came from one kind only, and channels of the others could be left out. All channels of all spectra are now used.
New
bootStraping_CubetakesregridFromZ,regridMethod,conserveFluxandprimarybeam, so a stack made with them can be bootstrapped.OneD_Stacker.set_centers(see above).readCoordsacceptspathlibpaths.The first examples (README, home page,
basic_example.py, notebook) show the three ways to give the stacking positions, and the basic forms of a position (degrees, sexagesimal,SkyCoord, pixels).The logo is the LineStacker lettering followed by the round icon, everywhere a logo appears.
Clearer messages
A line stack whose positions do not all have a spectral value (z) says so. It failed with
could not convert string to float: 'continuum'.subsample_OneDrefuses stacking options it does not know. A misspelt option, such ascentre='fit', was ignored.subsample_OneDwarns when spectra share a name, since their grades are summed under it.verbose=Trueon one call also draws the progress bar whenLineStacker.verboseis False.tests/test_validation.pyreads only the last two lines printed by its CASA-log subprocess: casaconfig can print warnings before them.
Example scripts¶
LineStacker/Example/*/*.py are ported (the originals were Python 2 and used
taskinit); cube/continuum_example.py is new. They read cubes with
LineStacker.image.readCube (no casatools calls of their own). The cube
examples now take their positions from catalogues, cube/sources.csv and
cube/sources_extended.csv (ra, dec, z and the cube of each source), and
basic_example.py and the notebook show the same stack made from the
catalogue (readCatalog), from Python arrays (makeCoords) and from the
coordinate files of 1.x (readCoords); the scripts run from any folder. Where
coordinate files are used, cube names come from
str.removesuffix('_coord.txt'); the old strip('_coords.txt') removed
characters, not a suffix, and only worked by luck with the example names.
makeCoords accepts astropy table columns (it failed on columns, which carry
a unit attribute even without a unit).