def export_roi_to_workspace_mdevent(self, slicepoint: Sequence[Optional[float]], bin_params: Sequence[float], limits: tuple, transpose: bool): """ Export 2D roi to a separate workspace. :param slicepoint: ND sequence of either None or float. A float defines the point in that dimension for the slice. :param bin_params: ND sequence containing the number of bins for each dimension :param limits: An optional ND sequence containing limits for plotting dimensions. If not provided the full extent of each dimension is used :param transpose: If true the limits are transposed w.r.t the data """ workspace = self._get_ws() if transpose: limits = limits[1], limits[0] params, xindex, yindex = _roi_binmd_parameters(workspace, slicepoint, bin_params, limits) params['OutputWorkspace'] = self._roi_name roi_ws = BinMD(InputWorkspace=self._get_ws(), **params) roi_ws.clearOriginalWorkspaces() if transpose: _inplace_transposemd(self._roi_name, axes=[yindex, xindex]) return f'ROI created: {self._roi_name}'
def PyExec(self): input_ws = self.getProperty("InputWorkspace").value extents = self.getProperty("Extents").value bins = self.getProperty("Bins").value # Get the UB from either the PeaksWS if provided, or from the input workspace if not self.getProperty("PeaksWorkspace").isDefault: peak_ws = self.getProperty("PeaksWorkspace").value self._lattice = peak_ws.sample().getOrientedLattice() else: self._lattice = input_ws.getExperimentInfo( 0).sample().getOrientedLattice() # Get axis names and units from u,v,w projections, as done in ConvertWANDSCDtoQ: w = np.eye(3) w[:, 0] = self.getProperty("Uproj").value w[:, 1] = self.getProperty("Vproj").value w[:, 2] = self.getProperty("Wproj").value char_dict = {0: '0', 1: '{1}', -1: '-{1}'} chars = ['H', 'K', 'L'] names = [ '[' + ','.join( char_dict.get(j, '{0}{1}').format( j, chars[np.argmax(np.abs(w[:, i]))]) for j in w[:, i]) + ']' for i in range(3) ] q = [self._lattice.qFromHKL(w[:, i]) for i in range(3)] units = ['in {:.3f} A^-1'.format(q[i].norm()) for i in range(3)] output_name = self.getPropertyValue("OutputWorkspace") CloneMDWorkspace(InputWorkspace=input_ws, OutputWorkspace=output_name) SetMDFrame(InputWorkspace=output_name, MDFrame='HKL', Axes='0,1,2') mdhist = BinMD( InputWorkspace=output_name, AxisAligned=False, NormalizeBasisVectors=False, BasisVector0='{},{},{},{},{}'.format(names[0], units[0], q[0].X(), q[0].Y(), q[0].Z()), BasisVector1='{},{},{},{},{}'.format(names[1], units[1], q[1].X(), q[1].Y(), q[1].Z()), BasisVector2='{},{},{},{},{}'.format(names[2], units[2], q[2].X(), q[2].Y(), q[2].Z()), OutputExtents=extents, OutputBins=bins) self.setProperty("OutputWorkspace", mdhist) mdhist.clearOriginalWorkspaces() DeleteWorkspace(mdhist)