sign_pbc

halotools.mock_observables.sign_pbc(x1, x2, period=None, equality_fill_val=0.0, return_pbc_correction=False)[source] [edit on github]

Return the sign of the unit vector pointing from x2 towards x1, that is, the sign of (x1 - x2), accounting for periodic boundary conditions.

If x1 > x2, returns 1. If x1 < x2, returns -1. If x1 == x2, returns equality_fill_val.

Parameters:

x1 : array

1-d array of length Npts. If period is not None, all values must be contained in [0, Lbox)

x2 : array

1-d array of length Npts. If period is not None, all values must be contained in [0, Lbox)

period : float, optional

Size of the periodic box. Default is None for non-periodic case.

equality_fill_val : float, optional

Value to return for cases where x1 == x2. Default is 0.

return_pbc_correction : bool, optional

If True, the sign_pbc function will additionally return a length Npts boolean array storing whether or not the input points had a PBC correction applied. Default is False.

Returns:

sgn : array

1-d array of length Npts.

Examples

>>> Lbox = 250.0
>>> x1 = 1.
>>> x2 = 249.
>>> result = sign_pbc(x1, x2, period=Lbox)
>>> assert result == 1
>>> result = sign_pbc(x1, x2, period=None)
>>> assert result == -1
>>> npts = 100
>>> x1 = np.random.uniform(0, Lbox, npts)
>>> x2 = np.random.uniform(0, Lbox, npts)
>>> result = sign_pbc(x1, x2, period=Lbox)