Пример #1
0
def setMapyx(fn, doc):
    """
    set doc.mapyx from the filename(fn)
    """
    arr = Mrc.bindFile(fn)
    nz = arr.Mrc.hdr.Num[-1] / (arr.Mrc.hdr.NumTimes * arr.Mrc.hdr.NumWaves *
                                2)
    arr = arr.reshape((arr.Mrc.hdr.NumTimes, arr.Mrc.hdr.NumWaves, nz, 2,
                       arr.Mrc.hdr.Num[1], arr.Mrc.hdr.Num[0]))
    doc.mapyx = arr
Пример #2
0
def setMapyx(fn, doc):
    """
    set doc.mapyx from the filename(fn)
    """
    arr = Mrc.bindFile(fn)
    nz = arr.Mrc.hdr.Num[-1] / (arr.Mrc.hdr.NumTimes * arr.Mrc.hdr.NumWaves * 2)
    arr = arr.reshape((arr.Mrc.hdr.NumTimes, 
                       arr.Mrc.hdr.NumWaves, 
                       nz, 
                       2, 
                       arr.Mrc.hdr.Num[1], 
                       arr.Mrc.hdr.Num[0]))
    doc.mapyx = arr
Пример #3
0
def main():
    """Collect input filename, create output file, and filter each slice"""

    input_path = sys.argv[1]
    if not os.path.exists(input_path):
        print "Cannot find file: " + input_path
        sys.exit()
    else:
        # Fourier Filter Stripes: copy to new file (data will be overwritten)
        output_path = addTag(input_path, "FFS")
        shutil.copy2(input_path, output_path)
        # NB. Mrc is a special numpy ndarray with extra metadata attached
        fMrc = Mrc.bindFile(output_path, writable=1)
        # make a view of the data ndarray that is a flat list of XY slices
        nplanes = reduce(lambda x, y: x * y, fMrc.shape[:-2])
        ny, nx = fMrc.shape[-2:]
        xy_slices = fMrc.reshape((nplanes, ny, nx))
        # filter out stripes from each slice of the whole stack (in-place)
        for p in range(nplanes):
            xy_slices[p, :, :] = filter_stripes(xy_slices[p, :, :])
Пример #4
0
    def __init__(self, MRC_path):
        ## gb, Oct2012 - load an Mrc file here in DataDoc - previously this 
        #  Class  was initialized with an existing Mrc object.
        #  Note an Mrc object is not just a numpy ndarray of pixels.
        image = Mrc.bindFile(MRC_path) 
        self.image = image

        ## Header for the image data, which tells us e.g. what the ordering
        # of X/Y/Z/time/wavelength is in the MRC file.
        self.imageHeader = Mrc.implement_hdr(image.Mrc.hdr._array.copy())
        ## Location the file is saved on disk.
        self.filePath = image.Mrc.path

        ## Number of wavelengths in the array.
        self.numWavelengths = self.imageHeader.NumWaves
        numTimepoints = self.imageHeader.NumTimes
        numX = self.imageHeader.Num[0]
        numY = self.imageHeader.Num[1]
        numZ = self.imageHeader.Num[2] // (self.numWavelengths * numTimepoints)
        ## Size in pixels of the data, since having it as a Numpy array
        # instead of a tuple (from self.imageArray.shape) is occasionally
        # handy.
        self.size = numpy.array([self.numWavelengths, numTimepoints, numZ, numY, numX], dtype = numpy.int)
        ## 5D array of pixel data, indexed as 
        # self.imageArray[wavelength][time][z][y][x]
        # In other words, in WTZYX order. In general we try to treat 
        # Z and time as "just another axis", but wavelength is dealt with
        # specially.
        self.imageArray = self.getImageArray()
        ## Datatype of our array.
        self.dtype = self.imageArray.dtype.type

        ## Averages for each wavelength, used to provide fill values when
        # taking slices.
        self.averages = []
        for wavelength in xrange(self.numWavelengths):
            self.averages.append(self.imageArray[wavelength].mean())

        ## Lower boundary of the cropped data.
        self.cropMin = numpy.array([0, 0, 0, 0, 0], numpy.int32)
        ## Upper boundary of the cropped data.
        self.cropMax = numpy.array(self.size, numpy.int32)
        
        ## Index of the single pixel that is visible in all different data
        # views.
        self.curViewIndex = numpy.array(self.size / 2, numpy.int)
        # Initial time view is at 0
        self.curViewIndex[1] = 0

        ## Parameters for transforming different wavelengths so they align 
        # with each other. Order is dx, dy, dz, angle, zoom
        self.alignParams = numpy.zeros((self.size[0], 5), numpy.float32)
        # Default zoom to 1.0
        self.alignParams[:,4] = 1.0

        ## List of functions to call whenever the alignment parameters change.
        # Each will be passed self.alignParams so it can take whatever
        # action is necessary.
        self.alignCallbacks = []

        ## gb, Oct2012
        # get a list of the true wavelengths so we can tell the user
        self.channelWaves = self.getChannelWaves()