hyri.measurement_operator.meas_op_hs#

Define the hyperspectral measurement operator wrapper.

This file provides a channel-wise wrapper that stacks monochromatic measurement operators and exposes a unified hyperspectral interface.

Class

MeasOpHyperspectral

Represent a hyperspectral measurement operator assembled per channel.

class hyri.measurement_operator.meas_op_hs.MeasOpHyperspectral(u: tuple[~torch.Tensor], v: tuple[~torch.Tensor], img_size: tuple[int, int], natural_weight: tuple[~torch.Tensor] = (tensor([[[1.]]]),), image_weight: tuple[~torch.Tensor] = (tensor([[[1.]]]),), precond_weight: tuple[~torch.Tensor] = (tensor([[[1.]]]),), meas_op_class: type[~hyri.measurement_operator.meas_op.MeasOp] = <class 'hyri.measurement_operator.meas_op_nufft_finufft.MeasOpFinufft'>, real_flag: bool = True, grid_size: tuple[int, int] = None, kernel_dim: int = 7, device: ~torch.device = device(type='cpu'), dtype: ~torch.dtype = torch.float32, verbose: bool = True, **kwargs: ~typing.Any)#

Bases: MeasOp

Represent a hyperspectral measurement operator assembled per channel.

This class wraps a monochromatic measurement-operator implementation and instantiates one local operator per spectral channel handled by the current process. Forward and adjoint applications are evaluated channel-wise, while norm estimation can aggregate local contributions across distributed ranks.

Shape:
  • Image tensor – (1, C_rank, H, W).

  • Visibility tensor – tuple of C_rank tensors, each with shape (1, 1, N_c).

  • Sampling-pattern coordinates :math:`u` and :math:`v` – tuples of C_rank tensors, each with shape (1, 1, N_c).

_num_ch_rank#

Number of local spectral channels owned by this rank.

Type:

int

_num_ch#

Per-rank channel counts across the active distributed job.

Type:

tuple[int, …]

_meas_op_ch#

Monochromatic operators for local channels.

Type:

list[MeasOp]

_distributed#

Whether torch.distributed is initialised.

Type:

bool

_rank#

Distributed rank index.

Type:

int

_world_size#

Number of distributed ranks.

Type:

int

_op_norm_ch#

Cached local per-channel norm estimates.

Type:

torch.Tensor | None

_op_norm_prime_ch#

Cached local per-channel twice-weighted norm estimates.

Type:

torch.Tensor | None

Example

>>> import torch
>>> u = ((2 * torch.pi) * torch.rand(1, 1, 8) - torch.pi,)
>>> v = ((2 * torch.pi) * torch.rand(1, 1, 8) - torch.pi,)
>>> op = MeasOpHyperspectral(u=u, v=v, img_size=(16, 16))
>>> image = torch.randn(1, 1, 16, 16)
>>> vis = op.forward_op(image)
>>> len(vis)
1

Initialise channel-wise measurement operators.

Parameters:
  • u (Tuple[torch.Tensor]) – Per-channel u sampling coordinates.

  • v (Tuple[torch.Tensor]) – Per-channel v sampling coordinates.

  • img_size (Tuple[int, int]) – Target image size (H, W).

  • natural_weight (Tuple[torch.Tensor], optional) – Per-channel natural weighting tensors. Length must be 1 or the local channel count.

  • image_weight (Tuple[torch.Tensor], optional) – Per-channel imaging weighting tensors. Length must be 1 or the local channel count.

  • precond_weight (Tuple[torch.Tensor], optional) – Per-channel preconditioning tensors. Length must be 1 or the local channel count.

  • meas_op_class (Type[MeasOp], optional) – Monochromatic operator class used for each channel. Default: MeasOpFinufft.

  • real_flag (bool, optional) – If True, keep adjoint outputs real when applicable. Default: True.

  • grid_size (Tuple[int, int], optional) – Backend-specific oversampled Fourier-grid size. Default: None.

  • kernel_dim (int, optional) – Backend-specific kernel support. Default: 7.

  • device (torch.device, optional) – Execution device. Default: torch.device("cpu").

  • dtype (torch.dtype, optional) – Image-domain dtype. Default: torch.float.

  • verbose (bool, optional) – Enable backend/operator logs. Default: True.

  • **kwargs – Additional backend-specific arguments forwarded to meas_op_class.

