Beispiel #1
0
def interpolate_KDTree(x, y, v, grid, logger):
    logger.info(datetime.datetime.now())
    logger.info(x.shape)
    known = zip(x, y)
    # print type(known)
    known = numpy.array(known)
    # print type(known), type(v), known.shape, v.shape
    lats = numpy.arange(15, 60, 0.01)
    lons = numpy.arange(70, 140, 0.01)
    # print lats.shape, lons.shape
    ask = []
    for i in range(len(lats)):
        for j in range(len(lons)):
            ask.append((lats[i], lons[j]))
    ask = numpy.array(ask)
    # print '-------------'
    # print type(ask),ask.shape
    leafsize = 10
    Nnear = 8
    eps = 0.005
    p = 2
    invdisttree = Invdisttree(known, v, leafsize=leafsize, stat=1)
    interpol = invdisttree(ask, nnear=Nnear, eps=eps, p=p)
    grid = interpol.reshape(4500, 7000)
    logger.info(datetime.datetime.now())
    del interpol
    return grid
Beispiel #2
0
    def __init__(self, **kw):

        # the path to files containing wave functions (to fit with)
        self._path = kw.get('p', '/data/users/mklymenko/science/H2_100/programing/dis/v2/')
        self._sn = kw.get('sn', 10)  # id of the system
        self._qn = kw.get('qn', 0)  # id of the wave function

        print '\n--------------------------------------------------------------'
        print 'The wave function is associated with the file'
        print self._path+'ff_'+str(self._sn)+'.dat'
        print '    the number of the quantum state is      {}'.format(self._qn)

        self.flag = kw.get('flag', 'none')

        if self.flag == 'int':
            print("Reading from file and creating the interpolant..."),
            stdout.flush()
            X, F = self.read_from_file(self._sn, self._qn, self._path)
            self.invdisttree = Invdisttree(X.T, F)
            print("Done!")

        print '--------------------------------------------------------------\n'
Beispiel #3
0
]

for j, g in enumerate(geom):
    for j1 in range(geom.orbitals[j]):
        ldos[:, j] += pdos[ind, :]
        ind += 1

args = geom[:, 0].argsort()
ldos = ldos[:, args]

from invdisttree import Invdisttree

xnew, ynew, znew = np.mgrid[-coords_min[0]:2 * coords_max[0]:300j,
                            -coords_min[1]:2 * coords_max[1]:10j,
                            -coords_min[2]:2 * coords_max[2]:10j]

size = xnew.shape
ldos_grid = np.zeros((len(energy), size[0], size[1], size[2]))

for j in range(len(energy)):
    print(j)
    interp = Invdisttree(
        np.vstack((geom.xyz[:, 0], geom.xyz[:, 1], geom.xyz[:, 2])).T,
        ldos[j, :])
    ldos_grid[j, :, :, :] = interp(np.vstack(
        (xnew.flatten(), ynew.flatten(), znew.flatten())).T,
                                   nnear=11,
                                   eps=0,
                                   p=1).reshape(xnew.shape)

print(ldos_grid)
Beispiel #4
0
    def do_fit(self):
        """ The function does the fitting procedure"""

        if (self._flag == 1):
            self._gf = [0.2]
            self._gf = self.par*(self._num_fu*len(self._sites)*2)
            x, F = self.read_from_file(
                self._sn, self._qn, self._path)  # read data from the file
            # ,ftol=1.0e-7,xtol=1.0e-8)
            popt, pcov = curve_fit(
                self.modelfun, x, F, p0=self._gf, maxfev=5000)
            self._gf = popt

        elif (self._flag == 2):

#            par=[0.0]*(self._num_fu*5)
#            for j in xrange(self._num_fu):
#                par[j*5]=0.0*math.copysign(1,(pow(-1,j)))
# self._gf[j*5]=0.1
#                par[j*5+1]=6.45
#                par[j*5+2]=0.0
#                par[j*5+3]=0.05
#                par[j*5+4]=1.0

            X, F = self.read_from_file(self._sn, self._qn, self._path)  # read data from the file

