public:meetings:2009-02_processing_school:exercise_02b

Source directory /data/lofarschool/users/station/Exercise-02B-station Michiel Brentjens

LOFAR stations are complete, self-contained radio telescopes. Every station is equipped with its own correlator. The stations can operate in 5 different frequency ranges: 10–80, 30–80, 110–190, 170–230, and 210–250 MHz. The first two modes use the LBA antennae, the others the HBA. The antenna voltages can be sampled at either 160 MHz or 200 MHz. The station correlator has the following operating modes:

• Computing dynamic spectra over the full frequency range of a certain

filter/clock combination for all antennae;

• Computing a full array correlation matrix in one sub band.

These data products are extremely useful for diagnosing problems in an observation.

Participants are assumed to have

• basic Python programming knowledge;
• an idea about the signal path within a station;
• a basic understanding of radio interferometry.

The goal of this exercise is to familiarize yourself with the full array correlation matrices (ACM) from the station correlator, as well as the diurnal total power variations in the system. After this exercise you should be able to

• inspect and verify array correlation matrices;
• recognize an X or Y dipole orientation from the total power curves;
• produce visibility curves as a function of time for a variety of

baseline lengths;

• tell us which signal paths should be repaired;
• tell us which antenna was wired the wrong way around.
• `lofarstation.py` is the Python software for reading

and plotting the station correlator data;

• `lofarstation.html` is a nicely rendered version of

`lofarstation.py`;

• `cs010.py` contains the positions of the LBA dipoles on CS010;
• `array-correlation-matrices` contains the subdirectories with the

array correlation matrices for this exercise;

• `Exercise-02B.txt` is the plain text version of this instruction;
• `Exercise-02B.html` is the HTML version of this instruction.

The first thing to do is changing to the exercise directory and starting the IPython shell:

```\$ cd /data/lofarschool/users/station/Exercise-02B-station/
\$ ipython -pylab lofarstation.py```

the screen should now look something like this:

```Python 2.5.1 (r251:54863, Jul 31 2008, 23:17:43)

IPython 0.8.1 -- An enhanced Interactive Python.
?       -> Introduction to IPython's features.
%magic  -> Information about IPython's 'magic' % functions.
help    -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

Welcome to pylab, a matplotlib-based Python environment.

In : ```

You may want to review the contents of lofarstation.py while doing this exercise.

The command `station_correlator_directories()` lists the directories that contain the dynamic spectra:

```In : station_correlator_directories()
Out:
[u'array-correlation-matrices/20081204-freq-scan',
u'array-correlation-matrices/20081204-freq-scan-wg',
u'array-correlation-matrices/20090202-school-acm-sb305-rcumode4']```

The datasets were all recorded in LBA mode with the clock at 200 MHz. The top two datasets used RCU mode 3 and the last one RCU mode 4. The top two datasets contain frequency sweeps with the station correlator. Each directory contains 512 array correlation matrices recorded with 1 second integration time. The first ACM is recorded in sub band 0, the next in 1, and the last one in sub band 511. The first directory contains correlations of the antenna signals. The second one consists of cross correlations of waveform generator signals. These waveform generator signals are very strong and can be controlled by the observers. The most recent dataset is a 24 hour observation in sub band 305 with 60 seconds integration per time step.

The contents of a directory can be viewed with e.g.

```In : full_path_listdir(station_correlator_directories()[-1])
Out: [u'array-correlation-matrices/2009....-rcumode4/20090202_090356_xst.dat']```

The data file name consists of the UTC date and time of the start of the first integration and the letters `_xst_`, which indicate that the file contains cross correlations (array correlation matrices).

The `data_files()` function returns a list of all `.dat` files in a directory:

```In : files = data_files(u'array-correlation-matrices/20081204-freq-scan-wg')
In : len(files)
Out: 512
In : files[0:3]
Out:
[u'array-correlation-matrices/20081204-freq-scan-wg/20081204_090456_xst.dat',
u'array-correlation-matrices/20081204-freq-scan-wg/20081204_090502_xst.dat',
u'array-correlation-matrices/20081204-freq-scan-wg/20081204_090508_xst.dat']```

The function `timeslots_in_acm_cube()` counts how many integrations are stored in a file.

```In : timeslots_in_acm_cube(data_files('array-correlation-matrices/20081204-freq-scan/'))
Out: 1L
In : timeslots_in_acm_cube('array-correlation-matrices/20090202-school-acm-sb305-rcumode4/20090202_090356_xst.dat')
Out: 1432L```

