コード例 #1
0
 def at(self, other_field):
     if self.compatible(other_field):
         return self
     if isinstance(other_field, CenteredGrid) and np.allclose(
             self.dx, other_field.dx):
         paddings = _required_paddings_transposed(self.box, self.dx,
                                                  other_field.box)
         if math.sum(paddings) == 0:
             origin_in_local = self.box.global_to_local(
                 other_field.box.lower) * self.resolution
             data = _crop_for_interpolation(self.data, origin_in_local,
                                            other_field.resolution)
             dimensions = self.resolution != other_field.resolution
             dimensions = [
                 d for d in math.spatial_dimensions(data)
                 if dimensions[d - 1]
             ]
             data = math.interpolate_linear(data, origin_in_local % 1.0,
                                            dimensions)
             return CenteredGrid(data,
                                 other_field.box,
                                 name=self.name,
                                 batch_size=self._batch_size)
         elif math.sum(paddings) < 16:
             padded = self.padded(np.transpose(paddings).tolist())
             return padded.at(other_field)
     return Field.at(self, other_field)
コード例 #2
0
 def at(self,
        other_field,
        collapse_dimensions=True,
        force_optimization=False,
        return_self_if_compatible=False):
     if self.compatible(
             other_field
     ):  # and return_self_if_compatible: not applicable for fields with Points
         return self
     if isinstance(other_field, CenteredGrid) and np.allclose(
             self.dx, other_field.dx):
         paddings = _required_paddings_transposed(self.box, self.dx,
                                                  other_field.box)
         if math.sum(paddings) == 0:
             origin_in_local = self.box.global_to_local(
                 other_field.box.lower) * self.resolution
             data = _crop_for_interpolation(self.data, origin_in_local,
                                            other_field.resolution)
             dimensions = self.resolution != other_field.resolution
             dimensions = [
                 d for d in math.spatial_dimensions(data)
                 if dimensions[d - 1]
             ]
             data = math.interpolate_linear(data, origin_in_local % 1.0,
                                            dimensions)
             return CenteredGrid(data,
                                 other_field.box,
                                 name=self.name,
                                 batch_size=self._batch_size)
         elif math.sum(paddings) < 16:
             padded = self.padded(np.transpose(paddings).tolist())
             return padded.at(other_field, collapse_dimensions,
                              force_optimization)
     return Field.at(self,
                     other_field,
                     force_optimization=force_optimization)