Exemplo n.º 1
0
    def loadIMAGE(self, event=None):
        wildcards = 'XRD image (*.edf,*.tif,*.tiff)|*.tif;*.tiff;*.edf|All files (*.*)|*.*'
        dlg = wx.FileDialog(self,
                            message='Choose XRD calibration file',
                            defaultDir=os.getcwd(),
                            wildcard=wildcards,
                            style=wx.FD_OPEN)

        path, read = None, False
        if dlg.ShowModal() == wx.ID_OK:
            read = True
            path = dlg.GetPath().replace('\\', '/')
        dlg.Destroy()

        if read:
            try:
                #                 self.raw_img = plt.imread(path)
                self.raw_img = tifffile.imread(path)
                #self.raw_img = fabio.open(path).data
            except:
                print('Image not properly opened.')
                pass
            self.plot2Dimg.display(self.raw_img)
            self.plot2Dimg.redraw()
            self.AutoContrast()

            self.entr_calimg.Clear()
            self.entr_calimg.SetValue(path)  #os.path.split(path)[-1]
Exemplo n.º 2
0
    def openMask(self,event=None):

        wildcards = 'pyFAI mask file (*.edf)|*.edf|All files (*.*)|*.*'
        dlg = wx.FileDialog(self, message='Choose pyFAI mask file',
                           defaultDir=os.getcwd(),
                           wildcard=wildcards, style=wx.FD_OPEN)

        path, read = None, False
        if dlg.ShowModal() == wx.ID_OK:
            read = True
            path = dlg.GetPath().replace('\\', '/')
        dlg.Destroy()

        if read:
            try:
                try:
                    raw_mask = np.array(tifffile.imread(path))
                except:
                    import fabio
                    raw_mask = fabio.open(path).data
                self.msk_img = np.ones(raw_mask.shape)-raw_mask
                self.checkIMAGE()
                print('Reading mask:\n\t%s' % path)
            except:
                print('\nCannot read as mask file: %s\n' % path)
                return

        self.ch_msk.SetValue(True)
        self.applyMask(event=True)
Exemplo n.º 3
0
    def loadIMAGE(self,event=None):
        wildcards = '2DXRD image files (*.*)|*.*|All files (*.*)|*.*'
        dlg = wx.FileDialog(self, message='Choose 2D XRD image',
                           defaultDir=os.getcwd(),
                           wildcard=wildcards, style=wx.FD_OPEN)

        path, read = '', False
        if dlg.ShowModal() == wx.ID_OK:
            read = True
            path = dlg.GetPath().replace('\\', '/')
        dlg.Destroy()

        if read:
            print('\nReading XRD image file: %s' % path)

            image,xrmfile = None,None
            try:
                xrmfile = h5py.File(path, 'r')
            except IOError:
                try:
                    from larch_plugins.xrmmap import read_xrd_netcdf #,GSEXRM_MapFile
                    image = read_xrd_netcdf(path)
                except TypeError:
                    try:
                        image = tifffile.imread(path)
                    except ValueError:
                        print('Could not read file.')
                        return

            iname = os.path.split(path)[-1]
            self.plot2Dxrd(iname, image, path=path, h5file=xrmfile)
Exemplo n.º 4
0
    def loadIMAGE(self,event=None): 
        wildcards = 'XRD image (*.edf,*.tif,*.tiff)|*.tif;*.tiff;*.edf|All files (*.*)|*.*'
        if os.path.exists(self.entr_calimg.GetValue()):
           dfltDIR = self.entr_calimg.GetValue()
        else:
           dfltDIR = os.getcwd()

        dlg = wx.FileDialog(self, message='Choose XRD calibration file',
                           defaultDir=dfltDIR,
                           wildcard=wildcards, style=wx.FD_OPEN)

        path, read = None, False
        if dlg.ShowModal() == wx.ID_OK:
            read = True
            path = dlg.GetPath().replace('\\', '/')
        dlg.Destroy()
        
        if read:
            try:
#                 self.raw_img = plt.imread(path)
                self.raw_img = tifffile.imread(path)
                #self.raw_img = fabio.open(path).data
            except:
                print('Image not properly opened.')
                pass
            self.plot2Dimg.display(self.raw_img)       
            self.plot2Dimg.redraw()
            self.AutoContrast()

            self.entr_calimg.Clear()
            self.entr_calimg.SetValue(path) #os.path.split(path)[-1]
Exemplo n.º 5
0
    def openMask(self, event=None):

        wildcards = 'pyFAI mask file (*.edf)|*.edf|All files (*.*)|*.*'
        dlg = wx.FileDialog(self,
                            message='Choose pyFAI mask file',
                            defaultDir=os.getcwd(),
                            wildcard=wildcards,
                            style=wx.FD_OPEN)

        path, read = None, False
        if dlg.ShowModal() == wx.ID_OK:
            read = True
            path = dlg.GetPath().replace('\\', '/')
        dlg.Destroy()

        if read:
            try:
                try:
                    raw_mask = np.array(tifffile.imread(path))
                except:
                    import fabio
                    raw_mask = fabio.open(path).data
                self.msk_img = np.ones(raw_mask.shape) - raw_mask
                self.checkIMAGE()
                print('Reading mask: %s' % path)
            except:
                print('Cannot read as mask file: %s' % path)
                return

        self.ch_msk.SetValue(True)
        self.applyMask(event=True)
