Skip to content
Snippets Groups Projects
Commit c31d6cd9 authored by Wouter Klijn's avatar Wouter Klijn
Browse files

Task #3139: Add ComplexArray.py

parent 3f82a5fe
No related branches found
No related tags found
No related merge requests found
......@@ -1118,6 +1118,7 @@ CEP/Pipeline/recipes/sip/demixing/bbs_TauA.parset eol=lf
CEP/Pipeline/recipes/sip/demixing/bbs_TauA_smoothcal.parset eol=lf
CEP/Pipeline/recipes/sip/demixing/bbs_VirA.parset eol=lf
CEP/Pipeline/recipes/sip/demixing/bbs_VirA_smoothcal.parset eol=lf
CEP/Pipeline/recipes/sip/helpers/ComplexArray.py -text
CEP/Pipeline/recipes/sip/helpers/WritableParmDB.py -text
CEP/Pipeline/recipes/sip/helpers/__init__.py eol=lf
CEP/Pipeline/recipes/sip/helpers/metadata.py eol=lf
......
import numpy
# Untested copu pasta of jon swinbanks code
class ComplexArray(object):
def __init__(self):
raise NotImplementedError
def get_amp(self):
return numpy.absolute(numpy.nan_to_num(self.data))
def set_amp(self, new_amps):
self.data = numpy.array(new_amps) * self.data / numpy.absolute(self.data)
amp = property(get_amp, set_amp)
Ampl = amp
def get_phase(self):
return numpy.angle(numpy.nan_to_num(self.data))
def set_phase(self, new_phase):
self.data = numpy.vectorize(cmath.rect)(
numpy.absolute(self.data), numpy.array(new_phase)
)
phase = property(get_phase, set_phase)
Phase = phase
def get_real(self):
return numpy.real(numpy.nan_to_num(self.data))
def set_real(self, new_real):
self.data = numpy.array(new_real) + 1j * numpy.imag(self.data)
real = property(get_real, set_real)
Real = real
def get_imag(self):
return numpy.imag(numpy.nan_to_num(self.data))
def set_imag(self, new_imag):
self.data = numpy.real(self.data) + 1j * numpy.array(new_imag)
imag = property(get_imag, set_imag)
Imag = imag
@property
def writeable(self):
return dict((key, getattr(self, key)) for key in self.keys)
class RealImagArray(ComplexArray):
keys = ("Real", "Imag")
def __init__(self, real, imag):
self.data = numpy.array(real) + 1j * numpy.array(imag)
class AmplPhaseArray(ComplexArray):
keys = ("Ampl", "Phase")
def __init__(self, ampl, phase):
self.data = numpy.vectorize(cmath.rect)(
numpy.array(ampl), numpy.array(phase)
)
ARRAY_TYPES = [RealImagArray, AmplPhaseArray]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment