/[escript]/trunk/downunder/py_src/datasources.py
ViewVC logotype

Diff of /trunk/downunder/py_src/datasources.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3964 by caltinay, Thu Sep 13 03:49:55 2012 UTC revision 3965 by caltinay, Fri Sep 14 01:23:17 2012 UTC
# Line 110  class DataSource(object): Line 110  class DataSource(object):
110      def _interpolateOnDomain(self, data):      def _interpolateOnDomain(self, data):
111          """          """
112          Helper method that interpolates data arrays onto the domain.          Helper method that interpolates data arrays onto the domain.
113            Currently this works like a nearest neighbour mapping, i.e. values
114            are directly inserted into data objects at closest location.
115            """
116            dom=self.getDomain()
117            dim=dom.getDim()
118            # determine number of values required per element
119            DPP=Scalar(0., Function(dom)).getNumberOfDataPoints()
120            for i in xrange(dim):
121                DPP=DPP/self._dom_NE[i]
122            DPP=int(DPP)
123    
124            # idx_mult.dot([x,y,z]) = flat index into data object
125            idx_mult=np.array([DPP]+self._dom_NE[:dim-1]).cumprod()
126    
127            # separate data arrays and coordinates
128            num_arrays=len(data[0])-dim
129            arrays=[]
130            for i in xrange(num_arrays):
131                d=Scalar(0., Function(dom))
132                d.expand()
133                arrays.append(d)
134    
135            for entry in data:
136                index=[int((entry[i]-self._dom_origin[i])/self._spacing[i]) for i in xrange(dim)]
137                index=int(idx_mult.dot(index))
138                for i in xrange(num_arrays):
139                    for p in xrange(DPP):
140                        arrays[i].setValueOfDataPoint(index+p, entry[dim+i])
141    
142            return arrays
143    
144        def _interpolateOnDomain_old(self, data):
145            """
146            Old interpolation method. Works only on ContinuousFunction and thus
147            produces wrong values once interpolated on Function.
148          """          """
149          dom=self.getDomain()          dom=self.getDomain()
150          dim=dom.getDim()          dim=dom.getDim()
# Line 206  class DataSource(object): Line 241  class DataSource(object):
241          z0, nz, dz = self.getVerticalExtents()          z0, nz, dz = self.getVerticalExtents()
242    
243          # number of elements (without padding)          # number of elements (without padding)
244          NE = [NX[0]-1, NX[1]-1, nz-1]          NE = [NX[0], NX[1], nz]
245    
246          # origin of domain (without padding)          # origin of domain (without padding)
247          origin = [X0[0], X0[1], z0]          origin = [X0[0], X0[1], z0]

Legend:
Removed from v.3964  
changed lines
  Added in v.3965

  ViewVC Help
Powered by ViewVC 1.1.26