Exemplo n.º 6
0
    def loadIMAGE(self, event=None):
        wildcards = 'XRD image (*.edf,*.tif,*.tiff)|*.tif;*.tiff;*.edf|All files (*.*)|*.*'
        dlg = wx.FileDialog(self,
                            message='Choose XRD image',
                            defaultDir=os.getcwd(),
                            wildcard=wildcards,
                            style=wx.FD_OPEN)

        path, read = None, False
        if dlg.ShowModal() == wx.ID_OK:
            read = True
            path = dlg.GetPath().replace('\\', '/')
        dlg.Destroy()

        if read:
            try:
                #                 self.raw_img = plt.imread(path)
                self.raw_img = tifffile.imread(path)
                #self.raw_img = fabio.open(path).data
            except:
                print('Image not properly opened.')
                self.raw_img = np.zeros((1024, 1024))
        else:
            print('No image selected.')
            self.raw_img = np.zeros((1024, 1024))
Exemplo n.º 7
0
def integrate_xrd_row(rowxrd2d,
                      calfile,
                      unit='q',
                      steps=10001,
                      wedge_limits=None,
                      mask=None,
                      dark=None,
                      flip=True):
    '''
    Uses pyFAI (poni) calibration file to produce 1D XRD data from a row of 2D XRD images 

    Must provide pyFAI calibration file
    
    rowxrd2d     : 2D diffraction images for integration
    calfile      : poni calibration file
    unit         : unit for integration data ('2th'/'q'); default is 'q'
    steps        : number of steps in integration data; default is 10000
    wedge_limits : azimuthal slice limits
    mask         : mask array for image
    dark         : dark image array
    flip         : vertically flips image to correspond with Dioptas poni file calibration
    '''

    if HAS_pyFAI:
        try:
            ai = pyFAI.load(calfile)
        except:
            print('Provided calibration file could not be loaded.')
            return

        if type(dark) is str:
            try:
                dark = np.array(tifffile.imread(xrd2dbkgd))
            except:
                dark = None

        dir = -1 if flip else 1
        attrs = {'mask': mask, 'dark': dark}
        if unit.startswith('2th'):
            attrs.update({'unit': '2th_deg'})
        else:
            attrs.update({'unit': 'q_A^-1'})

        if wedge_limits is not None:
            attrs.update({'azimuth_range': wedge_limits})

        q, xrd1d = [], []

        for i, xrd2d in enumerate(rowxrd2d):
            row_q, row_xrd1d = calcXRD1d(xrd2d[::dir, :], ai, steps, attrs)
            q += [row_q]
            xrd1d += [row_xrd1d]

        return np.array(q), np.array(xrd1d)
    else:
        print('pyFAI not imported. Cannot calculate 1D integration.')
Exemplo n.º 8
0
def integrate_xrd_row(rowxrd2d, calfile, unit='q', steps=2048,
                      wedge_limits=None, mask=None, dark=None,
                      flip=True):
    '''
    Uses pyFAI (poni) calibration file to produce 1D XRD data from a row of 2D XRD images

    Must provide pyFAI calibration file

    rowxrd2d     : 2D diffraction images for integration
    calfile      : poni calibration file
    unit         : unit for integration data ('2th'/'q'); default is 'q'
    steps        : number of steps in integration data; default is 10000
    wedge_limits : azimuthal slice limits
    mask         : mask array for image
    dark         : dark image array
    flip         : vertically flips image to correspond with Dioptas poni file calibration
    '''

    if not HAS_pyFAI:
        print('pyFAI not imported. Cannot calculate 1D integration.')
        return

    try:
        ai = pyFAI.load(calfile)
    except:
        print('calibration file "%s" could not be loaded.' % calfile)
        return

    if type(dark) is str:
        try:
            dark = np.array(tifffile.imread(xrd2dbkgd))
        except:
            dark = None

    dir = -1 if flip else 1
    attrs = dict(mask=mask, dark=dark, method='csr',
             polarization_factor=0.999, correctSolidAngle=True)

    if unit.startswith('2th'):
        attrs.update({'unit':'2th_deg'})
    else:
        attrs.update({'unit':'q_A^-1'})

    if wedge_limits is not None:
        attrs.update({'azimuth_range':wedge_limits})

    # print("Calc XRD 1D for row", ai, steps, attrs)
    q, xrd1d = [], []
    for i, xrd2d in enumerate(rowxrd2d):
        row_q,row_xrd1d = calcXRD1d(xrd2d[::dir,:], ai, steps, attrs)
        q     += [row_q]
        xrd1d += [row_xrd1d]

    return np.array(q), np.array(xrd1d)
