RACS-tools 4.3.2__tar.gz → 4.4.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {racs_tools-4.3.2 → racs_tools-4.4.1}/PKG-INFO +2 -1
- {racs_tools-4.3.2 → racs_tools-4.4.1}/pyproject.toml +1 -1
- {racs_tools-4.3.2 → racs_tools-4.4.1}/racs_tools/beamcon_3D.py +11 -3
- {racs_tools-4.3.2 → racs_tools-4.4.1}/racs_tools/convolve_uv.py +38 -26
- {racs_tools-4.3.2 → racs_tools-4.4.1}/racs_tools/gaussft.py +20 -15
- {racs_tools-4.3.2 → racs_tools-4.4.1}/LICENSE +0 -0
- {racs_tools-4.3.2 → racs_tools-4.4.1}/README.md +0 -0
- {racs_tools-4.3.2 → racs_tools-4.4.1}/racs_tools/__init__.py +0 -0
- {racs_tools-4.3.2 → racs_tools-4.4.1}/racs_tools/au2.py +0 -0
- {racs_tools-4.3.2 → racs_tools-4.4.1}/racs_tools/beamcon_2D.py +0 -0
- {racs_tools-4.3.2 → racs_tools-4.4.1}/racs_tools/getnoise_list.py +0 -0
- {racs_tools-4.3.2 → racs_tools-4.4.1}/racs_tools/logging.py +0 -0
- {racs_tools-4.3.2 → racs_tools-4.4.1}/racs_tools/parallel.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: racs-tools
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.4.1
|
|
4
4
|
Summary: Useful scripts for RACS.
|
|
5
5
|
License: BSD
|
|
6
6
|
License-File: LICENSE
|
|
@@ -13,6 +13,7 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.12
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.13
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
16
17
|
Provides-Extra: mpi
|
|
17
18
|
Requires-Dist: astropy (>=6)
|
|
18
19
|
Requires-Dist: mpi4py (>=3) ; extra == "mpi"
|
|
@@ -755,7 +755,7 @@ def initfiles(
|
|
|
755
755
|
ref_chan (int | None, optional): Reference channel index. Defaults to None.
|
|
756
756
|
|
|
757
757
|
Raises:
|
|
758
|
-
ValueError: If no Stokes axis is found in the header
|
|
758
|
+
ValueError: If no spectral or no Stokes axis is found in the header
|
|
759
759
|
|
|
760
760
|
Returns:
|
|
761
761
|
Path: Output filename
|
|
@@ -769,6 +769,12 @@ def initfiles(
|
|
|
769
769
|
|
|
770
770
|
## Header
|
|
771
771
|
spec_axis = wcs.spectral
|
|
772
|
+
# Checked on `naxis` because a missing axis does not give a scalar or a
|
|
773
|
+
# (1,) array: `crpix` comes back empty (shape (0,)), which `int` rejects
|
|
774
|
+
# with an unhelpful TypeError.
|
|
775
|
+
if spec_axis.naxis == 0:
|
|
776
|
+
msg = f"No spectral axis found in {filename}"
|
|
777
|
+
raise ValueError(msg)
|
|
772
778
|
# account for either an float or array of single float. Anything else should fail!
|
|
773
779
|
crpix = (
|
|
774
780
|
int(np.squeeze(spec_axis.wcs.crpix))
|
|
@@ -796,8 +802,10 @@ def initfiles(
|
|
|
796
802
|
ref_psf = commonbeams[crindex]
|
|
797
803
|
# Check the Stokes
|
|
798
804
|
stokes_axis = wcs.sub(["stokes"])
|
|
799
|
-
|
|
800
|
-
|
|
805
|
+
# A missing axis has `array_shape` None, not (), so test `naxis` instead
|
|
806
|
+
if stokes_axis.naxis == 0:
|
|
807
|
+
msg = f"No Stokes axis found in {filename}"
|
|
808
|
+
raise ValueError(msg)
|
|
801
809
|
nstokes = stokes_axis.array_shape[0]
|
|
802
810
|
if nstokes > 1:
|
|
803
811
|
logger.critical(
|
|
@@ -7,6 +7,7 @@ import gc
|
|
|
7
7
|
from typing import Literal, NamedTuple
|
|
8
8
|
|
|
9
9
|
import numpy as np
|
|
10
|
+
import scipy.fft
|
|
10
11
|
import scipy.signal
|
|
11
12
|
from astropy import convolution, units
|
|
12
13
|
from astropy import units as u
|
|
@@ -177,22 +178,39 @@ def convolve(
|
|
|
177
178
|
###
|
|
178
179
|
|
|
179
180
|
# Now we do the convolution
|
|
180
|
-
|
|
181
|
+
nan_mask = np.isnan(image)
|
|
182
|
+
nanflag = nan_mask.any()
|
|
181
183
|
|
|
182
184
|
if nanflag:
|
|
183
|
-
# Create a mask for the NaNs
|
|
184
|
-
mask = np.isnan(image).astype(np.int16)
|
|
185
185
|
logger.warning(
|
|
186
|
-
f"Image contains {
|
|
186
|
+
f"Image contains {nan_mask.sum()} "
|
|
187
|
+
f"({nan_mask.sum() / nan_mask.size * 100:0.1f}%) NaNs"
|
|
187
188
|
)
|
|
188
189
|
image = np.nan_to_num(image)
|
|
190
|
+
else:
|
|
191
|
+
del nan_mask
|
|
189
192
|
|
|
190
193
|
nx = image.shape[0]
|
|
191
194
|
ny = image.shape[1]
|
|
192
195
|
|
|
193
|
-
# The
|
|
194
|
-
|
|
195
|
-
|
|
196
|
+
# The image is real, so half of its spectrum is redundant. Transforming in
|
|
197
|
+
# the image's own precision and keeping only that half is what makes this
|
|
198
|
+
# affordable on a wide image: a single-precision plane never gets promoted
|
|
199
|
+
# to complex128, and the last axis is stored once rather than twice.
|
|
200
|
+
#
|
|
201
|
+
# Matched on kind and width rather than identity, because FITS data arrives
|
|
202
|
+
# big-endian (">f4") and `np.dtype(">f4") == np.float32` is False, which
|
|
203
|
+
# would send every real image down the double-precision path.
|
|
204
|
+
real_dtype = (
|
|
205
|
+
np.float32
|
|
206
|
+
if image.dtype.kind == "f" and image.dtype.itemsize <= 4
|
|
207
|
+
else np.float64
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
# The coordinates in FT domain. Only the non-redundant v are needed, to
|
|
211
|
+
# match the output of the real-input transform below.
|
|
212
|
+
u_image = np.fft.fftfreq(nx, d=dx.to(units.rad).value).astype(real_dtype)
|
|
213
|
+
v_image = np.fft.rfftfreq(ny, d=dy.to(units.rad).value).astype(real_dtype)
|
|
196
214
|
|
|
197
215
|
[g_final, g_ratio] = gaussft.gaussft(
|
|
198
216
|
bmin_in=old_beam.minor.to(units.deg).value,
|
|
@@ -204,40 +222,34 @@ def convolve(
|
|
|
204
222
|
u=u_image,
|
|
205
223
|
v=v_image,
|
|
206
224
|
)
|
|
207
|
-
g_final = g_final.astype(np.complex64)
|
|
208
225
|
del u_image
|
|
209
226
|
del v_image
|
|
210
227
|
|
|
211
|
-
# Perform the x-ing in the FT domain
|
|
212
|
-
|
|
228
|
+
# Perform the x-ing in the FT domain. The taper is applied in place, and
|
|
229
|
+
# the spectrum is consumed by its own inverse, so neither is duplicated.
|
|
230
|
+
im_f = scipy.fft.rfft2(image.astype(real_dtype, copy=False))
|
|
213
231
|
del image
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
232
|
+
im_f *= g_final
|
|
233
|
+
im_conv = scipy.fft.irfft2(im_f, s=(nx, ny), overwrite_x=True).astype(
|
|
234
|
+
np.float32, copy=False
|
|
235
|
+
)
|
|
217
236
|
del im_f
|
|
218
|
-
im_conv = np.fft.ifft2(M).astype(np.complex64)
|
|
219
|
-
im_conv = np.real(im_conv).astype(np.float32)
|
|
220
|
-
del M
|
|
221
237
|
|
|
222
238
|
if nanflag:
|
|
223
|
-
#
|
|
224
|
-
mask_f =
|
|
225
|
-
del
|
|
226
|
-
|
|
227
|
-
M = np.multiply(mask_f, g_final).astype(np.complex64)
|
|
239
|
+
# Convolve the NaN mask the same way, to find where the NaNs spread to
|
|
240
|
+
mask_f = scipy.fft.rfft2(nan_mask.astype(real_dtype))
|
|
241
|
+
del nan_mask
|
|
242
|
+
mask_f *= g_final
|
|
228
243
|
del g_final
|
|
244
|
+
mask_conv = scipy.fft.irfft2(mask_f, s=(nx, ny), overwrite_x=True)
|
|
229
245
|
del mask_f
|
|
230
|
-
# Invert the FT of the mask
|
|
231
|
-
mask_conv = np.fft.ifft2(M).astype(np.complex64)
|
|
232
|
-
mask_conv = np.real(mask_conv).astype(np.float32)
|
|
233
|
-
del M
|
|
234
246
|
# Use approx values to find the NaNs
|
|
235
247
|
# Need this to get around numerical issues
|
|
236
248
|
mask_conv = ~(mask_conv + 1 < 2)
|
|
237
249
|
logger.warning(
|
|
238
250
|
f"Convolved image contains {mask_conv.sum()} ({mask_conv.sum() / mask_conv.size * 100:0.1f}%) NaNs"
|
|
239
251
|
)
|
|
240
|
-
im_conv[mask_conv
|
|
252
|
+
im_conv[mask_conv] = np.nan
|
|
241
253
|
|
|
242
254
|
return ConvolutionResult(image=im_conv, scaling_factor=g_ratio)
|
|
243
255
|
|
|
@@ -25,6 +25,10 @@ def gaussft(
|
|
|
25
25
|
"""
|
|
26
26
|
Compute the Fourier transform of a 2D Gaussian for convolution.
|
|
27
27
|
|
|
28
|
+
The returned taper is real and takes the dtype of ``u`` and ``v``, so a
|
|
29
|
+
single-precision grid gives a single-precision taper. It is filled in one
|
|
30
|
+
pass, meaning only the taper itself is ever allocated at image size.
|
|
31
|
+
|
|
28
32
|
Parameters:
|
|
29
33
|
bmin_in (float): Intrinsic psf BMIN (degrees)
|
|
30
34
|
bmaj_in (float): Intrinsic psf BMAJ (degrees)
|
|
@@ -58,28 +62,29 @@ def gaussft(
|
|
|
58
62
|
bmin_in_rad / (2.0 * np.sqrt(2.0 * np.log(2.0))),
|
|
59
63
|
)
|
|
60
64
|
|
|
61
|
-
u_cosbpa, u_sinbpa = u * np.cos(bpa_rad), u * np.sin(bpa_rad)
|
|
62
|
-
u_cosbpa_in, u_sinbpa_in = u * np.cos(bpa_in_rad), u * np.sin(bpa_in_rad)
|
|
63
|
-
|
|
64
|
-
v_cosbpa, v_sinbpa = v * np.cos(bpa_rad), v * np.sin(bpa_rad)
|
|
65
|
-
v_cosbpa_in, v_sinbpa_in = v * np.cos(bpa_in_rad), v * np.sin(bpa_in_rad)
|
|
66
|
-
|
|
67
65
|
g_amp = np.sqrt(2.0 * np.pi * sx * sy)
|
|
68
66
|
|
|
69
67
|
dg_amp = np.sqrt(2.0 * np.pi * sx_in * sy_in)
|
|
70
68
|
|
|
71
69
|
g_ratio = g_amp / dg_amp
|
|
72
70
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
cos_bpa, sin_bpa = np.cos(bpa_rad), np.sin(bpa_rad)
|
|
72
|
+
cos_bpa_in, sin_bpa_in = np.cos(bpa_in_rad), np.sin(bpa_in_rad)
|
|
73
|
+
two_pi_sq = 2.0 * np.pi**2
|
|
74
|
+
|
|
75
|
+
g_final = np.empty((u.size, v.size), dtype=u.dtype)
|
|
76
|
+
for i in range(u.size):
|
|
77
|
+
u_cosbpa, u_sinbpa = u[i] * cos_bpa, u[i] * sin_bpa
|
|
78
|
+
u_cosbpa_in, u_sinbpa_in = u[i] * cos_bpa_in, u[i] * sin_bpa_in
|
|
79
|
+
for j in range(v.size):
|
|
80
|
+
ur = u_cosbpa - v[j] * sin_bpa
|
|
81
|
+
vr = u_sinbpa + v[j] * cos_bpa
|
|
82
|
+
g_arg = -two_pi_sq * ((sx * ur) ** 2 + (sy * vr) ** 2)
|
|
77
83
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
ur_in = u_cosbpa_in - v[j] * sin_bpa_in
|
|
85
|
+
vr_in = u_sinbpa_in + v[j] * cos_bpa_in
|
|
86
|
+
dg_arg = -two_pi_sq * ((sx_in * ur_in) ** 2 + (sy_in * vr_in) ** 2)
|
|
81
87
|
|
|
82
|
-
|
|
83
|
-
g_final = g_ratio * np.exp(g_arg - dg_arg)
|
|
88
|
+
g_final[i, j] = g_ratio * np.exp(g_arg - dg_arg)
|
|
84
89
|
|
|
85
90
|
return g_final, g_ratio
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|