File: python_deconvolution.rst

package info (click to toggle)
wsclean 3.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,296 kB
  • sloc: cpp: 129,246; python: 22,066; sh: 360; ansic: 230; makefile: 185
file content (28 lines) | stat: -rw-r--r-- 2,813 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Implementing custom strategies in Python
========================================

WSClean has an option to call a Python script instead of using one of its built-in approaches to perform the deconvolution. The option is called ``-python-deconvolution`` and takes as parameter the filename of the Python script, e.g.:

.. code-block:: bash

    wsclean -python-deconvolution my_deconvolution_script.py \
      -niter 1000 -auto-threshold 5 -mgain 0.8 input.ms

The Python script should declare a function with the name and signature ``deconvolve(residual, model, psf, meta)``. The first three parameters are numpy arrays. Both ``residual`` and ``model`` are 4-dimensional arrays with dimensions ``n_channels * n_polarizations * height * width``. The ``psf`` is a 3-dimensional cube with dimensions ``n_channels * height * width``; it does not have the polarization dimension because the PSF is assumed to be the same for all polarizations. The ``meta`` parameter is a dictionary with various meta information about the data or run:

* ``meta.major_iter_threshold``: Current requested major iteration threshold.
* ``meta.final_threshold``: Requested absolute final threshold. If a relative stopping threshold was specified, it is converted to an absolute value before calling this function.
* ``meta.mgain``: Requested major loop gain.
* ``meta.iteration_number``: Total number of iterations performed. The deconvolution function is responsible for updating this value.
* ``meta.max_iterations``: Requested maximum number of iterations.
* ``meta.channels``: An array, where each element has the properties ``frequency`` and ``weights``.
* ``meta.square_joined_channels``: Set to ``True`` when the user has requested squared channels during joining.
* ``meta.spectral_fitter``: An object that can apply the user-requested spectral fitting (see :doc:`wideband_deconvolution`). It has two methods that each take a spectrum, which is a list of ``n_channels`` flux density values.
  
  - ``fit(spectrum)``: returns the fitted coefficients
  - ``fit_and_evaluate(spectrum)``: returns the fitted spectrum

There are a few example Python files in the ``wsclean/scripts/python-examples`` directory of the repository, notably:

* `simple-deconvolution-example.py <https://gitlab.com/aroffringa/wsclean/-/blob/master/scripts/python-examples/simple-deconvolution-example.py>`_, which is a single-frequency, single-polarization algorithm that is similar to a basic clean method. It demonstrates the interface (note that it is slow and not aimed at performance comparisons).
* `mf-deconvolution-example.py <https://gitlab.com/aroffringa/wsclean/-/blob/master/scripts/python-examples/mf-deconvolution-example.py>`_, a similar algorithm, but this one makes use of the spectral fitter to demonstrate multi-frequency deconvolution.