Beispiel #1
0
    def __init__(
        self,
        data_source,
        conditionals,
        ds=None,
        field_parameters=None,
        base_object=None,
        locals=None,
    ):
        if locals is None:
            locals = {}
        validate_object(data_source, YTSelectionContainer)
        validate_sequence(conditionals)
        for condition in conditionals:
            validate_object(condition, str)
        validate_object(ds, Dataset)
        validate_object(field_parameters, dict)
        validate_object(base_object, YTSelectionContainer)

        self.conditionals = list(always_iterable(conditionals))
        if isinstance(data_source, YTCutRegion):
            # If the source is also a cut region, add its conditionals
            # and set the source to be its source.
            # Preserve order of conditionals.
            self.conditionals = data_source.conditionals + self.conditionals
            data_source = data_source.base_object

        super().__init__(
            data_source.center, ds, field_parameters, data_source=data_source
        )
        self.filter_fields = self._check_filter_fields()
        self.base_object = data_source
        self.locals = locals
        self._selector = None
Beispiel #2
0
 def __init__(self,
              axis,
              coords,
              ds=None,
              field_parameters=None,
              data_source=None):
     validate_axis(ds, axis)
     validate_sequence(coords)
     for c in coords:
         validate_float(c)
     validate_object(ds, Dataset)
     validate_object(field_parameters, dict)
     validate_object(data_source, YTSelectionContainer)
     super().__init__(ds, field_parameters, data_source)
     self.axis = fix_axis(axis, self.ds)
     xax = self.ds.coordinates.x_axis[self.axis]
     yax = self.ds.coordinates.y_axis[self.axis]
     self.px_ax = xax
     self.py_ax = yax
     # Even though we may not be using x,y,z we use them here.
     self.px_dx = f"d{'xyz'[self.px_ax]}"
     self.py_dx = f"d{'xyz'[self.py_ax]}"
     # Convert coordinates to code length.
     if isinstance(coords[0], YTQuantity):
         self.px = self.ds.quan(coords[0]).to("code_length")
     else:
         self.px = self.ds.quan(coords[0], "code_length")
     if isinstance(coords[1], YTQuantity):
         self.py = self.ds.quan(coords[1]).to("code_length")
     else:
         self.py = self.ds.quan(coords[1], "code_length")
     self.sort_by = "xyz"[self.axis]
Beispiel #3
0
 def __init__(
     self,
     center,
     normal,
     radius,
     height,
     fields=None,
     ds=None,
     field_parameters=None,
     data_source=None,
 ):
     validate_center(center)
     validate_3d_array(normal)
     validate_float(radius)
     validate_float(height)
     validate_sequence(fields)
     validate_object(ds, Dataset)
     validate_object(field_parameters, dict)
     validate_object(data_source, YTSelectionContainer)
     YTSelectionContainer3D.__init__(self, center, ds, field_parameters,
                                     data_source)
     self._norm_vec = np.array(normal) / np.sqrt(np.dot(normal, normal))
     self.set_field_parameter("normal", self._norm_vec)
     self.set_field_parameter("center", self.center)
     self.height = fix_length(height, self.ds)
     self.radius = fix_length(radius, self.ds)
     self._d = -1.0 * np.dot(self._norm_vec, self.center)
Beispiel #4
0
 def __init__(
     self,
     center,
     left_edge,
     right_edge,
     fields=None,
     ds=None,
     field_parameters=None,
     data_source=None,
 ):
     if center is not None:
         validate_center(center)
     validate_3d_array(left_edge)
     validate_3d_array(right_edge)
     validate_sequence(fields)
     validate_object(ds, Dataset)
     validate_object(field_parameters, dict)
     validate_object(data_source, YTSelectionContainer)
     YTSelectionContainer3D.__init__(self, center, ds, field_parameters, data_source)
     if not isinstance(left_edge, YTArray):
         self.left_edge = self.ds.arr(left_edge, "code_length", dtype="float64")
     else:
         # need to assign this dataset's unit registry to the YTArray
         self.left_edge = self.ds.arr(left_edge.copy(), dtype="float64")
     if not isinstance(right_edge, YTArray):
         self.right_edge = self.ds.arr(right_edge, "code_length", dtype="float64")
     else:
         # need to assign this dataset's unit registry to the YTArray
         self.right_edge = self.ds.arr(right_edge.copy(), dtype="float64")
