Skip to content

Commit d1558da

Browse files
authored
Merge pull request #37 from MWATelescope/fix_uvfits_baseline_decode
Fix uvfits baseline decode
2 parents 3dd75ae + 0c37a67 commit d1558da

File tree

5 files changed

+123
-12
lines changed

5 files changed

+123
-12
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "marlu"
3-
version = "0.16.0"
3+
version = "0.16.1"
44
authors = [
55
"Christopher H. Jordan <christopherjordan87@gmail.com>",
66
"Dev Null <dev.null@curtin.edu.au>",

RELEASES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<!-- markdownlint-disable=MD025 -->
22

3+
# Version 0.16.1 (2025-04-11)
4+
5+
- Fixed decode_uvfits_baseline bug (#36)
6+
- minor code reformatting
7+
38
# Version 0.16.0 (2025-04-10)
49

510
- update mwalib 1.8.7

src/averaging.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ pub type VisData33 = (Array3<Jones<f32>>, Array3<f32>);
203203
/// chunk of input visibilities:
204204
/// - unflagged weights are added together
205205
/// - if all visibilities in a chunk are flagged, then the result is the geometric
206-
/// mean of the chunk.
206+
/// mean of the chunk.
207207
/// - otherwise the visibility is the weighted mean of the unflagged visibilities.
208208
///
209209
/// This has been validated thoroughly against Cotter.

src/io/ms.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ impl MeasurementSetWriter {
464464
/// - `name` - Spectral Window name (`NAME` column)
465465
/// - `ref_freq` - Reference frequency (`REF_FREQUENCY` column)
466466
/// - `chan_info` - A two-dimensional array of shape (n, 4), containing the
467-
/// following for each channel:
467+
/// following for each channel:
468468
/// - `CHAN_FREQ` - the center frequencies
469469
/// - `CHAN_WIDTH` - channel widths,
470470
/// - `EFFECTIVE_BW` - effective noise bandwidths
@@ -521,14 +521,14 @@ impl MeasurementSetWriter {
521521
/// - `name` - Spectral Window name (`NAME` column)
522522
/// - `ref_freq` - Reference frequency (`REF_FREQUENCY` column)
523523
/// - `chan_info` - A two-dimensional array of shape (n, 4), containing the
524-
/// following for each channel:
524+
/// following for each channel:
525525
/// - `CHAN_FREQ` - the center frequencies
526526
/// - `CHAN_WIDTH` - channel widths,
527527
/// - `EFFECTIVE_BW` - effective noise bandwidths
528528
/// - `RESOLUTION` - resolutions.
529529
/// - `total_bw` - Total bandwidth (`TOTAL_BANDWIDTH` column)
530530
/// - `centre_subband_nr` - This is the "sky" channel number of the center coarse channel in
531-
/// the spectral window.
531+
/// the spectral window.
532532
/// - `flag` - Row flag (`FLAG_ROW` column)
533533
#[allow(clippy::too_many_arguments)]
534534
pub fn write_spectral_window_row_mwa(
@@ -677,7 +677,7 @@ impl MeasurementSetWriter {
677677
/// - `idx` - row index to write to (ensure enough rows have been added)
678678
/// - `corr_type` - The polarization type for each correlation product, as a Stokes enum.
679679
/// - `corr_product` - Indices describing receptors of feed going into correlation.
680-
/// Shape should be [n, 2] where n is the length of `corr_type`
680+
/// Shape should be [n, 2] where n is the length of `corr_type`
681681
/// - `flag_row` - Row flag
682682
#[allow(clippy::ptr_arg)]
683683
pub fn write_polarization_row(
@@ -771,8 +771,8 @@ impl MeasurementSetWriter {
771771
/// - `code` - Special characteristics of field, e.g. Bandpass calibrator
772772
/// - `time` - Time origin for direction and rate
773773
/// - `dir_info` - An array of polynomial coefficients to calculate a direction
774-
/// (RA, DEC) relative to `time`. The shape is [3, p, 2], where p is the maximum
775-
/// order of all polynomials, and there are three direction polynomials:
774+
/// (RA, DEC) relative to `time`. The shape is [3, p, 2], where p is the maximum
775+
/// order of all polynomials, and there are three direction polynomials:
776776
/// - `DELAY_DIR` - Direction of delay center (e.g. RA, DEC) in time
777777
/// - `PHASE_DIR` - Direction of phase center (e.g. RA, DEC) in time
778778
/// - `REFERENCE_DIR` - Direction of reference center (e.g. RA, DEC) in time
@@ -830,8 +830,8 @@ impl MeasurementSetWriter {
830830
/// - `code` - Special characteristics of field, e.g. Bandpass calibrator
831831
/// - `time` - Time origin for direction and rate
832832
/// - `dir_info` - An array of polynomial coefficients to calculate a direction
833-
/// (RA, DEC) relative to `time`. The shape is [3, p, 2], where p is the maximum
834-
/// order of all polynomials, and there are three direction polynomials:
833+
/// (RA, DEC) relative to `time`. The shape is [3, p, 2], where p is the maximum
834+
/// order of all polynomials, and there are three direction polynomials:
835835
/// - `DELAY_DIR` - Direction of delay center (e.g. RA, DEC) in time
836836
/// - `PHASE_DIR` - Direction of phase center (e.g. RA, DEC) in time
837837
/// - `REFERENCE_DIR` - Direction of reference center (e.g. RA, DEC) in time
@@ -1605,7 +1605,7 @@ impl MeasurementSetWriter {
16051605
/// - `state_id` - ID for this observing state
16061606
/// - `sigma` - Estimated rms noise for channel with unity bandpass response
16071607
/// - `data` - an `[n, p]` shaped ndarray of complex visibilities, where `n`
1608-
/// is the number of channels, and p is the number of polarizations
1608+
/// is the number of channels, and p is the number of polarizations
16091609
/// - `flags` - an `[n, p]` shaped ndarray of boolean flags.
16101610
/// - `weights` - a `[p]` shaped ndarray of weights for each polarization
16111611
///

src/io/uvfits.rs

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub const fn encode_uvfits_baseline(ant1: usize, ant2: usize) -> usize {
8080
/// start at 1.
8181
#[allow(dead_code)]
8282
pub const fn decode_uvfits_baseline(bl: usize) -> (usize, usize) {
83-
if bl < 65_535 {
83+
if bl <= 65_535 {
8484
let ant2 = bl % 256;
8585
let ant1 = (bl - ant2) / 256;
8686
(ant1, ant2)
@@ -2830,4 +2830,110 @@ mod tests {
28302830
}
28312831
}
28322832
}
2833+
2834+
#[test]
2835+
fn test_encode_uvfits_baseline_256t() {
2836+
// test hand calculated edge cases
2837+
assert_eq!(encode_uvfits_baseline(1,1), 257);
2838+
assert_eq!(encode_uvfits_baseline(1,2), 258);
2839+
assert_eq!(encode_uvfits_baseline(1,255), 511);
2840+
assert_eq!(encode_uvfits_baseline(1,256), 67840);
2841+
assert_eq!(encode_uvfits_baseline(127,127), 32639);
2842+
assert_eq!(encode_uvfits_baseline(127,255), 32767);
2843+
assert_eq!(encode_uvfits_baseline(127,256), 325888);
2844+
assert_eq!(encode_uvfits_baseline(128,128), 32896);
2845+
assert_eq!(encode_uvfits_baseline(128,255), 33023);
2846+
assert_eq!(encode_uvfits_baseline(128,256), 327936);
2847+
assert_eq!(encode_uvfits_baseline(254,254), 65278);
2848+
assert_eq!(encode_uvfits_baseline(254,255), 65279);
2849+
assert_eq!(encode_uvfits_baseline(254,256), 585984);
2850+
assert_eq!(encode_uvfits_baseline(255,255), 65535);
2851+
assert_eq!(encode_uvfits_baseline(255,256), 588032);
2852+
assert_eq!(encode_uvfits_baseline(256,256), 590080);
2853+
}
2854+
2855+
#[test]
2856+
fn test_decode_uvfits_baseline_256t() {
2857+
// Test hand calculated edge cases
2858+
assert_eq!(decode_uvfits_baseline(257), (1,1));
2859+
assert_eq!(decode_uvfits_baseline(258), (1,2));
2860+
assert_eq!(decode_uvfits_baseline(511), (1,255));
2861+
assert_eq!(decode_uvfits_baseline(67840), (1,256));
2862+
assert_eq!(decode_uvfits_baseline(32639), (127,127));
2863+
assert_eq!(decode_uvfits_baseline(32767), (127,255));
2864+
assert_eq!(decode_uvfits_baseline(325888), (127,256));
2865+
assert_eq!(decode_uvfits_baseline(32896), (128,128));
2866+
assert_eq!(decode_uvfits_baseline(33023), (128,255));
2867+
assert_eq!(decode_uvfits_baseline(327936), (128,256));
2868+
assert_eq!(decode_uvfits_baseline(65278), (254,254));
2869+
assert_eq!(decode_uvfits_baseline(65279), (254,255));
2870+
assert_eq!(decode_uvfits_baseline(585984), (254,256));
2871+
assert_eq!(decode_uvfits_baseline(65535), (255,255));
2872+
assert_eq!(decode_uvfits_baseline(588032), (255,256));
2873+
assert_eq!(decode_uvfits_baseline(590080), (256,256));
2874+
}
28332875
}
2876+
2877+
#[test]
2878+
fn test_encode_decode_uvfits_all_baselines_128t() {
2879+
// Test all baselines can be encoded then decoded correctly
2880+
// MWAX 128T
2881+
let n_ants: usize= 128;
2882+
2883+
for ant1 in 1..=n_ants {
2884+
for ant2 in ant1..=n_ants {
2885+
let bl = encode_uvfits_baseline(ant1, ant2);
2886+
let (a1,a2) = decode_uvfits_baseline(bl);
2887+
assert_eq!(a1, ant1);
2888+
assert_eq!(a2, ant2);
2889+
}
2890+
}
2891+
}
2892+
2893+
#[test]
2894+
fn test_encode_decode_uvfits_all_baselines_256t() {
2895+
// Test all baselines can be encoded then decoded correctly
2896+
// MWAX 256T
2897+
let n_ants: usize= 256;
2898+
2899+
for ant1 in 1..=n_ants {
2900+
for ant2 in ant1..=n_ants {
2901+
let bl = encode_uvfits_baseline(ant1, ant2);
2902+
let (a1,a2) = decode_uvfits_baseline(bl);
2903+
assert_eq!(a1, ant1);
2904+
assert_eq!(a2, ant2);
2905+
}
2906+
}
2907+
}
2908+
2909+
#[test]
2910+
fn test_encode_decode_uvfits_all_baselines_264t() {
2911+
// Test all baselines can be encoded then decoded correctly
2912+
// MWAX 256T + 1 more receiver
2913+
let n_ants: usize= 264;
2914+
2915+
for ant1 in 1..=n_ants {
2916+
for ant2 in ant1..=n_ants {
2917+
let bl = encode_uvfits_baseline(ant1, ant2);
2918+
let (a1,a2) = decode_uvfits_baseline(bl);
2919+
assert_eq!(a1, ant1);
2920+
assert_eq!(a2, ant2);
2921+
}
2922+
}
2923+
}
2924+
2925+
#[test]
2926+
fn test_encode_decode_uvfits_all_baselines_512t() {
2927+
// Test all baselines can be encoded then decoded correctly
2928+
// MWAX 512T (Phase 4(!))
2929+
let n_ants: usize= 512;
2930+
2931+
for ant1 in 1..=n_ants {
2932+
for ant2 in ant1..=n_ants {
2933+
let bl = encode_uvfits_baseline(ant1, ant2);
2934+
let (a1,a2) = decode_uvfits_baseline(bl);
2935+
assert_eq!(a1, ant1);
2936+
assert_eq!(a2, ant2);
2937+
}
2938+
}
2939+
}

0 commit comments

Comments
 (0)