From 46f138452e8c30ff7289c587f283fa88495d894b Mon Sep 17 00:00:00 2001 From: Javier Gonzalez Date: Thu, 24 Mar 2022 11:27:50 -0400 Subject: [PATCH 1/2] Use np.isclose instead of equal in tests when checking floating point values --- chandra_aca/tests/test_maude_decom.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/chandra_aca/tests/test_maude_decom.py b/chandra_aca/tests/test_maude_decom.py index 43fafe6..4571df3 100755 --- a/chandra_aca/tests/test_maude_decom.py +++ b/chandra_aca/tests/test_maude_decom.py @@ -63,7 +63,8 @@ def test_vcdu_0_raw(): ref_data = test_data['686111007-686111017']['raw'] data = maude_decom.get_raw_aca_packets(686111007, 686111017) - for key in ['TIME', 'MJF', 'MNF']: + assert np.all(np.isclose(data['TIME'], ref_data['TIME'])) + for key in ['MJF', 'MNF']: assert np.all(data[key] == ref_data[key]) assert data['packets'] == ref_data['packets'] assert data['flags'] == ref_data['flags'] @@ -77,7 +78,7 @@ def test_blob_0_raw(): ref_data = test_data['686111007-686111017']['raw'] blobs = maude_decom.get_raw_aca_blobs(686111007, 686111017) t = maude.blobs_to_table(**blobs)[['TIME', 'CVCMJCTR', 'CVCMNCTR']] - assert np.all(t['TIME'] == ref_data['TIME']) + assert np.all(np.isclose(t['TIME'], ref_data['TIME'])) assert np.all(t['CVCMJCTR'] == ref_data['MJF']) assert np.all(t['CVCMNCTR'] == ref_data['MNF']) @@ -203,7 +204,10 @@ def test_vcdu_vs_level0(): table2 = maude_decom._get_aca_packets(raw, start, stop, combine=True, adjust_time=True, calibrate=True) for col, col2 in zip(table.itercols(), table2.itercols()): - assert np.all(col == col2) + if np.isreal(col.dtype): + assert np.all(np.isclose(col2, col)) + else: + assert np.all(col == col2) names = ['TIME', 'MJF', 'MNF', 'END_INTEG_TIME', 'INTEG', 'GLBSTAT', 'COMMCNT', 'COMMPROG', 'IMGROW0', 'IMGCOL0', 'IMGSCALE', 'BGDAVG', 'BGDRMS', From 634b3a6612e8f5a2a457e8d62e7041e61b0f5742 Mon Sep 17 00:00:00 2001 From: Jean Connelly Date: Mon, 28 Mar 2022 14:24:10 -0400 Subject: [PATCH 2/2] Update recent time isclose checks to atol=1e-3 --- chandra_aca/tests/test_maude_decom.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/chandra_aca/tests/test_maude_decom.py b/chandra_aca/tests/test_maude_decom.py index 4571df3..e5f6aaa 100755 --- a/chandra_aca/tests/test_maude_decom.py +++ b/chandra_aca/tests/test_maude_decom.py @@ -63,7 +63,7 @@ def test_vcdu_0_raw(): ref_data = test_data['686111007-686111017']['raw'] data = maude_decom.get_raw_aca_packets(686111007, 686111017) - assert np.all(np.isclose(data['TIME'], ref_data['TIME'])) + assert np.all(np.isclose(data['TIME'], ref_data['TIME'], rtol=0, atol=1e-3)) for key in ['MJF', 'MNF']: assert np.all(data[key] == ref_data[key]) assert data['packets'] == ref_data['packets'] @@ -78,7 +78,7 @@ def test_blob_0_raw(): ref_data = test_data['686111007-686111017']['raw'] blobs = maude_decom.get_raw_aca_blobs(686111007, 686111017) t = maude.blobs_to_table(**blobs)[['TIME', 'CVCMJCTR', 'CVCMNCTR']] - assert np.all(np.isclose(t['TIME'], ref_data['TIME'])) + assert np.all(np.isclose(t['TIME'], ref_data['TIME'], rtol=0, atol=1e-3)) assert np.all(t['CVCMJCTR'] == ref_data['MJF']) assert np.all(t['CVCMNCTR'] == ref_data['MNF']) @@ -204,8 +204,8 @@ def test_vcdu_vs_level0(): table2 = maude_decom._get_aca_packets(raw, start, stop, combine=True, adjust_time=True, calibrate=True) for col, col2 in zip(table.itercols(), table2.itercols()): - if np.isreal(col.dtype): - assert np.all(np.isclose(col2, col)) + if col.name in ['TIME', 'END_INTEG_TIME']: + assert np.all(np.isclose(col2, col, rtol=0, atol=1e-3)) else: assert np.all(col == col2)