Skip to content

Commit bee82bf

Browse files
committed
Code cleanup
Code cleanup from Pycharm - mostly PEP8 Added stokesI for PolarisationFrame and ReceptorFrame
1 parent b0a2fc8 commit bee82bf

35 files changed

Lines changed: 1145 additions & 615 deletions

‎arl/calibration/gaintable.py‎

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def create_gaintable_from_blockvisibility(vis: BlockVisibility, time_width: floa
2929
This makes an empty gain table consistent with the BlockVisibility.
3030
3131
:param vis: BlockVisibilty
32-
:param time_interval: Time interval between solutions (s)
32+
:param time_width: Time interval between solutions (s)
3333
:param frequency_width: Frequency solution width (Hz)
3434
:returns: GainTable
3535
@@ -42,7 +42,7 @@ def create_gaintable_from_blockvisibility(vis: BlockVisibility, time_width: floa
4242
ufrequency = numpy.unique(vis.frequency)
4343
nfrequency = len(ufrequency)
4444

45-
receptor_frame = Receptor_Frame(vis.polarisation_frame.type)
45+
receptor_frame = ReceptorFrame(vis.polarisation_frame.type)
4646
nrec = receptor_frame.nrec
4747
vnpol = vis.polarisation_frame.npol
4848

@@ -151,8 +151,8 @@ def solve_gaintable(vis: BlockVisibility, modelvis: BlockVisibility, phase_only=
151151

152152
# Now average over time, chan. The axes of X are time, antenna2, antenna1, chan, pol
153153

154-
Xave = numpy.average(X * Xwt, axis=(0))
155-
XwtAve = numpy.average(Xwt, axis=(0))
154+
Xave = numpy.average(X * Xwt, axis=0)
155+
XwtAve = numpy.average(Xwt, axis=0)
156156

157157
mask = XwtAve > 0.0
158158
Xave[mask] = Xave[mask] / XwtAve[mask]
@@ -225,26 +225,26 @@ def gain_substitution_scalar(gain, X, Xwt):
225225
nants, nchan, nrec, _ = gain.shape
226226
newgain = numpy.ones_like(gain, dtype='complex')
227227
gwt = numpy.zeros_like(gain, dtype='float')
228-
228+
229229
# We are going to work with Jones 2x2 matrix formalism so everything has to be
230230
# converted to that format
231231
X = X.reshape(nants, nants, nchan, nrec, nrec)
232232
Xwt = Xwt.reshape(nants, nants, nchan, nrec, nrec)
233-
233+
234234
for ant1 in range(nants):
235235
for chan in range(nchan):
236236
# Loop over e.g. 'RR', 'LL, or 'XX', 'YY' ignoring cross terms
237-
top = numpy.sum(X[:, ant1, chan, 0, 0] \
238-
* gain[:, chan, 0, 0] * Xwt[:, ant1, chan, 0, 0], axis=0)
239-
bot = numpy.sum((gain[:, chan, 0, 0] * numpy.conjugate(gain[:, chan, 0, 0])
240-
* Xwt[:, ant1, chan, 0, 0]).real, axis=0)
237+
top = numpy.sum(X[:, ant1, chan, 0, 0] \
238+
* gain[:, chan, 0, 0] * Xwt[:, ant1, chan, 0, 0], axis=0)
239+
bot = numpy.sum((gain[:, chan, 0, 0] * numpy.conjugate(gain[:, chan, 0, 0])
240+
* Xwt[:, ant1, chan, 0, 0]).real, axis=0)
241241

242-
if bot > 0.0:
243-
newgain[ant1, chan, 0, 0] = top / bot
244-
gwt[ant1, chan, 0, 0] = bot
245-
else:
246-
newgain[ant1, chan, 0, 0] = 0.0
247-
gwt[ant1, chan, 0, 0] = 0.0
242+
if bot > 0.0:
243+
newgain[ant1, chan, 0, 0] = top / bot
244+
gwt[ant1, chan, 0, 0] = bot
245+
else:
246+
newgain[ant1, chan, 0, 0] = 0.0
247+
gwt[ant1, chan, 0, 0] = 0.0
248248
return newgain, gwt
249249

250250

@@ -307,7 +307,7 @@ def gain_substitution_vector(gain, X, Xwt):
307307
if nrec > 0:
308308
newgain[..., 0, 1] = 0.0
309309
newgain[..., 1, 0] = 0.0
310-
310+
311311
gwt = numpy.zeros_like(gain, dtype='float')
312312

313313
# We are going to work with Jones 2x2 matrix formalism so everything has to be
@@ -349,6 +349,7 @@ def solve_antenna_gains_itsubs_matrix(gainshape, X, Xwt, niter=30, tol=1e-8, pha
349349
scalar self-calibration: Self-alignment, dynamic range and polarimetric fidelity,” Astronomy
350350
and Astrophysics Supplement Series, vol. 143, no. 3, pp. 515–534, May 2000.
351351
352+
:param gainshape: Shape of gaintable
352353
:param X: Equivalent point source visibility[nants, nants, ...]
353354
:param Xwt: Equivalent point source weight [nants, nants, ...]
354355
:param niter: Number of iterations
@@ -432,20 +433,20 @@ def solution_residual_scalar(gain, X, Xwt):
432433

433434
nants, nchan, nrec, _ = gain.shape
434435
X = X.reshape(nants, nants, nchan, nrec, nrec)
435-
436+
436437
Xwt = Xwt.reshape(nants, nants, nchan, nrec, nrec)
437-
438+
438439
residual = numpy.zeros([nchan, nrec, nrec])
439440
sumwt = numpy.zeros([nchan, nrec, nrec])
440-
441+
441442
for ant1 in range(nants):
442443
for ant2 in range(nants):
443444
for chan in range(nchan):
444445
error = X[ant2, ant1, chan, 0, 0] - \
445446
gain[ant1, chan, 0, 0] * numpy.conjugate(gain[ant2, chan, 0, 0])
446447
residual += (error * Xwt[ant2, ant1, chan, 0, 0] * numpy.conjugate(error)).real
447448
sumwt += Xwt[ant2, ant1, chan, 0, 0]
448-
449+
449450
residual = numpy.sqrt(residual / sumwt)
450451
return residual
451452

‎arl/data/data_models.py‎

Lines changed: 37 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from astropy import units as u
99
from astropy.coordinates import SkyCoord
1010

11-
from arl.data.polarisation import Polarisation_Frame, Receptor_Frame
11+
from arl.data.polarisation import PolarisationFrame, ReceptorFrame
1212

1313
log = logging.getLogger(__name__)
1414

@@ -20,10 +20,10 @@ class Configuration:
2020
"""
2121

2222
def __init__(self, name='', data=None, location=None,
23-
names="%s", xyz=None, mount="alt-az", frame=None, receptor_frame=Receptor_Frame("linear")):
23+
names="%s", xyz=None, mount="alt-az", frame=None, receptor_frame=ReceptorFrame("linear")):
2424

2525
# Defaults
26-
if data is None and not xyz is None:
26+
if data is None and xyz is not None:
2727
desc = [('names', '<U6'),
2828
('xyz', '<f8', (3,)),
2929
('mount', '<U5')]
@@ -75,8 +75,8 @@ class GainTable:
7575
"""
7676

7777
def __init__(self, data=None, gain: numpy.array = None, time: numpy.array = None, weight: numpy.array = None,
78-
residual: numpy.array = None, frequency: numpy.array = None, receptor_frame: Receptor_Frame = \
79-
Receptor_Frame("linear")):
78+
residual: numpy.array = None, frequency: numpy.array = None,
79+
receptor_frame: ReceptorFrame = ReceptorFrame("linear")):
8080
""" Create a gaintable from arrays
8181
8282
The definition of gain is:
@@ -89,7 +89,7 @@ def __init__(self, data=None, gain: numpy.array = None, time: numpy.array = None
8989
:param frequency:
9090
:returns: Gaintable
9191
"""
92-
if data is None and not gain is None:
92+
if data is None and gain is not None:
9393
nrec = receptor_frame.nrec
9494
nrows = gain.shape[0]
9595
nants = gain.shape[1]
@@ -113,29 +113,28 @@ def size(self):
113113
size = 0
114114
size += self.data.size * sys.getsizeof(self.data)
115115
return size / 1024.0 / 1024.0 / 1024.0
116-
116+
117117
@property
118118
def time(self):
119119
return self.data['time']
120120

121121
@property
122122
def gain(self):
123123
return self.data['gain']
124-
124+
125125
@property
126126
def weight(self):
127127
return self.data['weight']
128128

129129
@property
130130
def residual(self):
131131
return self.data['residual']
132-
132+
133133
@property
134134
def nants(self):
135135
return self.data['gain'].shape[1]
136136

137137

138-
139138
class Image:
140139
"""Image class with Image data (as a numpy.array) and optionally the AstroPy WCS.
141140
@@ -169,10 +168,10 @@ def nchan(self): return self.data.shape[0]
169168

170169
@property
171170
def npol(self): return self.data.shape[1]
172-
171+
173172
@property
174173
def nheight(self): return self.data.shape[2]
175-
174+
176175
@property
177176
def nwidth(self): return self.data.shape[3]
178177

@@ -184,18 +183,19 @@ def frequency(self):
184183
@property
185184
def shape(self):
186185
return self.data.shape
187-
186+
188187
@property
189188
def phasecentre(self): return SkyCoord(self.wcs.wcs.crval[0] * u.deg, self.wcs.wcs.crval[1] * u.deg)
190189

190+
191191
class Skycomponent:
192192
""" A single Skycomponent with direction, flux, shape, and params for the shape
193193
194194
"""
195195

196196
def __init__(self,
197197
direction=None, frequency=None, name=None, flux=None, shape='Point',
198-
polarisation_frame=Polarisation_Frame('stokesIQUV'), **kwargs):
198+
polarisation_frame=PolarisationFrame('stokesIQUV'), **kwargs):
199199
""" Define the required structure
200200
201201
:param direction: SkyCoord
@@ -233,24 +233,13 @@ def __str__(self):
233233
234234
"""
235235
s = "Skycomponent:\n"
236-
s += "\tFlux: %s\n" % (self.flux)
237-
s += "\tDirection: %s\n" % (self.direction)
238-
s += "\tShape: %s\n" % (self.shape)
239-
s += "\tParams: %s\n" % (self.params)
240-
s += "\tPolaristation frame %s\n" %(self.polarisation_frame)
236+
s += "\tFlux: %s\n" % self.flux
237+
s += "\tDirection: %s\n" % self.direction
238+
s += "\tShape: %s\n" % self.shape
239+
s += "\tParams: %s\n" % self.params
240+
s += "\tPolarisation frame %s\n" % self.polarisation_frame
241241
return s
242242

243-
244-
class Skymodel:
245-
""" A skymodel consisting of a list of images and a list of skycomponents
246-
247-
"""
248-
249-
def __init__(self):
250-
self.images = [] # collection of numpy arrays
251-
self.components = [] # collection of SkyComponents
252-
253-
254243
class Visibility:
255244
""" Visibility table class
256245
@@ -264,9 +253,8 @@ class Visibility:
264253

265254
def __init__(self,
266255
data=None, frequency=None, channel_bandwidth=None, phasecentre=None, configuration=None,
267-
uvw=None, time=None, antenna1=None, antenna2=None, polarisation=None,
268-
vis=None, weight=None, imaging_weight=None, integration_time=None,
269-
polarisation_frame = Polarisation_Frame('stokesI')):
256+
uvw=None, time=None, antenna1=None, antenna2=None, vis=None, weight=None, imaging_weight=None,
257+
integration_time=None, polarisation_frame=PolarisationFrame('stokesI')):
270258
if data is None and vis is not None:
271259
if imaging_weight is None:
272260
imaging_weight = weight
@@ -293,7 +281,7 @@ def __init__(self,
293281
data['vis'] = vis
294282
data['weight'] = weight
295283
data['imaging_weight'] = imaging_weight
296-
284+
297285
self.data = data # numpy structured array
298286
self.phasecentre = phasecentre # Phase centre of observation
299287
self.configuration = configuration # Antenna/station configuration
@@ -312,7 +300,7 @@ def nvis(self):
312300
return self.data['vis'].shape[0]
313301

314302
@property
315-
def uvw(self): # In wavelengths in Visibility
303+
def uvw(self): # In wavelengths in Visibility
316304
return self.data['uvw']
317305

318306
@property
@@ -326,23 +314,23 @@ def v(self):
326314
@property
327315
def w(self):
328316
return self.data['uvw'][:, 2]
329-
317+
330318
@property
331319
def time(self):
332320
return self.data['time']
333-
321+
334322
@property
335323
def integration_time(self):
336324
return self.data['integration_time']
337-
325+
338326
@property
339327
def frequency(self):
340328
return self.data['frequency']
341-
329+
342330
@property
343331
def channel_bandwidth(self):
344332
return self.data['channel_bandwidth']
345-
333+
346334
@property
347335
def antenna1(self):
348336
return self.data['antenna1']
@@ -378,7 +366,7 @@ def __init__(self,
378366
data=None, frequency=None, channel_bandwidth=None, phasecentre=None, configuration=None,
379367
uvw=None, time=None,
380368
vis=None, weight=None, integration_time=None,
381-
polarisation_frame=Polarisation_Frame('stokesI')):
369+
polarisation_frame=PolarisationFrame('stokesI')):
382370
if data is None and vis is not None:
383371
ntimes = len(time)
384372
assert vis.shape == weight.shape
@@ -400,7 +388,6 @@ def __init__(self,
400388
data['weight'] = weight
401389

402390
self.data = data # numpy structured array
403-
self.time = time
404391
self.frequency = frequency
405392
self.channel_bandwidth = channel_bandwidth
406393
self.phasecentre = phasecentre # Phase centre of observation
@@ -414,15 +401,15 @@ def size(self):
414401
for col in self.data.dtype.fields.keys():
415402
size += self.data[col].nbytes
416403
return size / 1024.0 / 1024.0 / 1024.0
417-
404+
418405
@property
419406
def nchan(self):
420407
return self.data['vis'].shape[3]
421-
408+
422409
@property
423410
def npol(self):
424411
return self.data['vis'].shape[4]
425-
412+
426413
@property
427414
def nants(self):
428415
return self.data['vis'].shape[1]
@@ -446,15 +433,15 @@ def w(self):
446433
@property
447434
def vis(self):
448435
return self.data['vis']
449-
436+
450437
@property
451438
def weight(self):
452439
return self.data['weight']
453-
440+
454441
@property
455442
def integration_time(self):
456443
return self.data['integration_time']
457-
444+
458445
@property
459446
def nvis(self):
460447
return self.data.size
@@ -475,8 +462,8 @@ def __str__(self):
475462
476463
"""
477464
s = "Quality assessment:\n"
478-
s += "\tOrigin: %s\n" % (self.origin)
479-
s += "\tContext: %s\n" % (self.context)
465+
s += "\tOrigin: %s\n" % self.origin
466+
s += "\tContext: %s\n" % self.context
480467
s += "\tData:\n"
481468
for dataname in self.data.keys():
482469
s += "\t\t%s: %s\n" % (dataname, str(self.data[dataname]))

0 commit comments

Comments
 (0)