Skip to content

Commit

Permalink
Merge pull request #12 from epic-astronomy/new-lsl-api
Browse files Browse the repository at this point in the history
New LSL API
  • Loading branch information
adampbeardsley authored Jul 2, 2020
2 parents 1eeac73 + 5911868 commit f22d933
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
40 changes: 20 additions & 20 deletions LWA/LWA_bifrost.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import argparse
from collections import deque
from scipy.fftpack import fft
from astropy.constants import c as speed_of_light

import datetime
import ctypes
Expand All @@ -44,7 +45,6 @@
BFNoSpinZone() # noqa

# LWA Software Library Includes
from lsl.common.constants import c as speedOfLight
from lsl.reader.ldp import TBNFile, TBFFile
from lsl.common.stations import lwasv

Expand Down Expand Up @@ -127,7 +127,7 @@ def GenerateLocations(
"""
delta = (2 * grid_size * numpy.sin(numpy.pi * grid_resolution / 360)) ** -1
chan_wavelengths = speedOfLight / frequencies
chan_wavelengths = speed_of_light.value / frequencies
sample_grid = chan_wavelengths * delta
sll = sample_grid[0] / chan_wavelengths[0]
lsl_locs = lsl_locs.T
Expand Down Expand Up @@ -190,9 +190,9 @@ def main(self):
)

idf = TBNFile(self.filename)
cfreq = idf.getInfo("freq1")
srate = idf.getInfo("sampleRate")
tInt, tStart, data = idf.read(0.1, timeInSamples=True)
cfreq = idf.get_info("freq1")
srate = idf.get_info("sample_rate")
tInt, tStart, data = idf.read(0.1, time_in_samples=True)

# Setup the ring metadata and gulp sizes
ntime = data.shape[1]
Expand Down Expand Up @@ -227,7 +227,7 @@ def main(self):
while not self.shutdown_event.is_set():
# Get the current section to use
try:
_, _, next_data = idf.read(0.1, timeInSamples=True)
_, _, next_data = idf.read(0.1, time_in_samples=True)
except Exception as e:
print("TBNFillerOp: Error - '%s'" % str(e))
idf.close()
Expand Down Expand Up @@ -441,12 +441,12 @@ def main(self):
)

idf = TBFFile(self.filename)
srate = idf.getInfo("sampleRate")
chans = numpy.round(idf.getInfo("freq1") / srate).astype(numpy.int32)
srate = idf.get_info("sample_rate")
chans = numpy.round(idf.get_info("freq1") / srate).astype(numpy.int32)
chan0 = int(chans[0])
nchan = len(chans)
tInt, tStart, data = idf.read(0.1, timeInSamples=True)

tInt, tStart, data = idf.read(0.1, time_in_samples=True)
# Setup the ring metadata and gulp sizes
ntime = data.shape[2]
nstand, npol = data.shape[0] / 2, 2
Expand Down Expand Up @@ -480,7 +480,7 @@ def main(self):
while not self.shutdown_event.is_set():
# Get the current section to use
try:
_, _, next_data = idf.read(0.1, timeInSamples=True)
_, _, next_data = idf.read(0.1, time_in_samples=True)
except Exception as e:
print("TBFFillerOp: Error - '%s'" % str(e))
idf.close()
Expand Down Expand Up @@ -859,21 +859,21 @@ def main(self):
for i in range(nstand):
# X
a = self.antennas[2 * i + 0]
delay = a.cable.delay(freq) - a.stand.z / speedOfLight
delay = a.cable.delay(freq) - a.stand.z / speed_of_light.value
phases[:, :, i, 0, :, :] = numpy.exp(2j * numpy.pi * freq * delay)
phases[:, :, i, 0, :, :] /= numpy.sqrt(a.cable.gain(freq))
if npol == 2:
# Y
a = self.antennas[2 * i + 1]
delay = a.cable.delay(freq) - a.stand.z / speedOfLight
delay = a.cable.delay(freq) - a.stand.z / speed_of_light.value
phases[:, :, i, 1, :, :] = numpy.exp(2j * numpy.pi * freq * delay)
phases[:, :, i, 1, :, :] /= numpy.sqrt(a.cable.gain(freq))
# Explicit bad and suspect antenna masking - this will
# mask an entire stand if either pol is bad
if self.antennas[2 * i + 0].getStatus() < 33 or self.antennas[2 * i + 1].getStatus() < 33:
## Explicit bad and suspect antenna masking - this will
## mask an entire stand if either pol is bad
if self.antennas[2 * i + 0].combined_status < 33 or self.antennas[2 * i + 1].combined_status < 33:
phases[:, :, i, :, :, :] = 0.0
# Explicit outrigger masking - we probably want to do
# away with this at some point
## Explicit outrigger masking - we probably want to do
## away with this at some point
if a.stand.id == 256:
phases[:, :, i, :, :, :] = 0.0
phases = phases.conj()
Expand Down Expand Up @@ -1632,8 +1632,8 @@ def handle_signal_terminate(signum, frame):
# Setup Antennas
# TODO: Some sort of switch for other stations?

lwasv_antennas = lwasv.getAntennas()
lwasv_stands = lwasv.getStands()
lwasv_antennas = lwasv.antennas
lwasv_stands = lwasv.stands

# Setup threads

Expand Down
36 changes: 18 additions & 18 deletions LWA/LWA_bifrost_DFT.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import argparse
from collections import deque
from scipy.fftpack import fft
from astropy.constants import c as speed_of_light

import datetime
import ctypes
Expand Down Expand Up @@ -45,7 +46,6 @@
BFNoSpinZone() # noqa

# LWA Software Library Includes
from lsl.common.constants import c as speedOfLight
from lsl.reader.ldp import TBNFile, TBFFile
from lsl.common.stations import lwasv

Expand Down Expand Up @@ -167,7 +167,7 @@ def Generate_DFT_Locations(lsl_locs, frequencies, ntime, nchan, npol):
"""
lsl_locs = lsl_locs.T
lsl_locs = lsl_locs.copy()
chan_wavelengths = speedOfLight / frequencies
chan_wavelengths = speed_of_light.value / frequencies
dft_locs = numpy.zeros(shape=(nchan, npol, 3, lsl_locs.shape[1]))
for j in numpy.arange(npol):
for i in numpy.arange(nchan):
Expand Down Expand Up @@ -209,7 +209,7 @@ def GenerateLocations(
"""
delta = (2 * grid_size * numpy.sin(numpy.pi * grid_resolution / 360)) ** -1
chan_wavelengths = speedOfLight / frequencies
chan_wavelengths = speed_of_light.value / frequencies
sample_grid = chan_wavelengths * delta
sll = sample_grid[0] / chan_wavelengths[0]
lsl_locs = lsl_locs.T
Expand Down Expand Up @@ -270,9 +270,9 @@ def main(self):
)

idf = TBNFile(self.filename)
cfreq = idf.getInfo("freq1")
srate = idf.getInfo("sampleRate")
tInt, tStart, data = idf.read(0.1, timeInSamples=True)
cfreq = idf.get_info("freq1")
srate = idf.get_info("sample_rate")
tInt, tStart, data = idf.read(0.1, time_in_samples=True)

# Setup the ring metadata and gulp sizes
ntime = data.shape[1]
Expand Down Expand Up @@ -307,7 +307,7 @@ def main(self):
while not self.shutdown_event.is_set():
# Get the current section to use
try:
_, _, next_data = idf.read(0.1, timeInSamples=True)
_, _, next_data = idf.read(0.1, time_in_samples=True)
except Exception as e:
print("TBNFillerOp: Error - '%s'" % str(e))
idf.close()
Expand Down Expand Up @@ -512,12 +512,12 @@ def main(self):
)

idf = TBFFile(self.filename)
srate = idf.getInfo("sampleRate")
chans = numpy.round(idf.getInfo("freq1") / srate).astype(numpy.int32)
srate = idf.get_info("sample_rate")
chans = numpy.round(idf.get_info("freq1") / srate).astype(numpy.int32)
chan0 = int(chans[0])
nchan = len(chans)
tInt, tStart, data = idf.read(0.1, timeInSamples=True)

tInt, tStart, data = idf.read(0.1, time_in_samples=True)
# Setup the ring metadata and gulp sizes
ntime = data.shape[2]
nstand, npol = data.shape[0] / 2, 2
Expand Down Expand Up @@ -551,7 +551,7 @@ def main(self):
while not self.shutdown_event.is_set():
# Get the current section to use
try:
_, _, next_data = idf.read(0.1, timeInSamples=True)
_, _, next_data = idf.read(0.1, time_in_samples=True)
except Exception as e:
print("TBFFillerOp: Error - '%s'" % str(e))
idf.close()
Expand Down Expand Up @@ -988,13 +988,13 @@ def main(self):
for i in range(nstand):
# X
a = self.antennas[2 * i + 0]
delay = a.cable.delay(freq) - a.stand.z / speedOfLight
delay = a.cable.delay(freq) - a.stand.z / speed_of_light.value
phases[:, :, 0, i, :, :] = numpy.exp(2j * numpy.pi * freq * delay)
phases[:, :, 0, i, :, :] /= numpy.sqrt(a.cable.gain(freq))
if npol == 2:
# Y
a = self.antennas[2 * i + 1]
delay = a.cable.delay(freq) - a.stand.z / speedOfLight
delay = a.cable.delay(freq) - a.stand.z / speed_of_light.value
phases[:, :, 1, i, :, :] = numpy.exp(2j * numpy.pi * freq * delay)
phases[:, :, 1, i, :, :] /= numpy.sqrt(a.cable.gain(freq))
# Explicit outrigger masking - we probably want to do
Expand Down Expand Up @@ -1416,13 +1416,13 @@ def main(self):
for i in range(nstand):
# X
a = self.antennas[2 * i + 0]
delay = a.cable.delay(freq) - a.stand.z / speedOfLight
delay = a.cable.delay(freq) - a.stand.z / speed_of_light.value
phases[:, 0, i] = numpy.exp(2j * numpy.pi * freq * delay)
phases[:, 0, i] /= numpy.sqrt(a.cable.gain(freq))
if npol == 2:
# Y
a = self.antennas[2 * i + 1]
delay = a.cable.delay(freq) - a.stand.z / speedOfLight
delay = a.cable.delay(freq) - a.stand.z / speed_of_light.value
phases[:, 1, i] = numpy.exp(2j * numpy.pi * freq * delay)
phases[:, 1, i] /= numpy.sqrt(a.cable.gain(freq))
# Explicit outrigger masking - we probably want to do
Expand Down Expand Up @@ -2237,8 +2237,8 @@ def handle_signal_terminate(signum, frame):
# Setup Antennas
# TODO: Some sort of switch for other stations?

lwasv_antennas = lwasv.getAntennas()
lwasv_stands = lwasv.getStands()
lwasv_antennas = lwasv.antennas
lwasv_stands = lwasv.stands

# Setup threads

Expand Down

0 comments on commit f22d933

Please sign in to comment.