Loading autocnet/matcher/subpixel.py +1 −4 Original line number Diff line number Diff line Loading @@ -882,7 +882,6 @@ def subpixel_register_point_smart(point, # match to the source node. source = measures[reference_index] reference_index_id = source.imageid log.info(f'Using measure {source.id} on image {source.imageid}/{source.serial} as the reference.') log.info(f'Measure reference index is: {reference_index}') Loading Loading @@ -1362,9 +1361,7 @@ def smart_register_point(point, if not isinstance(point, Points): point = session.query(Points).filter(Points.id == point).one() print('Initial') measure_results = subpixel_register_point_smart(point, session, parameters=parameters, **shared_kwargs) print('Decider') measures_to_update, measures_to_set_false = decider(measure_results) log.info(f'Found {len(measures_to_update)} measures that found subpixel registration consensus. Running validation now...') # Validate that the new position has consensus Loading autocnet/transformation/affine.py +1 −5 Original line number Diff line number Diff line Loading @@ -67,9 +67,7 @@ def estimate_affine_from_sensors(reference_image, y_coords = [base_starty, base_stopy, base_stopy, base_starty, bcenter_y] # Dispatch to the sensor to get the a priori pixel location in the input image lons, lats = reference_image.sensormodel.sampline2lonlat(x_coords, y_coords, allowoutside=True) print(lons, lats) xs, ys = moving_image.sensormodel.lonlat2sampline(lons, lats, allowoutside=True) print(xs, ys) log.debug(f'Lon/Lats for affine estimate are: {list(zip(lons, lats))}') log.debug(f'Image X / Image Y for affine estimate are: {list(zip(xs, ys))}') Loading @@ -82,7 +80,7 @@ def estimate_affine_from_sensors(reference_image, base_gcps.append((base_x, base_y)) if len(dst_gcps) < 3: raise ValueError(f'Unable to find enough points to compute an affine transformation. Found {len(dst_corners)} points, but need at least 3.') raise ValueError(f'Unable to find enough points to compute an affine transformation. Found {len(dst_gcps)} points, but need at least 3.') log.debug(f'Number of GCPs for affine estimation: {len(dst_gcps)}') Loading Loading @@ -117,8 +115,6 @@ def estimate_local_affine(reference_roi, moving_roi): size_x = 60 # reference_roi.size_x + roi_buffer size_y = 60 # reference_roi.size_y + roi_buffer print('REF: ', reference_roi.x, reference_roi.y) affine_transform = estimate_affine_from_sensors(reference_roi.data, moving_roi.data, reference_roi.x, Loading autocnet/transformation/roi.py +1 −0 Original line number Diff line number Diff line Loading @@ -273,6 +273,7 @@ class Roi(): # series of checks to make sure all pixels inside image limits raster_xsize, raster_ysize = self.data.raster_size if min_x < 0 or min_y < 0 or min_x+x_read_length > raster_xsize or min_y+y_read_length > raster_ysize: print('FAILURE: ', self.data.file_name, min_x, min_y, x_read_length, y_read_length) raise IndexError('Image coordinates plus read buffer are outside of the available data. Please select a smaller ROI and/or a smaller read buffer.') pixels = [min_x, min_y, x_read_length, y_read_length] Loading tests/test_ctx_csm_3image_subpixel.py→tests/test_ctx_csm_3image_subpixel2.py +47 −44 Original line number Diff line number Diff line Loading @@ -19,53 +19,55 @@ def isis_mola_radius_dem(): return path @pytest.fixture def g17(isis_mola_radius_dem): def b10(isis_mola_radius_dem): # Start is sample:2000 line:5700 return {'id':0, 'name':'G17_024823_2204_XI_40N109W.crop.cub', 'path':get_path('G17_024823_2204_XI_40N109W.crop.cub'), 'serial':'MRO/CTX/1005587208:239', 'name':'B10_013615_2178_XI_37N117W.crop.cub', 'path':get_path('B10_013615_2178_XI_37N117W.crop.cub'), 'serial':'MRO/CTX/0930130710:231', 'cam_type':'csm', 'dem':isis_mola_radius_dem, 'dem_type':'radius'} @pytest.fixture def n11(isis_mola_radius_dem): def n12(isis_mola_radius_dem): return {'id':1, 'name':'N11_066770_2192_XN_39N109W.crop.cub', 'path':get_path('N11_066770_2192_XN_39N109W.crop.cub'), 'serial':'MRO/CTX/1287982533:042', 'name':'N12_067021_2177_XN_37N117W.crop.cub', 'path':get_path('N12_067021_2177_XN_37N117W.crop.cub'), 'serial':'MRO/CTX/1289671564:206', 'cam_type':'csm', 'dem':isis_mola_radius_dem, 'dem_type':'radius'} @pytest.fixture def p10(isis_mola_radius_dem): def k12(isis_mola_radius_dem): # Start is sample:1600 line:4950 return {'id':2, 'name':'P10_005031_2197_XI_39N109W.crop.cub', 'path':get_path('P10_005031_2197_XI_39N109W.crop.cub'), 'serial':'MRO/CTX/0872335765:217', 'name':'K12_058001_2177_XI_37N117W.crop.cub', 'path':get_path('K12_058001_2177_XI_37N117W.crop.cub'), 'serial':'MRO/CTX/1228947495:234', 'cam_type':'csm', 'dem':isis_mola_radius_dem, 'dem_type':'radius'} @pytest.fixture def g17_image(g17): return Images(**g17) def n12_image(n12): return Images(**n12) @pytest.fixture def n11_image(n11): return Images(**n11) def b10_image(b10): return Images(**b10) @pytest.fixture def p10_image(p10): return Images(**p10) def k12_image(k12): return Images(**k12) @pytest.fixture def measure_0(): data = [ {'id':0, 'imageid':0,'apriorisample':384.768,'aprioriline':278.000,'sample':384.768,'line':278.000,'pointid':0, 'measuretype':3}, {'id':1, 'imageid':1,'apriorisample':521.905,'aprioriline':209.568,'sample':521.905,'line':209.568, 'pointid':0, 'measuretype':3}, {'id':2, 'imageid':2,'apriorisample':355.483,'aprioriline':234.296,'sample':355.483,'line':234.296, 'pointid':0, 'measuretype':3} {'id':0, 'imageid':0,'apriorisample':442.7200012207031,'aprioriline':218.4800033569336,'sample':442.7200012207031,'line':218.4800033569336,'pointid':0, 'measuretype':3}, {'id':1, 'imageid':1,'apriorisample':755.95042324367,'aprioriline':1207.3857527191,'sample':755.95042324367,'line':1207.3857527191, 'pointid':0, 'measuretype':3}, {'id':2, 'imageid':2,'apriorisample':830.95897898574,'aprioriline':1549.7867781121,'sample':830.95897898574,'line':1549.7867781121, 'pointid':0, 'measuretype':3} ] return [Measures(**d) for d in data] Loading @@ -82,7 +84,7 @@ def points(measure_0): return pts @pytest.fixture def session(measure_0,g17_image,n11_image,p10_image): def session(measure_0,n12_image,b10_image,k12_image): # Mocked DB session with calls and responses. session = UnifiedAlchemyMagicMock(data=[ Loading @@ -104,23 +106,23 @@ def session(measure_0,g17_image,n11_image,p10_image): ),( [mock.call.query(Images), mock.call.filter(Images.id == 0)], [g17_image] [b10_image] ),( [mock.call.query(Images), mock.call.filter(Images.id == 1)], [n11_image] [n12_image] ),( [mock.call.query(Images), mock.call.filter(Images.id == 2)], [p10_image] [k12_image] ), ]) return session def test_ctx_pair_to_df(session, g17_image, n11_image, p10_image, n12_image, b10_image, k12_image, measure_0, points): """ Loading Loading @@ -159,29 +161,30 @@ def test_ctx_pair_to_df(session, session, parameters=parameters, shared_kwargs=shared_kwargs) print(measures_to_update) print(measures_to_set_false) assert measures_to_set_false == [] m0 = measures_to_update[0] assert m0['sample'] == 528.0616518160688 assert m0['line'] == 210.8722056871887 assert m0['template_metric'] == 0.8538808822631836 assert m0['ignore'] == False assert m0['template_shift'] == 445.17368002294427 # assert m0['sample'] == 528.0616518160688 # assert m0['line'] == 210.8722056871887 # assert m0['template_metric'] == 0.8538808822631836 # assert m0['ignore'] == False # assert m0['template_shift'] == 445.17368002294427 m1 = measures_to_update[1] assert m1['sample'] == 357.3392609551714 assert m1['line'] == 230.29507805238129 assert m1['template_metric'] == 0.6922665238380432 assert m1['ignore'] == False assert m1['template_shift'] == 175.5325037366171 # assert m1['sample'] == 357.3392609551714 # assert m1['line'] == 230.29507805238129 # assert m1['template_metric'] == 0.6922665238380432 # assert m1['ignore'] == False # assert m1['template_shift'] == 175.5325037366171 dfs = [] with mock.patch('pandas.read_sql') as db_response: db_cnet = pd.DataFrame([ [0, 0, g17_image.serial,measure_0[0].sample, measure_0[0].line, point.pointtype, measure_0[0].measuretype, 'test'], [1, 0, n11_image.serial,m0['sample'], m0['line'], point.pointtype, measure_0[1].measuretype, 'test'], [1, 0, p10_image.serial,m1['sample'], m1['line'], point.pointtype, measure_0[2].measuretype, 'test'], [0, 0, b10_image.serial,measure_0[0].sample, measure_0[0].line, point.pointtype, measure_0[0].measuretype, 'test'], [1, 0, n12_image.serial,m0['sample'], m0['line'], point.pointtype, measure_0[1].measuretype, 'test'], [1, 0, k12_image.serial,m1['sample'], m1['line'], point.pointtype, measure_0[2].measuretype, 'test'], ], columns=['id','pointid', 'serialnumber', 'sample', 'line', 'pointtype', 'measuretype','identifier']) Loading @@ -194,6 +197,6 @@ def test_ctx_pair_to_df(session, df.rename(columns={'pointtype':'pointType', 'measuretype':'measureType'}, inplace=True) to_isis(df, 'tests/artifacts/ctx_csm_trio_to_df.cnet', targetname='Mars') write_filelist([g17_image.path, n11_image.path, p10_image.path], 'tests/artifacts/ctx_csm_trio_to_df.lis') to_isis(df, 'tests/artifacts/ctx_csm_trio_to_df2.cnet', targetname='Mars') write_filelist([n12_image.path, b10_image.path, k12_image.path], 'tests/artifacts/ctx_csm_trio_to_df2.lis') assert False No newline at end of file tests/test_ctx_isis_3image_subpixel2.py 0 → 100644 +193 −0 Original line number Diff line number Diff line import os import pandas as pd import pytest import mock from mock_alchemy.mocking import UnifiedAlchemyMagicMock from plio.io.io_controlnetwork import to_isis, write_filelist from autocnet.matcher.subpixel import smart_register_point from autocnet.io.db.model import Points, Measures, Images from autocnet.io.db.controlnetwork import db_to_df from autocnet.examples import get_path @pytest.fixture def b10(): # Start is sample:2000 line:5700 return {'id':0, 'name':'B10_013615_2178_XI_37N117W.crop.cub', 'path':get_path('B10_013615_2178_XI_37N117W.crop.cub'), 'serial':'MRO/CTX/0930130710:231', 'cam_type':'isis'} @pytest.fixture def n12(): return {'id':1, 'name':'N12_067021_2177_XN_37N117W.crop.cub', 'path':get_path('N12_067021_2177_XN_37N117W.crop.cub'), 'serial':'MRO/CTX/1289671564:206', 'cam_type':'isis'} @pytest.fixture def k12(): return {'id':2, 'name':'K12_058001_2177_XI_37N117W.crop.cub', 'path':get_path('K12_058001_2177_XI_37N117W.crop.cub'), 'serial':'MRO/CTX/1228947495:234', 'cam_type':'isis'} @pytest.fixture def n12_image(n12): return Images(**n12) @pytest.fixture def b10_image(b10): return Images(**b10) @pytest.fixture def k12_image(k12): return Images(**k12) @pytest.fixture def measure_0(): data = [ {'id':0, 'imageid':0,'apriorisample':442.7200012207031,'aprioriline':218.4800033569336,'sample':442.7200012207031,'line':218.4800033569336,'pointid':0, 'measuretype':3}, {'id':1, 'imageid':1,'apriorisample':755.95042324367,'aprioriline':1207.3857527191,'sample':755.95042324367,'line':1207.3857527191, 'pointid':0, 'measuretype':3}, {'id':2, 'imageid':2,'apriorisample':830.95897898574,'aprioriline':1549.7867781121,'sample':830.95897898574,'line':1549.7867781121, 'pointid':0, 'measuretype':3} ] return [Measures(**d) for d in data] @pytest.fixture def points(measure_0): data = [{'id':0,'reference_index':0,'pointtype':2,'measures':[],'_apriori':''}, #{'id':1,'reference_index':1,'pointtype':2,'measures':[],'_apriori':''}, #{'id':2,'reference_index':1,'pointtype':2,'measures':[],'_apriori':''}, #{'id':3,'reference_index':1,'pointtype':2,'measures':[],'_apriori':''}, #{'id':4,'reference_index':1,'pointtype':2,'measures':[],'_apriori':''} ] pts = [Points(**d) for d in data] pts[0].measures = measure_0 return pts @pytest.fixture def session(measure_0,n12_image,b10_image,k12_image): # Mocked DB session with calls and responses. session = UnifiedAlchemyMagicMock(data=[ ( [mock.call.query(Measures), mock.call.filter(Measures.pointid == 0), mock.call.order_by(Measures.id)], measure_0 ),( [mock.call.query(Measures), mock.call.filter(Measures.id == 0), mock.call.order_by(Measures.id)], [measure_0[0]] ),( [mock.call.query(Measures), mock.call.filter(Measures.id == 1), mock.call.order_by(Measures.id)], [measure_0[1]] ),( [mock.call.query(Measures), mock.call.filter(Measures.id == 2), mock.call.order_by(Measures.id)], [measure_0[2]] ),( [mock.call.query(Images), mock.call.filter(Images.id == 0)], [b10_image] ),( [mock.call.query(Images), mock.call.filter(Images.id == 1)], [n12_image] ),( [mock.call.query(Images), mock.call.filter(Images.id == 2)], [k12_image] ), ]) return session def test_ctx_pair_to_df(session, n12_image, b10_image, k12_image, measure_0, points): """ This is an integration test that takes a pair of ISIS cube files and processes them through the smart_subpixel_matcher. This is the same matcher that was used by the CTX control project. The test sets up a session mock with the appropriate data. This directly of indirectly tests the following: - subpixel.smart_register_point - subpixel.subpixel_register_point_smart - subpixel.decider - subpixel.check_for_shift_consensus - subpixel.validate_candidate_measure - transformation.roi.Roi - transformation.affine.estimate_affine_transform """ # Pulled directly from CTX control project. parameters = [ {'match_kwargs': {'image_size':(60,60), 'template_size':(30,30)}}, {'match_kwargs': {'image_size':(75,75), 'template_size':(33,33)}}, {'match_kwargs': {'image_size':(90,90), 'template_size':(36,36)}}, {'match_kwargs': {'image_size':(110,110), 'template_size':(40,40)}}, {'match_kwargs': {'image_size':(125,125), 'template_size':(44,44)}}, {'match_kwargs': {'image_size':(140,140), 'template_size':(48,48)}} ] shared_kwargs = {'cost_func':lambda x,y:y, 'chooser':'smart_subpixel_registration'} for point in points: # Somewhere in subpixel, need to add the offsets back to samp/line based # on which image is being used. Every samp/line, patch time. measures_to_update, measures_to_set_false = smart_register_point(point, session, parameters=parameters, shared_kwargs=shared_kwargs) print(measures_to_update) print(measures_to_set_false) assert measures_to_set_false == [] m0 = measures_to_update[0] # assert m0['sample'] == 528.0616518160688 # assert m0['line'] == 210.8722056871887 # assert m0['template_metric'] == 0.8538808822631836 # assert m0['ignore'] == False # assert m0['template_shift'] == 445.17368002294427 m1 = measures_to_update[1] # assert m1['sample'] == 357.3392609551714 # assert m1['line'] == 230.29507805238129 # assert m1['template_metric'] == 0.6922665238380432 # assert m1['ignore'] == False # assert m1['template_shift'] == 175.5325037366171 dfs = [] with mock.patch('pandas.read_sql') as db_response: db_cnet = pd.DataFrame([ [0, 0, b10_image.serial,measure_0[0].sample, measure_0[0].line, point.pointtype, measure_0[0].measuretype, 'test'], [1, 0, n12_image.serial,m0['sample'], m0['line'], point.pointtype, measure_0[1].measuretype, 'test'], [1, 0, k12_image.serial,m1['sample'], m1['line'], point.pointtype, measure_0[2].measuretype, 'test'], ], columns=['id','pointid', 'serialnumber', 'sample', 'line', 'pointtype', 'measuretype','identifier']) db_response.return_value = db_cnet df = db_to_df(session) dfs.append(df) df = pd.concat(dfs) df.rename(columns={'pointtype':'pointType', 'measuretype':'measureType'}, inplace=True) to_isis(df, 'tests/artifacts/ctx_isis_trio_to_df2.cnet', targetname='Mars') write_filelist([n12_image.path, b10_image.path, k12_image.path], 'tests/artifacts/ctx_isis_trio_to_df2.lis') assert False No newline at end of file Loading
autocnet/matcher/subpixel.py +1 −4 Original line number Diff line number Diff line Loading @@ -882,7 +882,6 @@ def subpixel_register_point_smart(point, # match to the source node. source = measures[reference_index] reference_index_id = source.imageid log.info(f'Using measure {source.id} on image {source.imageid}/{source.serial} as the reference.') log.info(f'Measure reference index is: {reference_index}') Loading Loading @@ -1362,9 +1361,7 @@ def smart_register_point(point, if not isinstance(point, Points): point = session.query(Points).filter(Points.id == point).one() print('Initial') measure_results = subpixel_register_point_smart(point, session, parameters=parameters, **shared_kwargs) print('Decider') measures_to_update, measures_to_set_false = decider(measure_results) log.info(f'Found {len(measures_to_update)} measures that found subpixel registration consensus. Running validation now...') # Validate that the new position has consensus Loading
autocnet/transformation/affine.py +1 −5 Original line number Diff line number Diff line Loading @@ -67,9 +67,7 @@ def estimate_affine_from_sensors(reference_image, y_coords = [base_starty, base_stopy, base_stopy, base_starty, bcenter_y] # Dispatch to the sensor to get the a priori pixel location in the input image lons, lats = reference_image.sensormodel.sampline2lonlat(x_coords, y_coords, allowoutside=True) print(lons, lats) xs, ys = moving_image.sensormodel.lonlat2sampline(lons, lats, allowoutside=True) print(xs, ys) log.debug(f'Lon/Lats for affine estimate are: {list(zip(lons, lats))}') log.debug(f'Image X / Image Y for affine estimate are: {list(zip(xs, ys))}') Loading @@ -82,7 +80,7 @@ def estimate_affine_from_sensors(reference_image, base_gcps.append((base_x, base_y)) if len(dst_gcps) < 3: raise ValueError(f'Unable to find enough points to compute an affine transformation. Found {len(dst_corners)} points, but need at least 3.') raise ValueError(f'Unable to find enough points to compute an affine transformation. Found {len(dst_gcps)} points, but need at least 3.') log.debug(f'Number of GCPs for affine estimation: {len(dst_gcps)}') Loading Loading @@ -117,8 +115,6 @@ def estimate_local_affine(reference_roi, moving_roi): size_x = 60 # reference_roi.size_x + roi_buffer size_y = 60 # reference_roi.size_y + roi_buffer print('REF: ', reference_roi.x, reference_roi.y) affine_transform = estimate_affine_from_sensors(reference_roi.data, moving_roi.data, reference_roi.x, Loading
autocnet/transformation/roi.py +1 −0 Original line number Diff line number Diff line Loading @@ -273,6 +273,7 @@ class Roi(): # series of checks to make sure all pixels inside image limits raster_xsize, raster_ysize = self.data.raster_size if min_x < 0 or min_y < 0 or min_x+x_read_length > raster_xsize or min_y+y_read_length > raster_ysize: print('FAILURE: ', self.data.file_name, min_x, min_y, x_read_length, y_read_length) raise IndexError('Image coordinates plus read buffer are outside of the available data. Please select a smaller ROI and/or a smaller read buffer.') pixels = [min_x, min_y, x_read_length, y_read_length] Loading
tests/test_ctx_csm_3image_subpixel.py→tests/test_ctx_csm_3image_subpixel2.py +47 −44 Original line number Diff line number Diff line Loading @@ -19,53 +19,55 @@ def isis_mola_radius_dem(): return path @pytest.fixture def g17(isis_mola_radius_dem): def b10(isis_mola_radius_dem): # Start is sample:2000 line:5700 return {'id':0, 'name':'G17_024823_2204_XI_40N109W.crop.cub', 'path':get_path('G17_024823_2204_XI_40N109W.crop.cub'), 'serial':'MRO/CTX/1005587208:239', 'name':'B10_013615_2178_XI_37N117W.crop.cub', 'path':get_path('B10_013615_2178_XI_37N117W.crop.cub'), 'serial':'MRO/CTX/0930130710:231', 'cam_type':'csm', 'dem':isis_mola_radius_dem, 'dem_type':'radius'} @pytest.fixture def n11(isis_mola_radius_dem): def n12(isis_mola_radius_dem): return {'id':1, 'name':'N11_066770_2192_XN_39N109W.crop.cub', 'path':get_path('N11_066770_2192_XN_39N109W.crop.cub'), 'serial':'MRO/CTX/1287982533:042', 'name':'N12_067021_2177_XN_37N117W.crop.cub', 'path':get_path('N12_067021_2177_XN_37N117W.crop.cub'), 'serial':'MRO/CTX/1289671564:206', 'cam_type':'csm', 'dem':isis_mola_radius_dem, 'dem_type':'radius'} @pytest.fixture def p10(isis_mola_radius_dem): def k12(isis_mola_radius_dem): # Start is sample:1600 line:4950 return {'id':2, 'name':'P10_005031_2197_XI_39N109W.crop.cub', 'path':get_path('P10_005031_2197_XI_39N109W.crop.cub'), 'serial':'MRO/CTX/0872335765:217', 'name':'K12_058001_2177_XI_37N117W.crop.cub', 'path':get_path('K12_058001_2177_XI_37N117W.crop.cub'), 'serial':'MRO/CTX/1228947495:234', 'cam_type':'csm', 'dem':isis_mola_radius_dem, 'dem_type':'radius'} @pytest.fixture def g17_image(g17): return Images(**g17) def n12_image(n12): return Images(**n12) @pytest.fixture def n11_image(n11): return Images(**n11) def b10_image(b10): return Images(**b10) @pytest.fixture def p10_image(p10): return Images(**p10) def k12_image(k12): return Images(**k12) @pytest.fixture def measure_0(): data = [ {'id':0, 'imageid':0,'apriorisample':384.768,'aprioriline':278.000,'sample':384.768,'line':278.000,'pointid':0, 'measuretype':3}, {'id':1, 'imageid':1,'apriorisample':521.905,'aprioriline':209.568,'sample':521.905,'line':209.568, 'pointid':0, 'measuretype':3}, {'id':2, 'imageid':2,'apriorisample':355.483,'aprioriline':234.296,'sample':355.483,'line':234.296, 'pointid':0, 'measuretype':3} {'id':0, 'imageid':0,'apriorisample':442.7200012207031,'aprioriline':218.4800033569336,'sample':442.7200012207031,'line':218.4800033569336,'pointid':0, 'measuretype':3}, {'id':1, 'imageid':1,'apriorisample':755.95042324367,'aprioriline':1207.3857527191,'sample':755.95042324367,'line':1207.3857527191, 'pointid':0, 'measuretype':3}, {'id':2, 'imageid':2,'apriorisample':830.95897898574,'aprioriline':1549.7867781121,'sample':830.95897898574,'line':1549.7867781121, 'pointid':0, 'measuretype':3} ] return [Measures(**d) for d in data] Loading @@ -82,7 +84,7 @@ def points(measure_0): return pts @pytest.fixture def session(measure_0,g17_image,n11_image,p10_image): def session(measure_0,n12_image,b10_image,k12_image): # Mocked DB session with calls and responses. session = UnifiedAlchemyMagicMock(data=[ Loading @@ -104,23 +106,23 @@ def session(measure_0,g17_image,n11_image,p10_image): ),( [mock.call.query(Images), mock.call.filter(Images.id == 0)], [g17_image] [b10_image] ),( [mock.call.query(Images), mock.call.filter(Images.id == 1)], [n11_image] [n12_image] ),( [mock.call.query(Images), mock.call.filter(Images.id == 2)], [p10_image] [k12_image] ), ]) return session def test_ctx_pair_to_df(session, g17_image, n11_image, p10_image, n12_image, b10_image, k12_image, measure_0, points): """ Loading Loading @@ -159,29 +161,30 @@ def test_ctx_pair_to_df(session, session, parameters=parameters, shared_kwargs=shared_kwargs) print(measures_to_update) print(measures_to_set_false) assert measures_to_set_false == [] m0 = measures_to_update[0] assert m0['sample'] == 528.0616518160688 assert m0['line'] == 210.8722056871887 assert m0['template_metric'] == 0.8538808822631836 assert m0['ignore'] == False assert m0['template_shift'] == 445.17368002294427 # assert m0['sample'] == 528.0616518160688 # assert m0['line'] == 210.8722056871887 # assert m0['template_metric'] == 0.8538808822631836 # assert m0['ignore'] == False # assert m0['template_shift'] == 445.17368002294427 m1 = measures_to_update[1] assert m1['sample'] == 357.3392609551714 assert m1['line'] == 230.29507805238129 assert m1['template_metric'] == 0.6922665238380432 assert m1['ignore'] == False assert m1['template_shift'] == 175.5325037366171 # assert m1['sample'] == 357.3392609551714 # assert m1['line'] == 230.29507805238129 # assert m1['template_metric'] == 0.6922665238380432 # assert m1['ignore'] == False # assert m1['template_shift'] == 175.5325037366171 dfs = [] with mock.patch('pandas.read_sql') as db_response: db_cnet = pd.DataFrame([ [0, 0, g17_image.serial,measure_0[0].sample, measure_0[0].line, point.pointtype, measure_0[0].measuretype, 'test'], [1, 0, n11_image.serial,m0['sample'], m0['line'], point.pointtype, measure_0[1].measuretype, 'test'], [1, 0, p10_image.serial,m1['sample'], m1['line'], point.pointtype, measure_0[2].measuretype, 'test'], [0, 0, b10_image.serial,measure_0[0].sample, measure_0[0].line, point.pointtype, measure_0[0].measuretype, 'test'], [1, 0, n12_image.serial,m0['sample'], m0['line'], point.pointtype, measure_0[1].measuretype, 'test'], [1, 0, k12_image.serial,m1['sample'], m1['line'], point.pointtype, measure_0[2].measuretype, 'test'], ], columns=['id','pointid', 'serialnumber', 'sample', 'line', 'pointtype', 'measuretype','identifier']) Loading @@ -194,6 +197,6 @@ def test_ctx_pair_to_df(session, df.rename(columns={'pointtype':'pointType', 'measuretype':'measureType'}, inplace=True) to_isis(df, 'tests/artifacts/ctx_csm_trio_to_df.cnet', targetname='Mars') write_filelist([g17_image.path, n11_image.path, p10_image.path], 'tests/artifacts/ctx_csm_trio_to_df.lis') to_isis(df, 'tests/artifacts/ctx_csm_trio_to_df2.cnet', targetname='Mars') write_filelist([n12_image.path, b10_image.path, k12_image.path], 'tests/artifacts/ctx_csm_trio_to_df2.lis') assert False No newline at end of file
tests/test_ctx_isis_3image_subpixel2.py 0 → 100644 +193 −0 Original line number Diff line number Diff line import os import pandas as pd import pytest import mock from mock_alchemy.mocking import UnifiedAlchemyMagicMock from plio.io.io_controlnetwork import to_isis, write_filelist from autocnet.matcher.subpixel import smart_register_point from autocnet.io.db.model import Points, Measures, Images from autocnet.io.db.controlnetwork import db_to_df from autocnet.examples import get_path @pytest.fixture def b10(): # Start is sample:2000 line:5700 return {'id':0, 'name':'B10_013615_2178_XI_37N117W.crop.cub', 'path':get_path('B10_013615_2178_XI_37N117W.crop.cub'), 'serial':'MRO/CTX/0930130710:231', 'cam_type':'isis'} @pytest.fixture def n12(): return {'id':1, 'name':'N12_067021_2177_XN_37N117W.crop.cub', 'path':get_path('N12_067021_2177_XN_37N117W.crop.cub'), 'serial':'MRO/CTX/1289671564:206', 'cam_type':'isis'} @pytest.fixture def k12(): return {'id':2, 'name':'K12_058001_2177_XI_37N117W.crop.cub', 'path':get_path('K12_058001_2177_XI_37N117W.crop.cub'), 'serial':'MRO/CTX/1228947495:234', 'cam_type':'isis'} @pytest.fixture def n12_image(n12): return Images(**n12) @pytest.fixture def b10_image(b10): return Images(**b10) @pytest.fixture def k12_image(k12): return Images(**k12) @pytest.fixture def measure_0(): data = [ {'id':0, 'imageid':0,'apriorisample':442.7200012207031,'aprioriline':218.4800033569336,'sample':442.7200012207031,'line':218.4800033569336,'pointid':0, 'measuretype':3}, {'id':1, 'imageid':1,'apriorisample':755.95042324367,'aprioriline':1207.3857527191,'sample':755.95042324367,'line':1207.3857527191, 'pointid':0, 'measuretype':3}, {'id':2, 'imageid':2,'apriorisample':830.95897898574,'aprioriline':1549.7867781121,'sample':830.95897898574,'line':1549.7867781121, 'pointid':0, 'measuretype':3} ] return [Measures(**d) for d in data] @pytest.fixture def points(measure_0): data = [{'id':0,'reference_index':0,'pointtype':2,'measures':[],'_apriori':''}, #{'id':1,'reference_index':1,'pointtype':2,'measures':[],'_apriori':''}, #{'id':2,'reference_index':1,'pointtype':2,'measures':[],'_apriori':''}, #{'id':3,'reference_index':1,'pointtype':2,'measures':[],'_apriori':''}, #{'id':4,'reference_index':1,'pointtype':2,'measures':[],'_apriori':''} ] pts = [Points(**d) for d in data] pts[0].measures = measure_0 return pts @pytest.fixture def session(measure_0,n12_image,b10_image,k12_image): # Mocked DB session with calls and responses. session = UnifiedAlchemyMagicMock(data=[ ( [mock.call.query(Measures), mock.call.filter(Measures.pointid == 0), mock.call.order_by(Measures.id)], measure_0 ),( [mock.call.query(Measures), mock.call.filter(Measures.id == 0), mock.call.order_by(Measures.id)], [measure_0[0]] ),( [mock.call.query(Measures), mock.call.filter(Measures.id == 1), mock.call.order_by(Measures.id)], [measure_0[1]] ),( [mock.call.query(Measures), mock.call.filter(Measures.id == 2), mock.call.order_by(Measures.id)], [measure_0[2]] ),( [mock.call.query(Images), mock.call.filter(Images.id == 0)], [b10_image] ),( [mock.call.query(Images), mock.call.filter(Images.id == 1)], [n12_image] ),( [mock.call.query(Images), mock.call.filter(Images.id == 2)], [k12_image] ), ]) return session def test_ctx_pair_to_df(session, n12_image, b10_image, k12_image, measure_0, points): """ This is an integration test that takes a pair of ISIS cube files and processes them through the smart_subpixel_matcher. This is the same matcher that was used by the CTX control project. The test sets up a session mock with the appropriate data. This directly of indirectly tests the following: - subpixel.smart_register_point - subpixel.subpixel_register_point_smart - subpixel.decider - subpixel.check_for_shift_consensus - subpixel.validate_candidate_measure - transformation.roi.Roi - transformation.affine.estimate_affine_transform """ # Pulled directly from CTX control project. parameters = [ {'match_kwargs': {'image_size':(60,60), 'template_size':(30,30)}}, {'match_kwargs': {'image_size':(75,75), 'template_size':(33,33)}}, {'match_kwargs': {'image_size':(90,90), 'template_size':(36,36)}}, {'match_kwargs': {'image_size':(110,110), 'template_size':(40,40)}}, {'match_kwargs': {'image_size':(125,125), 'template_size':(44,44)}}, {'match_kwargs': {'image_size':(140,140), 'template_size':(48,48)}} ] shared_kwargs = {'cost_func':lambda x,y:y, 'chooser':'smart_subpixel_registration'} for point in points: # Somewhere in subpixel, need to add the offsets back to samp/line based # on which image is being used. Every samp/line, patch time. measures_to_update, measures_to_set_false = smart_register_point(point, session, parameters=parameters, shared_kwargs=shared_kwargs) print(measures_to_update) print(measures_to_set_false) assert measures_to_set_false == [] m0 = measures_to_update[0] # assert m0['sample'] == 528.0616518160688 # assert m0['line'] == 210.8722056871887 # assert m0['template_metric'] == 0.8538808822631836 # assert m0['ignore'] == False # assert m0['template_shift'] == 445.17368002294427 m1 = measures_to_update[1] # assert m1['sample'] == 357.3392609551714 # assert m1['line'] == 230.29507805238129 # assert m1['template_metric'] == 0.6922665238380432 # assert m1['ignore'] == False # assert m1['template_shift'] == 175.5325037366171 dfs = [] with mock.patch('pandas.read_sql') as db_response: db_cnet = pd.DataFrame([ [0, 0, b10_image.serial,measure_0[0].sample, measure_0[0].line, point.pointtype, measure_0[0].measuretype, 'test'], [1, 0, n12_image.serial,m0['sample'], m0['line'], point.pointtype, measure_0[1].measuretype, 'test'], [1, 0, k12_image.serial,m1['sample'], m1['line'], point.pointtype, measure_0[2].measuretype, 'test'], ], columns=['id','pointid', 'serialnumber', 'sample', 'line', 'pointtype', 'measuretype','identifier']) db_response.return_value = db_cnet df = db_to_df(session) dfs.append(df) df = pd.concat(dfs) df.rename(columns={'pointtype':'pointType', 'measuretype':'measureType'}, inplace=True) to_isis(df, 'tests/artifacts/ctx_isis_trio_to_df2.cnet', targetname='Mars') write_filelist([n12_image.path, b10_image.path, k12_image.path], 'tests/artifacts/ctx_isis_trio_to_df2.lis') assert False No newline at end of file