Skip to content

Instantly share code, notes, and snippets.

@d3v-null
Created October 26, 2026 10:46
Show Gist options
  • Select an option

  • Save d3v-null/792f82fc44580425c8aef5d0dd46e787 to your computer and use it in GitHub Desktop.

Select an option

Save d3v-null/792f82fc44580425c8aef5d0dd46e787 to your computer and use it in GitHub Desktop.
How the Birli/Marlu UVW-change plot (Marlu precession vs cotter) was generated

How the Birli UVW-change plot was made

UVW change

This plot is from MWATelescope/Birli#203. It shows how much the UVWs Birli writes change between Marlu 0.19.0, which agrees with cotter, and the unreleased precession on Marlu main (e739762: rotate by the apparent sidereal time; 150623a: take the phase centre's aberration out with a rigid rotation). The same changes are on feat/conventions, via Marlu#43.

Steps

The data are Birli's test files for 1254670392 (tests/data/1254670392_avg), using 2 coarse channels (gpubox 23 and 24) and 2 timesteps. Both Birli builds need aoflagger (apt-get install aoflagger-dev) for --no-rfi.

git clone https://github.com/MWATelescope/Birli && cd Birli
D=tests/data/1254670392_avg
ARGS="-m $D/1254670392.fixed.metafits --no-draw-progress --pfb-gains none \
  --no-cable-delay --no-geometric-delay --no-rfi --emulate-cotter --no-flag-dc \
  --flag-init 0 $D/1254670392_20191009153257_gpubox24_00.fits \
  $D/1254670392_20191009153257_gpubox23_00.fits"

# "old": Birli main, Marlu 0.19.0 from crates.io (cotter's frame)
git checkout cf741e5
cargo build --release --features aoflagger
./target/release/birli -u old.uvfits $ARGS

# "new": Birli#203 before the cotter-frame fix, on Marlu feat/conventions
git checkout e02aa91
cargo build --release --features aoflagger
./target/release/birli -u new.uvfits $ARGS

pip install numpy astropy matplotlib
python3 uvw_change.py old.uvfits new.uvfits birli_uvw_change.png

The script reads UU/VV/WW (in seconds, multiplied by c) and checks that the two files' baselines line up row for row. It then plots |Δu|, |Δv| and |Δw| in mm against baseline length, with Marlu's stated 8 cm/km bound on w and the 1e-5 m tolerance Birli's cotter tests use. The second panel shows the phase change 2π|Δw|/λ at 200 MHz, which is what the --emulate-cotter geometric-correction tests see. It prints the maximum differences. For this run the largest |Δw| is 4.9 cm on the 740 m baseline (6.9e-5 of the baseline length), which is 11.8° at 200 MHz.

Caveats

  • Later commits on Birli#203 make --emulate-cotter use Marlu's new UvwFrame::Cotter. Running the "new" step from the current branch tip with --emulate-cotter therefore gives (near) zero difference. To see the default frame's change from that tip, drop --emulate-cotter.
  • The uvfits random-group parameters are float32, so differences below ~1e-7 of the baseline length are rounding.
"""Compare the UVWs in two uvfits files written from the same data and plot
the difference against baseline length, plus the phase change that the w
difference makes at 200 MHz.
Usage: python3 uvw_change.py old.uvfits new.uvfits out.png
"""
import sys,numpy as np
from astropy.io import fits
import matplotlib; matplotlib.use("Agg"); import matplotlib.pyplot as plt
c=299792458.0
def load(p):
h=fits.open(p); d=h[0].data
uvw=np.stack([d.par('UU'),d.par('VV'),d.par('WW')],1)*c
bl=d.par('BASELINE'); t=d.par('DATE')
return uvw,bl,t
o,ob,ot=load(sys.argv[1]); n,nb,nt=load(sys.argv[2])
assert np.all(ob==nb)
L=np.linalg.norm(o,axis=1); d=n-o
m=L>1
print("rows",len(L),"max|b|",L.max())
for i,k in enumerate("uvw"):
r=np.abs(d[m,i])/L[m]; print(k,"max abs diff m",np.abs(d[:,i]).max(),"max rel",r.max())
# phase error at 200 MHz from w diff
lam=c/200e6
fig,ax=plt.subplots(1,2,figsize=(11,4.3))
for i,(k,col) in enumerate(zip("uvw",["#2a6fdb","#1aa37a","#e0523b"])):
ax[0].scatter(L[m]/1e3,np.abs(d[m,i])*1e3,s=2,color=col,label=k,alpha=.5,rasterized=True)
ax[0].plot([0,L.max()/1e3],[0,0.08*L.max()],color="0.4",ls="--",lw=1,label="8 cm/km (Marlu RELEASES bound on w)")
ax[0].plot([0,L.max()/1e3],[1e-2,1e-2],color="k",lw=0.8,ls=":",label="current test tolerance (1e-5 m)")
ax[0].set_xlabel("Baseline length (km)"); ax[0].set_ylabel("|Marlu main − Marlu 0.19 (= cotter)| (mm)")
ax[0].set_title("UVW change, 1254670392 (2 coarse chans, 2 ts)"); ax[0].legend(frameon=False,markerscale=4,fontsize=8)
ph=np.degrees(2*np.pi*np.abs(d[m,2])/lam)
ax[1].scatter(L[m]/1e3,ph,s=2,color="#e0523b",alpha=.5,rasterized=True)
ax[1].set_xlabel("Baseline length (km)"); ax[1].set_ylabel("phase change from Δw at 200 MHz (deg)")
ax[1].set_title("What the --emulate-cotter geometric-correction tests see")
for a in ax: a.grid(alpha=.25)
fig.tight_layout(); fig.savefig(sys.argv[3],dpi=150)
print("max phase deg",ph.max())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment