parameters: (self, dataset)
docstring: Automatic align the tilt axis to horizontal direction (x-axis)
docstring_summary: Automatic align the tilt axis to horizontal direction (x-axis)
docstring_tokens: Automatic align the tilt axis to horizontal direction ( x - axis )
function: def transform(self, dataset):
          """
            Automatic align the tilt axis to horizontal direction (x-axis)
          """
          self.progress.maximum = 1
  
          # Get Tilt Series
          tiltSeries = dataset.active_scalars
  
          if tiltSeries is None: #Check if data exists
              raise RuntimeError("No data array found!")
  
          (Nslice, Nray, Nproj) = tiltSeries.shape
          Intensity = np.zeros(tiltSeries.shape)
  
          self.progress.maximum = Nproj + 131 #coarse(90)+fine(41)
          step = 0
  
          self.progress.message = 'Initialization'
          #take FFT of all projections
          for i in range(Nproj):
              self.progress.message = ('Taking Fourier transform of tilt image'
                                       'No.%d/%d' % (i + 1, Nproj))
              tiltImage = tiltSeries[:, :, i]
              tiltImage_F = np.abs(np.fft.fft2(tiltImage))
              if (i == 0):
                  temp = tiltImage_F[0, 0]
              Intensity[:, :, i] = np.fft.fftshift(tiltImage_F / temp)
              step += 1
              self.progress.value = step
  
          #rescale intensity
          Intensity = np.power(Intensity, 0.2)
  
          #calculate variation itensity image
          Intensity_var = np.var(Intensity, axis=2)
          #search angles
          coarseStep = 2
          fineStep = 0.1
          coarseAngles = np.arange(-90, 90, coarseStep)
  
          Nx = Intensity_var.shape[0]
          Ny = Intensity_var.shape[1]
          N = np.round(np.min([Nx, Ny]) // 3)
  
          #coarse search
          I = np.zeros((coarseAngles.size, N))
          for a in range(coarseAngles.size):
              if self.canceled:
                  return
              self.progress.message = ('Calculating line intensity at angle %f'
                                       'degree' % (coarseAngles[a]))
              I[a, :] = calculateLineIntensity(Intensity_var, coarseAngles[a], N)
              step += 1
              self.progress.value = step
  
          I_sum = np.sum(I, axis=1)
          minIntensityIndex = np.argmin(I_sum)
          rot_ang = coarseAngles[minIntensityIndex]
  
          #now refine
          fineAngles = np.arange(rot_ang - coarseStep,
                                 rot_ang + coarseStep + fineStep, fineStep)
  
          #fine search
          I = np.zeros((fineAngles.size, N))
          for a in range(fineAngles.size):
              if self.canceled:
                  return
              self.progress.message = ('Calculating line intensity at angle %f'
                                       'degree' % (fineAngles[a]))
  
              I[a, :] = calculateLineIntensity(Intensity_var, fineAngles[a], N)
              step += 1
              self.progress.value = step
  
          I_sum = np.sum(I, axis=1)
          minIntensityIndex = np.argmin(I_sum)
          rot_ang = fineAngles[minIntensityIndex]
  
          self.progress.message = 'Rotating tilt series'
          axes = ((0, 1))
          shape = utils.rotate_shape(tiltSeries, -rot_ang, axes=axes)
          result = np.empty(shape, tiltSeries.dtype, order='F')
          ndimage.interpolation.rotate(
              tiltSeries, -rot_ang, axes=axes, output=result)
  
          print("rotate tilt series by %f degrees" % -rot_ang)
  
          # Set the result as the new scalars.
          dataset.active_scalars = result
function_tokens: def transform ( self , dataset ) : self . progress . maximum = 1 # Get Tilt Series tiltSeries = dataset . active_scalars if tiltSeries is None : #Check if data exists raise RuntimeError ( "No data array found!" ) ( Nslice , Nray , Nproj ) = tiltSeries . shape Intensity = np . zeros ( tiltSeries . shape ) self . progress . maximum = Nproj + 131 #coarse(90)+fine(41) step = 0 self . progress . message = 'Initialization' #take FFT of all projections for i in range ( Nproj ) : self . progress . message = ( 'Taking Fourier transform of tilt image' 'No.%d/%d' % ( i + 1 , Nproj ) ) tiltImage = tiltSeries [ : , : , i ] tiltImage_F = np . abs ( np . fft . fft2 ( tiltImage ) ) if ( i == 0 ) : temp = tiltImage_F [ 0 , 0 ] Intensity [ : , : , i ] = np . fft . fftshift ( tiltImage_F / temp ) step += 1 self . progress . value = step #rescale intensity Intensity = np . power ( Intensity , 0.2 ) #calculate variation itensity image Intensity_var = np . var ( Intensity , axis = 2 ) #search angles coarseStep = 2 fineStep = 0.1 coarseAngles = np . arange ( - 90 , 90 , coarseStep ) Nx = Intensity_var . shape [ 0 ] Ny = Intensity_var . shape [ 1 ] N = np . round ( np . min ( [ Nx , Ny ] ) // 3 ) #coarse search I = np . zeros ( ( coarseAngles . size , N ) ) for a in range ( coarseAngles . size ) : if self . canceled : return self . progress . message = ( 'Calculating line intensity at angle %f' 'degree' % ( coarseAngles [ a ] ) ) I [ a , : ] = calculateLineIntensity ( Intensity_var , coarseAngles [ a ] , N ) step += 1 self . progress . value = step I_sum = np . sum ( I , axis = 1 ) minIntensityIndex = np . argmin ( I_sum ) rot_ang = coarseAngles [ minIntensityIndex ] #now refine fineAngles = np . arange ( rot_ang - coarseStep , rot_ang + coarseStep + fineStep , fineStep ) #fine search I = np . zeros ( ( fineAngles . size , N ) ) for a in range ( fineAngles . size ) : if self . canceled : return self . progress . message = ( 'Calculating line intensity at angle %f' 'degree' % ( fineAngles [ a ] ) ) I [ a , : ] = calculateLineIntensity ( Intensity_var , fineAngles [ a ] , N ) step += 1 self . progress . value = step I_sum = np . sum ( I , axis = 1 ) minIntensityIndex = np . argmin ( I_sum ) rot_ang = fineAngles [ minIntensityIndex ] self . progress . message = 'Rotating tilt series' axes = ( ( 0 , 1 ) ) shape = utils . rotate_shape ( tiltSeries , - rot_ang , axes = axes ) result = np . empty ( shape , tiltSeries . dtype , order = 'F' ) ndimage . interpolation . rotate ( tiltSeries , - rot_ang , axes = axes , output = result ) print ( "rotate tilt series by %f degrees" % - rot_ang ) # Set the result as the new scalars. dataset . active_scalars = result