#            height, xx, width=self.moments(F)
#            Tracer()()
#            par=[0.0]*(self._num_fu*5)
#            for j in xrange(self._num_fu):
# par[j*5]=x[0,xx]
#                par[j*5]=X[0,xx]*math.copysign(1,(pow(-1,j)))
#                par[j*5+1]=X[1,xx]
#                par[j*5+2]=X[2,xx]
#                par[j*5+3]=0.007
#                par[j*5+4]=height*math.copysign(1,(pow(-1,j)))

            xi, yi, zi = np.mgrid[-6.5:6.5:160j, 4.0:8.9:160j, -7.5:7.5:160j]
            x, y, z = xi.flatten(), yi.flatten(), zi.flatten()
            XX = np.vstack((x, y, z))

            invdisttree = Invdisttree(X.T, F, leafsize=10, stat=1)
            AA = invdisttree(XX.T, nnear=130, eps=0, p=1)

#            aaa1,bbb1=self.detect_local_minima(-AA.reshape(xi.shape))
#            aaa2,bbb2=self.detect_local_maxima(-AA.reshape(xi.shape))
            if self.peaks==[]:
                print '\n---------------------------------------------------------------------'
                print 'Detecting maxima and minima of target function...',

                peaks_min, min_coord, peaks_max, max_coord = self.detect_min_max(AA.reshape(xi.shape))
                print 'done'
                print 'Number of the min peaks: {}'.format(len(peaks_min))
                print 'Number of the max peaks: {}'.format(len(peaks_max))
                print '---------------------------------------------------------------------\n'
    #            fig=plt.figure()
    #            ax = fig.add_subplot(111, projection='3d')
    #            ax.plot_surface(xi[:,:,60],yi[:,:,60],bbb2[:,:,60], cmap=cm.jet, linewidth=0.2)
    #            plt.hold(True)
    #            plt.show()

                if peaks_max==[]:
                    peaks=np.insert(peaks_min, np.arange(len(peaks_max)), peaks_max)
                    coords=np.insert(min_coord, np.arange(max_coord.shape[1]), max_coord, axis=1)
                else:
                    peaks = np.insert(peaks_max, np.arange(len(peaks_min)), peaks_min)
                    coords = np.insert(max_coord, np.arange(min_coord.shape[1]), min_coord, axis=1)

                self.peaks=peaks
                self.coords=coords

            par = [0.0]*(self._num_fu*5)
            j1 = 0
            aaaa = 1
            for j in xrange(self._num_fu):
                if (j > aaaa*self.coords.shape[1]-1):
                    j1 = 0
                    aaaa += 1
                par[j*5] = xi[self.coords[0, j1], self.coords[0, j1], self.coords[0, j1]]
                par[j*5+1] = yi[self.coords[1, j1], self.coords[1, j1], self.coords[1, j1]]
                par[j*5+2] = zi[self.coords[2, j1], self.coords[2, j1], self.coords[2, j1]]
                # par[j*5+3] = 0.1003+0.1000*math.copysign(1, (pow(-1, j)))
                par[j*5+3] = 0.0001
#                if j < 15:
#                    par[j*5+3] = 0.00001
#                else:
#                    par[j*5+3] = 0.0005
                par[j*5+4] = self.peaks[j1]
#                print(coords[0, j1], coords[1, j1], coords[2, j1])
                j1 += 1
            # popt, pcov = curve_fit(self.modelfun1, x[:,1:20000], F[1:20000],p0=par,maxfev=150000,xtol=1e-8,ftol=1e-8)
            popt, pcov = curve_fit(
                self.modelfun1, X, F, p0=par, maxfev=150000, xtol=1e-6,
                ftol=1e-8)
            # popt, pcov = curve_fit(self.modelfun1, XX, AA, p0=par)
            self._gf = popt
#             self.error=np.diagonal(pcov, offset=0)
#             print(pcov)
        else:
            # pass
            sys.exit("Wrong flag in do_fit")
Beispiel #5
0
 def get_value(self,x):
     X, F = self.read_from_file(self._sn, self._qn, self._path)
     invdisttree = Invdisttree(X.T, F, leafsize=10, stat=1)
     return invdisttree(x, nnear=130, eps=0, p=1)