Пример #1
0
 def _shift_resample(self,
                     resolution: Shape,
                     bounds: Box,
                     threshold=1e-5,
                     max_padding=20):
     assert math.all_available(
         bounds.lower, bounds.upper
     ), "Shift resampling requires 'bounds' to be available."
     lower = math.to_int32(
         math.ceil(
             math.maximum(0, self.box.lower - bounds.lower) / self.dx -
             threshold))
     upper = math.to_int32(
         math.ceil(
             math.maximum(0, bounds.upper - self.box.upper) / self.dx -
             threshold))
     total_padding = (math.sum(lower) + math.sum(upper)).numpy()
     if total_padding > max_padding:
         return NotImplemented
     elif total_padding > 0:
         from phi.field import pad
         padded = pad(
             self, {
                 dim: (int(lower[i]), int(upper[i]))
                 for i, dim in enumerate(self.shape.spatial.names)
             })
         grid_box, grid_resolution, grid_values = padded.box, padded.resolution, padded.values
     else:
         grid_box, grid_resolution, grid_values = self.box, self.resolution, self.values
     origin_in_local = grid_box.global_to_local(
         bounds.lower) * grid_resolution
     data = math.sample_subgrid(grid_values, origin_in_local, resolution)
     return data
Пример #2
0
 def _shift_resample(self, resolution, box, threshold=1e-5, max_padding=20):
     lower = math.to_int(
         math.ceil(
             math.maximum(0, self.box.lower - box.lower) / self.dx -
             threshold))
     upper = math.to_int(
         math.ceil(
             math.maximum(0, box.upper - self.box.upper) / self.dx -
             threshold))
     total_padding = math.sum(lower) + math.sum(upper)
     if total_padding > max_padding:
         return NotImplemented
     elif total_padding > 0:
         from phi.field import pad
         padded = pad(
             self, {
                 dim: (int(lower[i]), int(upper[i]))
                 for i, dim in enumerate(self.shape.spatial.names)
             })
         grid_box, grid_resolution, grid_values = padded.box, padded.resolution, padded.values
     else:
         grid_box, grid_resolution, grid_values = self.box, self.resolution, self.values
     origin_in_local = grid_box.global_to_local(box.lower) * grid_resolution
     data = math.sample_subgrid(grid_values, origin_in_local, resolution)
     return data
Пример #3
0
 def extrapolation_helper(elements, t_shift, v_field, mask):
     shift = math.ceil(math.max(
         math.abs(elements.center - points.center))) - t_shift
     t_shift += shift
     v_field, mask = extrapolate_valid(v_field, mask, int(shift))
     v_field *= accessible
     return v_field, mask, t_shift
Пример #4
0
 def after_gather(self, selection: dict):
     result = self
     for name, selection in selection.items():
         if isinstance(selection, int):
             result = result.without(name)
         elif isinstance(selection, slice):
             start = selection.start or 0
             stop = selection.stop or self.get_size(name)
             step = selection.step or 1
             if stop < 0:
                 stop += self.get_size(name)
                 assert stop >= 0
             new_size = math.to_int(math.ceil(math.wrap((stop - start) / step)))
             if new_size.rank == 0:
                 new_size = int(new_size)  # NumPy array not allowed because not hashable
             result = result.with_size(name, new_size)
         else:
             raise NotImplementedError(f"{type(selection)} not supported. Only (int, slice) allowed.")
     return result
Пример #5
0
def _required_paddings_transposed(box, dx, target):
    lower = math.to_int(
        math.ceil(math.maximum(0, box.lower - target.lower) / dx))
    upper = math.to_int(
        math.ceil(math.maximum(0, target.upper - box.upper) / dx))
    return [lower, upper]