A file containing a single ACM can be read with the `read_acm()` function. If a file contains multiple ACMs, use the `read_acm_cube()` function. We are now going to read a couple of different array correlation matrices, which are all recorded in subband 305. The central frequency of this subband is

```In : subband_frequencies_mhz()
Out: 59.5703125```

We assign variable names to the ACMs in order to make handling them a bit easier.

```In : acm_sky=read_acm(
data_files('array-correlation-matrices/20081204-freq-scan/'))
data_files('array-correlation-matrices/20081204-freq-scan-wg/'))
'array-correlation-matrices/20090202-school-acm-sb305-rcumode4/20090202_090356_xst.dat')```

Verify that the arrays have the correct shape:

```In : acm_sky.shape
Out: (96, 96)
In : acm_wg.shape
Out: (96, 96)
In : acmcube.shape
Out: (1432, 96, 96)```

#### Inspection I: frequency sweeps

The ACMs can be inspected using the `plot_complex_image()` function. It has optional `plot_title`, `scale`, and `textsize` parameters. When `scale=True`, the _Real_ and _Abs_ plots have the same amplitude scale as the _Imag_ plot for easy comparison.

```In : plot_complex_image(acm_sky,'Sky visibilities sb 305')
In : plot_complex_image(acm_sky,'Sky visibilities sb 305',scale=True)
In : plot_complex_image(acm_wg,'Waveform generator test sb 305')
In : plot_complex_image(acm_wg,'Waveform generator test sb 305',scale=True)```

In the waveform generator test the amplitude of the waveform generators increases exponentially as a function of RCU number in order to achieve a nice linear gradient on a logarithmic scale. The phases of the waveform generators span the range from 0 up to (not including) 2π.

There are a few interesting features in these plots. The first is that the _Real_ diagonal is very strong when observing the sky, whereas it does not stand out in the waveform generator test.

Why?

Let us inspect the range of values in these array correlation matrices.

```In : abs(acm_sky).max()
In : abs(acm_sky).min()
In : abs(acm_wg).max()
In : abs(acm_wg).min()```

There we have it.

The second is that although the amplitudes nicely show the promised exponential increase as a function of RCU number, the phases have blocks that are exactly 180 degrees out of phase. It is believed that this is caused by the fact that one cannot divide 200 million (the number of clock samples per seconds) evenly by 1024 (the length of the FFT in the polyphase filter), hence the remainder of the first second is processed in the second second, yielding a different number of samples per subband in the even seconds as compared to the odd seconds. It is believed that the n x 180 degree phase (actually a slope as a function of subband number) is due to the waveform generators starting up with a different phase in the even and odd seconds, and the fact that we cannot program all waveform generators at CS010 within one second. This claim, however, has not yet been verified. If true, the n x 180 degree phase shift should not occur when we take care to start the waveform generators all in even (or odd) seconds.

We can run some basic sanity checks on the ACMs. For one thing they should be Hermitian:

```In : plot_complex_image(acm_sky - transpose(conjugate(acm_sky)),
'Sky visibilities sb 305')
In : plot_complex_image(acm_wg - transpose(conjugate(acm_wg)),
'Waveform generator test sb 305')```

Right. We should investigate this a bit further. It appears to be a constant offset, independent of the input power.

Is that correct?

If so, is it some special value?

Let us find out.

```In : h = acm_wg-transpose(conjugate(acm_wg))
In : h[h != 0.0]
In : unique(h[h != 0.0])```

In order to track down the cause, it would be nice to see precisely when the error occurs. We can collect data from the entire frequency scan for a couple of RCUs and plot their powers as a function of subband. The functions `foreach_acm_in()` and `vis()` are very useful in this respect. The value that is plotted in input 26, for example, reads as:

`   "for each ACM in directory ...., retrieve visibility 0,0"`

One can pass `foreach_acm_in()` any function that operates on a 2D ACM, such as `is_hermitian()`, which is also defined below. First we plot a couple of relevant spectra.

```In : clf()

In : semilogy(foreach_acm_in('array-correlation-matrices/20081204-freq-scan', vis(0,0)), label='sky rcu 0')
In : semilogy(foreach_acm_in('array-correlation-matrices/20081204-freq-scan-wg', vis(0,0)), label='wg rcu 0')
In : semilogy(foreach_acm_in('array-correlation-matrices/20081204-freq-scan-wg', vis(48,48)), label='wg rcu 48')
In : semilogy(foreach_acm_in('array-correlation-matrices/20081204-freq-scan-wg', vis(94,94)), label='wg rcu 94')
In : legend()```

