coords.Coords.bump#

Coords.bump(dir, a, func=None, dist=None, xb=1.0)#

Create a 1-, 2-, or 3-dimensional bump in a Coords.

A bump is a local modification of the coordinates of a collection of points. The bump can be 1-, 2- or 3-dimensional, meaning that the intensity of the coordinate modification varies in 1, 2 or 3 axis directions. In all cases, the bump only changes one coordinate of the points. This method can produce various effects, but one of the most common uses is to force a surface to be indented at some point.

Parameters#

dir: int, one of (0,1,2)

The axis of the coordinates to be modified.

a: point (3,)

The point that sets the bump location and intensity.

func: callable, optional

A function that returns the bump intensity in function of the distance from the bump point a. The distance is the Euclidean distance over all directions except dir. The function takes a single (positive) float value and returns a float (the bump intensity). Its value should not be zero at the origin. The function may include constants, which can be specified as xb. If no function is specified, the default function will be used: lambda x: np.where(x<xb,1.-(x/3)**2,0) This makes the bump quadratically die out over a distance xb.

dist: int or tuple of ints, optional

Specifies how the distance from points to the bump point a is measured. It can be a single axis number (0,1,2) or a tuple of two or three axis numbers. If a single axis, the bump will vary only in one direction and distance is measured along that direction and is signed. If two or three axes, distance is the (always positive) euclidean distance over these directions and the bump will vary in these directions. Default value is the set of 3 axes minus the direction of modification dir.

xb: float or list of floats

Constant(s) to be used in func. Often, this includes the distance over which the bump will extend. The default bump function will reach zero at this distance.

Returns#

Coords

A Coords with same shape as input, but having a localized change of coordinates as specified by the parameters.

Examples#

One-dimensional bump in a linear set of points.

>>> X = Coords(np.arange(6).reshape(-1,1))
>>> X.bump(1,[3.,5.,0.],dist=0)
Coords([[0., 0., 0.],
        [1., 0., 0.],
        [2., 0., 0.],
        [3., 5., 0.],
        [4., 0., 0.],
        [5., 0., 0.]])
>>> X.bump(1,[3.,5.,0.],dist=0,xb=3.)
Coords([[0.    , 0.    , 0.    ],
        [1.    , 2.7778, 0.    ],
        [2.    , 4.4444, 0.    ],
        [3.    , 5.    , 0.    ],
        [4.    , 4.4444, 0.    ],
        [5.    , 2.7778, 0.    ]])

Create a grid a points in xz-plane, with a bump in direction y with a maximum 5 at x=1.5, z=0., extending over a distance 2.5.

>>> X = Coords(np.arange(4).reshape(-1,1)).replicate(4,dir=2)
>>> X.bump(1,[1.5,5.,0.],xb=2.5)
Coords([[[0.    , 3.75  , 0.    ],
        [1.    , 4.8611, 0.    ],
        [2.    , 4.8611, 0.    ],
        [3.    , 3.75  , 0.    ]],

        [[0.    , 3.1944, 1.    ],
        [1.    , 4.3056, 1.    ],
        [2.    , 4.3056, 1.    ],
        [3.    , 3.1944, 1.    ]],

        [[0.    , 0.    , 2.    ],
        [1.    , 2.6389, 2.    ],
        [2.    , 2.6389, 2.    ],
        [3.    , 0.    , 2.    ]],

        [[0.    , 0.    , 3.    ],
        [1.    , 0.    , 3.    ],
        [2.    , 0.    , 3.    ],
        [3.    , 0.    , 3.    ]]])