Beispiel #5
0
 def __init__(self, data_objects, ds=None, field_parameters=None, data_source=None):
     validate_sequence(data_objects)
     for obj in data_objects:
         validate_object(obj, YTSelectionContainer)
     validate_object(ds, Dataset)
     validate_object(field_parameters, dict)
     validate_object(data_source, YTSelectionContainer)
     YTSelectionContainer3D.__init__(self, None, ds, field_parameters, data_source)
     self.data_objects = list(always_iterable(data_objects))
Beispiel #6
0
 def __init__(self,
              obj_list,
              ds=None,
              field_parameters=None,
              data_source=None,
              center=None):
     validate_sequence(obj_list)
     validate_object(ds, Dataset)
     validate_object(field_parameters, dict)
     validate_object(data_source, YTSelectionContainer)
     if center is not None:
         validate_center(center)
     YTSelectionContainer3D.__init__(self, center, ds, field_parameters,
                                     data_source)
     self._obj_ids = np.array([o.id - o._id_offset for o in obj_list],
                              dtype="int64")
     self._obj_list = obj_list
Beispiel #7
0
    def __init__(
        self,
        center,
        A,
        B,
        C,
        e0,
        tilt,
        fields=None,
        ds=None,
        field_parameters=None,
        data_source=None,
    ):
        validate_center(center)
        validate_float(A)
        validate_float(B)
        validate_float(C)
        validate_3d_array(e0)
        validate_float(tilt)
        validate_sequence(fields)
        validate_object(ds, Dataset)
        validate_object(field_parameters, dict)
        validate_object(data_source, YTSelectionContainer)
        YTSelectionContainer3D.__init__(self, center, ds, field_parameters, data_source)
        # make sure the magnitudes of semi-major axes are in order
        if A < B or B < C:
            raise YTEllipsoidOrdering(ds, A, B, C)
        # make sure the smallest side is not smaller than dx
        self._A = self.ds.quan(A, "code_length")
        self._B = self.ds.quan(B, "code_length")
        self._C = self.ds.quan(C, "code_length")
        if self._C < self.index.get_smallest_dx():
            raise YTSphereTooSmall(self.ds, self._C, self.index.get_smallest_dx())
        self._e0 = e0 = e0 / (e0 ** 2.0).sum() ** 0.5
        self._tilt = tilt

        # find the t1 angle needed to rotate about z axis to align e0 to x
        t1 = np.arctan(e0[1] / e0[0])
        # rotate e0 by -t1
        RZ = get_rotation_matrix(t1, (0, 0, 1)).transpose()
        r1 = (e0 * RZ).sum(axis=1)
        # find the t2 angle needed to rotate about y axis to align e0 to x
        t2 = np.arctan(-r1[2] / r1[0])
        """
        calculate the original e1
        given the tilt about the x axis when e0 was aligned
        to x after t1, t2 rotations about z, y
        """
        RX = get_rotation_matrix(-tilt, (1, 0, 0)).transpose()
        RY = get_rotation_matrix(-t2, (0, 1, 0)).transpose()
        RZ = get_rotation_matrix(-t1, (0, 0, 1)).transpose()
        e1 = ((0, 1, 0) * RX).sum(axis=1)
        e1 = (e1 * RY).sum(axis=1)
        e1 = (e1 * RZ).sum(axis=1)
        e2 = np.cross(e0, e1)

        self._e1 = e1
        self._e2 = e2

        self.set_field_parameter("A", A)
        self.set_field_parameter("B", B)
        self.set_field_parameter("C", C)
        self.set_field_parameter("e0", e0)
        self.set_field_parameter("e1", e1)
        self.set_field_parameter("e2", e2)