Beispiel #1
0
 def test_all_keys(self):
     input_dict = {'x': [0], 'y': [1], 'z': [0, 1, 2]}
     output_dict = {
         'x': np.array([0, 0, 0]),
         'y': np.array([1, 1, 1]),
         'z': [0, 1, 2]
     }
     np.testing.assert_equal(repeat_sing_dims(input_dict), output_dict)
Beispiel #2
0
def to_cartesian(r, theta, phi):
    x, y, z = transform_spherical_to_cartesian([r, theta, phi])
    return repeat_sing_dims({'x': x, 'y': y, 'z': z})
Beispiel #3
0
def detector_points(coords={}, x=None, y=None, z=None, r=None, theta=None,
                    phi=None, normals=None, name=None):
    """
    Returns a one-dimensional set of detector coordinates at which scattering
    calculations are to be done.

    Parameters
    ----------
    coords : dict, optional
        Dictionary of detector coordinates. Default: empty dictionary.
        Typical usage should not pass this argument, giving other parameters
        (Cartesian `x`, `y`, and `z` or polar `r`, `theta`, and `phi`
        coordinates) instead.
    x, y : int or array_like, optional
        Cartesian x and y coordinates of detectors.
    z : int or array_like, optional
        Cartesian z coordinates of detectors. If not specified, assume `z` = 0.
    r : int or array_like, optional
        Spherical polar radial coordinates of detectors. If not specified,
        assume `r` = infinity (far-field).
    theta : int or array_like, optional
        Spherical polar coordinates (polar angle from z axis) of detectors.
    phi : int or array_like, optional
        Spherical polar azimuthal coodinates of detectors.
    name : string

    Returns
    -------
    grid : DataArray object
        DataArray of zeros with calculated coordinates.

    Notes
    -----
    Specify either the Cartesian or the polar coordinates of your detector.
    This may be helpful for modeling static light scattering calculations.
    Use detector_grid() to specify coordinates of a grid of pixels (e.g.,
    a digital camera.)

    """
    if normals is not None:
        raise ValueError(NORMALS_DEPRECATION_MESSAGE)
    updatelist = {'x': x, 'y': y, 'z': z, 'r': r, 'theta': theta, 'phi': phi}
    coords = updated(coords, updatelist)
    if 'x' in coords and 'y' in coords:
        keys = ['x', 'y', 'z']
        if coords.get('z') is None:
            coords['z'] = 0

    elif 'theta' in coords and 'phi' in coords:
        keys = ['r', 'theta', 'phi']
        if coords.get('r') is None:
            coords['r'] = np.inf
    else:
        raise CoordSysError()

    if name is None:
        name = 'data'

    coords = repeat_sing_dims(coords, keys)
    coords = updated(coords, {key: ('point', coords[key]) for key in keys})
    return xr.DataArray(np.zeros(len(coords[keys[0]][1])), dims=['point'],
                        coords=coords, name=name)
Beispiel #4
0
 def test_nothing_to_repeat(self):
     input_dict = {'x': [0], 'y': [1], 'z': [0, 1, 2]}
     repeated = repeat_sing_dims(input_dict, ['x', 'y'])
     self.assertEqual(repeated, input_dict)
Beispiel #5
0
 def test_repeat_some_keys(self):
     input_dict = {'x': [0], 'y': [1], 'z': [0, 1, 2]}
     output_dict = {'x': np.array([0, 0, 0]), 'y': [1], 'z': [0, 1, 2]}
     repeated = repeat_sing_dims(input_dict, ['x', 'z'])
     np.testing.assert_equal(repeated, output_dict)
Beispiel #6
0
 def test_input_isnt_modified(self):
     input_dict = {'x': [0], 'y': [1], 'z': [0, 1, 2]}
     repeat_sing_dims(input_dict)
     self.assertEqual(input_dict, {'x': [0], 'y': [1], 'z': [0, 1, 2]})