A helper module containing a class to keep track of vectors in different coordinate systems.

class qcodes.math_utils.field_vector.FieldVector(x: Optional[float] = None, y: Optional[float] = None, z: Optional[float] = None, r: Optional[float] = None, theta: Optional[float] = None, phi: Optional[float] = None, rho: Optional[float] = None)[source]

Bases: object

A convenient class to keep track of vectors representing physical fields. The idea is that a vector instance stores a representation in Cartesian, spherical and cylindrical coordinates. All arguments are optional, however the user needs to provide one of the combinations of either (x, y, z) values or (rho, phi, z) values or (r, theta, phi) values at instantiation for a meaningful computation of the other representation, immediately.

  • x – represents the norm of the projection of the vector along the x-axis

  • y – represents the norm of the projection of the vector along the y-axis

  • z – represents the norm of the projection of the vector along the z-axis

  • r – represents the norm of the vector

  • theta – represents the angle of the vector with respect to the positive z-axis

  • rho – represents the norm of the projection of the vector on to the xy-plane

  • phi – represents the angle of rho with respect to the positive x-axis

attributes = ['x', 'y', 'z', 'r', 'theta', 'phi', 'rho']
repr_format = 'cartesian'
copy(other: qcodes.math_utils.field_vector.T) None[source]

Copy the properties of other vector to yourself.

set_vector(**new_values: float) None[source]

Reset the the values of the vector.


>>> f = FieldVector(x=0, y=2, z=6)
>>> f.set_vector(x=9, y=3, z=1)
>>> f.set_vector(r=1, theta=30.0, phi=10.0)
# The following should raise a value error:
# "Can only set vector with a complete value set"
>>> f.set_vector(x=9, y=0)
# Although mathematically it is possible to compute the complete
# vector from the values given, this is too hard to implement with
# generality (and not worth it), so the following will raise the
# above-mentioned ValueError too.
>>> f.set_vector(x=9, y=0, r=3)
set_component(**new_values: float) None[source]

Set a single component of the vector to some new value. It is disallowed for the user to set vector components manually as this can lead to inconsistencies (e.g. x and rho are not independent of each other, setting one has to effect the other).


>>> f = FieldVector(x=2, y=3, z=4)
# Since r is part of the set (r, theta, phi) representing
# spherical coordinates, setting r means that theta and phi are
# kept constant and only r is changed. After changing r,
# (x, y, z) values are recomputed, as is the rho coordinate.
# Internally we arrange this by setting x, y, z and rho to None
# and calling self._compute_unknowns().
>>> f.set_component(r=10)

new_values (dict) – Keys representing parameter names and values the values to be set.

get_components(*names: str)[source]

Get field components by name.

is_equal(other: qcodes.math_utils.field_vector.FieldVector) bool[source]

Returns True if other is equivalent to self, False otherwise.

norm(ord: Union[str, float] = 2) float[source]

Returns the norm of this field vector. See np.norm for the definition of the ord keyword argument.

distance(other, ord: Union[str, float] = 2) float[source]
property x: Optional[float]
property y: Optional[float]
property z: Optional[float]
property rho: Optional[float]
property theta: Optional[float]
property r: Optional[float]
property phi: Optional[float]
repr_cartesian() str[source]
repr_spherical() str[source]
repr_cylindrical() str[source]
as_homogeneous() numpy.ndarray[source]
classmethod from_homogeneous(hvec: numpy.ndarray) qcodes.math_utils.field_vector.T[source]