Repository navigation
Sum utu.spectrum.synthesize() as a matrix product, and add axis_shift for velocity-resolved emission measures - #17
Merged
Conversation
…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
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
synthesize()formed the product of the contribution function, theemission 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 andevery line at once, and sums it with the emission measure using
na.vecdot(), which does that matrix product with BLAS. If the kernelof every line and bin does not fit in
_size_blockelements, as wherethe 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_shiftargument names an axis ofemission_measurealongwhich 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
shiftandwidth_nonthermal.emission_measuremust have that axis, with as many elements along itas any other argument, so that its plasma is not counted once for each
shift, and
velocitymust not vary along it. The profile of each bin isa 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
TypeErrorbefore. Thisneeds named-arrays 2.19 for
na.vecdot().New tests compare
axis_shiftwith the sum of separate syntheses ofits 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