Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC spinning off a process to compute parallactic angles #266

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions africanus/rime/parangles_casa.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

import threading
from multiprocessing import Process, Queue

import numpy as np

Expand All @@ -16,23 +16,33 @@
casa_import_error = None
have_casa_parangles = True

# Create thread local storage for the measures server
_thread_local = threading.local()


@requires_optional('pyrap.measures', 'pyrap.quanta', casa_import_error)
def casa_parallactic_angles(times, antenna_positions, field_centre,
zenith_frame='AZEL'):

q = Queue()
p = Process(
target=_casa_parallactic_angles,
args=(times, antenna_positions, field_centre, zenith_frame, q)
)

p.start()
parangles = q.get()
p.join()

return parangles


@requires_optional('pyrap.measures', 'pyrap.quanta', casa_import_error)
def _casa_parallactic_angles(times, antenna_positions, field_centre,
zenith_frame, q):
"""
Computes parallactic angles per timestep for the given
reference antenna position and field centre.
"""

try:
meas_serv = _thread_local.meas_serv
except AttributeError:
# Create a measures server
_thread_local.meas_serv = meas_serv = pyrap.measures.measures()
meas_serv = pyrap.measures.measures()

# Create direction measure for the zenith
zenith = meas_serv.direction(zenith_frame, '0deg', '90deg')
Expand All @@ -47,7 +57,7 @@ def casa_parallactic_angles(times, antenna_positions, field_centre,
fc_rad = meas_serv.direction('J2000', *(pq.quantity(f, 'rad')
for f in field_centre))

return np.asarray([
q.put(np.asarray([
# Set current time as the reference frame
meas_serv.do_frame(meas_serv.epoch("UTC", pq.quantity(t, "s")))
and
Expand All @@ -58,3 +68,4 @@ def casa_parallactic_angles(times, antenna_positions, field_centre,
for rp in reference_positions
]
for t in times])
)