Phase¶
- class baseband_tasks.phases.Phase(phase1, phase2=None, copy=True, subok=False)[source] [edit on github]¶
Bases:
AngleRepresent two-part phase.
With one part the integer cycle count and the other the fractional phase.
The class is a high-precision version of
Anglethat aims to behave just like it, but use its precision in operations where possible – decaying to aQuantityotherwise.For instance, addition and subtraction preserve precision, as do multiplication and division with dimensionless quantities. Similarly, trigonometric functions use just the fractional phase.
The phase can either be purely real or purely imaginary, not mixed. If imaginary, using it in
expwill again preserve precision.- Parameters:
- phase1, phase2array or
Quantity Two-part phase. If not quantities, the assumed units are cycles.
- copybool, optional
Ensure a copy is made. Only relevant if
phase1is aPhaseandphase2is not given.- subokbool, optional
If
False(default), the returned array will be forced to be aPhase. Otherwise,Phasesubclasses will be passed through. Only relevant ifphase1orphase2is aPhasesubclass.
- phase1, phase2array or
Notes
The machinery to keep precision is not complete; in particular, reductions such as summing along an axis will currently lose precision.
Strings passed in to
phase1orphase2are first converted to standard doubles, which may lead to loss of precision. For long strings, use thefrom_stringclass method instead.Attributes Summary
Full cycle, including phase, as a regular Angle.
Fractional phase, between -0.5 and 0.5 cycles.
Rounded cycle count.
The numerical value.
Methods Summary
argmax([axis, out])Return indices of the maximum values along the given axis.
argmin([axis, out])Return indices of the minimum values along the given axis.
argsort([axis])Returns the indices that would sort the phase array.
astype(dtype[, order, casting, subok, copy])Copy of the array, cast to a specified type.
from_angles(phase1[, phase2, factor, ...])Create a Phase instance from two angles.
from_string(string)Create Phase instance from a long string.
max([axis, out, keepdims])Maximum along a given axis.
min([axis, out, keepdims])Minimum along a given axis.
ptp([axis, out, keepdims])Peak to peak (maximum - minimum) along a given axis.
sort([axis])Return a copy sorted along the specified axis.
to(unit[, equivalencies])The phase in a different unit.
to_string([unit, decimal, sep, precision, ...])A string representation of the Phase.
to_value([unit, equivalencies])The numerical value, possibly in a different unit.
Attributes Documentation
- cycle¶
Full cycle, including phase, as a regular Angle.
The result will use a standard double, and thus likely loose precision.
- frac¶
Fractional phase, between -0.5 and 0.5 cycles.
- int¶
Rounded cycle count.
- value¶
The numerical value.
The result will use a standard double, and thus likely loose precision.
See also
to_valueGet the numerical value in a given unit.
Methods Documentation
- argmax(axis=None, out=None)[source] [edit on github]¶
Return indices of the maximum values along the given axis.
- argmin(axis=None, out=None)[source] [edit on github]¶
Return indices of the minimum values along the given axis.
- argsort(axis=-1)[source] [edit on github]¶
Returns the indices that would sort the phase array.
- astype(dtype, order='K', casting='unsafe', subok=True, copy=True)[source] [edit on github]¶
Copy of the array, cast to a specified type.
As
numpy.ndarray.astype, but using knowledge of format to cast to floats.
- classmethod from_angles(phase1, phase2=None, factor=None, divisor=None, out=None)[source] [edit on github]¶
Create a Phase instance from two angles.
The two angles will be added, and possibly multiplied by a factor or divided by a divisor, preserving precision using two doubles, one for the integer part and one for the remainder.
Note that this class method is mostly meant for internal use.
- classmethod from_string(string)[source] [edit on github]¶
Create Phase instance from a long string.
The string has to be a standard decimal string, i.e., no attempt is made to parse an angle.
- max(axis=None, out=None, keepdims=False)[source] [edit on github]¶
Maximum along a given axis.
This is similar to
max(), but adapted to ensure that the full precision is used.
- min(axis=None, out=None, keepdims=False)[source] [edit on github]¶
Minimum along a given axis.
This is similar to
min(), but adapted to ensure that the full precision is used.
- ptp(axis=None, out=None, keepdims=False)[source] [edit on github]¶
Peak to peak (maximum - minimum) along a given axis.
This is similar to
ptp(), but adapted to ensure that the full precision is used.Note
for numpy >= 2.0,
np.ptp(phase)no longer defers to this method.
- sort(axis=-1)[source] [edit on github]¶
Return a copy sorted along the specified axis.
This is similar to
sort(), but internally uses indexing withlexsort()to ensure that the full precision given by the two doubles is kept.- Parameters:
- axisint or None
Axis to be sorted. If
None, the flattened array is sorted. By default, sort over the last axis.
- to(unit, equivalencies=[])[source] [edit on github]¶
The phase in a different unit.
For any unit except “cycle”, this will likely loose precision as an
AngleorQuantityis returned.
- to_string(unit=None, decimal=True, sep='fromunit', precision=None, alwayssign=False, pad=False, fields=3, format=None)[source] [edit on github]¶
A string representation of the Phase.
By default, uses a decimal representation that is guaranteed to preserve precision to within 1e-16 cycles. Otherwise, uses
astropy.coordinates.Angle.to_string.
- to_value(unit=None, equivalencies=[])[source] [edit on github]¶
The numerical value, possibly in a different unit.
The result will use a standard double, and thus likely loose precision.