Skip to content

acquisition_parameter

acquisition_parameter

Interface class for acquisition parameters.

AcquisitionParameter dataclass

AcquisitionParameter(larmor_frequency: float = 2000000.0, b1_scaling: float = 1.0, gradient_offset: Dimensions = _gradient_offset_factory(), fov_scaling: Dimensions = _fov_scaling_factory(), channel_assignment: Dimensions = _channel_factory(), ddc_method: DDCMethod = FIR, num_averages: int = 1, averaging_delay: float = 0.0, state_filepath: str = str(home() / 'nexus-console/acquisition-parameter.state'), _initialized: bool = False)

Runtime parameters of an acquisition.

In contrast to the static device configuration, acquisition parameters describe the state of a measurement session (e.g. calibrated Larmor frequency and B1 scaling) and are passed to AcquisitionControl.set_sequence for each acquisition.

The parameter state is persisted as JSON: it is written to state_filepath on instantiation and on every mutation of an attribute (including mutations of nested Dimensions attributes). Assignments are type-checked against the field annotations. On import of the console package, the last saved state is loaded and exposed as console.parameter.

larmor_frequency class-attribute instance-attribute

larmor_frequency: float = 2000000.0

Larmor frequency in Hz.

b1_scaling class-attribute instance-attribute

b1_scaling: float = 1.0

Scaling of the B1 field (RF transmit power).

gradient_offset class-attribute instance-attribute

gradient_offset: Dimensions = field(default_factory=_gradient_offset_factory)

Static gradient offsets (e.g. for linear shimming) in mV.

Given per physical output channel (x: channel 1, y: channel 2, z: channel 3) and applied as hardware DC offset of the transmit card for the duration of an acquisition.

fov_scaling class-attribute instance-attribute

fov_scaling: Dimensions = field(default_factory=_fov_scaling_factory)

Scaling factor of the logical gradient waveforms gx, gy and gz.

channel_assignment class-attribute instance-attribute

channel_assignment: Dimensions = field(default_factory=_channel_factory)

Assignment of the logical gradients x, y, z to the physical transmit channels 1, 2, 3.

Must be a permutation of {1, 2, 3}.

ddc_method class-attribute instance-attribute

ddc_method: DDCMethod = DDCMethod.FIR

Decimation filter method.

num_averages class-attribute instance-attribute

num_averages: int = 1

Number of acquisition averages.

averaging_delay class-attribute instance-attribute

averaging_delay: float = 0.0

Delay in seconds between acquisition averages.

state_filepath class-attribute instance-attribute

state_filepath: str = str(Path.home() / 'nexus-console/acquisition-parameter.state')

Default file path for acquisition parameter state.

Don't enforce a Path object here to prevent conflicts when sending acquisition parameter instances between different OS.

to_dict

to_dict(use_strings: bool = False) -> dict

Return acquisition parameters as dictionary.

Parameters:

  • use_strings (bool, default: False ) –

    boolean flag indicating if values of dictionary should be represented as strings, by default False

Returns:

  • Acquisition parameter dictionary –
Source code in src/console/interfaces/acquisition_parameter.py
def to_dict(self, use_strings: bool = False) -> dict:
    """Return acquisition parameters as dictionary.

    Parameters
    ----------
    use_strings
        boolean flag indicating if values of dictionary should be represented as strings, by default False

    Returns
    -------
        Acquisition parameter dictionary
    """
    if use_strings:
        return {key: str(value) for key, value in asdict(self, dict_factory=_dict_factory).items()}
    return asdict(self, dict_factory=_dict_factory)

save

save(filepath: str | Path | None = None) -> None

Save current acquisition parameter state.

Parameters:

  • filepath (str or Path or None, default: None ) –

    Path to the JSON state file. If None, state_filepath is used (default <home>/nexus-console/acquisition-parameter.state). If the path does not end with .state, it is interpreted as directory and the filename acquisition-parameter.state is appended.

Source code in src/console/interfaces/acquisition_parameter.py
def save(self, filepath: str | Path | None = None) -> None:
    """Save current acquisition parameter state.

    Parameters
    ----------
    filepath : str or Path or None, optional
        Path to the JSON state file. If None, `state_filepath` is used
        (default ``<home>/nexus-console/acquisition-parameter.state``).
        If the path does not end with ``.state``, it is interpreted as directory and the
        filename ``acquisition-parameter.state`` is appended.
    """
    _path = Path(filepath or self.state_filepath)
    if not _path.name.endswith(".state"):
        _path = _path / "acquisition-parameter.state"
    _path.parent.mkdir(parents=True, exist_ok=True)
    _path.write_text(json.dumps(self.to_dict(), indent=2))

load classmethod

load(filepath: Path | str | None = None) -> Optional[AcquisitionParameter]

Load and return acquisition parameter state.

Parameters:

  • filepath (Path or str or None, default: None ) –

    Path to acquisition parameter state file. If the path does not end with .state, the filename acquisition-parameter.state is appended.

Returns:

  • AcquisitionParameter or None –

    Instance of acquisition parameters with state loaded from the provided path, or None if the state file does not exist or cannot be parsed (the error is logged).

Source code in src/console/interfaces/acquisition_parameter.py
@classmethod
def load(cls, filepath: Path | str | None = None) -> Optional["AcquisitionParameter"]:
    """
    Load and return acquisition parameter state.

    Parameters
    ----------
    filepath : Path or str or None, optional
        Path to acquisition parameter state file. If the path does not end with
        ``.state``, the filename ``acquisition-parameter.state`` is appended.

    Returns
    -------
    AcquisitionParameter or None
        Instance of acquisition parameters with state loaded from the provided path, or None if the
        state file does not exist or cannot be parsed (the error is logged).
    """
    log = logging.getLogger("AcqParam")

    # Resolve file path
    _path = filepath or cls.state_filepath
    _path = Path(_path)

    # Enforce `.state` suffix
    if not _path.name.endswith(".state"):
        _path = _path / "acquisition-parameter.state"

    try:
        data = json.loads(_path.read_text())
        return cls(**data)
    except Exception:
        log.exception(
            "Error loading AcquisitionParameter state file '%s'.",
            str(_path),
        )
        return None