Esempio n. 1
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_iterable(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')
     else:
         # need to assign this dataset's unit registry to the YTArray
         self.left_edge = self.ds.arr(left_edge.copy())
     if not isinstance(right_edge, YTArray):
         self.right_edge = self.ds.arr(right_edge, 'code_length')
     else:
         # need to assign this dataset's unit registry to the YTArray
         self.right_edge = self.ds.arr(right_edge.copy())
Esempio n. 2
0
 def __init__(self,
              normal,
              center,
              north_vector=None,
              ds=None,
              field_parameters=None,
              data_source=None):
     validate_3d_array(normal)
     validate_center(center)
     if north_vector is not None:
         validate_3d_array(north_vector)
     validate_object(ds, Dataset)
     validate_object(field_parameters, dict)
     validate_object(data_source, YTSelectionContainer)
     YTSelectionContainer2D.__init__(self, 4, ds, field_parameters,
                                     data_source)
     self._set_center(center)
     self.set_field_parameter('center', center)
     # Let's set up our plane equation
     # ax + by + cz + d = 0
     self.orienter = Orientation(normal, north_vector=north_vector)
     self._norm_vec = self.orienter.normal_vector
     self._d = -1.0 * np.dot(self._norm_vec, self.center)
     self._x_vec = self.orienter.unit_vectors[0]
     self._y_vec = self.orienter.unit_vectors[1]
     # First we try all three, see which has the best result:
     self._rot_mat = np.array([self._x_vec, self._y_vec, self._norm_vec])
     self._inv_mat = np.linalg.pinv(self._rot_mat)
     self.set_field_parameter('cp_x_vec', self._x_vec)
     self.set_field_parameter('cp_y_vec', self._y_vec)
     self.set_field_parameter('cp_z_vec', self._norm_vec)
Esempio n. 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_iterable(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)
Esempio n. 4
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_iterable(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)
Esempio n. 5
0
 def __init__(
     self, obj_list, ds=None, field_parameters=None, data_source=None, center=None
 ):
     validate_iterable(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
Esempio n. 6
0
 def __init__(
     self, axis, coord, center=None, ds=None, field_parameters=None, data_source=None
 ):
     validate_axis(ds, axis)
     validate_float(coord)
     # center is an optional parameter
     if center is not None:
         validate_center(center)
     validate_object(ds, Dataset)
     validate_object(field_parameters, dict)
     validate_object(data_source, YTSelectionContainer)
     YTSelectionContainer2D.__init__(self, axis, ds, field_parameters, data_source)
     self._set_center(center)
     self.coord = coord
Esempio n. 7
0
 def __init__(self, center, radius, ds=None,
              field_parameters=None, data_source=None):
     validate_center(center)
     validate_float(radius)
     validate_object(ds, Dataset)
     validate_object(field_parameters, dict)
     validate_object(data_source, YTSelectionContainer)
     super(YTSphere, self).__init__(center, ds,
                                        field_parameters, data_source)
     # Unpack the radius, if necessary
     radius = fix_length(radius, self.ds)
     if radius < self.index.get_smallest_dx():
         raise YTSphereTooSmall(ds, radius.in_units("code_length"),
                                self.index.get_smallest_dx().in_units("code_length"))
     self.set_field_parameter('radius', radius)
     self.set_field_parameter("center", self.center)
     self.radius = radius
Esempio n. 8
0
def test_validate_center():
    validate_center("max")
    validate_center("MIN_")

    with assert_raises(TypeError) as ex:
        validate_center("avg")
    desired = ("Expected 'center' to be in ['c', 'center', 'm', 'max', 'min'] "
               "or the prefix to be 'max_'/'min_', received 'avg'.")
    assert_equal(str(ex.exception), desired)

    validate_center(YTQuantity(0.25, "cm"))
    validate_center([0.25, 0.25, 0.25])

    class CustomCenter:
        def __init__(self, center):
            self.center = center

    with assert_raises(TypeError) as ex:
        validate_center(CustomCenter(10))
    desired = ("Expected 'center' to be a numeric object of type "
               "list/tuple/np.ndarray/YTArray/YTQuantity, received "
               "'yt.tests.test_funcs.test_validate_center.<locals>."
               "CustomCenter'.")
    assert_equal(str(ex.exception)[:50], desired[:50])