def __init__(self, file_root, time=0, freq=0, level="approx"): # Get model fname = file_root + ".uvh5" print("Get true model from", fname) uvdata = UVData() uvdata.read_uvh5(fname) assert uvdata.Nants_data == uvdata.Nants_telescope, \ "Not all antennas have data" nant = uvdata.Nants_data # Map antenna numbers to the vis index ants_to_baseline = [] for i in range(nant): for j in range(i + 1, nant): ants_to_baseline.append((i, j)) assert uvdata.Nbls-nant == len(ants_to_baseline), \ "Data does not contain expected number of baselines" nvis = len(ants_to_baseline) # Load model V_model = np.zeros(nvis, dtype=np.complex64) for i, bl in enumerate(ants_to_baseline): V_model[i] = uvdata.get_data(bl[0], bl[1], "XX")[time][freq] # Get true gains fname = file_root + ".calfits" print("Get true gains from", fname) uvc = UVCal() uvc.read_calfits(fname) g_bar = np.zeros(nant, dtype=np.complex64) for i in range(nant): g_bar[i] = uvc.get_gains(i)[0, 0] # Get V_obs fname = file_root + "_g.uvh5" print("Get V_obs from", fname) uvdata = UVData() uvdata.read_uvh5(fname) assert uvdata.Nants_data == uvdata.Nants_telescope, \ "Not all antennas have data" assert uvdata.Nbls-nant == nvis, \ "Data does not contain expected number of baselines" # Load V_obs V = np.zeros(nvis, dtype=np.complex64) for i, bl in enumerate(ants_to_baseline): V[i] = uvdata.get_data(bl[0], bl[1], "XX")[time][freq] self.level = level self.nant = nant self.nvis = nvis self.g_bar = g_bar self.V_model = V_model self.x = np.zeros(g_bar.size, dtype=np.complex64) self.V_obs = V self.obs_variance = np.full(V.size, 1) self.redundant_groups, _, _ = uvdata.get_redundancies()
def __init__(self, file_root, time=0, freq=0, level="approx"): """ file_root: str The file path referring to a non-redundant-pipeline simulation "case". Use that path to select files from the simulation based on their extension. """ # Get V_obs from last file generated by analyse_sims.py fname = file_root + "_g.uvh5" print("Get V_obs from", fname) uvdata = UVData() uvdata.read_uvh5(fname) assert uvdata.Nants_data == uvdata.Nants_telescope, \ "Not all antennas have data" nant = uvdata.Nants_data # Map antenna numbers to the vis index ants_to_baseline = [] for i in range(nant): for j in range(i + 1, nant): ants_to_baseline.append((i, j)) assert uvdata.Nbls-nant == len(ants_to_baseline), \ "Data does not contain expected number of baselines" nvis = len(ants_to_baseline) # Load V_obs V = np.zeros(nvis, dtype=np.complex64) for i, bl in enumerate(ants_to_baseline): V[i] = uvdata.get_data(bl[0], bl[1], "XX")[time][freq] # Get things out of calibration: model, redundant groups, weights fname = file_root + "_g_cal_dict.npz" print("Get model from", fname) cal = hkl.load(fname) baseline_groups = cal["all_reds"] redundant_groups = [[] for bg in baseline_groups] assert len(cal["v_omnical"].keys()) == len(baseline_groups), \ "Number of baseline groups: "+str(len(baseline_groups))+ \ " Number of model groups: "+str(len(cal["v_omnical"].keys())) V_model = np.zeros(nvis, dtype=np.complex64) for key in cal["v_omnical"].keys(): baseline = (key[0], key[1]) # Find the baselines in this group. First item will be "ants" group_index = -1 for i in range(len(baseline_groups)): if (baseline_groups[i][0][0], baseline_groups[i][0][1]) == baseline: group_index = i break if group_index == -1: raise RuntimeError("Couldn't find redundant group for model " + str(key)) for bl in baseline_groups[group_index]: try: i = ants_to_baseline.index((bl[0], bl[1])) V_model[i] = cal["v_omnical"][key][time][freq] except: i = ants_to_baseline.index((bl[1], bl[0])) V_model[i] = np.conj(cal["v_omnical"][key][time][freq]) redundant_groups[group_index].append(i) assert np.min(np.abs(V_model)) > 0, "Model has missing values" # Get the weights used by calibration num_weights = len(list(cal["omni_meta"]["data_wgts"])) assert num_weights == V.size, "Not enough weights for baselines " + str( num_weights) + " " + str(V.size) weights = np.zeros(V.size) for key in cal["omni_meta"]["data_wgts"].keys(): try: i = ants_to_baseline.index((key[0], key[1])) except: i = ants_to_baseline.index((key[1], key[0])) weights[i] = cal["omni_meta"]["data_wgts"][key][time][freq] # Get the gains generated from calibration fname = file_root + "_g_new.calfits" print("Get gains from", fname) uvc = UVCal() uvc.read_calfits(fname) g_bar = np.zeros(nant, dtype=np.complex64) for i in range(nant): g_bar[i] = uvc.get_gains(i)[0, 0] self.level = level self.nant = nant self.nvis = nvis self.V_obs = V self.V_model = V_model self.g_bar = g_bar self.x = np.zeros(g_bar.size, dtype=np.complex64) self.obs_variance = weights self.redundant_groups = redundant_groups