@@ -49,10 +49,18 @@ def polar_to_complex(amp, phase, phase_degrees=False):
4949 """
5050 Convert polar coordinates (i.e., amplitude and phase) to complex numbers.
5151
52+ Given as:
53+
54+ ``A * exp(j * phi)``
55+
56+ where, ``A`` is the amplitude and ``phi`` is the phase.
57+
5258 Parameters
5359 ----------
54- complex_vals : array-like
55- Complex number values.
60+ amp : array-like
61+ Amplitude values.
62+ phase : array-like
63+ Phase angle values.
5664 phase_degrees : bool
5765 Whether the phase angles are given in 'degrees'. If ``False``, 'radians'
5866 is assumed.
@@ -71,7 +79,7 @@ def polar_to_complex(amp, phase, phase_degrees=False):
7179 if amp .shape != phase .shape :
7280 raise ValueError ()
7381
74- return amp * ( np .cos ( phase ) + 1j * np . sin ( phase ) )
82+ return amp * np .exp ( 1j * phase )
7583
7684
7785def _check_is_similar (* grids , exact_type = True ):
@@ -963,6 +971,7 @@ def __init__(
963971 waves_coming_from = waves_coming_from ,
964972 )
965973 self ._phase_degrees = False
974+ self ._phase_leading = True
966975
967976 @classmethod
968977 def from_amp_phase (
@@ -972,6 +981,7 @@ def from_amp_phase(
972981 amp ,
973982 phase ,
974983 phase_degrees = False ,
984+ phase_leading = True ,
975985 freq_hz = True ,
976986 degrees = True ,
977987 clockwise = True ,
@@ -999,6 +1009,13 @@ def from_amp_phase(
9991009 phase_degrees : bool
10001010 If the RAO phase values are given in 'degrees'. If ``False``, 'radians'
10011011 is assumed.
1012+ phase_leading : bool
1013+ Whether the phase values follow the 'leading' convention (``True``)
1014+ or the 'lagging' convention (``False``). Mathematically, an RAO with
1015+ phase lead convention is expressed as a complex number of the form
1016+ ``A * exp(j * phi)``, where ``A`` represents the amplitude and ``phi``
1017+ represents the phase angle. Whereas an RAO with phase lag convention
1018+ is expressed as ``A * exp(-j * phi)``.
10021019 freq_hz : bool
10031020 If frequency is given in 'Hz'. If ``False``, 'rad/s' is assumed.
10041021 degrees : bool
@@ -1025,6 +1042,9 @@ def from_amp_phase(
10251042 that are folded about a symmetry plane.
10261043
10271044 """
1045+ if not phase_leading :
1046+ phase = - np .asarray_chkfinite (phase )
1047+
10281048 rao_complex = polar_to_complex (amp , phase , phase_degrees = phase_degrees )
10291049
10301050 rao = cls (
@@ -1037,6 +1057,7 @@ def from_amp_phase(
10371057 waves_coming_from = waves_coming_from ,
10381058 )
10391059 rao ._phase_degrees = phase_degrees
1060+ rao ._phase_leading = phase_leading
10401061 return rao
10411062
10421063 def differentiate (self , n = 1 ):
@@ -1057,7 +1078,9 @@ def differentiate(self, n=1):
10571078 new ._vals = new ._vals * ((1j * new ._freq .reshape (- 1 , 1 )) ** n )
10581079 return new
10591080
1060- def to_amp_phase (self , phase_degrees = None , freq_hz = None , degrees = None ):
1081+ def to_amp_phase (
1082+ self , phase_degrees = None , phase_leading = None , freq_hz = None , degrees = None
1083+ ):
10611084 """
10621085 Return the RAO as amplitude and phase values.
10631086
@@ -1066,6 +1089,15 @@ def to_amp_phase(self, phase_degrees=None, freq_hz=None, degrees=None):
10661089 phase_degrees : bool
10671090 If phase values should be returned in 'degrees'. If ``False``, 'radians'
10681091 is used. Defaults to original units used during initialization or ``False``.
1092+ phase_leading : bool
1093+ Whether the phase values should follow the 'leading' convention (``True``)
1094+ or the 'lagging' convention (``False``). If ``None``, it defaults to
1095+ the convention given during initialization, or the lagging convention
1096+ if no convention was specified during initialization. Mathematically,
1097+ an RAO with phase lead convention is expressed as a complex number of
1098+ the form ``A * exp(j * phi)``, where ``A`` represents the amplitude and
1099+ ``phi`` represents the phase angle. Whereas an RAO with phase lag convention
1100+ is expressed as ``A * exp(-j * phi)``.
10691101 freq_hz : bool
10701102 If frequencies should be returned in 'Hz'. If ``False``, 'rad/s' is used.
10711103 Defaults to original units used during initialization.
@@ -1092,9 +1124,19 @@ def to_amp_phase(self, phase_degrees=None, freq_hz=None, degrees=None):
10921124 degrees = self ._degrees
10931125 if phase_degrees is None :
10941126 phase_degrees = self ._phase_degrees
1127+ if phase_leading is None :
1128+ phase_leading = self ._phase_leading
10951129
10961130 freq , dirs , vals = self .grid (freq_hz = freq_hz , degrees = degrees )
1097- vals_amp , vals_phase = complex_to_polar (vals , phase_degrees = phase_degrees )
1131+ vals_amp , vals_phase = complex_to_polar (vals , phase_degrees = False )
1132+
1133+ if not phase_leading :
1134+ vals_phase = - vals_phase
1135+ vals_phase = np .where (np .isclose (vals_phase , - np .pi ), np .pi , vals_phase )
1136+
1137+ if phase_degrees :
1138+ vals_phase = (180.0 / np .pi ) * vals_phase
1139+
10981140 return freq , dirs , vals_amp , vals_phase
10991141
11001142 def __repr__ (self ):
0 commit comments