less repetition

This commit is contained in:
Martin Diehl 2022-11-14 12:42:13 +01:00
parent c8e5e9e34a
commit ba4ac5c108
1 changed files with 4 additions and 3 deletions

View File

@ -972,15 +972,16 @@ class Grid:
# materials: 1 # materials: 1
""" """
options = ('nearest',False,None)
orig = tuple(map(np.linspace,self.origin + self.size/self.cells*.5, orig = tuple(map(np.linspace,self.origin + self.size/self.cells*.5,
self.origin + self.size - self.size/self.cells*.5,self.cells)) self.origin + self.size - self.size/self.cells*.5,self.cells))
interpolator = partial(interpolate.RegularGridInterpolator,
points=orig,method='nearest',bounds_error=False,fill_value=None)
new = grid_filters.coordinates0_point(cells,self.size,self.origin) new = grid_filters.coordinates0_point(cells,self.size,self.origin)
return Grid(material = interpolate.RegularGridInterpolator(orig,self.material,*options)(new).astype(int), return Grid(material = interpolator(values=self.material)(new).astype(int),
size = self.size, size = self.size,
origin = self.origin, origin = self.origin,
initial_conditions = {k: interpolate.RegularGridInterpolator(orig,v,*options)(new) initial_conditions = {k: interpolator(values=v)(new)
for k,v in self.initial_conditions.items()}, for k,v in self.initial_conditions.items()},
comments = self.comments+[util.execution_stamp('Grid','scale')], comments = self.comments+[util.execution_stamp('Grid','scale')],
) )