From 6764534d840f7222b4d2abe4d4f07a69d503b251 Mon Sep 17 00:00:00 2001 From: Javier Gonzalez Date: Tue, 2 Jun 2020 07:12:57 -0400 Subject: [PATCH 1/3] mod to be able to get 8x8 images in aca_l0.get_slot_data --- mica/archive/aca_l0.py | 53 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/mica/archive/aca_l0.py b/mica/archive/aca_l0.py index 981535f3..d9acd6e6 100644 --- a/mica/archive/aca_l0.py +++ b/mica/archive/aca_l0.py @@ -42,6 +42,25 @@ 'arc5gl_query': 'ACA0', 'fileglob': '*fits.gz'} +ACA_DTYPE_2 = (('TIME', '>f8'), ('QUALITY', '>i4'), ('MJF', '>i4'), + ('MNF', '>i4'), + ('END_INTEG_TIME', '>f8'), ('INTEG', '>f4'), ('GLBSTAT', '|u1'), + ('COMMCNT', '|u1'), ('COMMPROG', '|u1'), ('IMGFID1', '|u1'), + ('IMGNUM1', '|u1'), ('IMGFUNC1', '|u1'), ('IMGSTAT', '|u1'), + ('IMGROW0', '>i2'), ('IMGCOL0', '>i2'), ('IMGSCALE', '>i2'), + ('BGDAVG', '>i2'), ('IMGFID2', '|u1'), ('IMGNUM2', '|u1'), + ('IMGFUNC2', '|u1'), ('BGDRMS', '>i2'), ('TEMPCCD', '>f4'), + ('TEMPHOUS', '>f4'), ('TEMPPRIM', '>f4'), ('TEMPSEC', '>f4'), + ('BGDSTAT', '|u1'), ('IMGFID3', '|u1'), ('IMGNUM3', '|u1'), + ('IMGFUNC3', '|u1'), ('IMGFID4', '|u1'), ('IMGNUM4', '|u1'), + ('IMGFUNC4', '|u1'), ('IMGRAW', '>f4', (8, 8)), + ('HD3TLM62', '|u1'), + ('HD3TLM63', '|u1'), ('HD3TLM64', '|u1'), ('HD3TLM65', '|u1'), + ('HD3TLM66', '|u1'), ('HD3TLM67', '|u1'), ('HD3TLM72', '|u1'), + ('HD3TLM73', '|u1'), ('HD3TLM74', '|u1'), ('HD3TLM75', '|u1'), + ('HD3TLM76', '|u1'), ('HD3TLM77', '|u1'), + ('IMGSIZE', '>i4'), ('FILENAME', 'f8'), ('QUALITY', '>i4'), ('MJF', '>i4'), ('MNF', '>i4'), ('END_INTEG_TIME', '>f8'), ('INTEG', '>f4'), ('GLBSTAT', '|u1'), @@ -95,8 +114,21 @@ def get_options(): return opt +def _mask(n): + m = np.zeros((8, 8), dtype=bool) + if n == 6: + m[:, [0, -1]] = True + m[[0, -1]] = True + m[[1, 1, -2, -2], [1, -2, 1, -2]] = True + if n == 4: + m[:, [0, 1, -2, -1]] = True + m[[0, 1, -2, -1]] = True + return m + + def get_slot_data(start, stop, slot, imgsize=None, db=None, data_root=None, columns=None, + img_shape_8x8=False ): """ For a the given parameters, retrieve telemetry and construct a @@ -135,7 +167,10 @@ def get_slot_data(start, stop, slot, imgsize=None, data_files = _get_file_records(start, stop, slots=[slot], imgsize=imgsize, db=db, data_root=data_root) - dtype = [k for k in ACA_DTYPE if k[0] in columns] + if img_shape_8x8: + dtype = [k for k in ACA_DTYPE_2 if k[0] in columns] + else: + dtype = [k for k in ACA_DTYPE if k[0] in columns] if not len(data_files): # return an empty masked array return ma.zeros(0, dtype=dtype) @@ -163,10 +198,18 @@ def get_slot_data(start, stop, slot, imgsize=None, if 'FILENAME' in columns: all_rows['FILENAME'][rowcount:(rowcount + len(chunk))] = f['filename'] if 'IMGRAW' in columns: - all_rows['IMGRAW'].reshape(rows, 8, 8)[ - rowcount:(rowcount + len(chunk)), 0:f_imgsize, 0:f_imgsize] = ( - chunk.field('IMGRAW').reshape(len(chunk), - f_imgsize, f_imgsize)) + if img_shape_8x8: + if f_imgsize == 8: + all_rows['IMGRAW'][rowcount:(rowcount + len(chunk))] = chunk.field('IMGRAW') + else: + i = (8 - f_imgsize) // 2 + all_rows['IMGRAW'][rowcount:(rowcount + len(chunk)), i:-i, i:-i] = \ + chunk.field('IMGRAW') + else: + all_rows['IMGRAW'].reshape(rows, 8, 8)[ + rowcount:(rowcount + len(chunk)), 0:f_imgsize, 0:f_imgsize] = ( + chunk.field('IMGRAW').reshape(len(chunk), + f_imgsize, f_imgsize)) rowcount += len(chunk) # just include the rows in the requested time range in the returned data From b6d231d11c4498d762243a5c291fb8bb42a5e91f Mon Sep 17 00:00:00 2001 From: Javier Gonzalez Date: Tue, 20 Oct 2020 13:01:14 -0400 Subject: [PATCH 2/3] define ACA_DTYPE_8x8 in terms of ACA_DTYPE, renamed img_shape_8x8 argument to centered_8x8, removed orphan _mask function, modified dtype definition inside get_slot_data. Other simplifications. --- mica/archive/aca_l0.py | 71 +++++++++++++----------------------------- 1 file changed, 22 insertions(+), 49 deletions(-) diff --git a/mica/archive/aca_l0.py b/mica/archive/aca_l0.py index d9acd6e6..3820c410 100644 --- a/mica/archive/aca_l0.py +++ b/mica/archive/aca_l0.py @@ -42,25 +42,6 @@ 'arc5gl_query': 'ACA0', 'fileglob': '*fits.gz'} -ACA_DTYPE_2 = (('TIME', '>f8'), ('QUALITY', '>i4'), ('MJF', '>i4'), - ('MNF', '>i4'), - ('END_INTEG_TIME', '>f8'), ('INTEG', '>f4'), ('GLBSTAT', '|u1'), - ('COMMCNT', '|u1'), ('COMMPROG', '|u1'), ('IMGFID1', '|u1'), - ('IMGNUM1', '|u1'), ('IMGFUNC1', '|u1'), ('IMGSTAT', '|u1'), - ('IMGROW0', '>i2'), ('IMGCOL0', '>i2'), ('IMGSCALE', '>i2'), - ('BGDAVG', '>i2'), ('IMGFID2', '|u1'), ('IMGNUM2', '|u1'), - ('IMGFUNC2', '|u1'), ('BGDRMS', '>i2'), ('TEMPCCD', '>f4'), - ('TEMPHOUS', '>f4'), ('TEMPPRIM', '>f4'), ('TEMPSEC', '>f4'), - ('BGDSTAT', '|u1'), ('IMGFID3', '|u1'), ('IMGNUM3', '|u1'), - ('IMGFUNC3', '|u1'), ('IMGFID4', '|u1'), ('IMGNUM4', '|u1'), - ('IMGFUNC4', '|u1'), ('IMGRAW', '>f4', (8, 8)), - ('HD3TLM62', '|u1'), - ('HD3TLM63', '|u1'), ('HD3TLM64', '|u1'), ('HD3TLM65', '|u1'), - ('HD3TLM66', '|u1'), ('HD3TLM67', '|u1'), ('HD3TLM72', '|u1'), - ('HD3TLM73', '|u1'), ('HD3TLM74', '|u1'), ('HD3TLM75', '|u1'), - ('HD3TLM76', '|u1'), ('HD3TLM77', '|u1'), - ('IMGSIZE', '>i4'), ('FILENAME', 'f8'), ('QUALITY', '>i4'), ('MJF', '>i4'), ('MNF', '>i4'), ('END_INTEG_TIME', '>f8'), ('INTEG', '>f4'), ('GLBSTAT', '|u1'), @@ -80,6 +61,9 @@ ('HD3TLM76', '|u1'), ('HD3TLM77', '|u1'), ('IMGSIZE', '>i4'), ('FILENAME', ' Date: Fri, 6 Nov 2020 17:50:09 -0500 Subject: [PATCH 3/3] added aca_l0 test the replicates test_get_l0_images but using slot_data directly --- mica/archive/tests/test_aca_l0.py | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/mica/archive/tests/test_aca_l0.py b/mica/archive/tests/test_aca_l0.py index d9776324..71c28e01 100644 --- a/mica/archive/tests/test_aca_l0.py +++ b/mica/archive/tests/test_aca_l0.py @@ -75,3 +75,43 @@ def test_get_l0_images(): assert np.all(np.abs(rcen - rcs) < 0.05) assert np.all(np.abs(ccen - ccs) < 0.05) + + +@pytest.mark.skipif('not has_l0_2007_archive or not has_asp_l1', reason='Test requires 2007 L0 archive') +def test_get_slot_data_8x8(): + """ + Do a validation test of get_l0_images: + - Get 20 mins of image data for slot 6 of obsid 8008 (very nice clean stars) + - Do first moment centroids in row and col + - Compare to aspect pipeline FM centroids for same slot data + + This is a deep test that all the signs are right. If not then everything + breaks badly because the star image doesn't move in sync with row0, col0. + """ + start = '2007:002:06:00:00' + stop = '2007:002:06:20:00' + + slot_data = aca_l0.get_slot_data(start, stop, slot=6, centered_8x8=True) + + files = asp_l1.get_files(8008, content=['ACACENT']) + acen = Table.read(files[0]) + # Pick FM centroids for slot 6 + ok = (acen['alg'] == 1) & (acen['slot'] == 6) + acen = acen[ok] + + # Row and col centroids + times = slot_data['TIME'] + + # Easy way to do FM centroids with mgrid + rw, cw = np.mgrid[0:8, 0:8] + + img_raw = slot_data['IMGRAW'] # np.round(slot_data['IMGRAW']).astype(int) + norm = np.sum(img_raw, axis=(1, 2)) + rcs = np.sum(img_raw * rw, axis=(1, 2)) / norm + slot_data['IMGROW0'] - 1 + ccs = np.sum(img_raw * cw, axis=(1, 2)) / norm + slot_data['IMGCOL0'] - 1 + + rcen = interpolate(acen['cent_i'], acen['time'], times) + ccen = interpolate(acen['cent_j'], acen['time'], times) + + assert np.all(np.abs(rcen - rcs) < 0.05) + assert np.all(np.abs(ccen - ccs) < 0.05)