Exemplo n.º 1
0
def updateHeaderUsingArray(header,
                           a,
                           calc_stats=True,
                           reset_origin=True,
                           mz=None):
    '''
	Fills in values of MRC header dictionary using the given array.
	'''
    ndims = len(a.shape)
    nx = a.shape[-1]
    ny = nz = 1
    if ndims > 1:
        ny = a.shape[-2]
        if ndims > 2:
            nz = a.shape[-3]
    header['nx'] = nx
    header['ny'] = ny
    header['nz'] = nz

    mode = numpy2mrc[a.dtype.type]
    header['mode'] = mode

    if mz is None:
        mz = nz
    header['mx'] = nx
    header['my'] = ny
    header['mz'] = mz

    try:
        psize = weakattr.get(a, 'pixelsize')
    except AttributeError:
        header['xlen'] = nx
        header['ylen'] = ny
        header['zlen'] = nz
    else:
        header['xlen'] = nx * psize['x']
        header['ylen'] = ny * psize['y']
        header['zlen'] = mz * psize['x']

    if calc_stats:
        stats = arraystats.all(a)
        header['amin'] = stats['min']
        header['amax'] = stats['max']
        header['amean'] = stats['mean']
        header['rms'] = stats['std']

    if reset_origin is True:
        ### changed next lines to be equivalent to proc3d origin=0,0,0
        header['xorigin'] = 0
        header['yorigin'] = 0
        header['zorigin'] = 0
    if ndims < 3:
        header['nxstart'] = 0
        header['nystart'] = 0
        header['nzstart'] = 0
    else:
        header['nxstart'] = nx / -2
        header['nystart'] = ny / -2
        header['nzstart'] = nz / -2
Exemplo n.º 2
0
def updateHeaderUsingArray(header, a, calc_stats=True, reset_origin=True, mz=None):
    """
	Fills in values of MRC header dictionary using the given array.
	"""
    ndims = len(a.shape)
    nx = a.shape[-1]
    ny = nz = 1
    if ndims > 1:
        ny = a.shape[-2]
        if ndims > 2:
            nz = a.shape[-3]
    header["nx"] = nx
    header["ny"] = ny
    header["nz"] = nz

    mode = numpy2mrc[a.dtype.type]
    header["mode"] = mode

    if mz is None:
        mz = nz
    header["mx"] = nx
    header["my"] = ny
    header["mz"] = mz

    try:
        psize = weakattr.get(a, "pixelsize")
    except AttributeError:
        header["xlen"] = nx
        header["ylen"] = ny
        header["zlen"] = nz
    else:
        header["xlen"] = nx * psize["x"]
        header["ylen"] = ny * psize["y"]
        header["zlen"] = mz * psize["x"]

    if calc_stats:
        stats = arraystats.all(a)
        header["amin"] = stats["min"]
        header["amax"] = stats["max"]
        header["amean"] = stats["mean"]
        header["rms"] = stats["std"]

    if reset_origin is True:
        ### changed next lines to be equivalent to proc3d origin=0,0,0
        header["xorigin"] = 0
        header["yorigin"] = 0
        header["zorigin"] = 0
    if ndims < 3:
        header["nxstart"] = 0
        header["nystart"] = 0
        header["nzstart"] = 0
    else:
        header["nxstart"] = nx / -2
        header["nystart"] = ny / -2
        header["nzstart"] = nz / -2
Exemplo n.º 3
0
def updateHeaderUsingArray(header, a, calc_stats=True, reset_origin=True):
	'''
	Fills in values of MRC header dictionary using the given array.
	'''
	ndims = len(a.shape)
	nx = a.shape[-1]
	ny = nz = 1
	if ndims > 1:
		ny = a.shape[-2]
		if ndims > 2:
			nz = a.shape[-3]
	header['nx'] = nx
	header['ny'] = ny
	header['nz'] = nz

	mode = numpy2mrc[a.dtype.type]
	header['mode'] = mode

	header['mx'] = nx
	header['my'] = ny
	header['mz'] = nz

	try:
		psize = weakattr.get(a, 'pixelsize')
	except AttributeError:
		header['xlen'] = nx
		header['ylen'] = ny
		header['zlen'] = nz
	else:
		header['xlen'] = nx * psize['x']
		header['ylen'] = ny * psize['y']
		header['zlen'] = nz * psize['x']

	if calc_stats:
		stats = arraystats.all(a)
		header['amin'] = stats['min']
		header['amax'] = stats['max']
		header['amean'] = stats['mean']
		header['rms'] = stats['std']

	if reset_origin is True:
		### changed next lines to be equivalent to proc3d origin=0,0,0
		header['xorigin'] = 0
		header['yorigin'] = 0
		header['zorigin'] = 0
	if ndims < 3:
		header['nxstart'] = 0
		header['nystart'] = 0
		header['nzstart'] = 0
	else:	
		header['nxstart'] = nx / -2
		header['nystart'] = ny / -2
		header['nzstart'] = nz / -2
Exemplo n.º 4
0
def getHeader(a):
    """
Return the MRC header for the array, if it has one.
	"""
    return weakattr.get(a, "mrcheader")
Exemplo n.º 5
0
def getHeader(a):
	'''
Return the MRC header for the array, if it has one.
	'''
	return weakattr.get(a, 'mrcheader')
Exemplo n.º 6
0
def getCachedStats(a):
	try:
		return a.stats
	except AttributeError:
		return weakattr.get(a, 'stats')
def getCachedStats(a):
	try:
		return a.stats
	except AttributeError:
		return weakattr.get(a, 'stats')