Index: readers/DataReader.py
===================================================================
--- readers/DataReader.py	(revision ee5479d87a6847a88412711549784f4ceb78d9cf)
+++ readers/DataReader.py	(revision ee5479d87a6847a88412711549784f4ceb78d9cf)
@@ -0,0 +1,169 @@
+import os, sys
+import pylab
+from copy import deepcopy
+import math
+class DataReader:
+    """ Simple data reader for Igor data files """
+    
+    def __init__(self, filename=None):
+        """ Init
+            @param filename: Name of Igor data file to read
+        """
+        self.file = filename
+        self.x = []
+        self.y = []
+        self.image = []
+        
+        # Detector info
+        self.wavelength = 0.0
+        self.distance   = 0.0
+        self.center_x   = 63.5
+        self.center_y   = 63.5
+        
+    def read(self,filename=None):
+        """ Read file """
+        # Check if the file is there
+        self.file=filename
+        if not os.path.isfile(self.file):
+            raise ValueError, \
+            "Specified file %s is not a regular file" % self.file
+        
+        # Read file
+        f = open(self.file,'r')
+        buf = f.read()
+        
+        # Get content
+        dataStarted = False
+        
+        
+        lines = buf.split('\n')
+        itot = 0
+        self.x = []
+        self.y = []
+        self.image = []
+        
+        ncounts = 0
+        
+        #x = pylab.arange(0, 128, 1)
+        #y = pylab.arange(0, 128, 1)
+        x = pylab.arange(-.5, .5, 1.0/128)
+        y = pylab.arange(-.5, .5, 1.0/128)
+        X, Y = pylab.meshgrid(x, y)
+        Z = deepcopy(X)
+        
+        xmin = None
+        xmax = None
+        ymin = None
+        ymax = None
+        
+        i_x = 0
+        i_y = -1
+        
+        isInfo = False
+        isCenter = False
+        for line in lines:
+            
+            # Find setup info line
+            if isInfo:
+                isInfo = False
+                line_toks = line.split()
+                # Wavelength in Angstrom
+                try:
+                    wavelength = float(line_toks[1])
+                except:
+                    raise ValueError,"DataReader: can't read this file, missing wavelength"
+                # Distance in meters
+                try:
+                    distance = float(line_toks[3])
+                except:
+                    raise ValueError,"DataReader: can't read this file, missing distance"
+                
+            if line.count("LAMBDA")>0:
+                isInfo = True
+                
+            # Find center info line
+            if isCenter:
+                isCenter = False                
+                line_toks = line.split()
+                # Center in bin number
+                center_x = float(line_toks[0])
+                center_y = float(line_toks[1])
+
+            if line.count("BCENT")>0:
+                isCenter = True
+                
+        
+            # Find data start
+            if line.count("***")>0:
+                dataStarted = True
+                
+                # Check that we have all the info
+                if wavelength == None \
+                    or distance == None \
+                    or center_x == None \
+                    or center_y == None:
+                    raise ValueError, "Missing information in data file"
+                
+            if dataStarted == True:
+                try:
+                    value = float(line)
+                except:
+                    continue
+                
+                # Get bin number
+                if math.fmod(itot, 128)==0:
+                    i_x = 0
+                    i_y += 1
+                else:
+                    i_x += 1
+                    
+                Z[i_y][i_x] = value
+                ncounts += 1 
+                
+                # Det 640 x 640 mm
+                # Q = 4pi/lambda sin(theta/2)
+                # Bin size is 0.5 cm
+                theta = (i_x-center_x+1)*0.5 / distance / 100.0
+                qx = 4.0*math.pi/wavelength * math.sin(theta/2.0)
+                if xmin==None or qx<xmin:
+                    xmin = qx
+                if xmax==None or qx>xmax:
+                    xmax = qx
+                
+                theta = (i_y-center_y+1)*0.5 / distance / 100.0
+                qy = 4.0*math.pi/wavelength * math.sin(theta/2.0)
+                if ymin==None or qy<ymin:
+                    ymin = qy
+                if ymax==None or qy>ymax:
+                    ymax = qy
+                
+                
+                if not qx in self.x:
+                    self.x.append(qx)
+                if not qy in self.y:
+                    self.y.append(qy)
+                
+                itot += 1
+                  
+                  
+        theta = 0.25 / distance / 100.0
+        xstep = 4.0*math.pi/wavelength * math.sin(theta/2.0)
+        
+        theta = 0.25 / distance / 100.0
+        ystep = 4.0*math.pi/wavelength * math.sin(theta/2.0)
+        
+        # Store q max 
+        if xmax>ymax:
+            self.qmax = xmax
+        else:
+            self.qmax = ymax
+        
+        #config.printEVT("Read %g points from file %s" % (ncounts, self.file))
+  
+        self.wavelength = wavelength
+        self.distance   = distance*1000.0
+        self.center_x = center_x
+        self.center_y = center_y
+        
+        return Z, xmin-xstep/2.0, xmax+xstep/2.0, ymin-ystep/2.0, ymax+ystep/2.0
+     
Index: readers/TXT2_Reader.py
===================================================================
--- readers/TXT2_Reader.py	(revision ee5479d87a6847a88412711549784f4ceb78d9cf)
+++ readers/TXT2_Reader.py	(revision ee5479d87a6847a88412711549784f4ceb78d9cf)
@@ -0,0 +1,64 @@
+# class Loader  to load any king of file
+import wx
+import string,numpy
+class Reader:
+    """
+        This class is loading values from given file or value giving by the user
+        should be able to read only 2 columns of data
+    """
+    
+    def _init_(self,x=None,y=None,dx=None,dy=None):
+        # variable to store loaded values
+        self.x = x
+        self.y = y
+        self.dx = dx
+        self.dy = dy
+    
+    def read(self,path, format=None):
+        """ Store the values loaded from file in local variables """
+        if not path == None:
+            input_f =  open(path,'r')
+            buff = input_f.read()
+            lines = buff.split('\n')
+            self.x=[]
+            self.y=[]
+            self.dx = [] 
+            self.dy=[]
+            value="can't read" 
+            for line in lines:
+                toks = line.split()
+                try:
+                    x = float(toks[0])
+                    self.x.append(x)
+                except:
+                    print "READ ERROR", line
+                try:
+                    y = float(toks[1])
+                    self.y.append(y)
+                except:
+                    print "READ ERROR", line
+                try:
+                    dy=float(toks[2])
+                    self.dy.append(dy)
+
+                except:
+                    print "READ ERROR", line
+
+            if(( self.x==[])or (self.y==[])) or (self.dy !=[]):
+                print "went here"
+                #return value
+                raise ValueError, "Reader1 can't read"
+            else:
+                #msg="R1 reading: \n"+"this x :"+ str(self.x) +"\n"+"this y:"+str(self.y)+"\n"+"this dy :"+str(self.dy)+"\n"
+                #return msg
+                print "TXT2_Reader reading: \n"
+                return self.x,self.y,self.dy
+                
+   
+       
+    
+if __name__ == "__main__": 
+    read= Reader()
+    read.load("testdata_line.txt")
+    
+            
Index: readers/TXT3_Reader.py
===================================================================
--- readers/TXT3_Reader.py	(revision ee5479d87a6847a88412711549784f4ceb78d9cf)
+++ readers/TXT3_Reader.py	(revision ee5479d87a6847a88412711549784f4ceb78d9cf)
@@ -0,0 +1,66 @@
+# class Loader  to load any king of file
+import wx
+import string,numpy
+class Reader:
+    """
+        This class is loading values from given file or value giving by the user
+    """
+    
+    def _init_(self,filename=None,x=None,y=None,dx=None,dy=None):
+        # variable to store loaded values
+        self.x = x
+        self.y = y
+        self.dx = dx
+        self.dy = dy
+        self.filename = filename
+        
+    def read(self,path, format=None):
+        """ Store the values loaded from file in local variables 
+            can read 3 columns of data
+        """
+        if not path == None:
+            input_f =  open(path,'r')
+            buff = input_f.read()
+            lines = buff.split('\n')
+            self.x=[]
+            self.y=[]
+            self.dx = [] 
+            self.dy=[]
+            value="can't read" 
+            for line in lines:
+                toks = line.split()
+                try:  
+                    x = float(toks[0])
+                    y = float(toks[1]) 
+                    dy = float(toks[2])
+                   
+                    self.x.append(x)
+                    self.y.append(y)
+                    self.dy.append(dy)
+               
+                except:
+                    print "READ ERROR", line
+        
+                self.dx = numpy.zeros(len(self.x))
+                # Sanity check
+                if not len(self.x) == len(self.dx):
+                    raise ValueError, "x and dx have different length"
+                if not len(self.y) == len(self.dy):
+                    raise ValueError, "y and dy have different length"
+           
+            if (self.x==[] or self.y==[])and (self.dy==[]):
+                raise ValueError, "txtReader can't read"
+            else:
+                #msg="txtReader  Reading:\n"+"this x :"+ str(self.x) +"\n"+"this y:"+str(self.y)+"\n"+"this dy :"+str(self.dy)+"\n"
+                #return msg
+                print "TXT3_Reader reading: \n"
+                return self.x,self.y,self.dy
+                
+  
+if __name__ == "__main__": 
+    read= Reader()
+    #read= Reader(filename="testdata_line.txt")
+    print read.load("test.dat")
+    
+    
+            
Index: readers/danse_reader.py
===================================================================
--- readers/danse_reader.py	(revision ee5479d87a6847a88412711549784f4ceb78d9cf)
+++ readers/danse_reader.py	(revision ee5479d87a6847a88412711549784f4ceb78d9cf)
@@ -0,0 +1,214 @@
+"""
+    Test plug-in
+"""
+
+import math
+import pylab
+import copy
+import numpy
+class ReaderInfo:
+    """
+    """
+    ## Wavelength [A]
+    wavelength = 0.0
+    ## Number of x bins
+    xbins = 128
+    ## Number of y bins
+    ybins = 128
+    ## Beam center X [pixel number]
+    center_x = 65
+    ## Beam center Y [pixel number]
+    center_y = 65
+    ## Distance from sample to detector [m]
+    distance = 11.0
+    ## Qx values [A-1]
+    x_vals = []
+    ## Qy xalues [A-1]
+    y_vals = []
+    ## Qx min
+    xmin = 0.0
+    ## Qx max
+    xmax = 1.0
+    ## Qy min
+    ymin = 0.0
+    ## Qy max
+    ymax = 1.0
+    ## Image
+    image = None
+    ## Pixel size
+    pixel_size = 0.5
+    ## Error on each pixel
+    error = None
+class DataReader:
+    """
+        Example data manipulation
+    """
+    ## File type
+    type = ["DANSE files (*.sans)|*.sans"]
+    ## Extension
+    ext  = ['.sans']    
+        
+    def read(self, filename=None):
+        """
+            Open and read the data in a file
+            @param file: path of the file
+        """
+        
+        read_it = False
+        for item in self.ext:
+            if filename.lower().find(item)>=0:
+                read_it = True
+                
+        if read_it:
+            
+            datafile = open(filename, 'r')
+            
+            # defaults
+            # wavelength in Angstrom
+            wavelength = 10.0
+            # Distance in meter
+            distance   = 11.0
+            # Pixel number of center in x
+            center_x   = 65
+            # Pixel number of center in y
+            center_y   = 65
+            # Pixel size [mm]
+            pixel      = 5.0
+            # Size in x, in pixels
+            size_x     = 128
+            # Size in y, in pixels
+            size_y     = 128
+            # Format version
+            fversion   = 1.0
+            
+            read_on = True
+            while read_on:
+                line = datafile.readline()
+                if line.find("DATA:")>=0:
+                    read_on = False
+                    break
+                toks = line.split(':')
+                if toks[0]=="FORMATVERSION":
+                    fversion = float(toks[1])
+                if toks[0]=="WAVELENGTH":
+                    wavelength = float(toks[1])
+                elif toks[0]=="DISTANCE":
+                    distance = float(toks[1])
+                elif toks[0]=="CENTER_X":
+                    center_x = float(toks[1])
+                elif toks[0]=="CENTER_Y":
+                    center_y = float(toks[1])
+                elif toks[0]=="PIXELSIZE":
+                    pixel = float(toks[1])
+                elif toks[0]=="SIZE_X":
+                    size_x = int(toks[1])
+                elif toks[0]=="SIZE_Y":
+                    size_y = int(toks[1])
+            
+            # Read the data
+            data = []
+            error = []
+            if fversion==1.0:
+                data_str = datafile.readline()
+                data = data_str.split(' ')
+            else:
+                read_on = True
+                while read_on:
+                    data_str = datafile.readline()
+                    if len(data_str)==0:
+                        read_on = False
+                    else:
+                        toks = data_str.split()
+                        try:
+                            val = float(toks[0])
+                            err = float(toks[1])
+                            data.append(val)
+                            error.append(err)
+                        except:
+                            print "Skipping line:%s" % data_str
+                            print sys.exc_value
+            
+            # Initialize 
+            x_vals = []
+            y_vals = [] 
+            ymin = None
+            ymax = None
+            xmin = None
+            xmax = None
+            Z = None
+        
+            
+            x = numpy.zeros(size_x)
+            y = numpy.zeros(size_y)
+            X, Y = pylab.meshgrid(x, y)
+            Z = copy.deepcopy(X)
+            E = copy.deepcopy(X)
+            itot = 0
+            i_x = 0
+            i_y = 0
+            
+            # Qx and Qy vectors
+            for i_x in range(size_x):
+                theta = (i_x-center_x+1)*pixel / distance / 100.0
+                qx = 4.0*math.pi/wavelength * math.sin(theta/2.0)
+                x_vals.append(qx)
+                if xmin==None or qx<xmin:
+                    xmin = qx
+                if xmax==None or qx>xmax:
+                    xmax = qx
+            
+            ymin = None
+            ymax = None
+            for i_y in range(size_y):
+                theta = (i_y-center_y+1)*pixel / distance / 100.0
+                qy = 4.0*math.pi/wavelength * math.sin(theta/2.0)
+                y_vals.append(qy)
+                if ymin==None or qy<ymin:
+                    ymin = qy
+                if ymax==None or qy>ymax:
+                    ymax = qy
+            
+            for i_pt in range(len(data)):
+                val = data[i_pt]
+                try:
+                    value = float(val)
+                except:
+                    continue
+                
+                # Get bin number
+                if math.fmod(itot, size_x)==0:
+                    i_x = 0
+                    i_y += 1
+                else:
+                    i_x += 1
+                    
+                Z[size_y-1-i_y][i_x] = value
+                if fversion>1.0:
+                    E[size_y-1-i_y][i_x] = error[i_pt]
+                
+                itot += 1
+                
+            output = ReaderInfo()
+            output.wavelength = wavelength
+            output.xbins      = size_x
+            output.ybins      = size_y
+            output.center_x   = center_x
+            output.center_y   = center_y
+            # Store the distance in [mm]
+            output.distance   = distance*1000.0
+            output.x_vals     = x_vals
+            output.y_vals     = y_vals
+            output.xmin       = xmin
+            output.xmax       = xmax
+            output.ymin       = ymin
+            output.ymax       = ymax
+            output.pixel_size = pixel
+            output.image      = Z
+            if not fversion==1.1:
+                #output.error  = E
+                raise ValueError,"Danse_reader can't read this file"
+            else:
+                print "Danse_reader Reading : \n"
+                return output
+        
+        return None
Index: readers/tiff_reader.py
===================================================================
--- readers/tiff_reader.py	(revision ee5479d87a6847a88412711549784f4ceb78d9cf)
+++ readers/tiff_reader.py	(revision ee5479d87a6847a88412711549784f4ceb78d9cf)
@@ -0,0 +1,150 @@
+
+import Image
+import math
+class ReaderInfo:
+    """
+    """
+    ## Wavelength [A]
+    wavelength = 0.0
+    ## Number of x bins
+    xbins = 128
+    ## Number of y bins
+    ybins = 128
+    ## Beam center X [pixel number]
+    center_x = 65
+    ## Beam center Y [pixel number]
+    center_y = 65
+    ## Distance from sample to detector [m]
+    distance = 11.0
+    ## Qx values [A-1]
+    x_vals = []
+    ## Qy xalues [A-1]
+    y_vals = []
+    ## Qx min
+    xmin = 0.0
+    ## Qx max
+    xmax = 1.0
+    ## Qy min
+    ymin = 0.0
+    ## Qy max
+    ymax = 1.0
+    ## Image
+    image = None
+    ## Pixel size
+    pixel_size = 0.5
+    ## Error on each pixel
+    error = None
+    
+class DataReader:
+    """
+        Example data manipulation
+    """
+    ## File type
+    type = []
+    ## Extension
+    ext  = ['tif', 'jpg', 'png', 'jpeg', 'tiff', 'gif', 'bmp']    
+        
+    def read(self, filename=None):
+        """
+            Open and read the data in a file
+            @param file: path of the file
+        """
+        
+        read_it = False
+        for item in self.ext:
+            if filename.lower().find(item)>=0:
+                read_it = True
+                
+        if read_it:
+            import Image
+            import pylab
+            import copy
+            import numpy
+            
+            wavelength, distance, center_x, center_y, pixel = 10.0, 11.0, 65, 65, 1.0
+            
+            
+            
+            # Initialize 
+            x_vals = []
+            y_vals = [] 
+            ymin = None
+            ymax = None
+            xmin = None
+            xmax = None
+            Z = None
+        
+            
+            im = Image.open(filename)
+            
+            # Detector size should be 128x128, the file is 190x190
+            print "-> Image size:", im.size, im.format, im.mode
+            data = im.getdata()
+            x = numpy.zeros(im.size[0])
+            y = numpy.zeros(im.size[1])
+            X, Y = pylab.meshgrid(x, y)
+            Z = copy.deepcopy(X)
+            itot = 0
+            i_x = 0
+            i_y = 0
+            
+            # Qx and Qy vectors
+            for i_x in range(im.size[0]):
+                theta = (i_x-center_x+1)*pixel / distance / 100.0
+                qx = 4.0*math.pi/wavelength * math.sin(theta/2.0)
+                x_vals.append(qx)
+                if xmin==None or qx<xmin:
+                    xmin = qx
+                if xmax==None or qx>xmax:
+                    xmax = qx
+            
+            ymin = None
+            ymax = None
+            for i_y in range(im.size[1]):
+                theta = (i_y-center_y+1)*pixel / distance / 100.0
+                qy = 4.0*math.pi/wavelength * math.sin(theta/2.0)
+                y_vals.append(qy)
+                if ymin==None or qy<ymin:
+                    ymin = qy
+                if ymax==None or qy>ymax:
+                    ymax = qy
+            
+            for val in data:
+                
+                try:
+                    value = float(val)
+                except:
+                    continue
+                
+                # Get bin number
+                if math.fmod(itot, im.size[0])==0:
+                    i_x = 0
+                    i_y += 1
+                else:
+                    i_x += 1
+                    
+                Z[im.size[1]-1-i_y][i_x] = value
+                
+                itot += 1
+                
+            output = ReaderInfo()
+            output.wavelength = wavelength
+            output.xbins      = im.size[0]
+            output.ybins      = im.size[1]
+            output.center_x   = center_x
+            output.center_y   = center_y
+            output.distance   = distance
+            output.x_vals     = x_vals
+            output.y_vals     = y_vals
+            output.xmin       = xmin
+            output.xmax       = xmax
+            output.ymin       = ymin
+            output.ymax       = ymax
+            output.image      = Z
+            output.pixel_size = pixel
+                
+            return output
+        
+        return None
+
+
