Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .codespellrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ ignore-words-list =
process,
technik,
thirdparty,
lamba
lamba,
sav
3 changes: 3 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"sphinx_changelog",
"sphinx_design",
"sphinx_gallery.gen_gallery",
"sphinxcontrib.bibtex",
]

# Add any paths that contain templates here, relative to this directory.
Expand Down Expand Up @@ -77,6 +78,8 @@
autodoc_typehints = "description"
autoclass_content = "init"

bibtex_bibfiles = ["references.bib"]

# -- Options for intersphinx extension ---------------------------------------

# Example configuration for intersphinx: refer to the Python standard library.
Expand Down
6 changes: 6 additions & 0 deletions docs/reference/bibliography.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _bibliography_xrayvision:

Bibliography
------------

.. bibliography::
2 changes: 2 additions & 0 deletions docs/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ Reference
transform
utils
visibility
uv-smooth
bibliography

../whatsnew/index
8 changes: 8 additions & 0 deletions docs/reference/uv-smooth.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. _uv-smooth:

UV-SMOOTH ('xrayvision.uv_smooth')
**********************************

The ``uv_smooth`` submodule contains the uv_smooth image reconstruction technique.

.. automodapi:: xrayvision.uv_smooth
11 changes: 11 additions & 0 deletions docs/references.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@article{Massone2009_uv_smooth,
title={Hard X-ray Imaging of Solar Flares Using Interpolated Visibilities},
volume={703},
url={http://adsabs.harvard.edu/cgi-bin/nph-data_query?bibcode=2009ApJ...703.2004M&link_type=EJOURNAL},
DOI={10.1088/0004-637x/703/2/2004},
abstractNote={RHESSI produces solar flare images with the finest angular and spectral resolutions ever achieved at hard X-ray energies. Because this instrument uses indirect, collimator-based imaging techniques, the “native” output of which is in the form of “visibilities” (two-dimensional spatial Fourier components of the image), the development and application of robust, accurate, visibility-based image reconstruction techniques is required. Recognizing that the density of spatial-frequency (u, v) coverage by RHESSI is much sparser than that normally encountered in radio astronomy, we therefore introduce a method for image reconstruction from a relatively sparse distribution of sampled visibilities. The method involves spline interpolation at spatial frequencies less than the largest sampled frequency and the imposition of a positivity constraint on the image to reduce the ringing effects resulting from an unconstrained Fourier transform inversion procedure. Using simulated images consisting both of assumed mathematical forms and of the type of structure typically associated with solar flares, we validate the fidelity, accuracy, and robustness with which the new procedure recovers input images. The method faithfully recovers both single and multiple sources, both compact and extended, over a dynamic range of ~10:1. The performance of the method, which we term as uv_smooth, is compared with other RHESSI image reconstruction algorithms currently in use and its advantages summarized. We also illustrate the application of the method using RHESSI observations of four solar flares.},
number={2},
journal={The Astrophysical Journal},
author={Massone, Anna Maria and Emslie, A Gordon and Hurford, G J and Prato, Marco and Kontar, Eduard P and Piana, Michele},
year={2009},
pages={2004–2016} }
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ build-backend = 'setuptools.build_meta'
[project]
name = "xrayvisim"
description = "An open-source Python library for Fourier or synthesis X-Ray imaging instruments."
requires-python = ">=3.9"
requires-python = ">=3.11"
readme = {file = "README.rst", content-type="text/x-rst"}
license = "BSD-3-Clause"
license-files = ["LICENSE.rst"]
authors = [{name="Shane Maloney", email = "shane.maloney@dias.ie"}]
dependencies = [
"astropy>=6.0.0",
"numpy>=1.24.0",
"numpy>=1.25.0",
"packaging>=23.0",
"scipy>=1.13",
"xarray>=2023.5.0"
Expand Down Expand Up @@ -59,7 +59,8 @@ docs = [
"sphinx-gallery>=0.13.0",
"sphinxext-opengraph>=0.6.0",
"xrayvisim[all]",
"pydata-sphinx-theme>=0.16.0"
"pydata-sphinx-theme>=0.16.0",
"sphinxcontrib-bibtex"
]
dev = ["xrayvisim[tests,docs]"]

Expand Down Expand Up @@ -91,7 +92,7 @@ version_file = "xrayvision/_version.py"

[tool.mypy]
disable_error_code = "import-untyped"
python_version = "py39"
python_version = "3.11"

[ tool.gilesbot ]

Expand Down
2 changes: 1 addition & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
target-version = "py39"
target-version = "py311"
line-length = 120
exclude = [
".git,",
Expand Down
35 changes: 17 additions & 18 deletions xrayvision/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

"""

from typing import Union, Optional
from collections.abc import Iterable

import astropy.units as u
Expand Down Expand Up @@ -71,11 +70,11 @@ def clean(
dirty_map: Quantity,
dirty_beam: Quantity,
pixel_size: Quantity[u.arcsec / u.pix] = None,
clean_beam_width: Optional[Quantity[u.arcsec]] = 4.0 * u.arcsec,
gain: Optional[float] = 0.1,
thres: Optional[float] = None,
clean_beam_width: Quantity[u.arcsec] | None = 4.0 * u.arcsec,
gain: float | None = 0.1,
thres: float | None = None,
niter: int = 5000,
) -> Union[Quantity, NDArray[np.float64]]:
) -> Quantity | NDArray[np.float64]:
r"""
Clean the image using Hogbom's original method.

Expand Down Expand Up @@ -176,10 +175,10 @@ def vis_clean(
vis: Visibilities,
shape: Quantity[u.pix],
pixel_size: Quantity[u.arcsec / u.pix],
clean_beam_width: Optional[Quantity[u.arcsec]] = 4.0,
niter: Optional[int] = 5000,
map: Optional[bool] = True,
gain: Optional[float] = 0.1,
clean_beam_width: Quantity[u.arcsec] | None = 4.0,
niter: int | None = 5000,
map: bool | None = True,
gain: float | None = 0.1,
**kwargs,
):
r"""
Expand Down Expand Up @@ -258,12 +257,12 @@ def ms_clean(
dirty_map: Quantity,
dirty_beam: Quantity,
pixel_size: Quantity[u.arcsec / u.pix],
scales: Union[Iterable, NDArray, None] = None,
scales: Iterable | NDArray | None = None,
clean_beam_width: Quantity = 4.0 * u.arcsec,
gain: float = 0.1,
thres: float = 0.01,
niter: int = 5000,
) -> Union[Quantity, NDArray[np.float64]]:
) -> Quantity | NDArray[np.float64]:
r"""
Clean the map using a multiscale clean algorithm.

Expand Down Expand Up @@ -406,13 +405,13 @@ def vis_ms_clean(
vis: Visibilities,
shape: Quantity[u.pix],
pixel_size: Quantity[u.arcsec / u.pix],
scales: Optional[Iterable],
clean_beam_width: Optional[Quantity[u.arcsec]] = 4.0,
niter: Optional[int] = 5000,
map: Optional[bool] = True,
gain: Optional[float] = 0.1,
thres: Optional[float] = 0.01,
) -> Union[Quantity, NDArray[np.float64]]:
scales: Iterable | None,
clean_beam_width: Quantity[u.arcsec] | None = 4.0,
niter: int | None = 5000,
map: bool | None = True,
gain: float | None = 0.1,
thres: float | None = 0.01,
) -> Quantity | NDArray[np.float64]:
r"""
Clean the visibilities using a multiscale clean method.

Expand Down
4 changes: 1 addition & 3 deletions xrayvision/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Force MPL to use non-gui backends for testing.
import matplotlib

try:
pass
import matplotlib
except ImportError:
pass
else:
Expand Down
18 changes: 8 additions & 10 deletions xrayvision/imaging.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Optional

import astropy.units as apu
import numpy as np
from astropy.units import Quantity
Expand Down Expand Up @@ -56,7 +54,7 @@ def get_weights(vis: Visibilities, scheme: str = "natural", norm: bool = True) -


@apu.quantity_input()
def validate_and_expand_kwarg(q: Quantity, name: Optional[str] = "") -> Quantity:
def validate_and_expand_kwarg(q: Quantity, name: str | None = "") -> Quantity:
r"""
Expand a scalar or array of size one to size two by repeating.

Expand Down Expand Up @@ -97,8 +95,8 @@ def image_to_vis(
*,
u: Quantity[apu.arcsec**-1],
v: Quantity[apu.arcsec**-1],
phase_center: Optional[Quantity[apu.arcsec]] = (0.0, 0.0) * apu.arcsec,
pixel_size: Optional[Quantity[apu.arcsec / apu.pix]] = 1.0 * apu.arcsec / apu.pix,
phase_center: Quantity[apu.arcsec] | None = (0.0, 0.0) * apu.arcsec,
pixel_size: Quantity[apu.arcsec / apu.pix] | None = 1.0 * apu.arcsec / apu.pix,
) -> Visibilities:
r"""
Return a Visibilities object created from the image and u, v sampling.
Expand Down Expand Up @@ -135,7 +133,7 @@ def image_to_vis(
def vis_to_image(
vis: Visibilities,
shape: Quantity[apu.pix] = (65, 65) * apu.pixel,
pixel_size: Optional[Quantity[apu.arcsec / apu.pix]] = 1 * apu.arcsec / apu.pix,
pixel_size: Quantity[apu.arcsec / apu.pix] | None = 1 * apu.arcsec / apu.pix,
scheme: str = "natural",
) -> Quantity:
"""
Expand Down Expand Up @@ -180,8 +178,8 @@ def vis_psf_map(
vis: Visibilities,
*,
shape: Quantity[apu.pix] = (65, 65) * apu.pixel,
pixel_size: Optional[Quantity[apu.arcsec / apu.pix]] = 1 * apu.arcsec / apu.pix,
scheme: Optional[str] = "natural",
pixel_size: Quantity[apu.arcsec / apu.pix] | None = 1 * apu.arcsec / apu.pix,
scheme: str | None = "natural",
) -> GenericMap:
r"""
Create a map of the point spread function for given the visibilities.
Expand Down Expand Up @@ -259,8 +257,8 @@ def vis_psf_image(
def vis_to_map(
vis: Visibilities,
shape: Quantity[apu.pix] = (65, 65) * apu.pixel,
pixel_size: Optional[Quantity[apu.arcsec / apu.pix]] = 1 * apu.arcsec / apu.pixel,
scheme: Optional[str] = "natural",
pixel_size: Quantity[apu.arcsec / apu.pix] | None = 1 * apu.arcsec / apu.pixel,
scheme: str | None = "natural",
) -> GenericMap:
r"""
Create a map by performing a back projection of inverse transform on the visibilities.
Expand Down
7 changes: 3 additions & 4 deletions xrayvision/mem.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""

from types import SimpleNamespace
from typing import Union, Optional

import astropy.units as apu
import numpy as np
Expand Down Expand Up @@ -580,12 +579,12 @@ def mem(
shape: Quantity[apu.pix],
pixel_size: Quantity[apu.arcsec / apu.pix],
*,
percent_lambda: Optional[Quantity[apu.percent]] = 0.02 * apu.percent,
percent_lambda: Quantity[apu.percent] | None = 0.02 * apu.percent,
maxiter: int = 1000,
tol: float = 1e-3,
map: bool = True,
total_flux: Optional[Quantity] = None,
) -> Union[Quantity, NDArray[np.float64]]:
total_flux: Quantity | None = None,
) -> Quantity | NDArray[np.float64]:
r"""
Maximum Entropy Method visibility based image reconstruction

Expand Down
Empty file.
22 changes: 22 additions & 0 deletions xrayvision/simulation/instruments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import astropy.units as u
import numpy as np


def rhessi_like_uv_coverage():
"""
Creates RHESSI-like u, v coverage coverage distribution.
"""
# Approximate RHESSI spatial frequencies (arcsec^-1) for subcollimators 1-9,
# based on typical RHESSI grid pitches of 2.26, 3.92, 6.79, 11.76, 20.36, 35.27, 61.08, 105.8, 183.2 arcsec.
isc = np.arange(0, 9) # index subcollimator (isc) detectors 1-9
resolutions = [2.26, 3.92, 6.79, 11.76, 20.36, 35.27, 61.08, 105.8, 183.2] * u.arcsec
radii = 1 / resolutions

# 32 evenly-spaced rotation angles per detector (simulates spacecraft rotation)
n_angles = 32
angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False)

u_comp = np.outer(radii, np.cos(angles))
v_comp = np.outer(radii, np.sin(angles))

return {"u": u_comp, "v": v_comp, "det": isc[:, None] * np.ones(u_comp.shape)}
Empty file.
6 changes: 6 additions & 0 deletions xrayvision/simulation/tests/test_instruments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from xrayvision.simulation.instruments import rhessi_like_uv_coverage


def test_rhessi_like_uv_coverage():
out = rhessi_like_uv_coverage()
assert out["u"].shape == out["v"].shape == out["det"].shape == (9, 32)
Loading