Skip to content

Commit ea050a8

Browse files
committed
Fix conversion of non-crosspol power beams to real
Don't use np.real_if_close because it's flaky (seen to fail in Conda builds but not in our standard CI). Instead warn if the imaginary part is larger than expected (presumably because of floating point accuracy issues) and then force to real.
1 parent f8a44d2 commit ea050a8

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Fixed
8+
- Fixed a bug in converting non-crosspol power beams to real in `UVBeam.efield_to_power`.
79

810
## [2.2.3] - 2021-10-13
911

pyuvdata/uvbeam/uvbeam.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,22 @@ def efield_to_power(
885885
"no examples to work with."
886886
)
887887

888-
power_data = np.real_if_close(power_data, tol=1000)
888+
if not calc_cross_pols:
889+
max_abs_imag = np.max(np.abs(power_data.imag))
890+
if not np.isclose(
891+
max_abs_imag,
892+
0,
893+
rtol=beam_object._data_array.tols[0],
894+
atol=beam_object._data_array.tols[1],
895+
): # pragma: no cover
896+
warnings.warn(
897+
"The calculated power beam has a non-zero imaginary component "
898+
f"(the maximum absolute imaginary component is {max_abs_imag}). "
899+
"The power beam should be real because the crosspols are not "
900+
"calculated. Setting the power beam equal to the real part of the "
901+
"calculated power beam."
902+
)
903+
power_data = power_data.real
889904

890905
beam_object.data_array = power_data
891906
beam_object.Nfeeds = None

0 commit comments

Comments
 (0)