Skip to content

Commit 42e22fe

Browse files
authored
Merge branch 'main' into fix_source_vis
2 parents 13c314c + 3a74e62 commit 42e22fe

22 files changed

+613
-90
lines changed

.readthedocs.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: 2
2+
3+
build:
4+
os: ubuntu-24.04
5+
apt_packages:
6+
- graphviz
7+
tools:
8+
python: "3.10"
9+
jobs:
10+
pre_create_environment:
11+
- mkdir -p /home/docs/.casa/data
12+
13+
python:
14+
install:
15+
- method: pip
16+
path: .
17+
extra_requirements:
18+
- docs
19+
20+
sphinx:
21+
configuration: docs/conf.py

docs/changes/11.feature.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Add plotting submodule
2+
- Add ``radiotools.plotting.px2radec`` utility function

docs/changes/14.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug in ``radiotools.cleaning.WSClean`` that handled ``mf-weighting`` flag incorrectly

docs/changes/15.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Added `min_alt` and `max_alt` parameters to be able to adapt to simulation or telescope altitude restrictions.

docs/changes/16.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Added `desc_id` parameter to change what desc_id the gridded visibilities must have

docs/changes/17.optimization.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Add test for source visibility altitude restrictions in `tests/test_source_visibility.py`
2+
- Fix typo in `utils.py`

docs/changes/19.maintenance.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- Remove forced rotation and inversion in plots
2+
- Change binning of grid
3+
- Use `numpy.float128` to ensure numerical stability
4+
- Add column name optional parameters to FITS import (default now `UU`, `VV`)
5+
- Remove flip and invert in `create_attributes` method

docs/changes/21.maintenance.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Update maintainers of the package

docs/changes/8.feature.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- Add analysis submodule
2+
- Add ``radiotools.analysis.get_source_rms`` function
3+
- Add ``radiotools.analysis.dynamic_range`` function that calculates the dynamic range as a function of the maximum pixel value of an image and the RMS of the source
4+
5+
- Add ``rms`` function to ``radiotools.utils``

pyproject.toml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ readme = "README.rst"
99
authors = [
1010
{ name = "radionets-project developers" }
1111
]
12+
maintainers = [
13+
{ name = "Anno Knierim", email = "[email protected]" },
14+
{ name = "Tom Groß", email = "[email protected]" },
15+
]
1216
license = { text = "MIT" }
1317
classifiers = [
1418
"Intended Audience :: Science/Research",
@@ -47,7 +51,26 @@ dev = [
4751
]
4852

4953
all = [
50-
"radiotools[dev]"
54+
"radiotools"
55+
]
56+
57+
docs = [
58+
"radiotools[all]",
59+
"graphviz",
60+
"ipython",
61+
"jupyter",
62+
"nbsphinx",
63+
"notebook",
64+
"numpydoc",
65+
"pandas",
66+
"pydata_sphinx_theme",
67+
"pypandoc",
68+
"sphinx",
69+
"sphinx-design",
70+
"sphinx_automodapi",
71+
"sphinxcontrib-bibtex",
72+
"tomli; python_version < '3.11'",
73+
"toml"
5174
]
5275

5376
[project.urls]

radiotools/analysis/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .analysis import dynamic_range, get_source_rms
2+
3+
__all__ = ["dynamic_range", "get_source_rms"]

radiotools/analysis/analysis.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import torch
2+
from astropy.io import fits
3+
from numpy.typing import ArrayLike
4+
5+
from radiotools.utils import rms
6+
7+
8+
def get_source_rms(image: ArrayLike, center: tuple[int, int], *, offset=75):
9+
"""Get the root mean square (RMS) of a given source.
10+
11+
Parameters
12+
----------
13+
image : array_like, shape (N, M)
14+
Array containing image data of the source.
15+
center : tuple[int, int]
16+
Tuple of the center coordinates where the RMS
17+
is calculated for a region spanned by ``offset``.
18+
offset : int, optional
19+
Offset that spans a region around ``center``:
20+
21+
.. code::
22+
x0 = center_x - offset
23+
x1 = center_x + offset
24+
25+
y0 = center_y - offset
26+
y1 = center_y + offset
27+
28+
Default: 75
29+
30+
Returns
31+
-------
32+
rms : float
33+
RMS for the given source.
34+
"""
35+
center_x = int(center[0])
36+
center_y = int(center[1])
37+
38+
x0 = center_x - offset
39+
x1 = center_x + offset
40+
41+
y0 = center_y - offset
42+
y1 = center_y + offset
43+
44+
_rms = torch.from_numpy(rms(image[x0:x1, y0:y1]))
45+
46+
return torch.mean(_rms)
47+
48+
49+
def dynamic_range(path: str, *, offset: int = 75):
50+
"""Computes the dynamic range of a source.
51+
52+
Parameters
53+
----------
54+
path : str or Path
55+
Path to a FITS file containing image data of the source.
56+
offset : int, optional
57+
Offset for the region around the center pixel of the source.
58+
Used to compute the RMS value of the source. Default: 75
59+
60+
Returns
61+
-------
62+
dr : float
63+
Dynamic range of the source.
64+
"""
65+
hdu = fits.open(path)
66+
67+
image = hdu[0].data[0, 0, ...]
68+
center = hdu[0].header["CRPIX1"], hdu[0].header["CRPIX2"]
69+
70+
_rms = get_source_rms(image, center, offset=75)
71+
72+
dr = image.max() / _rms
73+
74+
return dr

radiotools/cleaning/clean.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,35 @@ def __init__(
8282
_clean_config["auto-threshold"] = _clean_config.pop("auto_threshold")
8383
_clean_config["auto-mask"] = _clean_config.pop("auto_mask")
8484

85+
# We need to handle the case if size is an int and not a list.
86+
# This assumes, however, that x- and y- size are the same
8587
if isinstance(_clean_config["size"], int):
8688
_clean_config["size"] = [_clean_config["size"]] * 2
8789

90+
# mf-weighting and no-mf-weighting are flags without arguments.
91+
# Since the wrapper only takes the bool mf_weighting as input,
92+
# we have to handle both cases and pass the respective WSClean
93+
# flags with an empty string as "argument".
8894
if _clean_config["mf_weighting"] is False:
8995
del _clean_config["mf_weighting"]
9096
_clean_config["no-mf-weighting"] = ""
9197
else:
98+
del _clean_config["mf_weighting"]
9299
_clean_config["mf-weighting"] = ""
93100

101+
# Same as with mf-weighting, WSClean has two flags -- verbose
102+
# and quiet -- to handle output during cleaning. The wrapper
103+
# only takes the bool verbose as input, as such we have to
104+
# handle both cases.
94105
if _clean_config["verbose"] is False:
95106
del _clean_config["verbose"]
96107
_clean_config["quiet"] = ""
97108
else:
98109
del _clean_config["verbose"]
99110

111+
# multiscale is another case of a flag without any arguments.
112+
# As such, we have to either delete the key and value pair,
113+
# or replace the bool with an empty string.
100114
if _clean_config["multiscale"] is False:
101115
del _clean_config["multiscale"]
102116
else:

0 commit comments

Comments
 (0)