def setUp(self): self.test_folder = tempfile.mkdtemp(suffix='template_test/') self.tif_folder = os.path.join(self.test_folder, 'tiffs/') os.mkdir(self.tif_folder) # copy across the process list to the working directory self.process_list_path = os.path.join(self.test_folder, 'xrd_template_test.nxs') shutil.copyfile(tu.get_test_process_path('xrd_template_test.nxs'), self.process_list_path) utils.populate_plugins() self.process_list = Content() self.process_list.fopen(self.process_list_path, update=False) for idx in self.process_list.get_positions(): self.process_list.refresh(idx) self.detX_axis_label = {'dim': '$idx_detx', 'name': 'detector_x', 'value': None, 'units': 'pixels'} self.detY_axis_label = {'dim': '$idx_dety', 'name': 'detector_y', 'value': None, 'units': 'pixels'} self.yaml = OrderedDict() # now make some standard modifications self.yaml['inherit'] = [tu.get_test_data_path(os.path.join('i18_templates', 'xrd_calibration.yml'))] self.yaml['xrd'] = OrderedDict() self.yaml['xrd']['params'] = {} self.yaml['xrd']['data'] = {} self.yaml['xrd']['data']['folder'] = self.tif_folder self.yaml['xrd']['params']['cfile'] = \ "$h5py.File('%s', 'r')" % tu.get_test_data_path('LaB6_calibration_new.nxs') self.yaml['xrd']['patterns'] = {} self.yaml['xrd']['patterns']['DIFFRACTION'] = {'core_dims': '$(idx_detx, idx_dety)', 'slice_dims': '$tuple([d for d in dims if d not in [idx_detx, idx_dety]])'} self.yaml['xrd']['axis_labels'] = {} self.yaml['xrd']['metadata'] = {} self.data_file_path = 'test_data.nxs' self.data_file = h5.File(self.data_file_path, 'w') # this will have the axes in.
def setUp(self): self.test_folder = tempfile.mkdtemp(suffix='template_test/') self.tif_folder = os.path.join(self.test_folder, 'tiffs/') os.mkdir(self.tif_folder) # copy across the process list to the working directory self.process_list_path = os.path.join(self.test_folder, 'xrd_template_test.nxs') shutil.copyfile(tu.get_test_process_path('xrd_template_test.nxs'), self.process_list_path) utils.populate_plugins() self.process_list = Content() self.process_list.fopen(self.process_list_path, update=False) for idx in self.process_list.get_positions(): self.process_list.refresh(idx) self.detX_axis_label = { 'dim': '$idx_detx', 'name': 'detector_x', 'value': None, 'units': 'pixels' } self.detY_axis_label = { 'dim': '$idx_dety', 'name': 'detector_y', 'value': None, 'units': 'pixels' } self.yaml = OrderedDict() # now make some standard modifications self.yaml['inherit'] = [ tu.get_test_data_path( os.path.join('i18_templates', 'xrd_calibration.yml')) ] self.yaml['xrd'] = OrderedDict() self.yaml['xrd']['params'] = {} self.yaml['xrd']['data'] = {} self.yaml['xrd']['data']['folder'] = self.tif_folder self.yaml['xrd']['params']['cfile'] = \ "$h5py.File('%s', 'r')" % tu.get_test_data_path('LaB6_calibration_new.nxs') self.yaml['xrd']['patterns'] = {} self.yaml['xrd']['patterns']['DIFFRACTION'] = { 'core_dims': '$(idx_detx, idx_dety)', 'slice_dims': '$tuple([d for d in dims if d not in [idx_detx, idx_dety]])' } self.yaml['xrd']['axis_labels'] = {} self.yaml['xrd']['metadata'] = {} self.data_file_path = 'test_data.nxs' self.data_file = h5.File(self.data_file_path, 'w') # this will have the axes in.
def test_refresh(self): cu.populate_plugins() path = os.path.dirname(os.path.realpath(__file__)).split('scripts')[0] nxs_in_tests, plugins_in_tests = \ tu.get_process_list(path + '/savu/test/travis') lists = tu.get_test_process_list(path + 'test_data/process_lists') \ + tu.get_test_process_list(path+'test_data/test_process_lists') nxs_used = list(set(nxs_in_tests).intersection(set(lists))) test_path = path + '/test_data/test_process_lists' test_path2 = path + '/test_data/process_lists' exclude = ['simple_fit_test_XRF.nxs'] for f in [n for n in nxs_used if n not in exclude]: print f if os.path.exists(os.path.join(test_path, f)): self._refresh_process_file(os.path.join(test_path, f)) else: self._refresh_process_file(os.path.join(test_path2, f))
def test_refresh(self): cu.populate_plugins() path = os.path.dirname(os.path.realpath(__file__)).split('scripts')[0] nxs_in_tests, plugins_in_tests = \ tu.get_process_list(path + '/savu/test/travis') lists = tu.get_test_process_list(path + 'test_data/process_lists') \ + tu.get_test_process_list(path+'test_data/test_process_lists') nxs_used = list(set(nxs_in_tests).intersection(set(lists))) test_path = path + '/test_data/test_process_lists' test_path2 = path + '/test_data/process_lists' exclude = ['simple_fit_test_XRF.nxs'] for f in [n for n in nxs_used if n not in exclude]: print "Refreshing process list", f, "..." if os.path.exists(os.path.join(test_path, f)): self._refresh_process_file(os.path.join(test_path, f)) else: self._refresh_process_file(os.path.join(test_path2, f))
def test_i08_notaux(self): cu.populate_plugins() data_file = tu.get_test_big_data_path('pymca_live_processing_test/i08-10471.nxs') data = h5.File(data_file,'r')['/entry/xmapMca/data'] inputs = {} inputs['data'] = data[0,0,0,:] inputs['dataset_name'] = '' inputs['xaxis_title'] = None metaOnly = False self.persistence = {} self.persistence['sys_path_0_lock'] = threading.Lock() self.persistence['sys_path_0_set'] = False self.persistence['plugin_object'] = None self.persistence['axis_labels'] = None self.persistence['axis_values'] = None self.persistence['string_key'] = None self.persistence['parameters'] = None self.persistence['aux'] = {} params={} params['config']={} params['config']['value'] = tu.get_test_big_data_path('pymca_live_processing_test/10471.cfg') path2plugin = pu.dawn_plugins['Pymca']['path2plugin']# set by dawn-side code self.runSavu(path2plugin, params, metaOnly, inputs)
def test_i08_REGRESSION(self): cu.populate_plugins() data_file = h5.File(tu.get_test_big_data_path('pymca_live_processing_test/dawn_test_result/result.nxs'),'r') data = data_file['/raw_entry/xmapMca/data'] inputs = {} inputs['dataset_name'] = '' inputs['xaxis_title'] = None metaOnly = True self.persistence = {} self.persistence['sys_path_0_lock'] = threading.Lock() self.persistence['sys_path_0_set'] = False self.persistence['plugin_object'] = None self.persistence['axis_labels'] = None self.persistence['axis_values'] = None self.persistence['string_key'] = None self.persistence['parameters'] = None self.persistence['aux'] = {} params={} params['config']={} params['config']['value'] = tu.get_test_big_data_path('pymca_live_processing_test/10471.cfg') path2plugin = pu.dawn_plugins['Pymca']['path2plugin']# set by dawn-side code pts = [(39,51), (45,25), (18,29), (37,96), (8,110)] # just do 5 points for now, is full regression necessary? for y,x in pts: inputs['data'] = data[x,y,0,:] out = self.runSavu(path2plugin, params, metaOnly, inputs) aux = out['auxiliary'] entry = 'entry/auxiliary/0-Python Script - Savu/' for key in aux.keys(): print(key,x,y) foo=data_file[entry+key+'/data'][x,y] self.assertAlmostEqual(aux[key],foo,delta=0.5)
def test_load_plugin(self): cu.populate_plugins() plugin_path = pu.dawn_plugins[dawn_plugins.keys()[0]]['path2plugin'] inst = pu.get_plugin(plugin_path) sl = inst.__dict__['slice_list'] exp = inst.__dict__['exp']
def test_dawn_plugin_params_found(self): cu.populate_plugins() self.assertTrue(isinstance( pu.dawn_plugin_params[pu.dawn_plugins.keys()[0]], dict))
def test_dawn_plugins_found(self): cu.populate_plugins() self.assertGreater(len(pu.dawn_plugins), 0)
def test_populate_plugins(self): cu.populate_plugins()
# refresh positions = content.get_positions() for pos_str in positions: content.refresh(pos_str) # save content.save(content.filename) def generate_test(path): def test(self): self._refresh_process_file(path) return test if __name__ == "__main__": cu.populate_plugins() path = os.path.dirname(os.path.realpath(__file__)).split('scripts')[0] nxs_in_tests, plugins_in_tests = \ tplu.get_process_list(path + '/savu/test/travis') lists = tplu.get_test_process_list(path + 'test_data/process_lists') \ + tplu.get_test_process_list(path+'test_data/test_process_lists') nxs_used = list(set(nxs_in_tests).intersection(set(lists))) test_path = path + '/test_data/test_process_lists' test_path2 = path + '/test_data/process_lists' exclude = ['multimodal/simple_fit_test_XRF.nxs'] for f in [n for n in nxs_used if n not in exclude]: print("Refreshing process list", f, "...") if os.path.exists(os.path.join(test_path, f)):
def test_dawn_plugin_params_found(self): cu.populate_plugins() self.assertTrue( isinstance(pu.dawn_plugin_params[pu.dawn_plugins.keys()[0]], dict))