Precomposed Modules#
For convenience, we provide some “precomposed” modules which may be useful for simple imaging or modeling applications. In general, though, we encourage you to compose your own set of layers if your application requires it. The source code for a precomposed network can provide useful a starting point. We also recommend checking out the PyTorch documentation on modules.
- class mpol.precomposed.GriddedNet(coords: GridCoords, nchan: int = 1, base_cube: Tensor | None = None)[source]#
Note
This module is provided as a starting point. However, we recommend that you don’t get too comfortable using it and instead write your own (custom) modules following PyTorch idioms, potentially using the source of this routine as a reference point. Using the torch module system directly is much more powerful and expressive.
A basic but functional network for RML imaging. Designed to optimize a model image using the entirety of the dataset in a
mpol.datasets.GriddedDataset
(i.e., gradient descent). For stochastic gradient descent (SGD), where the model is only seeing a fraction of the dataset with each iteration, we recommend defining your own module in your analysis code, following the ‘Getting Started’ guide.graph TD subgraph GriddedNet bc(BaseCube) --> HannConvCube HannConvCube --> ImageCube ImageCube --> FourierLayer end FourierLayer --> il([Loss]) ad[[Dataset]] --> il([Loss])- Parameters:
coords (
mpol.coordinates.GridCoords
)nchan (int) – the number of channels in the base cube. Default = 1.
base_cube (
mpol.images.BaseCube
orNone
) – a pre-packed base cube to initialize the model with. If None, assumestorch.zeros
.
After the object is initialized, instance variables can be accessed, for example
- Variables:
bcube – the
BaseCube
instanceicube – the
ImageCube
instancefcube – the
FourierCube
instance
For example, you’ll likely want to access the
self.icube.sky_model
at some point.- forward() Tensor [source]#
Feed forward to calculate the model visibilities. In this step, a
BaseCube
is fed to aHannConvCube
is fed to aImageCube
is fed to aFourierCube
to produce the visibility cube.- Return type:
1D complex torch tensor of model visibilities.
- predict_loose_visibilities(uu: Tensor, vv: Tensor) Tensor [source]#
Use the
mpol.fourier.NuFFT
to calculate loose model visibilities from the cube stored toself.icube.packed_cube
.- Parameters:
uu (
torch.Tensor
of class:`torch.double) – array of u spatial frequency coordinates, not including Hermitian pairs. Units of [\(\mathrm{k}\lambda\)]vv (
torch.Tensor
of class:`torch.double) – array of v spatial frequency coordinates, not including Hermitian pairs. Units of [\(\mathrm{k}\lambda\)]
- Returns:
:class:`torch.Tensor` of `class – model visibilities corresponding to
uu
andvv
locations.- Return type:
torch.complex128