Exemplo n.º 9
0
def read_xrd_data(filepath):

    if not os.path.exists(filepath):
        return

    try:
        data = np.array(tifffile.imread(filepath))
    except:  # TypeError:
        try:
            from larch_plugins.xrmmap import read_xrd_netcdf
            data = np.array(read_xrd_netcdf(filepath))
        except:
            try:
                data = xrd1d(file=filepath).I
            except:
                return
    return data
Exemplo n.º 10
0
    def openBkgd(self, event=None):

        wildcards = 'XRD background image (*.edf,*.tif,*.tiff)|*.tif;*.tiff;*.edf|All files (*.*)|*.*'
        dlg = wx.FileDialog(self,
                            message='Choose XRD background image',
                            defaultDir=os.getcwd(),
                            wildcard=wildcards,
                            style=wx.FD_OPEN)

        path, read = None, False
        if dlg.ShowModal() == wx.ID_OK:
            read = True
            path = dlg.GetPath().replace('\\', '/')
        dlg.Destroy()

        if read:
            self.bkgd = tifffile.imread(path)
            self.checkIMAGE()
Exemplo n.º 11
0
    def loadIMAGE(self, event=None):

        wildcards = 'XRD image (*.edf,*.tif,*.tiff)|*.tif;*.tiff;*.edf|All files (*.*)|*.*'
        dlg = wx.FileDialog(self,
                            message='Choose 2D XRD image',
                            defaultDir=os.getcwd(),
                            wildcard=wildcards,
                            style=wx.FD_OPEN)

        path, read = None, False
        if dlg.ShowModal() == wx.ID_OK:
            read = True
            path = dlg.GetPath().replace('\\', '/')
        dlg.Destroy()

        if read:
            print('Reading file: %s' % path)
            newimg = tifffile.imread(path)

            self.plot2Dxrd(newimg, os.path.split(path)[-1])
Exemplo n.º 12
0
    def openBkgd(self,event=None):

        wildcards = 'XRD background image (*.edf,*.tif,*.tiff)|*.tif;*.tiff;*.edf|All files (*.*)|*.*'
        dlg = wx.FileDialog(self, message='Choose XRD background image',
                           defaultDir=os.getcwd(),
                           wildcard=wildcards, style=wx.FD_OPEN)

        path, read = None, False
        if dlg.ShowModal() == wx.ID_OK:
            read = True
            path = dlg.GetPath().replace('\\', '/')
        dlg.Destroy()

        if read:
            try:
                self.bkgd_img = np.array(tifffile.imread(path))
                self.checkIMAGE()
                print('Reading background:\n\t%s' % path)
            except:
                print('\nCannot read as an image file: %s\n' % path)
                return
Exemplo n.º 13
0
    def loadIMAGE(self,event=None): 
        wildcards = 'XRD image (*.edf,*.tif,*.tiff)|*.tif;*.tiff;*.edf|All files (*.*)|*.*'
        dlg = wx.FileDialog(self, message='Choose XRD image',
                           defaultDir=os.getcwd(),
                           wildcard=wildcards, style=wx.FD_OPEN)

        path, read = None, False
        if dlg.ShowModal() == wx.ID_OK:
            read = True
            path = dlg.GetPath().replace('\\', '/')
        dlg.Destroy()
        
        if read:
            try:
#                 self.raw_img = plt.imread(path)
                self.raw_img = tifffile.imread(path)
                #self.raw_img = fabio.open(path).data
            except:
                print('Image not properly opened.')
                self.raw_img = np.zeros((1024,1024))
        else:
            print('No image selected.')
            self.raw_img = np.zeros((1024,1024))            
Exemplo n.º 14
0
    def openBkgd(self, event=None):

        wildcards = 'XRD background image (*.edf,*.tif,*.tiff)|*.tif;*.tiff;*.edf|All files (*.*)|*.*'
        dlg = wx.FileDialog(self,
                            message='Choose XRD background image',
                            defaultDir=os.getcwd(),
                            wildcard=wildcards,
                            style=wx.FD_OPEN)

        path, read = None, False
        if dlg.ShowModal() == wx.ID_OK:
            read = True
            path = dlg.GetPath().replace('\\', '/')
        dlg.Destroy()

        if read:
            try:
                self.bkgd_img = np.array(tifffile.imread(path))
                self.checkIMAGE()
                print('Reading background: %s' % path)
            except:
                print('Cannot read as an image file: %s' % path)
                return
Exemplo n.º 15
0
def read_tiff(fname, _larch=None, *args, **kws):
    """read image data from a TIFF file as an array"""
    return imread(fname, *args, **kws)
def read_tiff(fname, _larch=None, *args, **kws):
    """read image data from a TIFF file as an array"""
    return imread(fname, *args, **kws)