def loadUBFiles(self, ubFiles, omegaHand, phiHand, omegaLogName, phiLogName): """ load the ub files and update the :param ubFiles: list of paths to saved UB files :param omegaHand: handedness of omega rotation (ccw/cw) :param phiHand: handedness of phi rotation (ccw/cw) :param omegaLogName: name of log entry for omega angle :param phiLogName: name of log entry for phi angle :return: matUB: list containing the UB for each run :return: omega: array of omega values from log of each run :return: phiRef: array of nominal phi values from log of each run """ matUB = [] # container to hold UB matrix arrays omega = np.zeros( len(ubFiles)) # rot around vertical axis (assumed to be correct) phiRef = np.zeros( len(ubFiles)) # rot around gonio axis (needs to be refined) for irun in range(0, len(ubFiles)): # get rotation angles from logs (handedness given in input) # these rotation matrices are defined in right-handed coordinate system (i.e. omegaHand = 1 etc.) _, fname = path.split(ubFiles[irun]) dataPath = FileFinder.findRuns(fname.split('.mat')[0])[0] tmpWS = CreateSampleWorkspace(StoreInADS=False) if dataPath[-4:] == ".raw": # assume log is kept separately in a .log file with same path LoadLog(Workspace=tmpWS, Filename="".join(dataPath[:-4] + '.log')) elif dataPath[-4:] == '.nxs': # logs are kept with data in nexus file LoadNexusLogs(Workspace=tmpWS, Filename=dataPath) # read omega and phi (in RH coords) omega[irun] = omegaHand * tmpWS.getRun().getLogData( omegaLogName).value[0] phiRef[irun] = phiHand * tmpWS.getRun().getLogData( phiLogName).value[0] # load UB LoadIsawUB(InputWorkspace=tmpWS, Filename=ubFiles[irun], CheckUMatrix=True) tmpUB = tmpWS.sample().getOrientedLattice().getUB() # permute axes to use IPNS convention (as in saved .mat file) matUB += [tmpUB[[2, 0, 1], :]] DeleteWorkspace(tmpWS) return matUB, omega, phiRef
def test_output_sample_logs_without_rb_number(self, mock_csv, mock_path, mock_logger): mock_writer = MagicMock() mock_csv.writer.return_value = mock_writer mock_path.return_value = self.test_dir ws = CreateSampleWorkspace() self.model._output_sample_logs("ENGINX", "00000", "00000", ws, None) self.assertEqual(5, len(ws.getRun().keys())) self.assertEqual(1, mock_logger.information.call_count) self.assertEqual(4, mock_writer.writerow.call_count)