Then it is time to test for hermitianness in a more automatic way. We define the Python function `is_hermitian()`.

```In : unique((acm_sky-transpose(conjugate(acm_sky))) ==0.0)
Out: array([ True], dtype=bool)

In : unique((acm_wg-transpose(conjugate(acm_wg))) ==0.0)
Out: array([False,  True], dtype=bool)

In : def is_hermitian(matrix):
return len(unique((matrix - transpose(conjugate(matrix)))== 0.0))==1

In : is_hermitian(acm_wg)
Out: False

In : is_hermitian(acm_sky)
Out: True```

Good. Now we collect data on which frequency channels are affected in the waveform generator test, and in the sky visibilities.

```In : sky_hermitian = foreach_acm_in('array-correlation-matrices/20081204-freq-scan', is_hermitian)
In : wg_hermitian = foreach_acm_in('array-correlation-matrices/20081204-freq-scan-wg', is_hermitian)
In : semilogy((sky_hermitian == False)*3e12,label='sky not hermitian')
In : semilogy((wg_hermitian == False)*2e13,label='wg not hermitian')
In : legend()```

(note: you may have to issue a clf() command before plotting to clear the plotting window and see changes.) Apparently the error occurs when the total powers are larger than some minimum threshold value. Adventurous types may try to find out which:

```In : log2(min(foreach_acm_in('array-correlation-matrices/20081204-freq-scan',
lambda acm: median(diagonal(acm)))[sky_hermitian==False]))```

Why?

#### Inspection II: time sequences

We will continue now with analysing `acmcube`. As you may remember, this cube contains 60 second integrations for a total duration of approximately 24 hours. The function `timeseries()` can be used to retrieve the visibility of a certain RCU pair as a function of time, e.g. the XX and YY auto correlations:

```In : clf()
In : plot(timeseries(acmcube,10,10).real,label='XX')
In : plot(timeseries(acmcube,11,11).real, label='YY')
In : legend()```

As you can readily see, the total power peaks first in the XX correlation, followed by the YY correlation after a couple of hours.

Why?

It is instructive to see the behaviour of the sky visibilities as a function of time for a number of different baselines. To that end we will build up a 2×2 panel of graphs.

```In : clf()
In : subplot(221)
In : station_map(cs010)

In : subplot(222)
In : title('short: 28-32')
In : plot(timeseries(acmcube,28,32).real)
In : plot(timeseries(acmcube,28,32).imag)
In : axis([0,1440,-1e7,1e7])

In : subplot(223)
In : title('intermediate: 0-24')
In : plot(timeseries(acmcube,0,24).real)
In : plot(timeseries(acmcube,0,24).imag)
In : axis([0,1440,-1e7,1e7])

In : subplot(224)
In : title('long: 46-68')
In : plot(timeseries(acmcube,46,68).real)
In : plot(timeseries(acmcube,46,68).imag)
In : axis([0,1440,-1e7,1e7])```

Fortunately the fringe frequency increases with baseline length. Furthermore, as expected, the shortest baseline picks up a lot more power than the others. This is mainly due to the large scale diffuse Galactic emission, which is not picked up at baselines beyond 4–6 wavelengths. It is clear that one needs intra-station baselines in order to properly map the diffuse Galactic foreground.

A final sanity check on the data is to plot _all_ auto correlations in the acmcube as a function of time:

`In : plot_autocorrelations(acmcube)`

Which signal paths are flaky?

Which rcus are wired the wrong way around?

What is, in your opinion, the most striking property of the flaky signal paths?

`In : plot_complex_image(acm_sky, plot_title="Sky ACM", scale=True)`
`In : plot_complex_image(acm_wg, plot_title="Waveform generator ACM")`
```In : clf()
In : subplot(221)
In : station_map(cs010)

In : subplot(222)
In : title('short: 28-32')
In : plot(timeseries(acmcube,28,32).real)
In : plot(timeseries(acmcube,28,32).imag)
In : axis([0,1440,-1e7,1e7])

In : subplot(223)
In : title('intermediate: 0-24')
In : plot(timeseries(acmcube,0,24).real)
In : plot(timeseries(acmcube,0,24).imag)
In : axis([0,1440,-1e7,1e7])

In : subplot(224)
In : title('long: 46-68')
In : plot(timeseries(acmcube,46,68).real)
In : plot(timeseries(acmcube,46,68).imag)
In : axis([0,1440,-1e7,1e7])```