Exemplo n.º 1
0
def unRotationalAverage(xdata, ydata, shape):
	"""
	compute the rotational average of a 2D numpy array
	"""
	image = imagefun.fromRadialFunction(funcrad, shape, 
		xdata=xdata, ydata=ydata, dtype=numpy.float64)
	return image
Exemplo n.º 2
0
def unEllipticalAverage(xdata, ydata, ellipratio, ellipangle, shape):
    """
	compute the rotational average of a 2D numpy array

	ellip angle is positive toward y-axis
	"""
    radial = getEllipticalDistanceArray(ellipratio, ellipangle, shape)
    radial = radial / math.sqrt(ellipratio)
    image = imagefun.fromRadialFunction(funcrad,
                                        shape,
                                        xdata=xdata,
                                        ydata=ydata)

    def funcrc(r, c, radial, **kwargs):
        rr = numpy.array(numpy.floor(r), dtype=numpy.int)
        cc = numpy.array(numpy.floor(c), dtype=numpy.int)
        rad = radial[rr, cc]
        return funcrad(rad, **kwargs)

    result = numpy.fromfunction(funcrc,
                                shape,
                                radial=radial,
                                xdata=xdata,
                                ydata=ydata,
                                dtype=numpy.float64)
    return result
Exemplo n.º 3
0
def unRotationalAverage(xdata, ydata, shape):
        """
        compute the rotational average of a 2D numpy array
        """
        image = imagefun.fromRadialFunction(funcrad, shape, 
                xdata=xdata, ydata=ydata, dtype=numpy.float64)
        return image
Exemplo n.º 4
0
def twodHann(size):
	rsize = int(math.ceil(size*math.sqrt(2)))
	xdata = numpy.arange(rsize)+0.5
	xdata = xdata - xdata.mean()
	ydata = numpy.hanning(rsize)
	#ydata = numpy.hstack(([1], ydata))
	hanntwod = imagefun.fromRadialFunction(funcrad, (size,size), xdata=xdata, ydata=ydata)
	return hanntwod
Exemplo n.º 5
0
def unEllipticalAverage(xdata, ydata, ellipratio, ellipangle, shape):
	"""
	compute the rotational average of a 2D numpy array

	ellip angle is positive toward y-axis
	"""
	radial = getEllipticalDistanceArray(ellipratio, ellipangle, shape)
	radial = radial/math.sqrt(ellipratio)
	image = imagefun.fromRadialFunction(funcrad, shape, xdata=xdata, ydata=ydata)
	def funcrc(r, c, radial, **kwargs):
		rr = numpy.array(numpy.floor(r), dtype=numpy.int)
		cc = numpy.array(numpy.floor(c), dtype=numpy.int)
		rad = radial[rr,cc]
		return funcrad(rad, **kwargs)
	result = numpy.fromfunction(funcrc, shape, radial=radial, 
		xdata=xdata, ydata=ydata, dtype=numpy.float64)
	return result
	def prepareEnvelope(self, scaleFactor=1.0):
		"""
		Original envelop mrc pixel size was 0.98 Angstroms, but may be better to say 1.04 Angstroms

		Now converts a 1D array into the 2D spectra
		"""
		apDisplay.printMsg("Creating 2D envelop from 1D array")
		envelope = self.params['envelopefile']
		if envelope is None:
			return
		spi = open(envelope, 'r')
		radialdata = []
		for line in spi:
			sline = line.strip()
			if not sline or sline[0] == ";":
				continue
			spidict = operations.spiderInLine(line)
			# second float column
			radialvalue = spidict['floatlist'][1]
			radialdata.append(radialvalue)
		spi.close()

		### create envelop in 2D
		xdata = numpy.arange(0, len(radialdata), 1.0, dtype=numpy.float32)
		rdata = numpy.array(radialdata, dtype=numpy.float32)
		def funcrad(r, xdata=None, rdata=None):
			return numpy.interp(r, xdata, rdata)
		envshape = (4096, 4096)
		envcalc = imagefun.fromRadialFunction(funcrad, envshape, xdata=xdata, rdata=rdata)

		### scale envelope
		if abs(scaleFactor - 1.0) > 0.01:
			print "scaling envelope by", scaleFactor
			envcalc = ndimage.zoom(envcalc, zoom=scaleFactor, mode='nearest')
		### shift center of envelope to the edges
		envamp = self.center(envcalc)
		### mutliply real envelope function by image fft
		self.envamp = (envamp - envamp.min()) / (envamp.max() - envamp.min())
		apDisplay.printMsg("Successfully created 2D envelop from 1D array")
	def prepareEnvelope(self, scaleFactor=1.0):
		"""
		Original envelop mrc pixel size was 0.98 Angstroms, but may be better to say 1.04 Angstroms

		Now converts a 1D array into the 2D spectra
		"""
		apDisplay.printMsg("Creating 2D envelop from 1D array")
		envelope = self.params['envelopefile']
		if envelope is None:
			return
		spi = open(envelope, 'r')
		radialdata = []
		for line in spi:
			sline = line.strip()
			if not sline or sline[0] == ";":
				continue
			spidict = operations.spiderInLine(line)
			# second float column
			radialvalue = spidict['floatlist'][1]
			radialdata.append(radialvalue)
		spi.close()

		### create envelop in 2D
		xdata = numpy.arange(0, len(radialdata), 1.0, dtype=numpy.float32)
		rdata = numpy.array(radialdata, dtype=numpy.float32)
		def funcrad(r, xdata=None, rdata=None):
			return numpy.interp(r, xdata, rdata)
		envshape = (4096, 4096)
		envcalc = imagefun.fromRadialFunction(funcrad, envshape, xdata=xdata, rdata=rdata)

		### scale envelope
		if abs(scaleFactor - 1.0) > 0.01:
			print "scaling envelope by", scaleFactor
			envcalc = ndimage.zoom(envcalc, zoom=scaleFactor, mode='nearest')
		### shift center of envelope to the edges
		envamp = self.center(envcalc)
		### mutliply real envelope function by image fft
		self.envamp = (envamp - envamp.min()) / (envamp.max() - envamp.min())
		apDisplay.printMsg("Successfully created 2D envelop from 1D array")
Exemplo n.º 8
0
	def Array1dintoArray2d(self, array1d, shape):
		array2d = imagefun.fromRadialFunction(self.funcrad, shape, rdata=rdata, zdata=array1d)
		return array2d