4545except ImportError :
4646 import ConfigParser as configparser
4747import os
48+ import copy
4849import numpy as np
4950from scipy import special
5051
@@ -477,7 +478,7 @@ def control_points(self, deformed=True):
477478
478479 return box_points .T
479480
480- def reflect (self , axis = 0 ):
481+ def reflect (self , axis = 0 , in_place = True ):
481482 """
482483 Reflect the lattice of control points along the direction defined
483484 by `axis`. In particular the origin point of the lattice is preserved.
@@ -492,6 +493,17 @@ def reflect(self, axis=0):
492493 :param int axis: axis along which the reflection is performed.
493494 Default is 0. Possible values are 0, 1, or 2, corresponding
494495 to x, y, and z respectively.
496+ :param bool in_place: if True, the object attributes are modified in
497+ place; if False, a new object is return with the reflected lattice.
498+ Default is True.
499+ :return: a new object with the same parameters and the reflected
500+ lattice if `in_place` is False, otherwise NoneType.
501+
502+ :Example:
503+
504+ >>> ffd.reflect(axis=0, in_place=True) # irreversible
505+ >>> # or ...
506+ >>> refle_ffd = ffd.reflect(axis=0, in_place=False)
495507 """
496508 # check axis value
497509 if axis not in (0 , 1 , 2 ):
@@ -508,6 +520,9 @@ def reflect(self, axis=0):
508520 "points in the symmetry plane along that axis."
509521 )
510522
523+ if in_place is False :
524+ self = copy .deepcopy (self )
525+
511526 # double the control points in the given axis -1 (the symmetry plane)
512527 self .n_control_points [axis ] = 2 * self .n_control_points [axis ] - 1
513528 # double the box length
@@ -536,6 +551,10 @@ def reflect(self, axis=0):
536551 reflection [2 ] *
537552 np .flip (self .array_mu_z , axis )[indeces ],
538553 axis = axis )
554+ if in_place is False :
555+ return self
556+
557+
539558
540559 def __call__ (self , src_pts ):
541560 """
0 commit comments