Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a check to verify autos are real-only #1110

Merged
merged 26 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
37ec72d
Adding methods to check/fix autos for imag components
kartographer Dec 11, 2021
5fe370b
Adding auto check defaults on read/write
kartographer Dec 11, 2021
efa4508
Fixing a couple of bugs with argument passing inside of uvdata
kartographer Dec 12, 2021
c825758
Adding auto-fix/check to FHD
kartographer Dec 12, 2021
749d979
Adding auto fix/check to MIRIAD
kartographer Dec 12, 2021
78131e8
Adding auto-fix/check to MS
kartographer Dec 12, 2021
00dcc87
Adding checking/fixing of autos to MWA corr_fits
kartographer Dec 12, 2021
ebdb807
Add checking and fixing of autos to uvfits
kartographer Dec 12, 2021
0401f76
Adding fixing/checking of autos to UVH5
kartographer Dec 12, 2021
1bff4fd
Add check to mir read
kartographer Dec 12, 2021
2908b58
Filitering out new warning for known tests
kartographer Dec 12, 2021
03f9094
Filtering new warning, and slightly changing one test due to linter c…
kartographer Dec 12, 2021
fd78b98
Adding sma-mir dataset to conftest, since its used in multiple places
kartographer Dec 12, 2021
6bdb495
Cleaning up tests following moving fixtures
kartographer Dec 12, 2021
a914686
Adding new tests for coverage, fixing things up after moving fixtures
kartographer Dec 12, 2021
3e16dd3
Fixing new auto test, since original test file didnt actually have an…
kartographer Dec 12, 2021
e23f351
Adding message on how to fix non-real autos in check()
kartographer Dec 12, 2021
125ca59
Doc string updates
kartographer Dec 12, 2021
f3771d6
More docstring fixes, making sure to pass check arguments to MIR reader
kartographer Dec 12, 2021
d3b1208
Fix to a small bug potentially caused parts of check to be skipped if…
kartographer Dec 12, 2021
c07d2b3
Updating CHANGELOG
kartographer Dec 12, 2021
ac35cc7
Small tweak to tests to improve coverage
kartographer Dec 12, 2021
4ac9c9a
Small test fix to failing test post rebase
kartographer Dec 13, 2021
858522c
Adding fix_autos to write_uvh5_part, adding test coverage
kartographer Dec 17, 2021
994c8d8
Fixing naming conventions in test fixtures to be a bit more uniform
kartographer Dec 30, 2021
3b77261
Cleaning up post-rebase
kartographer Jan 13, 2022
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Added
- Added new functionality to `UVData.check` to verify that auto-correlations are real-only,
along with an option to force them to be real-only if non-zero imaginary components are detected.

## [2.2.6] - 2022-01-12

### Added
Expand Down
7 changes: 6 additions & 1 deletion pyuvdata/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2671,7 +2671,7 @@ def test_mean_weights_and_weights_square():
assert np.allclose(wso, np.sum(1.0 / (np.arange(data.shape[1]) + 1) ** 2))

# Zero weights
w = np.ones_like(w)
w = np.ones_like(data)
w[0, :] = 0
w[:, 0] = 0
out, wo = uvutils.mean_collapse(data, weights=w, axis=0, return_weights=True)
Expand Down Expand Up @@ -2810,6 +2810,7 @@ def test_and_collapse_errors():
pytest.raises(ValueError, uvutils.and_collapse, data)


@pytest.mark.filterwarnings("ignore:Fixing auto-correlations to be be real-only,")
@pytest.mark.filterwarnings("ignore:The uvw_array does not match the expected values")
def test_uvcalibrate_apply_gains_oldfiles():
# read data
Expand Down Expand Up @@ -2863,6 +2864,7 @@ def test_uvcalibrate_apply_gains_oldfiles():


@pytest.mark.filterwarnings("ignore:When converting a delay-style cal to future array")
@pytest.mark.filterwarnings("ignore:Fixing auto-correlations to be be real-only,")
@pytest.mark.filterwarnings("ignore:The uvw_array does not match the expected values")
@pytest.mark.parametrize("uvd_future_shapes", [True, False])
@pytest.mark.parametrize("uvc_future_shapes", [True, False])
Expand Down Expand Up @@ -2918,6 +2920,7 @@ def test_uvcalibrate_delay_oldfiles(uvd_future_shapes, uvc_future_shapes):

@pytest.mark.parametrize("uvc_future_shapes", [True, False])
@pytest.mark.parametrize("uvd_future_shapes", [True, False])
@pytest.mark.filterwarnings("ignore:Fixing auto-correlations to be be real-only,")
@pytest.mark.parametrize("flip_gain_conj", [False, True])
@pytest.mark.parametrize("gain_convention", ["divide", "multiply"])
def test_uvcalibrate(
Expand Down Expand Up @@ -3363,6 +3366,7 @@ def test_uvcalibrate_wideband_gain(uvcalibrate_data):
uvutils.uvcalibrate(uvd, uvc, inplace=False)


@pytest.mark.filterwarnings("ignore:Fixing auto-correlations to be be real-only")
@pytest.mark.filterwarnings("ignore:The uvw_array does not match the expected values")
@pytest.mark.filterwarnings("ignore:When converting a delay-style cal to future array")
@pytest.mark.filterwarnings("ignore:Nfreqs will be required to be 1 for wide_band cals")
Expand Down Expand Up @@ -3401,6 +3405,7 @@ def test_uvcalibrate_delay_multispw(uvcalibrate_data):
uvutils.uvcalibrate(uvd, uvc, inplace=False)


@pytest.mark.filterwarnings("ignore:Fixing auto-correlations to be be real-only,")
@pytest.mark.filterwarnings("ignore:The uvw_array does not match the expected values")
@pytest.mark.parametrize("future_shapes", [True, False])
def test_apply_uvflag(future_shapes):
Expand Down
10 changes: 10 additions & 0 deletions pyuvdata/uvdata/fhd.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ def read_fhd(
check_extra=True,
run_check_acceptability=True,
strict_uvw_antpos_check=False,
check_autos=True,
fix_autos=True,
):
"""
Read in data from a list of FHD files.
Expand Down Expand Up @@ -369,6 +371,12 @@ def read_fhd(
strict_uvw_antpos_check : bool
Option to raise an error rather than a warning if the check that
uvws match antenna positions does not pass.
check_autos : bool
Check whether any auto-correlations have non-zero imaginary values in
data_array (which should not mathematically exist). Default is True.
fix_autos : bool
If auto-correlations with imaginary values are found, fix those values so
that they are real-only in data_array. Default is False.

Raises
------
Expand Down Expand Up @@ -711,4 +719,6 @@ def read_fhd(
run_check_acceptability=run_check_acceptability,
strict_uvw_antpos_check=strict_uvw_antpos_check,
allow_flip_conj=True,
check_autos=check_autos,
fix_autos=fix_autos,
)
8 changes: 8 additions & 0 deletions pyuvdata/uvdata/mir.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def read_mir(
run_check_acceptability=True,
strict_uvw_antpos_check=False,
allow_flex_pol=True,
check_autos=True,
fix_autos=False,
):
"""
Read in data from an SMA MIR file, and map to the UVData model.
Expand Down Expand Up @@ -80,6 +82,12 @@ def read_mir(
"flexible polarization", which compresses the polarization-axis of various
attributes to be of length 1, sets the `flex_spw_polarization_array`
attribute to define the polarization per spectral window. Default is True.
check_autos : bool
Check whether any auto-correlations have non-zero imaginary values in
data_array (which should not mathematically exist). Default is True.
fix_autos : bool
If auto-correlations with imaginary values are found, fix those values so
that they are real-only in data_array. Default is False.
"""
# Use the mir_parser to read in metadata, which can be used to select data.
mir_data = mir_parser.MirParser(filepath)
Expand Down
20 changes: 20 additions & 0 deletions pyuvdata/uvdata/miriad.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,8 @@ def read_miriad(
calc_lst=True,
fix_old_proj=False,
fix_use_ant_pos=True,
check_autos=True,
fix_autos=True,
):
"""
Read in data from a miriad file.
Expand Down Expand Up @@ -808,6 +810,12 @@ def read_miriad(
If setting `fix_old_proj` to True, use the antenna positions to derive the
correct uvw-coordinates rather than using the baseline vectors. Default is
True.
check_autos : bool
Check whether any auto-correlations have non-zero imaginary values in
data_array (which should not mathematically exist). Default is True.
fix_autos : bool
If auto-correlations with imaginary values are found, fix those values so
that they are real-only in data_array. Default is False.

Raises
------
Expand Down Expand Up @@ -1569,6 +1577,8 @@ def read_miriad(
run_check_acceptability=run_check_acceptability,
strict_uvw_antpos_check=strict_uvw_antpos_check,
allow_flip_conj=True,
check_autos=check_autos,
fix_autos=fix_autos,
)

def write_miriad(
Expand All @@ -1581,6 +1591,8 @@ def write_miriad(
strict_uvw_antpos_check=False,
no_antnums=False,
calc_lst=False,
check_autos=True,
fix_autos=False,
):
"""
Write the data to a miriad file.
Expand Down Expand Up @@ -1615,6 +1627,12 @@ def write_miriad(
marks the midpoint). Default is False, which instead uses a simple formula
for correcting the LSTs, expected to be accurate to approximately 0.1 µsec
precision.
check_autos : bool
Check whether any auto-correlations have non-zero imaginary values in
data_array (which should not mathematically exist). Default is True.
fix_autos : bool
If auto-correlations with imaginary values are found, fix those values so
that they are real-only in data_array. Default is False.

Raises
------
Expand Down Expand Up @@ -1651,6 +1669,8 @@ def write_miriad(
run_check_acceptability=run_check_acceptability,
check_freq_spacing=True,
strict_uvw_antpos_check=strict_uvw_antpos_check,
check_autos=check_autos,
fix_autos=fix_autos,
)

if os.path.exists(filepath):
Expand Down
21 changes: 20 additions & 1 deletion pyuvdata/uvdata/ms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,8 @@ def write_ms(
check_extra=True,
run_check_acceptability=True,
strict_uvw_antpos_check=False,
check_autos=True,
fix_autos=False,
):
"""
Write a CASA measurement set (MS).
Expand All @@ -1078,7 +1080,12 @@ def write_ms(
strict_uvw_antpos_check : bool
Option to raise an error rather than a warning if the check that
uvws match antenna positions does not pass.

check_autos : bool
Check whether any auto-correlations have non-zero imaginary values in
data_array (which should not mathematically exist). Default is True.
fix_autos : bool
If auto-correlations with imaginary values are found, fix those values so
that they are real-only in data_array. Default is False.
"""
if not casa_present: # pragma: no cover
raise ImportError(no_casa_message) from casa_error
Expand All @@ -1088,6 +1095,8 @@ def write_ms(
check_extra=check_extra,
run_check_acceptability=run_check_acceptability,
strict_uvw_antpos_check=strict_uvw_antpos_check,
check_autos=check_autos,
fix_autos=fix_autos,
)

if os.path.exists(filepath):
Expand Down Expand Up @@ -1876,6 +1885,8 @@ def read_ms(
raise_error=True,
read_weights=True,
allow_flex_pol=False,
check_autos=True,
fix_autos=True,
):
"""
Read in a casa measurement set.
Expand Down Expand Up @@ -1931,6 +1942,12 @@ def read_ms(
"flexible polarization", which compresses the polarization-axis of various
attributes to be of length 1, sets the `flex_spw_polarization_array`
attribute to define the polarization per spectral window. Default is True.
check_autos : bool
Check whether any auto-correlations have non-zero imaginary values in
data_array (which should not mathematically exist). Default is True.
fix_autos : bool
If auto-correlations with imaginary values are found, fix those values so
that they are real-only in data_array. Default is True.

Raises
------
Expand Down Expand Up @@ -2273,4 +2290,6 @@ def read_ms(
run_check_acceptability=run_check_acceptability,
strict_uvw_antpos_check=strict_uvw_antpos_check,
allow_flip_conj=True,
check_autos=check_autos,
fix_autos=fix_autos,
)
10 changes: 10 additions & 0 deletions pyuvdata/uvdata/mwa_corr_fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,8 @@ def read_mwa_corr_fits(
check_extra=True,
run_check_acceptability=True,
strict_uvw_antpos_check=False,
check_autos=True,
fix_autos=True,
):
"""
Read in MWA correlator gpu box files.
Expand Down Expand Up @@ -1189,6 +1191,12 @@ def read_mwa_corr_fits(
strict_uvw_antpos_check : bool
Option to raise an error rather than a warning if the check that
uvws match antenna positions does not pass.
check_autos : bool
Check whether any auto-correlations have non-zero imaginary values in
data_array (which should not mathematically exist). Default is True.
fix_autos : bool
If auto-correlations with imaginary values are found, fix those values so
that they are real-only in data_array. Default is True.


Raises
Expand Down Expand Up @@ -1820,4 +1828,6 @@ def read_mwa_corr_fits(
run_check_acceptability=run_check_acceptability,
strict_uvw_antpos_check=strict_uvw_antpos_check,
allow_flip_conj=True,
check_autos=check_autos,
fix_autos=fix_autos,
)
51 changes: 27 additions & 24 deletions pyuvdata/uvdata/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,6 @@ def casa_uvfits(casa_uvfits_main):
return


@pytest.fixture(scope="session")
def mir_data_main():
testfile = os.path.join(DATA_PATH, "sma_test.mir")
mir_data = MirParser(
testfile, load_vis=True, load_raw=True, load_auto=True, has_auto=True,
)

yield mir_data


@pytest.fixture(scope="function")
def mir_data(mir_data_main):
mir_data = mir_data_main.copy()

yield mir_data


@pytest.fixture(scope="session")
def hera_uvh5_main():
# read in test file for the resampling in time functions
Expand Down Expand Up @@ -116,16 +99,36 @@ def paper_miriad(paper_miriad_main):
del uv_in


@pytest.fixture(params=[True, False])
def mir_data_object(request):
"""Make MIR data object for tests. Param to read autocorr data."""
has_auto = request.param
@pytest.fixture(scope="session")
def sma_mir_main():
# read in test file for the resampling in time functions
uv_object = UVData()
testfile = os.path.join(DATA_PATH, "sma_test.mir")
uv_object.read(testfile)

yield uv_object


@pytest.fixture(scope="function")
def sma_mir(sma_mir_main):
# read in test file for the resampling in time functions
uv_object = sma_mir_main.copy()

yield uv_object


@pytest.fixture(scope="session")
def mir_data_main():
testfile = os.path.join(DATA_PATH, "sma_test.mir")
mir_data = MirParser(
testfile, load_vis=True, load_raw=True, load_auto=True, has_auto=has_auto
testfile, load_vis=True, load_raw=True, load_auto=True, has_auto=True,
)

yield mir_data

# cleanup
del mir_data

@pytest.fixture(scope="function")
def mir_data(mir_data_main):
mir_data = mir_data_main.copy()

yield mir_data
Loading