Phase

class baseband_tasks.phases.Phase(phase1, phase2=None, copy=True, subok=False)[source] [edit on github]

Bases: astropy.coordinates.Angle

Represent two-part phase.

With one part the integer cycle count and the other the fractional phase.

The class is a high-precision version of Angle that aims to behave just like it, but use its precision in operations where possible – decaying to a Quantity otherwise.

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 exp will 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 phase1 is a Phase and phase2 is not given.

subokbool, optional

If False (default), the returned array will be forced to be a Phase. Otherwise, Phase subclasses will be passed through. Only relevant if phase1 or phase2 is a Phase subclass.

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 phase1 or phase2 are first converted to standard doubles, which may lead to loss of precision. For long strings, use the from_string class method instead.

Attributes Summary

cycle

Full cycle, including phase, as a regular Angle.

frac

Fractional phase, between -0.5 and 0.5 cycles.

int

Rounded cycle count.

value

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_value

Get 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.

Parameters
phase1Quantity

With angular units.

phase2Quantity or None

With angular units.

factorfloat or complex

Posisble factor to multiply the angles with.

divisorfloat or complex

Posisble divisor to divide the angles by.

Raises
ValueError

If the result is not purely real or purely imaginary

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.

sort(axis=- 1)[source] [edit on github]

Return a copy sorted along the specified axis.

This is similar to sort(), but internally uses indexing with lexsort() 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 Angle or Quantity is 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.