Skip to content

Sum utu.spectrum.synthesize() as a matrix product, and add axis_shift for velocity-resolved emission measures - #17

Merged
roytsmart merged 2 commits into
mainfrom
feature/synthesize-vecdot
Nov 9, 2026
Merged

roytsmart merged 2 commits into
mainfrom
feature/synthesize-vecdot

Conversation

@roytsmart

@roytsmart roytsmart commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

synthesize() formed the product of the contribution function, the
emission measure and the profile at every temperature and in every
pixel, one bin of velocity at a time, and then summed it over
temperature. For a map, building that product is most of the work, and
it is not needed. Unless the profile or the contribution function varies
from pixel to pixel, the spectral radiance per unit emission measure in
each bin of temperature, the kernel, has no axes of the map, and the sum
is a matrix product of the kernel and the emission measure.
synthesize() now computes the kernel for every bin of velocity and
every line at once, and sums it with the emission measure using
na.vecdot(), which does that matrix product with BLAS. If the kernel
of every line and bin does not fit in _size_block elements, as where
the profile varies from pixel to pixel and the kernel is as large as the
map, the kernel and the radiance it gives are computed in blocks of bins
and of lines which fit in it together.

The new axis_shift argument names an axis of emission_measure along
which the plasma is binned by line-of-sight velocity, as in a
velocity-resolved DEM. It is summed over as well as axis_temperature,
each bin with the profile of its own shift and width_nonthermal.
emission_measure must have that axis, with as many elements along it
as any other argument, so that its plasma is not counted once for each
shift, and velocity must not vary along it. The profile of each bin is
a Gaussian, so plasma spread evenly across a bin is approximated by one
of the same variance.

A velocity-resolved DEM of a MURaM active-region simulation, of shape
(logT=24, vdop=33, x=1024, y=1024), now synthesizes in 8.4 s, with the
25 brightest lines of the ESIS-II passband in 64 bins of velocity. The
old code took 4.8 s for one line on a 128 x 128 slice of it, which is
about 2 hours for the whole cube and all the lines. The result agrees
with a separately written single-precision contraction to 5e-7 of each
line's peak.

The sum is taken in the units of the spectral radiance per unit
emission measure, so the result, which may be large, is never
converted. Its axes are in the order of the arguments, as before,
whether it is computed in one piece or in blocks, and it takes 1.06
times its own memory in blocks. An uncertain emission measure gives an
uncertain result either way, where it raised TypeError before. This
needs named-arrays 2.19 for na.vecdot().

New tests compare axis_shift with the sum of separate syntheses of
its bins, in one piece and in blocks, and with the emission measure
summed first where every bin has the same shift. They check how many
blocks of lines and of bins each case is split into, that the blocks
give the same result, of the same type and with its axes in the same
order, including an uncertain emission measure and a last block which is
not full, and cover a profile along an axis with no elements and the new
errors. A second example in the docstring synthesizes a
velocity-resolved emission measure.

🤖 Generated with Claude Code

https://claude.ai/code/session_017xqpht97bF4FWsACAA4wQa

…ift` for velocity-resolved emission measures

`synthesize()` formed the product of the contribution function, the
emission measure and the profile at every temperature and in every
pixel, one bin of velocity at a time, and then summed it over
temperature. For a map, building that product is most of the work, and
it is not needed. Unless the profile varies from pixel to pixel, the
spectral radiance per unit emission measure in each bin of temperature,
the kernel, has no axes of the map, and the sum is a matrix product of
the kernel and the emission measure. `synthesize()` now computes the
kernel for every bin of velocity and every line at once, and sums it
with the emission measure using `na.vecdot()`, which does that matrix
product with BLAS. Where the profile does vary from pixel to pixel, the
kernel is as large as the map, and it is computed in blocks of bins and
of lines which fit in `_size_block` elements. That limit now bounds the
kernel, not the product.

The new `axis_shift` argument names an axis of `emission_measure` along
which the plasma is binned by line-of-sight velocity, as in a
velocity-resolved DEM. It is summed over as well as `axis_temperature`,
each bin with the profile of its own `shift` and `width_nonthermal`.
`emission_measure` must have that axis, and `velocity` must not vary
along it.

A velocity-resolved DEM of a MURaM active-region simulation, of shape
(logT=24, vdop=33, x=1024, y=1024), now synthesizes in 8.4 s, with the
25 brightest lines of the ESIS-II passband in 64 bins of velocity. The
old code took 4.8 s for one line on a 128 x 128 slice of it, which is
about 2 hours for the whole cube and all the lines. The result agrees
with a separately written single-precision contraction to 5e-7 of each
line's peak.

The sum is taken in the units of the spectral radiance per unit
emission measure, so the result, which may be large, is never
converted. This needs named-arrays 2.19 for `na.vecdot()`.

New tests compare `axis_shift` with the sum of separate syntheses of
its bins, check blocks of lines and of bins against a single block, with
a shift which varies from pixel to pixel and a last block which is not
full, and cover the new errors. A second example in the docstring
synthesizes a velocity-resolved emission measure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xqpht97bF4FWsACAA4wQa
@read-the-docs-community

read-the-docs-community Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 utu | 🛠️ Build #35759663 | 📁 Comparing 187b78a against latest (ea429ec)

  🔍 Preview build  

2 files changed
± _autosummary/utu.spectrum.synthesize.html
± _modules/utu/spectrum/_synthesis.html

@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (ea429ec) to head (187b78a).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #17   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           21        21           
  Lines         1431      1514   +83     
=========================================
+ Hits          1431      1514   +83     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

An emission measure with one element along `axis_shift` was broadcast
against the shifts and summed, which counted its plasma once for each of
them, three times over for three shifts. It now has to have as many
elements along `axis_shift` as every other argument. `axis_shift` may
not be `axis_velocity` either, which blamed the bins of velocity.

The block size bounded only the kernel, not the radiance each block
gives, which has every axis of the map of the emission measure. Two
blocks of bins of a map along x, with the profile the same in every
pixel, took 2.01 times the memory of the result, where main took 1.06.
If the kernel of every line and bin fits in `_size_block`, the result is
still computed in one piece. Otherwise the kernel and the radiance of a
block are bounded together, which brings that case back to 1.06. An
axis of the kernel with no elements no longer divides by zero.

The result computed in one piece had its axes in the order
`na.vecdot()` gives them, and the result computed in blocks in the order
of the arguments, as on main. Both now have the order of the arguments,
the one-piece result as a transposed view. The result computed in blocks
is allocated from the first block, so it is uncertain if the block is,
where it raised `TypeError`. The units of the kernel are converted
before the fraction, which has every axis of the kernel, is multiplied
in.

The docstrings say that the kernel has axes of the map where the
contribution function varies from pixel to pixel as well as the
profile, that a Gaussian of the same variance approximates plasma
spread evenly across a bin, and which errors `axis_shift` raises. The
example takes the centers and the widths of its bins with
`cell_centers()` and `volume_cell()`.

`test_synthesize_blocks` now checks how many blocks each case is split
into, the type of the result and the order of its axes, and covers an
uncertain emission measure. New tests cover `axis_shift` in blocks, with
a shift the same in every bin, equal to `axis_velocity` or `axis`, and
with one bin of emission measure for three shifts, and a profile which
varies along an axis with no elements. The changed files are formatted
with black.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xqpht97bF4FWsACAA4wQa
@roytsmart
roytsmart merged commit fdae758 into main Nov 9, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant