-
Notifications
You must be signed in to change notification settings - Fork 11
Extra keywords and frequency differencing #91
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
base: main
Are you sure you want to change the base?
Changes from all commits
17d1064
305f31c
558f8c6
b673059
94193d0
3b31495
b10a0f3
ad33658
02e7871
8932d26
8296354
e487242
173ff52
38199bd
bf3bf8d
ba595d9
71c664a
15088d0
3c850ee
8fda8ef
2c76b05
ea50606
b2e9d1a
e638152
ed71833
3c5e0ab
09d1b4e
e41a693
74f72eb
a6987f0
89106d5
6fdab99
ebd737b
a3a222c
689ff30
96a3d69
432dad9
7f4a7a5
5169e78
1cfb820
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,25 @@ def test_init(): | |
| # Check that the weights summed correctly | ||
| assert np.all(test_weights == ins.weights_array), "Weights did not sum properly" | ||
|
|
||
| def test_extra_keywords(): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test doesn't appear to check whether diff_freq is set, etc. |
||
| obs = '1061313128_99bl_1pol_half_time' | ||
| testfile = os.path.join(DATA_PATH, '%s.uvfits' % obs) | ||
| file_type = 'uvfits' | ||
|
|
||
| ss = SS() | ||
| ss.read(testfile, flag_choice='original', diff=True) | ||
| ins = INS(ss) | ||
|
|
||
| assert ss.extra_keywords['dif_time'] is True | ||
| assert ins.extra_keywords['dif_time'] is True | ||
|
|
||
| ss.read(testfile, flag_choice='original', diff=False) | ||
| ins = INS(ss) | ||
|
|
||
| assert ss.extra_keywords['dif_time'] is False | ||
| assert ins.extra_keywords['dif_time'] is False | ||
|
|
||
|
|
||
|
|
||
| def test_no_diff_start(): | ||
| obs = '1061313128_99bl_1pol_half_time' | ||
|
|
@@ -109,6 +128,36 @@ def test_polyfit(): | |
| ins.metric_ms = ins.mean_subtract() | ||
| assert np.all(ins.metric_ms.mask), "The metric_ms array was not all masked" | ||
|
|
||
| def test_flag_uvf_freq(): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test checks the error handling, but I don't see that it ever checks that the answer is right when the right calls are made. |
||
| obs = '1061313128_99bl_1pol_half_time' | ||
| testfile = os.path.join(DATA_PATH, '%s.uvfits' % obs) | ||
| file_type = 'uvfits' | ||
| prefix = os.path.join(DATA_PATH, '%s_test' % obs) | ||
| flags_outfile = '%s_SSINS_flags.h5' % prefix | ||
|
|
||
| ss = SS() | ||
| ss.read(testfile, diff_freq=True) | ||
|
|
||
| uvd = UVData() | ||
| uvd.read(testfile) | ||
|
|
||
| uvf = UVFlag(uvd, mode='flag', waterfall=True) | ||
| # start with some flags so that we can test the intended OR operation | ||
| uvf.flag_array[6, :] = True | ||
| ins = INS(ss) | ||
|
|
||
| # Check error handling | ||
| with pytest.raises(ValueError): | ||
| bad_uvf = UVFlag(uvd, mode='metric', waterfall=True) | ||
| err_uvf = ins.flag_uvf(uvf=bad_uvf) | ||
| with pytest.raises(ValueError): | ||
| bad_uvf = UVFlag(uvd, mode='flag', waterfall=False) | ||
| err_uvf = ins.flag_uvf(uvf=bad_uvf) | ||
| with pytest.raises(ValueError): | ||
| bad_uvf = UVFlag(uvd, mode='flag', waterfall=True) | ||
| # Pretend the data is off by 1 freq | ||
| bad_uvf.freq_array += 1 | ||
| err_uvf = ins.flag_uvf(uvf=bad_uvf) | ||
|
|
||
| @pytest.mark.filterwarnings("ignore:Reordering", "ignore:SS.read") | ||
| def test_mask_to_flags(): | ||
|
|
@@ -236,6 +285,10 @@ def test_write_mwaf(): | |
| testfile = os.path.join(DATA_PATH, '%s.h5' % obs) | ||
| prefix = os.path.join(DATA_PATH, '%s_test' % obs) | ||
| ins = INS(testfile) | ||
| #to override the fact that the data files don't have dif_ keywords set | ||
| ins.extra_keywords['dif_time'] = True | ||
| ins.extra_keywords['dif_freq'] = False | ||
|
|
||
| mwaf_files = [os.path.join(DATA_PATH, '1061313128_12.mwaf')] | ||
| bad_mwaf_files = [os.path.join(DATA_PATH, 'bad_file_path')] | ||
| metafits_file = os.path.join(DATA_PATH, '1061313128.metafits') | ||
|
|
@@ -431,3 +484,17 @@ def test_add(): | |
| assert np.all(combo_ins.metric_array.mask == first_ins.metric_array.mask) | ||
| assert np.all(combo_ins.metric_array.data == truth_ins.metric_array.data) | ||
| assert np.all(combo_ins.metric_array.mask == truth_ins.metric_array.mask) | ||
|
|
||
| def test_mask_to_flags_2(): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test also does not check anything other than that the code runs through. I think the smaller test files should support a "gets the correct answer" test. If not, you can use "select-on-read" functionality to make a testable object where it is not too hard to calculate the answer ahead of time through alternate means (you could even modify the starting data array to make this easy). |
||
| #verify array sizes | ||
| ss = SS() | ||
| filepath = 'SSINS/data/1061313128_99bl_1pol_half_time.uvfits' | ||
| ss.read(filepath, diff=True) | ||
| ins = INS(ss) | ||
| flags = ins.mask_to_flags() | ||
| ss.read(filepath, diff=False, diff_freq=True) | ||
| ins = INS(ss) | ||
| flags = ins.mask_to_flags() | ||
| ss.read(filepath, diff=True, diff_freq=True) | ||
| ins = INS(ss) | ||
| flags = ins.mask_to_flags() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,19 +9,20 @@ | |
| Tests the various capabilities of the sky_subtract class | ||
| """ | ||
|
|
||
|
|
||
| @pytest.mark.filterwarnings("ignore:Reordering", "ignore:SS.read") | ||
|
|
||
| def test_SS_read(): | ||
| obs = '1061313128_99bl_1pol_half_time' | ||
| testfile = os.path.join(DATA_PATH, '%s.uvfits' % obs) | ||
|
|
||
| ss = SS() | ||
|
|
||
| # Test reading in only metadata skips if block and warning | ||
| with pytest.warns(PendingDeprecationWarning, match="SS.read will be renamed"): | ||
| ss.read(testfile, read_data=False) | ||
| ss.read(testfile, read_data=False) | ||
| assert ss.data_array is None, "Data array is not None" | ||
|
|
||
| # See that it is not yet flagged as diffed | ||
| assert ss.extra_keywords['dif_freq'] is False | ||
|
|
||
| # Test select on read and diff | ||
| ss.read(testfile, times=np.unique(ss.time_array)[1:10], diff=True) | ||
| assert ss.Ntimes == 8, "Number of times after diff disagrees!" | ||
|
|
@@ -64,11 +65,74 @@ def test_diff(): | |
| assert np.all(ss.uvw_array == diff_uvw), "uvw_arrays disagree!" | ||
| assert np.all(ss.ant_1_array == np.array([0, 0])), "ant_1_array disagrees!" | ||
| assert np.all(ss.ant_2_array == np.array([1, 2])), "ant_2_array disagrees!" | ||
| assert ss.extra_keywords['dif_freq'] is False | ||
| assert ss.extra_keywords['dif_time'] is True | ||
|
|
||
|
|
||
| def test_keyword_override_time(): | ||
| obs = '1061313128_99bl_1pol_half_time' | ||
| testfile = os.path.join(DATA_PATH, '%s.uvfits' % obs) | ||
| ss = SS() | ||
| ss.read(testfile, read_data=False, diff=False, diff_freq=False, override_keyword='dif_time') | ||
| assert ss.extra_keywords['dif_time'] is True | ||
|
|
||
|
|
||
| def test_keyword_override_freq(): | ||
| obs = '1061313128_99bl_1pol_half_time' | ||
| ss = SS() | ||
| testfile = os.path.join(DATA_PATH, '%s.uvfits' % obs) | ||
| ss.read(testfile, read_data=False, diff=False, diff_freq=False, override_keyword='dif_freq') | ||
| assert ss.extra_keywords['dif_freq'] is True | ||
|
|
||
|
|
||
| def test_keyword_override_both(): | ||
| obs = '1061313128_99bl_1pol_half_time' | ||
| ss = SS() | ||
| testfile = os.path.join(DATA_PATH, '%s.uvfits' % obs) | ||
| ss.read(testfile, read_data=False, diff=False, diff_freq=False, override_keyword='both') | ||
| assert ss.extra_keywords['dif_time'] is True | ||
| assert ss.extra_keywords['dif_freq'] is True | ||
|
|
||
| #checks whether diff_freq reads in and out, and the diff values are sane | ||
| def test_diff_freq(): | ||
| obs = '1061313128_99bl_1pol_half_time' | ||
| testfile = os.path.join(DATA_PATH, '%s.uvfits' % obs) | ||
|
|
||
| ss = SS() | ||
| uv = UVData() | ||
|
|
||
| # Read in two times and two baselines of data, so that the diff is obvious. | ||
| uv.read(testfile, read_data=False) | ||
| times = np.unique(uv.time_array)[:2] | ||
| bls = [(0, 1), (0, 2)] | ||
| uv.read(testfile, times=times, bls=bls) | ||
|
|
||
| diff_dat = np.diff(uv.data_array, axis=2) | ||
|
|
||
| ss.read(testfile, diff=False, diff_freq=True, times=times, bls=bls) | ||
| print(ss._data_array.form) | ||
| #ss.reorder_blts(order='baseline') | ||
| assert np.all(ss.data_array == diff_dat), "Data values are different!" | ||
| assert ss.extra_keywords['dif_freq'] is True | ||
| assert ss.extra_keywords['dif_time'] is False | ||
|
|
||
| #checks whether diff_freq masks properly | ||
| def test_diff_freq_mask(): | ||
| obs = '1061313128_99bl_1pol_half_time' | ||
| testfile = os.path.join(DATA_PATH, '%s.uvfits' % obs) | ||
| ss = SS() | ||
|
|
||
| #read in test file | ||
| ss.read(testfile, read_data=True, diff=False, diff_freq=False) | ||
| ss.apply_flags(flag_choice='original') | ||
| assert ss.flag_array is not None | ||
| temp_array = np.logical_or(ss.flag_array, ss.flag_array) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line and those below confuse me. This line should just return a copy of ss.flag_array, since ORing an array with itself will just return an array with 1 everywhere that the original array was nonzero and 0 otherwise, and the flag array is already boolean. Due to this, the next two lines are guaranteed to satisfy the assertion, since |
||
| nonzero_or = np.count_nonzero(temp_array) | ||
| nonzero_flags = np.count_nonzero(ss.flag_array[::2]) | ||
| assert (nonzero_or > nonzero_flags) | ||
|
|
||
| @pytest.mark.filterwarnings("ignore:SS.read", "ignore:Reordering") | ||
| def test_apply_flags(): | ||
|
|
||
| obs = '1061313128_99bl_1pol_half_time' | ||
| testfile = os.path.join(DATA_PATH, '%s.uvfits' % obs) | ||
| file_type = 'uvfits' | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.