def test_load_all_indiv(self): """ Load a few files with different options and check they load correctly """ group_name = 'all_fits_rect' for fpath in self._fits_paths: group = msapi.LoadFITS(Filename=fpath, LoadAsRectImg=True, OutputWorkspace=group_name) group_norect_name = 'all_fits_norect' for fpath in self._fits_paths: group_norect = msapi.LoadFITS(Filename=fpath, LoadAsRectImg=False, OutputWorkspace=group_norect_name) self.assertEquals(group.size(), group_norect.size()) for idx in range(0, group.size()): img_a = group.getItem(idx) size_a = img_a.getNumberHistograms() * img_a.blocksize() img_b = group_norect.getItem(idx) size_b = img_b.getNumberHistograms() * img_b.blocksize() self.assertEquals(size_a, size_b) self.assertEquals(img_a.getTitle(), img_b.getTitle()) for row in [0, 100, 200, 300, 400, 511]: self.assertEquals( img_a.readY(row)[0], img_b.readY(row * img_a.blocksize() + 0)) msapi.DeleteWorkspace(group_name) msapi.DeleteWorkspace(group_norect_name)
def test_load_save_load(self): """ Check that nothing is lost in a Load/Save/Load cycle """ group_name = 'all_indiv' for fpath in self._fits_paths: msapi.LoadFITS(Filename=fpath, LoadAsRectImg=True, OutputWorkspace=group_name) group = msapi.mtd[group_name] for idx in range(0, group.size()): # Save img_loaded = group.getItem(idx) save_filename = 'test.fits' msapi.SaveFITS(Filename=save_filename, InputWorkspace=img_loaded) # Re-load and compare reload_name = 'indiv_fits_reloaded' grp_reloaded = msapi.LoadFITS(Filename=save_filename, LoadAsRectImg=True, OutputWorkspace=reload_name) self.assertEquals(1, grp_reloaded.size()) img_reloaded = grp_reloaded.getItem(0) self.assertEquals(img_loaded.getNumberHistograms(), img_reloaded.getNumberHistograms()) self.assertEquals(img_loaded.blocksize(), img_reloaded.blocksize()) (comp_result, tbl_messages) = msapi.CompareWorkspaces(img_loaded, img_reloaded) num_rows = tbl_messages.rowCount() txt_messages = [tbl_messages.row(idx) for idx in range(0, num_rows)] self.assertTrue(comp_result, "Workspace comparison failed. Details: {0}".format(txt_messages)) msapi.DeleteWorkspace(grp_reloaded) msapi.DeleteWorkspace(group_name)
def setUp(self): # example files to make a stack of images _raw_files = ['LARMOR00005328_Metals_000_SummedImg_1.fits', 'LARMOR00005329_Metals_000_SummedImg_2.fits', 'LARMOR00005330_Metals_000_SummedImg_3.fits', 'LARMOR00005331_Metals_000_SummedImg_4.fits', 'LARMOR00005332_Metals_000_SummedImg_5.fits' ] # a name for the stack / group of workspaces _data_wsname = 'small_img_stack' self.__class__.test_input_dir = 'some_imaging_test_path_in' self.__class__.test_output_dir = 'some_imaging_test_path_out' if not self.__class__.data_wsg: filename_string = ",".join(_raw_files) # Load all images into a workspace group, one matrix workspace per image self.__class__.data_wsg = sapi.LoadFITS(Filename=filename_string, LoadAsRectImg=True, OutputWorkspace=_data_wsname) self.__class__.data_vol = self._ws_group_to_data_vol(self.data_wsg) # double-check before every test that the input workspaces are available and of the # correct types if not self.data_wsg or not _data_wsname in mtd: raise RuntimeError("Input workspace not available") # this could use assertIsInstance (new in version 2.7) self.assertTrue(isinstance(self.data_wsg, WorkspaceGroup)) img_workspaces = [ self.data_wsg.getItem(i) for i in range(0, self.data_wsg.size()) ] for wksp in img_workspaces: self.assertTrue(isinstance(wksp, MatrixWorkspace))
def test_run_ok(self): if not os.path.exists(self._out_dir): os.mkdir(self._out_dir) num_proj, num_bands = msapi.ImggAggregateWavelengths(InputPath = self._raw_files_dir, OutputPath = self._out_dir) self.assertEquals(num_proj, 4) self.assertEquals(num_bands, 6) # (x,y) coordinates of some pixels ref_positions = [(44, 77), (312, 265), (480, 397), (118, 109), (0, 0), (511, 0), (0, 511), (511, 511)] # Their expected values in every of the output images ref_values = [[0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [2, 1, 2, 3, 6, 5, 2, 3], [5, 3, 4, 7, 4, 1, 5, 5]] for ref_val in ref_values: self.assertEquals(len(ref_positions), len(ref_val)) for image_idx, fname in enumerate(self._expected_out_fnames): fname = os.path.join(self._out_dir, fname) group_name = 'loaded_fits' group = msapi.LoadFITS(Filename=fname, LoadAsRectImg=True, OutputWorkspace=group_name) self.assertEquals(image_idx+1, group.size()) wks = group.getItem(group.size()-1) self.assertEquals(wks.getNumberHistograms(), 512) self.assertEquals(wks.blocksize(), 512) for pos_idx, pos in enumerate(ref_positions): self.assertEquals(wks.readY(pos[1])[pos[0]], ref_values[image_idx][pos_idx]) msapi.DeleteWorkspace(group_name) self._cleanup_dirs_files()
def test_load_all_at_once(self): """ A batch load, as when stacks are loaded at once """ all_filepaths = ','.join(self._fits_paths) group = msapi.LoadFITS(Filename=all_filepaths, LoadAsRectImg=True) self.assertEquals(group.size(), len(self._fits_paths)) msapi.DeleteWorkspace(group)