def load_imagedata(self):
     try:
         dir = self.shot[self.shot.index(":\\") + 2 : self.shot.rindex("\\") + 1]
         shotnum = self.shot[self.shot.rindex("_") + 1 : self.shot.rindex(".ascii")]
     except ValueError:
         print " *** Not a valid column density path *** "
         return None
     # Set data path
     # Prepare PlotData object
     print dir
     print shotnum
     return load(dir, shotnum)
    def load_imagedata(self):
        try:
            directory = self.shotdir
	    if self.selectedshot == []:
		    filename = self.shots[0]
	    else:
		    filename = self.selectedshot[0]
            #shotnum = filename[filename.rindex('_')+1:filename.rindex('.ascii')]
	    shotnum = filename[:filename.index('_')]
        except ValueError:
            print " *** Not a valid path *** " 
            return None
        # Set data path
        # Prepare PlotData object
	print "Loading file #%s from %s" % (filename,directory)
        return import_data.load(directory,filename), import_data.load_report(directory,shotnum)
def fitfermi2d(data):
    params = moments(data)
    errorfunction = lambda p: ravel( numpy.vectorize(fermi2d(*p))(*indices(data.shape)) - data)
    p, success = optimize.leastsq(errorfunction, params)
    return p, numpy.vectorize(fermi2d(*p))(*indices(data.shape))
    
#def fitgaus2d(data):
#   params = del moments(data)[1]  #Was trying to get moments withouth the BetaMu parameter, because the gaussian fit doesn't care about the fugacity. 
#    errorfunction = lambda p: ravel( numpy.vectorize(gaus2d(*p))(*indices(data.shape)) - data)
#    p, success = optimize.leastsq(errorfunction, params)
#    return p, numpy.vectorize(fermi2d(*p))(*indices(data.shape))
    

if __name__ == '__main__':
    #Data matrix
    data = import_data.load('','6043')
    data = crop(data)
    
    print data.shape
    
    
    Xin,Yin = mgrid[0:512,0:512]
    
    t0=time.time()
    
    #Fake result
    p=[2e6, -1., 50., 100. ,256.,256., 0.5, 0.01, 0.01]  #starting parameters for the fit
    # atom number,  BetaMu, radius along g, radius along y, center along g, center along y
    #fitdata = numpy.vectorize(fermi2d(*p))(Xin, Yin)
    
    errs=(errorfunc(data))(p)