mwa_hyperbeam/lib.rs
1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5//! Primary beam code for the Murchison Widefield Array.
6
7pub mod analytic;
8mod constants;
9mod factorial;
10pub mod fee;
11mod ffi;
12mod legendre;
13mod types;
14
15#[cfg(feature = "python")]
16mod python;
17
18// Re-exports.
19cfg_if::cfg_if! {
20 if #[cfg(any(feature = "cuda", feature = "hip"))] {
21 mod gpu;
22 /// The float type use in GPU code. This depends on how `hyperbeam` was
23 /// compiled (used cargo feature "gpu-single" or not).
24 pub use gpu::{GpuFloat, GpuComplex};
25 }
26}
27
28pub use marlu::{AzEl, Jones}; // So that callers can have a different version of Marlu.
29
30use ndarray::ArrayView1;
31
32/// Ensure that any delays of 32 have an amplitude (dipole gain) of 0.
33///
34/// The results are bad otherwise!
35/// Also ensure that we have 32 dipole gains (amps) here.
36/// Also return a Rust array of delays for convenience.
37pub fn fix_amps_ndarray(amps: ArrayView1<f64>, delays: ArrayView1<u32>) -> ([f64; 32], [u32; 16]) {
38 let mut full_amps: [f64; 32] = [1.0; 32];
39 full_amps
40 .iter_mut()
41 .zip(amps.iter().cycle())
42 .zip(delays.iter().cycle())
43 .for_each(|((out_amp, &in_amp), &delay)| {
44 if delay == 32 {
45 *out_amp = 0.0;
46 } else {
47 *out_amp = in_amp;
48 }
49 });
50
51 // So that we don't have to do .as_slice().unwrap() on our ndarrays outside
52 // of this function, return a Rust array of delays here.
53 let mut delays_a: [u32; 16] = [0; 16];
54 delays_a.iter_mut().zip(delays).for_each(|(da, d)| *da = *d);
55
56 (full_amps, delays_a)
57}