Note

Each process constructs operators only for its local channel subset. When torch.distributed is active, global channel counts are gathered so distributed norm estimates can combine contributions across ranks.

forward_op(x: Tensor) → tuple[Tensor, ...]#

Apply the hyperspectral forward operator channel-wise.

Parameters:

x (torch.Tensor) – Input tensor with shape (1, C_rank, H, W).

Returns:

Tuple of measurement-domain tensors, one per local channel.

Return type:

Tuple[torch.Tensor, …]

Note

The channel dimension of x is split across the locally owned monochromatic operators in index order.

adjoint_op(y: tuple[Tensor, ...]) → Tensor#

Apply the hyperspectral adjoint operator channel-wise.

Parameters:

y (Tuple[torch.Tensor, ...]) – Tuple of measurement-domain tensors, one per local channel.

Returns:

Reconstructed local image cube with shape (1, C_rank, H, W).

Return type:

torch.Tensor

Note

The input tuple must contain one measurement tensor per local channel in the same order used during construction.

get_op_norm(compute_flag=False, rel_tol=1e-05, max_iter=500, verbose=False) → float#

Estimate the global spectral norm of the hyperspectral operator.

This overrides the base implementation to aggregate vector norms across distributed ranks.

Parameters:
  • compute_flag (bool, optional) – Force recomputation if True. Default: False.

  • rel_tol (float, optional) – Relative stopping tolerance. Default: 1e-5.

  • max_iter (int, optional) – Maximum power iterations. Default: 500.

  • verbose (bool, optional) – Print iteration progress on rank 0. Default: False.

Returns:

Estimated spectral norm.

Return type:

float

Note

In distributed runs, the power iteration uses an all-reduce on the squared vector norm so the returned value reflects the global hyperspectral operator rather than only the local rank.

get_op_norm_ch(compute_flag=False, rel_tol=1e-05, max_iter=500, verbose=False) → Tensor#

Return per-channel spectral-norm estimates.

Parameters:
  • compute_flag (bool, optional) – Force recomputation if True. Default: False.

  • rel_tol (float, optional) – Relative stopping tolerance forwarded to channel operators. Default: 1e-5.

  • max_iter (int, optional) – Maximum power iterations forwarded to channel operators. Default: 500.

  • verbose (bool, optional) – Print channel progress when enabled. Default: False.

Returns:

Tensor of shape (1, C_rank, 1, 1) containing local per-channel norm estimates.

Return type:

torch.Tensor

get_op_norm_prime_ch(rel_tol=1e-05, max_iter=500, verbose=False) → Tensor#

Return per-channel twice-weighted norm estimates.

These values are typically used to correct heuristic noise levels for weighted imaging.

Parameters:
  • rel_tol (float, optional) – Relative stopping tolerance forwarded to channel operators. Default: 1e-5.

  • max_iter (int, optional) – Maximum power iterations forwarded to channel operators. Default: 500.

  • verbose (bool, optional) – Print channel progress when enabled. Default: False.

Returns:

Tensor of shape (1, C_rank, 1, 1) containing local per-channel twice-weighted norm estimates.

Return type:

torch.Tensor

get_psf() → Tensor#

Compute local-channel PSFs.

Returns:

Local PSF tensor with shape (1, C_rank, H, W).

Return type:

torch.Tensor

Note

This method returns only the PSFs owned by the current rank. It does not gather channel blocks across distributed processes.

set_real_flag(real_flag: bool) → None#

Set the real-output flag for all local channel operators.

Parameters:

real_flag (bool) – New real-output flag.

set_precond_weight(precond_weight: tuple[Tensor, ...]) → None#

Set per-channel preconditioning weights.

Parameters:

precond_weight (Tuple[torch.Tensor, ...]) – Preconditioning tensors, one per local channel.

Note

Updating these weights invalidates cached global and per-channel norm estimates.