ReconPlugin#
- class pulserver.recon.ReconPlugin[source]#
Bases:
ABCBase class for reconstruction plugins.
The runtime drives one MRD stream through three hooks:
startup()once, before any acquisition;recon()for each reconstruction unit as it closes; andfinish()once, after the last unit. Onlyrecon()is abstract; the framework methodreceive()is not overridden.A unit is the set of readouts reconstructed together: those of one branch and encoding space that share every image counter (slice, contrast, phase, repetition, set, average) not listed in
axesormerge. The counters inaxesare axes of the unit’s k-space instead, and those inmergeare laid out along none;segmentand the user counters separate no units unlesssegmentis listed. Each accepted acquisition runs through thegadgets, then joins the unit of the branchbranch_for()names, which places it by its flags (seeReconData). A unit closes when the flagtriggersnames for its branch has arrived for every combination of the counters inaxesandmerge. It leaves the plugin beforerecon()runs, so its buffers are freed oncerecon()returns; the memory a stream holds is bounded by the units open at once. Units still open atLAST_IN_MEASUREMENTor at the end of the stream are reconstructed then, in the order they opened and under their own branches.Each stream runs on its own
spawn()of the module-levelPLUGIN, so state set in the hooks belongs to one stream.context.examis shared across the series of an exam; a plugin adds to it and never clears it.- Parameters:
gadgets –
Gadgetsteps applied to every accepted readout on arrival, in order, before it is placed; each receives a copy of the acquisition, which it may update to describe the readout it returns.triggers –
{branch: flag}: theAcquisitionFlagthat closes a unit of the branch, combined with|for either of several. The first branch declared receives the readoutsbranch_for()does not route elsewhere. The default is{"imaging": LAST_IN_MEASUREMENT}.axes – Counters of a unit placed along axes of its k-space and waited for by the closing flag, instead of separating units: any of
repetition,phase,slice,contrast,set,averageandsegment. Their extents are the header’s encoding limits.merge – Counters of a unit waited for by the closing flag and laid out along no axis, instead of separating units: any of
repetition,phase,slice,contrast,setandaverage. A readout is placed by its other counters whatever its value of a merged one, so readouts that share them replace one another, with a warning; the echoes of one train, which fill phase encodes of their own, do not. A buffer holds one k-space however many values a merged counter takes. Their extents are the header’s encoding limits.require_flags – Flags an acquisition must all carry to be accepted. A combined
AcquisitionFlagcounts as its members.reject_flags – Flags any one of which excludes an acquisition.
buffered – Place readouts in
ReconData.dataandReconData.ref. Disable for streams whose header does not describe their encoding spaces; the plugin then readsReconData.acquisitions, and a unit closes at the first flag, whatever itsaxes.chain – Deprecated alias of
gadgets; warns.branches – Deprecated alias of
triggers, mapping{flag: branch}; warns.
- Attributes:
gadgets (tuple of Gadget)
triggers (dict)
axes (tuple of str)
merge (tuple of str) – Read when a stream starts, so a subclass may assign it after
super().__init__.
Examples
>>> import numpy as np >>> import pulserver.mrd as mrd >>> import pulserver.recon as recon >>> class DropNoise(recon.Gadget): ... def __call__(self, acquisition, data): ... noise = mrd.has_acquisition_flag(acquisition, "ACQ_IS_NOISE_MEASUREMENT") ... return None if noise else data >>> class RootSumOfSquares(recon.ReconPlugin): ... def __init__(self): ... super().__init__( ... gadgets=[DropNoise()], ... triggers={"imaging": mrd.AcquisitionFlag.LAST_IN_SLICE}, ... axes=("average",), ... ) ... def recon(self, context, branch, data): ... kspace = data.data.kspace ... return recon.ReconResult(np.sqrt(np.sum(np.abs(kspace) ** 2, axis=0))) >>> RootSumOfSquares().triggers["imaging"] <AcquisitionFlag.LAST_IN_SLICE: 128>
Methods
Return the branch an acquisition belongs to, or |
|
Run once, after the last unit has been reconstructed. |
|
Reconstruct every unit still open under its own branch, then call |
|
Return this stream's first gadget of type |
|
Take in one acquisition and reconstruct the units it completes. |
|
Hold a waveform for the next units that close; see |
|
Reconstruct one unit. |
|
Reconstruct one ISMRMRD HDF5 file in this process, through the same hooks. |
|
Return the instance one stream runs on. |
|
Start every gadget and lay out the units' encoding spaces from the header. |