def like_me(self, **overrides): if 'center' in overrides: return super().like_me(**overrides) for i, coord in enumerate(('x', 'y', 'z')): if coord in overrides: overrides['center[{}]'.format(i)] = overrides[coord] del overrides[coord] return self.from_parameters(updated(self.parameters, overrides))
def test_updated_keep_None(self): input_dict = {'a': 1, 'b': 2, 'c': 3, 'd': 4} update_dict = {'c': 5, 'd': None, 'e': 6} output_dict = updated(input_dict, update_dict, False) self.assertEqual(input_dict, {'a': 1, 'b': 2, 'c': 3, 'd': 4}) self.assertEqual(output_dict, { 'a': 1, 'b': 2, 'c': 5, 'd': None, 'e': 6 })
def update_metadata(a, medium_index=None, illum_wavelen=None, illum_polarization=None, normals=None, noise_sd=None): """Returns a copy of an image with updated metadata in its 'attrs' field. Parameters ---------- a : xarray.DataArray image to update. medium_index : float Updated refractive index of the medium in the image. illum_wavelen : float Updated wavelength of illumination in the image. illum_polarization : list-like Updated polarization of illumination in the image. noise_sd : float standard deviation of Gaussian noise in the image. Returns ------- b : xarray.DataArray copy of input image with updated metadata. """ if normals is not None: raise ValueError(NORMALS_DEPRECATION_MESSAGE) attrlist = { 'medium_index': medium_index, 'illum_wavelen': dict_to_array(a, illum_wavelen), 'illum_polarization': dict_to_array(a, to_vector(illum_polarization)), 'noise_sd': dict_to_array(a, noise_sd) } b = a.copy() b.attrs = updated(b.attrs, attrlist) for attr in attrlist: if not hasattr(b, attr): b.attrs[attr] = None return b
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)
def test_kw_takes_priority(self): input_dict = {'a': 1, 'b': 2, 'c': 3, 'd': 4} update_dict = {'c': 5, 'd': None, 'e': 6} output_dict = updated(input_dict, update_dict, b=7, e=8) self.assertEqual(input_dict, {'a': 1, 'b': 2, 'c': 3, 'd': 4}) self.assertEqual(output_dict, {'a': 1, 'b': 7, 'c': 5, 'd': 4, 'e': 8})
def test_updated_from_kw(self): input_dict = {'a': 1, 'b': 2, 'c': 3, 'd': 4} output_dict = updated(input_dict, b=7, c=None, e=8) self.assertEqual(input_dict, {'a': 1, 'b': 2, 'c': 3, 'd': 4}) self.assertEqual(output_dict, {'a': 1, 'b': 7, 'c': 3, 'd': 4, 'e': 8})