Skip to content

Commit 9729bcb

Browse files
authored
Fix for units and numpy ops (#73)
* Fix for units and numpy ops * Fix for readonly array * New test
1 parent f63fa35 commit 9729bcb

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

racs_tools/beamcon_2D.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def get_common_beam(
324324
flags = np.array([beam == ZERO_BEAM for beam in beams]) | flags
325325

326326
if cutoff is not None:
327-
flags = beams.major > cutoff * u.arcsec | flags
327+
flags = beams.major.to(u.arcsec).value > cutoff | flags
328328
if np.all(flags):
329329
logger.critical(
330330
"All beams are larger than cutoff. All outputs will be blanked!"

racs_tools/convolve_uv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ def smooth(
536536
if np.any(np.isnan(new_image)):
537537
logger.warning(f"{np.isnan(new_image).sum()} NaNs present in smoothed output")
538538

539-
new_image *= fac
539+
new_image = fac * new_image
540540

541541
# Ensure the output data-type is the same as the input
542542
return new_image.astype(out_dtype)

tests/test_2d.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,55 @@ def make_2d_image(tmpdir) -> TestImage:
7676
outf.unlink()
7777

7878

79+
@pytest.fixture
80+
def make_2d_image_smaller(tmpdir) -> TestImage:
81+
"""Make a fake 2D image from with a Gaussian beam.
82+
83+
Args:
84+
beam (Beam): Gaussian beam.
85+
86+
Returns:
87+
str: Name of the output FITS file.
88+
"""
89+
pix_scale = 2.5 * u.arcsec
90+
91+
beam = Beam(10 * u.arcsec, 10 * u.arcsec, 10 * u.deg)
92+
93+
data = beam.as_kernel(pixscale=pix_scale, x_size=100, y_size=100).array
94+
data /= data.max()
95+
96+
hdu = fits.PrimaryHDU(data=data)
97+
98+
hdu.header = beam.attach_to_header(hdu.header)
99+
hdu.header["BUNIT"] = "Jy/beam"
100+
hdu.header["CDELT1"] = -pix_scale.to(u.deg).value
101+
hdu.header["CDELT2"] = pix_scale.to(u.deg).value
102+
hdu.header["CRPIX1"] = 50
103+
hdu.header["CRPIX2"] = 50
104+
hdu.header["CRVAL1"] = 0
105+
hdu.header["CRVAL2"] = 0
106+
hdu.header["CTYPE1"] = "RA---SIN"
107+
hdu.header["CTYPE2"] = "DEC--SIN"
108+
hdu.header["CUNIT1"] = "deg"
109+
hdu.header["CUNIT2"] = "deg"
110+
hdu.header["EQUINOX"] = 2000.0
111+
hdu.header["RADESYS"] = "FK5"
112+
hdu.header["LONPOLE"] = 180.0
113+
hdu.header["LATPOLE"] = 0.0
114+
115+
outf = Path(tmpdir) / "2d_smaller.fits"
116+
hdu.writeto(outf, overwrite=True)
117+
118+
yield TestImage(
119+
path=outf,
120+
beam=beam,
121+
data=data,
122+
pix_scale=pix_scale,
123+
)
124+
125+
outf.unlink()
126+
127+
79128
@pytest.fixture
80129
def mirsmooth(make_2d_image: TestImage) -> TestImage:
81130
"""Smooth a FITS image to a target beam using MIRIAD.
@@ -219,3 +268,14 @@ def test_smooth(make_2d_image: TestImage, mirsmooth: TestImage):
219268
assert np.allclose(
220269
smooth_data, mirsmooth.data, atol=1e-5
221270
), f"Smooth with {conv_mode} does not match miriad"
271+
272+
273+
def test_get_common_beam(make_2d_image, make_2d_image_smaller):
274+
common_beam = beamcon_2D.smooth_fits_files(
275+
infile_list=[make_2d_image.path, make_2d_image_smaller.path],
276+
cutoff=10,
277+
)
278+
assert (
279+
common_beam.major.to(u.arcsec).value
280+
== make_2d_image_smaller.beam.major.to(u.arcsec).value
281+
)

0 commit comments

Comments
 (0)