From cf9e084d5227785caaa66111719fbb1d20802d81 Mon Sep 17 00:00:00 2001 From: Josh Dillon Date: Wed, 30 Sep 2020 18:59:46 -0700 Subject: [PATCH] Add notebook for paper plots for calibration and LST-binning --- test-series/4/test-4.0.0b.ipynb | 5010 +++++++++++++++++++++++++++++++ 1 file changed, 5010 insertions(+) create mode 100644 test-series/4/test-4.0.0b.ipynb diff --git a/test-series/4/test-4.0.0b.ipynb b/test-series/4/test-4.0.0b.ipynb new file mode 100644 index 0000000..087f2d4 --- /dev/null +++ b/test-series/4/test-4.0.0b.ipynb @@ -0,0 +1,5010 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "ExecuteTime": { + "end_time": "2020-09-30T18:49:04.201278Z", + "start_time": "2020-09-30T18:49:04.195773Z" + } + }, + "source": [ + "# Validation Step 4 | End-to-End Data Analysis | Calibration Plots for the Validation Paper\n", + "\n", + "Josh Dillon & the HERA Validation Team\n", + "\n", + "September, 2020" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Introduction\n", + "\n", + "This notebook contains code for plotting results that assess calibration in Validation Step 4, the end-to-end run of the H1C validation effort. It is designed to be run at NRAO. This notebook is meant for the purposes of reproducing these plots, rather than fully explaining them. See the Validation paper for more detail. For the code that ran this analysis, refer to [the pipeline repo](https://github.com/HERA-Team/hera_pipelines/tree/main/pipelines/validation/h1c_idr2_2) and especially [the configuration TOML](https://github.com/HERA-Team/hera_pipelines/blob/main/pipelines/validation/h1c_idr2_2/idr2_2_validation.toml). Further explaination of the equivalent real data products can be found in [this memo](http://reionization.org/manual_uploads/HERA069_IDR2.2_Memo_v3.html)." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "ExecuteTime": { + "end_time": "2020-09-30T22:48:33.820189Z", + "start_time": "2020-09-30T22:48:33.817101Z" + } + }, + "outputs": [], + "source": [ + "# This is where to save the results plots, modify if you want to re-run\n", + "plots_folder = '/users/jsdillon/lustre/Validation/Validation_Paper_Plots/'" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Software" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "ExecuteTime": { + "end_time": "2020-09-30T22:48:41.567329Z", + "start_time": "2020-09-30T22:48:33.823316Z" + } + }, + "outputs": [], + "source": [ + "import hera_cal\n", + "import uvtools\n", + "import numpy as np\n", + "import scipy\n", + "from scipy import stats\n", + "import matplotlib\n", + "from copy import deepcopy\n", + "import glob, os\n", + "import matplotlib.pyplot as plt\n", + "import uvtools\n", + "from tqdm.notebook import tqdm\n", + "from hera_cal import io, apply_cal, delay_filter, noise\n", + "from hera_cal import utils, redcal\n", + "from hera_cal.smooth_cal import CalibrationSmoother\n", + "from pyuvdata import UVData, UVCal, UVFlag\n", + "import pyuvdata\n", + "\n", + "%matplotlib notebook" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "ExecuteTime": { + "end_time": "2020-09-30T22:48:41.574401Z", + "start_time": "2020-09-30T22:48:41.569516Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Module pyuvdata ....\tVersion 2.1.2.dev23+.......\tGit None\n", + "Module hera_cal ....\tVersion 3.0 .......\tGit 3e411d467fd6d425dda0ff48b4c5d6336a7c4fb7\n", + "Module uvtools ....\tVersion 0.1.0 .......\tGit 4070105863c362dd3c86ab0791590b10e3de6576\n", + "Module numpy ....\tVersion 1.18.1 .......\tGit None\n", + "Module scipy ....\tVersion 1.4.1 .......\tGit None\n", + "Module matplotlib ....\tVersion 3.1.3 .......\tGit None\n" + ] + } + ], + "source": [ + "for module in [pyuvdata, hera_cal, uvtools, np, scipy, matplotlib]:\n", + " if hasattr(module, 'version'):\n", + " gh = getattr(module.version, 'git_hash', None)\n", + " else:\n", + " gh = None\n", + " print(\"Module {:<11}....\\tVersion {:<12}.......\\tGit {}\".format(module.__name__, module.__version__[:12], gh))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Load True Gains and Recovered Gains" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "ExecuteTime": { + "end_time": "2020-09-30T22:48:41.591943Z", + "start_time": "2020-09-30T22:48:41.576545Z" + } + }, + "outputs": [], + "source": [ + "refant_num = 83 # this is an antenna that's unflagged for the entire data set\n", + "cmp = 'sum'\n", + "JDs = ['2458098', '2458099', '2458101', '2458102', '2458103', '2458106', '2458107', '2458108', '2458110', '2458111']" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "ExecuteTime": { + "end_time": "2020-09-30T23:04:49.177240Z", + "start_time": "2020-09-30T22:48:41.593758Z" + } + }, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "a7eb8e48857645b5a6f18078b4638840", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(FloatProgress(value=0.0, max=10.0), HTML(value='')))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(FloatProgress(value=0.0, max=66.0), HTML(value='')))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "invalid value encountered in greater\n", + "invalid value encountered in greater\n", + "Mean of empty slice\n", + "Mean of empty slice\n", + "Mean of empty slice\n", + "Mean of empty slice\n", + "Mean of empty slice\n", + "Mean of empty slice\n", + "Mean of empty slice\n", + "Mean of empty slice\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(FloatProgress(value=0.0, max=66.0), HTML(value='')))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(FloatProgress(value=0.0, max=66.0), HTML(value='')))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(FloatProgress(value=0.0, max=66.0), HTML(value='')))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(FloatProgress(value=0.0, max=66.0), HTML(value='')))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(FloatProgress(value=0.0, max=66.0), HTML(value='')))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(FloatProgress(value=0.0, max=66.0), HTML(value='')))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(FloatProgress(value=0.0, max=66.0), HTML(value='')))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(FloatProgress(value=0.0, max=66.0), HTML(value='')))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(FloatProgress(value=0.0, max=66.0), HTML(value='')))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "# Dictionaries to save the per-day results averaged over time and antenna\n", + "avg_relative_errors_true = {}\n", + "avg_phase_error_true = {}\n", + "avg_relative_amp_error_true = {}\n", + "avg_relative_errors_refl = {}\n", + "avg_phase_error_refl = {}\n", + "avg_relative_amp_error_refl = {}\n", + "avg_amplitude_ratio_smooth_over_true = {}\n", + "avg_amplitude_ratio_smooth_over_refl = {}\n", + "\n", + "# Loop over days\n", + "for JD in tqdm(JDs):\n", + " # Load the recovered gain solutions after smooth_cal\n", + " cs_data = CalibrationSmoother(sorted(glob.glob(f'/lustre/aoc/projects/hera/Validation/test-4.0.0/pipeline/{JD}_{cmp}/zen.*.{cmp}.corrupt.smooth_abs.calfits')))\n", + " \n", + " # Load simulated banpasses, with (cs_refl) and without (cs_true) refleciton systematics. \n", + " # Arguably, cs_refl is more \"true\" than cs_true, but that's a quirk of the naming scheme\n", + " cs_true = CalibrationSmoother(sorted(glob.glob(f'/lustre/aoc/projects/hera/Validation/test-4.0.0/data/gains/{JD}.{cmp}.true_gains.calfits')))\n", + " cs_refl = CalibrationSmoother(sorted(glob.glob(f'/lustre/aoc/projects/hera/Validation/test-4.0.0/data/gains/{JD}.{cmp}.reflections.calfits')))\n", + " for ant in cs_refl.gain_grids:\n", + " cs_refl.gain_grids[ant] *= cs_true.gain_grids[ant]\n", + " \n", + " # Terms to set the the reference antenna to match across\n", + " true_rephasor = {jpol: np.abs(cs_true.gain_grids[(refant_num, jpol)]) / (cs_true.gain_grids[(refant_num, jpol)]) for jpol in ['Jee', 'Jnn']}\n", + " refl_rephasor = {jpol: np.abs(cs_refl.gain_grids[(refant_num, jpol)]) / (cs_refl.gain_grids[(refant_num, jpol)]) for jpol in ['Jee', 'Jnn']} \n", + " smooth_rephasor = {jpol: np.abs(cs_data.gain_grids[(refant_num, jpol)]) / (cs_data.gain_grids[(refant_num, jpol)]) for jpol in ['Jee', 'Jnn']}\n", + "\n", + " # placeholders to save results for all antennas\n", + " relative_errors_true = []\n", + " rel_amp_errors_true = []\n", + " phs_errors_true = []\n", + " relative_errors_refl = []\n", + " rel_amp_errors_refl = []\n", + " phs_errors_refl = []\n", + " amp_ratio_true = []\n", + " amp_ratio_refl = []\n", + " \n", + " # loop over antennas\n", + " for ant in tqdm(cs_data.gain_grids, leave=False):\n", + " # Compute ampltiude ratios compared to cs_true\n", + " amp_ratio = np.abs(cs_data.gain_grids[ant]) / np.abs(cs_true.gain_grids[ant])\n", + " amp_ratio[cs_data.flag_grids[ant]] = np.nan\n", + " amp_ratio_true.append(amp_ratio)\n", + " \n", + " # Compute ampltiude ratios compared to cs_reflt\n", + " amp_ratio = np.abs(cs_data.gain_grids[ant]) / np.abs(cs_refl.gain_grids[ant])\n", + " amp_ratio[cs_data.flag_grids[ant]] = np.nan\n", + " amp_ratio_refl.append(amp_ratio)\n", + " \n", + " # Compute diffs relative to cs_true\n", + " diff = cs_true.gain_grids[ant] * true_rephasor[ant[1]] - cs_data.gain_grids[ant] * smooth_rephasor[ant[1]]\n", + " diff[cs_data.flag_grids[ant]] = np.nan\n", + " relative_errors_true.append(np.abs(diff) / np.abs(cs_true.gain_grids[ant]))\n", + " \n", + " # Compute amplitudes of those diffs relative to cs_true\n", + " amp_diff = np.abs(cs_true.gain_grids[ant]) - np.abs(cs_data.gain_grids[ant])\n", + " amp_diff[cs_data.flag_grids[ant]] = np.nan\n", + " rel_amp_errors_true.append(np.abs(amp_diff) / np.abs(cs_true.gain_grids[ant]))\n", + " \n", + " # Compute phases of those diffs relative to cs_true \n", + " phs_diff = np.angle(cs_true.gain_grids[ant] * true_rephasor[ant[1]]) - np.angle(cs_data.gain_grids[ant] * smooth_rephasor[ant[1]])\n", + " phs_diff[cs_data.flag_grids[ant]] = np.nan\n", + " phs_diff = np.abs(phs_diff)\n", + " # Handle phase jumps appropriately\n", + " phs_diff[phs_diff > np.pi] = np.abs(2*np.pi - phs_diff[phs_diff > np.pi])\n", + " phs_errors_true.append(phs_diff)\n", + " \n", + " # Compute diffs relative to cs_refl\n", + " diff = cs_refl.gain_grids[ant] * refl_rephasor[ant[1]] - cs_data.gain_grids[ant] * smooth_rephasor[ant[1]]\n", + " diff[cs_data.flag_grids[ant]] = np.nan\n", + " relative_errors_refl.append(np.abs(diff) / np.abs(cs_refl.gain_grids[ant]))\n", + " \n", + " # Compute amplitudes of those diffs relative to cs_refl\n", + " amp_diff = np.abs(cs_refl.gain_grids[ant]) - np.abs(cs_data.gain_grids[ant])\n", + " amp_diff[cs_data.flag_grids[ant]] = np.nan\n", + " rel_amp_errors_refl.append(np.abs(amp_diff) / np.abs(cs_refl.gain_grids[ant]))\n", + " \n", + " # Compute phases of those diffs relative to cs_refl\n", + " phs_diff = np.angle(cs_refl.gain_grids[ant] * refl_rephasor[ant[1]]) - np.angle(cs_data.gain_grids[ant] * smooth_rephasor[ant[1]])\n", + " phs_diff[cs_data.flag_grids[ant]] = np.nan\n", + " phs_diff = np.abs(phs_diff)\n", + " # Handle phase jumps appropriately \n", + " phs_diff[phs_diff > np.pi] = np.abs(2*np.pi - phs_diff[phs_diff > np.pi])\n", + " phs_errors_refl.append(phs_diff) \n", + " \n", + " # average up all diffs/errors over unflagged antennas and times\n", + " avg_relative_errors_true[JD] = np.nanmean(relative_errors_true, axis=(0,1))\n", + " avg_relative_amp_error_true[JD] = np.nanmean(rel_amp_errors_true, axis=(0,1))\n", + " avg_phase_error_true[JD] = np.nanmean(phs_errors_true, axis=(0,1))\n", + "\n", + " avg_relative_errors_refl[JD] = np.nanmean(relative_errors_refl, axis=(0,1))\n", + " avg_relative_amp_error_refl[JD] = np.nanmean(rel_amp_errors_refl, axis=(0,1))\n", + " avg_phase_error_refl[JD] = np.nanmean(phs_errors_refl, axis=(0,1))\n", + " \n", + " avg_amplitude_ratio_smooth_over_true[JD] = np.nanmean(amp_ratio_true, axis=(0,1))\n", + " avg_amplitude_ratio_smooth_over_refl[JD] = np.nanmean(amp_ratio_refl, axis=(0,1))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Plot Comparison of True and Recovered Gain Solutions" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "ExecuteTime": { + "end_time": "2020-09-30T23:04:49.926149Z", + "start_time": "2020-09-30T23:04:49.180209Z" + }, + "scrolled": false + }, + "outputs": [ + { + "data": { + "application/javascript": [ + "/* Put everything inside the global mpl namespace */\n", + "window.mpl = {};\n", + "\n", + "\n", + "mpl.get_websocket_type = function() {\n", + " if (typeof(WebSocket) !== 'undefined') {\n", + " return WebSocket;\n", + " } else if (typeof(MozWebSocket) !== 'undefined') {\n", + " return MozWebSocket;\n", + " } else {\n", + " alert('Your browser does not have WebSocket support. ' +\n", + " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", + " 'Firefox 4 and 5 are also supported but you ' +\n", + " 'have to enable WebSockets in about:config.');\n", + " };\n", + "}\n", + "\n", + "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", + " this.id = figure_id;\n", + "\n", + " this.ws = websocket;\n", + "\n", + " this.supports_binary = (this.ws.binaryType != undefined);\n", + "\n", + " if (!this.supports_binary) {\n", + " var warnings = document.getElementById(\"mpl-warnings\");\n", + " if (warnings) {\n", + " warnings.style.display = 'block';\n", + " warnings.textContent = (\n", + " \"This browser does not support binary websocket messages. \" +\n", + " \"Performance may be slow.\");\n", + " }\n", + " }\n", + "\n", + " this.imageObj = new Image();\n", + "\n", + " this.context = undefined;\n", + " this.message = undefined;\n", + " this.canvas = undefined;\n", + " this.rubberband_canvas = undefined;\n", + " this.rubberband_context = undefined;\n", + " this.format_dropdown = undefined;\n", + "\n", + " this.image_mode = 'full';\n", + "\n", + " this.root = $('
');\n", + " this._root_extra_style(this.root)\n", + " this.root.attr('style', 'display: inline-block');\n", + "\n", + " $(parent_element).append(this.root);\n", + "\n", + " this._init_header(this);\n", + " this._init_canvas(this);\n", + " this._init_toolbar(this);\n", + "\n", + " var fig = this;\n", + "\n", + " this.waiting = false;\n", + "\n", + " this.ws.onopen = function () {\n", + " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", + " fig.send_message(\"send_image_mode\", {});\n", + " if (mpl.ratio != 1) {\n", + " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", + " }\n", + " fig.send_message(\"refresh\", {});\n", + " }\n", + "\n", + " this.imageObj.onload = function() {\n", + " if (fig.image_mode == 'full') {\n", + " // Full images could contain transparency (where diff images\n", + " // almost always do), so we need to clear the canvas so that\n", + " // there is no ghosting.\n", + " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", + " }\n", + " fig.context.drawImage(fig.imageObj, 0, 0);\n", + " };\n", + "\n", + " this.imageObj.onunload = function() {\n", + " fig.ws.close();\n", + " }\n", + "\n", + " this.ws.onmessage = this._make_on_message_function(this);\n", + "\n", + " this.ondownload = ondownload;\n", + "}\n", + "\n", + "mpl.figure.prototype._init_header = function() {\n", + " var titlebar = $(\n", + " '
');\n", + " var titletext = $(\n", + " '
');\n", + " titlebar.append(titletext)\n", + " this.root.append(titlebar);\n", + " this.header = titletext[0];\n", + "}\n", + "\n", + "\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", + "\n", + "}\n", + "\n", + "\n", + "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", + "\n", + "}\n", + "\n", + "mpl.figure.prototype._init_canvas = function() {\n", + " var fig = this;\n", + "\n", + " var canvas_div = $('
');\n", + "\n", + " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", + "\n", + " function canvas_keyboard_event(event) {\n", + " return fig.key_event(event, event['data']);\n", + " }\n", + "\n", + " canvas_div.keydown('key_press', canvas_keyboard_event);\n", + " canvas_div.keyup('key_release', canvas_keyboard_event);\n", + " this.canvas_div = canvas_div\n", + " this._canvas_extra_style(canvas_div)\n", + " this.root.append(canvas_div);\n", + "\n", + " var canvas = $('');\n", + " canvas.addClass('mpl-canvas');\n", + " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", + "\n", + " this.canvas = canvas[0];\n", + " this.context = canvas[0].getContext(\"2d\");\n", + "\n", + " var backingStore = this.context.backingStorePixelRatio ||\n", + "\tthis.context.webkitBackingStorePixelRatio ||\n", + "\tthis.context.mozBackingStorePixelRatio ||\n", + "\tthis.context.msBackingStorePixelRatio ||\n", + "\tthis.context.oBackingStorePixelRatio ||\n", + "\tthis.context.backingStorePixelRatio || 1;\n", + "\n", + " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", + "\n", + " var rubberband = $('');\n", + " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", + "\n", + " var pass_mouse_events = true;\n", + "\n", + " canvas_div.resizable({\n", + " start: function(event, ui) {\n", + " pass_mouse_events = false;\n", + " },\n", + " resize: function(event, ui) {\n", + " fig.request_resize(ui.size.width, ui.size.height);\n", + " },\n", + " stop: function(event, ui) {\n", + " pass_mouse_events = true;\n", + " fig.request_resize(ui.size.width, ui.size.height);\n", + " },\n", + " });\n", + "\n", + " function mouse_event_fn(event) {\n", + " if (pass_mouse_events)\n", + " return fig.mouse_event(event, event['data']);\n", + " }\n", + "\n", + " rubberband.mousedown('button_press', mouse_event_fn);\n", + " rubberband.mouseup('button_release', mouse_event_fn);\n", + " // Throttle sequential mouse events to 1 every 20ms.\n", + " rubberband.mousemove('motion_notify', mouse_event_fn);\n", + "\n", + " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", + " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", + "\n", + " canvas_div.on(\"wheel\", function (event) {\n", + " event = event.originalEvent;\n", + " event['data'] = 'scroll'\n", + " if (event.deltaY < 0) {\n", + " event.step = 1;\n", + " } else {\n", + " event.step = -1;\n", + " }\n", + " mouse_event_fn(event);\n", + " });\n", + "\n", + " canvas_div.append(canvas);\n", + " canvas_div.append(rubberband);\n", + "\n", + " this.rubberband = rubberband;\n", + " this.rubberband_canvas = rubberband[0];\n", + " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", + " this.rubberband_context.strokeStyle = \"#000000\";\n", + "\n", + " this._resize_canvas = function(width, height) {\n", + " // Keep the size of the canvas, canvas container, and rubber band\n", + " // canvas in synch.\n", + " canvas_div.css('width', width)\n", + " canvas_div.css('height', height)\n", + "\n", + " canvas.attr('width', width * mpl.ratio);\n", + " canvas.attr('height', height * mpl.ratio);\n", + " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", + "\n", + " rubberband.attr('width', width);\n", + " rubberband.attr('height', height);\n", + " }\n", + "\n", + " // Set the figure to an initial 600x600px, this will subsequently be updated\n", + " // upon first draw.\n", + " this._resize_canvas(600, 600);\n", + "\n", + " // Disable right mouse context menu.\n", + " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", + " return false;\n", + " });\n", + "\n", + " function set_focus () {\n", + " canvas.focus();\n", + " canvas_div.focus();\n", + " }\n", + "\n", + " window.setTimeout(set_focus, 100);\n", + "}\n", + "\n", + "mpl.figure.prototype._init_toolbar = function() {\n", + " var fig = this;\n", + "\n", + " var nav_element = $('
');\n", + " nav_element.attr('style', 'width: 100%');\n", + " this.root.append(nav_element);\n", + "\n", + " // Define a callback function for later on.\n", + " function toolbar_event(event) {\n", + " return fig.toolbar_button_onclick(event['data']);\n", + " }\n", + " function toolbar_mouse_event(event) {\n", + " return fig.toolbar_button_onmouseover(event['data']);\n", + " }\n", + "\n", + " for(var toolbar_ind in mpl.toolbar_items) {\n", + " var name = mpl.toolbar_items[toolbar_ind][0];\n", + " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", + " var image = mpl.toolbar_items[toolbar_ind][2];\n", + " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", + "\n", + " if (!name) {\n", + " // put a spacer in here.\n", + " continue;\n", + " }\n", + " var button = $('');\n", + " button.click(method_name, toolbar_event);\n", + " button.mouseover(tooltip, toolbar_mouse_event);\n", + " nav_element.append(button);\n", + " }\n", + "\n", + " // Add the status bar.\n", + " var status_bar = $('');\n", + " nav_element.append(status_bar);\n", + " this.message = status_bar[0];\n", + "\n", + " // Add the close button to the window.\n", + " var buttongrp = $('
');\n", + " var button = $('');\n", + " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", + " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", + " buttongrp.append(button);\n", + " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", + " titlebar.prepend(buttongrp);\n", + "}\n", + "\n", + "mpl.figure.prototype._root_extra_style = function(el){\n", + " var fig = this\n", + " el.on(\"remove\", function(){\n", + "\tfig.close_ws(fig, {});\n", + " });\n", + "}\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function(el){\n", + " // this is important to make the div 'focusable\n", + " el.attr('tabindex', 0)\n", + " // reach out to IPython and tell the keyboard manager to turn it's self\n", + " // off when our div gets focus\n", + "\n", + " // location in version 3\n", + " if (IPython.notebook.keyboard_manager) {\n", + " IPython.notebook.keyboard_manager.register_events(el);\n", + " }\n", + " else {\n", + " // location in version 2\n", + " IPython.keyboard_manager.register_events(el);\n", + " }\n", + "\n", + "}\n", + "\n", + "mpl.figure.prototype._key_event_extra = function(event, name) {\n", + " var manager = IPython.notebook.keyboard_manager;\n", + " if (!manager)\n", + " manager = IPython.keyboard_manager;\n", + "\n", + " // Check for shift+enter\n", + " if (event.shiftKey && event.which == 13) {\n", + " this.canvas_div.blur();\n", + " // select the cell after this one\n", + " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", + " IPython.notebook.select(index + 1);\n", + " }\n", + "}\n", + "\n", + "mpl.figure.prototype.handle_save = function(fig, msg) {\n", + " fig.ondownload(fig, null);\n", + "}\n", + "\n", + "\n", + "mpl.find_output_cell = function(html_output) {\n", + " // Return the cell and output element which can be found *uniquely* in the notebook.\n", + " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", + " // IPython event is triggered only after the cells have been serialised, which for\n", + " // our purposes (turning an active figure into a static one), is too late.\n", + " var cells = IPython.notebook.get_cells();\n", + " var ncells = cells.length;\n", + " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", + " data = data.data;\n", + " }\n", + " if (data['text/html'] == html_output) {\n", + " return [cell, data, j];\n", + " }\n", + " }\n", + " }\n", + " }\n", + "}\n", + "\n", + "// Register the function which deals with the matplotlib target/channel.\n", + "// The kernel may be null if the page has been refreshed.\n", + "if (IPython.notebook.kernel != null) {\n", + " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", + "}\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "plt.figure(figsize=(5,4))\n", + "x = np.linspace(.5,2.5,200)\n", + "plt.hist(np.hstack(list(all_1D_chisq.values())), x, density=True, alpha=.5, \n", + " label='Redundant Calibration $\\chi^2$ / DoF\\n(All times, frequencies,\\npolarizations, and nights)')\n", + "k = DoF * 2\n", + "plt.plot(x, stats.chi2.pdf(x*k, k)*k, '--', label=\"Ideal $\\chi^2$ Distribution\".format(k), c='grey')\n", + "plt.xlabel('$\\chi^2/\\,$DoF (Unitless)')\n", + "plt.ylabel('Probability Density')\n", + "plt.legend()\n", + "plt.xlim([np.min(x), np.max(x)])\n", + "plt.tight_layout()\n", + "plt.savefig(plots_folder + 'chisq_distribution.pdf')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Figure 2** | Comparison of ideal and recovered redundant calibration calibration $\\chi^2$ / DoF. The difference is due to per-baseline systematics (e.g. cross-talk). See Validation paper for a full caption." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Plot Array Configuration and Antenna Flags" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "ExecuteTime": { + "end_time": "2020-09-30T23:08:04.337427Z", + "start_time": "2020-09-30T23:08:04.081351Z" + } + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Telescope RIMEz calculation is not in known_telescopes.\n" + ] + }, + { + "data": { + "application/javascript": [ + "/* Put everything inside the global mpl namespace */\n", + "window.mpl = {};\n", + "\n", + "\n", + "mpl.get_websocket_type = function() {\n", + " if (typeof(WebSocket) !== 'undefined') {\n", + " return WebSocket;\n", + " } else if (typeof(MozWebSocket) !== 'undefined') {\n", + " return MozWebSocket;\n", + " } else {\n", + " alert('Your browser does not have WebSocket support. ' +\n", + " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", + " 'Firefox 4 and 5 are also supported but you ' +\n", + " 'have to enable WebSockets in about:config.');\n", + " };\n", + "}\n", + "\n", + "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", + " this.id = figure_id;\n", + "\n", + " this.ws = websocket;\n", + "\n", + " this.supports_binary = (this.ws.binaryType != undefined);\n", + "\n", + " if (!this.supports_binary) {\n", + " var warnings = document.getElementById(\"mpl-warnings\");\n", + " if (warnings) {\n", + " warnings.style.display = 'block';\n", + " warnings.textContent = (\n", + " \"This browser does not support binary websocket messages. \" +\n", + " \"Performance may be slow.\");\n", + " }\n", + " }\n", + "\n", + " this.imageObj = new Image();\n", + "\n", + " this.context = undefined;\n", + " this.message = undefined;\n", + " this.canvas = undefined;\n", + " this.rubberband_canvas = undefined;\n", + " this.rubberband_context = undefined;\n", + " this.format_dropdown = undefined;\n", + "\n", + " this.image_mode = 'full';\n", + "\n", + " this.root = $('
');\n", + " this._root_extra_style(this.root)\n", + " this.root.attr('style', 'display: inline-block');\n", + "\n", + " $(parent_element).append(this.root);\n", + "\n", + " this._init_header(this);\n", + " this._init_canvas(this);\n", + " this._init_toolbar(this);\n", + "\n", + " var fig = this;\n", + "\n", + " this.waiting = false;\n", + "\n", + " this.ws.onopen = function () {\n", + " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", + " fig.send_message(\"send_image_mode\", {});\n", + " if (mpl.ratio != 1) {\n", + " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", + " }\n", + " fig.send_message(\"refresh\", {});\n", + " }\n", + "\n", + " this.imageObj.onload = function() {\n", + " if (fig.image_mode == 'full') {\n", + " // Full images could contain transparency (where diff images\n", + " // almost always do), so we need to clear the canvas so that\n", + " // there is no ghosting.\n", + " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", + " }\n", + " fig.context.drawImage(fig.imageObj, 0, 0);\n", + " };\n", + "\n", + " this.imageObj.onunload = function() {\n", + " fig.ws.close();\n", + " }\n", + "\n", + " this.ws.onmessage = this._make_on_message_function(this);\n", + "\n", + " this.ondownload = ondownload;\n", + "}\n", + "\n", + "mpl.figure.prototype._init_header = function() {\n", + " var titlebar = $(\n", + " '
');\n", + " var titletext = $(\n", + " '
');\n", + " titlebar.append(titletext)\n", + " this.root.append(titlebar);\n", + " this.header = titletext[0];\n", + "}\n", + "\n", + "\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", + "\n", + "}\n", + "\n", + "\n", + "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", + "\n", + "}\n", + "\n", + "mpl.figure.prototype._init_canvas = function() {\n", + " var fig = this;\n", + "\n", + " var canvas_div = $('
');\n", + "\n", + " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", + "\n", + " function canvas_keyboard_event(event) {\n", + " return fig.key_event(event, event['data']);\n", + " }\n", + "\n", + " canvas_div.keydown('key_press', canvas_keyboard_event);\n", + " canvas_div.keyup('key_release', canvas_keyboard_event);\n", + " this.canvas_div = canvas_div\n", + " this._canvas_extra_style(canvas_div)\n", + " this.root.append(canvas_div);\n", + "\n", + " var canvas = $('');\n", + " canvas.addClass('mpl-canvas');\n", + " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", + "\n", + " this.canvas = canvas[0];\n", + " this.context = canvas[0].getContext(\"2d\");\n", + "\n", + " var backingStore = this.context.backingStorePixelRatio ||\n", + "\tthis.context.webkitBackingStorePixelRatio ||\n", + "\tthis.context.mozBackingStorePixelRatio ||\n", + "\tthis.context.msBackingStorePixelRatio ||\n", + "\tthis.context.oBackingStorePixelRatio ||\n", + "\tthis.context.backingStorePixelRatio || 1;\n", + "\n", + " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", + "\n", + " var rubberband = $('');\n", + " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", + "\n", + " var pass_mouse_events = true;\n", + "\n", + " canvas_div.resizable({\n", + " start: function(event, ui) {\n", + " pass_mouse_events = false;\n", + " },\n", + " resize: function(event, ui) {\n", + " fig.request_resize(ui.size.width, ui.size.height);\n", + " },\n", + " stop: function(event, ui) {\n", + " pass_mouse_events = true;\n", + " fig.request_resize(ui.size.width, ui.size.height);\n", + " },\n", + " });\n", + "\n", + " function mouse_event_fn(event) {\n", + " if (pass_mouse_events)\n", + " return fig.mouse_event(event, event['data']);\n", + " }\n", + "\n", + " rubberband.mousedown('button_press', mouse_event_fn);\n", + " rubberband.mouseup('button_release', mouse_event_fn);\n", + " // Throttle sequential mouse events to 1 every 20ms.\n", + " rubberband.mousemove('motion_notify', mouse_event_fn);\n", + "\n", + " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", + " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", + "\n", + " canvas_div.on(\"wheel\", function (event) {\n", + " event = event.originalEvent;\n", + " event['data'] = 'scroll'\n", + " if (event.deltaY < 0) {\n", + " event.step = 1;\n", + " } else {\n", + " event.step = -1;\n", + " }\n", + " mouse_event_fn(event);\n", + " });\n", + "\n", + " canvas_div.append(canvas);\n", + " canvas_div.append(rubberband);\n", + "\n", + " this.rubberband = rubberband;\n", + " this.rubberband_canvas = rubberband[0];\n", + " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", + " this.rubberband_context.strokeStyle = \"#000000\";\n", + "\n", + " this._resize_canvas = function(width, height) {\n", + " // Keep the size of the canvas, canvas container, and rubber band\n", + " // canvas in synch.\n", + " canvas_div.css('width', width)\n", + " canvas_div.css('height', height)\n", + "\n", + " canvas.attr('width', width * mpl.ratio);\n", + " canvas.attr('height', height * mpl.ratio);\n", + " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", + "\n", + " rubberband.attr('width', width);\n", + " rubberband.attr('height', height);\n", + " }\n", + "\n", + " // Set the figure to an initial 600x600px, this will subsequently be updated\n", + " // upon first draw.\n", + " this._resize_canvas(600, 600);\n", + "\n", + " // Disable right mouse context menu.\n", + " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", + " return false;\n", + " });\n", + "\n", + " function set_focus () {\n", + " canvas.focus();\n", + " canvas_div.focus();\n", + " }\n", + "\n", + " window.setTimeout(set_focus, 100);\n", + "}\n", + "\n", + "mpl.figure.prototype._init_toolbar = function() {\n", + " var fig = this;\n", + "\n", + " var nav_element = $('
');\n", + " nav_element.attr('style', 'width: 100%');\n", + " this.root.append(nav_element);\n", + "\n", + " // Define a callback function for later on.\n", + " function toolbar_event(event) {\n", + " return fig.toolbar_button_onclick(event['data']);\n", + " }\n", + " function toolbar_mouse_event(event) {\n", + " return fig.toolbar_button_onmouseover(event['data']);\n", + " }\n", + "\n", + " for(var toolbar_ind in mpl.toolbar_items) {\n", + " var name = mpl.toolbar_items[toolbar_ind][0];\n", + " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", + " var image = mpl.toolbar_items[toolbar_ind][2];\n", + " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", + "\n", + " if (!name) {\n", + " // put a spacer in here.\n", + " continue;\n", + " }\n", + " var button = $('');\n", + " button.click(method_name, toolbar_event);\n", + " button.mouseover(tooltip, toolbar_mouse_event);\n", + " nav_element.append(button);\n", + " }\n", + "\n", + " // Add the status bar.\n", + " var status_bar = $('');\n", + " nav_element.append(status_bar);\n", + " this.message = status_bar[0];\n", + "\n", + " // Add the close button to the window.\n", + " var buttongrp = $('
');\n", + " var button = $('');\n", + " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", + " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", + " buttongrp.append(button);\n", + " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", + " titlebar.prepend(buttongrp);\n", + "}\n", + "\n", + "mpl.figure.prototype._root_extra_style = function(el){\n", + " var fig = this\n", + " el.on(\"remove\", function(){\n", + "\tfig.close_ws(fig, {});\n", + " });\n", + "}\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function(el){\n", + " // this is important to make the div 'focusable\n", + " el.attr('tabindex', 0)\n", + " // reach out to IPython and tell the keyboard manager to turn it's self\n", + " // off when our div gets focus\n", + "\n", + " // location in version 3\n", + " if (IPython.notebook.keyboard_manager) {\n", + " IPython.notebook.keyboard_manager.register_events(el);\n", + " }\n", + " else {\n", + " // location in version 2\n", + " IPython.keyboard_manager.register_events(el);\n", + " }\n", + "\n", + "}\n", + "\n", + "mpl.figure.prototype._key_event_extra = function(event, name) {\n", + " var manager = IPython.notebook.keyboard_manager;\n", + " if (!manager)\n", + " manager = IPython.keyboard_manager;\n", + "\n", + " // Check for shift+enter\n", + " if (event.shiftKey && event.which == 13) {\n", + " this.canvas_div.blur();\n", + " // select the cell after this one\n", + " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", + " IPython.notebook.select(index + 1);\n", + " }\n", + "}\n", + "\n", + "mpl.figure.prototype.handle_save = function(fig, msg) {\n", + " fig.ondownload(fig, null);\n", + "}\n", + "\n", + "\n", + "mpl.find_output_cell = function(html_output) {\n", + " // Return the cell and output element which can be found *uniquely* in the notebook.\n", + " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", + " // IPython event is triggered only after the cells have been serialised, which for\n", + " // our purposes (turning an active figure into a static one), is too late.\n", + " var cells = IPython.notebook.get_cells();\n", + " var ncells = cells.length;\n", + " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", + " data = data.data;\n", + " }\n", + " if (data['text/html'] == html_output) {\n", + " return [cell, data, j];\n", + " }\n", + " }\n", + " }\n", + " }\n", + "}\n", + "\n", + "// Register the function which deals with the matplotlib target/channel.\n", + "// The kernel may be null if the page has been refreshed.\n", + "if (IPython.notebook.kernel != null) {\n", + " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", + "}\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "plt.figure(figsize=(10,4))\n", + "plt.subplot(121)\n", + "plt.imshow(abs_ratio, aspect='auto', cmap='inferno',\n", + " extent=[cs_abs.freqs[0]/1e6, cs_abs.freqs[-1]/1e6, cs_abs.time_grid[-1]-2458098, cs_abs.time_grid[0]-2458098])\n", + "plt.clim([1,1.1])\n", + "plt.colorbar(label='Absolute Calibration Gain Amplitude Bias')\n", + "plt.xlabel('Frequency (MHz)')\n", + "plt.ylabel('JD - 2458098')\n", + "\n", + "plt.subplot(122)\n", + "plt.imshow(smooth_ratio, aspect='auto', cmap='inferno',\n", + " extent=[cs_abs.freqs[0]/1e6, cs_abs.freqs[-1]/1e6, cs_abs.time_grid[-1]-2458098, cs_abs.time_grid[0]-2458098])\n", + "plt.clim([1,1.1])\n", + "plt.colorbar(label='Smoothed Calibration Gain Amplitude Bias')\n", + "plt.xlabel('Frequency (MHz)')\n", + "plt.ylabel('JD - 2458098')\n", + "\n", + "plt.tight_layout()\n", + "plt.savefig(plots_folder + 'abscal_bias.pdf')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Figure 4** | Bias in absolute calibration amplitude, both before and after calibration smoothing. This effect is [better explained here](https://github.com/HERA-Team/hera_cal/issues/642), and [being fixed for future analysis here](https://github.com/HERA-Team/hera_cal/pull/647). See Validation paper for a full caption." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Plot metrics assessing noise in LST-binned data on a single file, `LST.1.69139`" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "ExecuteTime": { + "end_time": "2020-09-30T23:09:30.939841Z", + "start_time": "2020-09-30T23:09:12.227692Z" + } + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "antenna_diameters is not set. Using known values for HERA.\n", + "antenna_diameters is not set. Using known values for HERA.\n" + ] + } + ], + "source": [ + "# Load LST-binned visibilities, and the standard deviation over nights of those LST-binned visibilities\n", + "hd = io.HERAData('/lustre/aoc/projects/hera/Validation/test-4.0.0/pipeline/LSTBIN/sum/zen.grp1.of1.LST.1.69139.HH.OCRSL.uvh5')\n", + "data, flags, nsamples = hd.read()\n", + "hd_std = io.HERAData('/lustre/aoc/projects/hera/Validation/test-4.0.0/pipeline/LSTBIN/sum/zen.grp1.of1.STD.1.69139.HH.OCRSL.uvh5')\n", + "data_std, flags_std, nsamples_std = hd_std.read()" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "ExecuteTime": { + "end_time": "2020-09-30T23:09:31.023167Z", + "start_time": "2020-09-30T23:09:30.941395Z" + } + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Telescope RIMEz calculation is not in known_telescopes.\n" + ] + } + ], + "source": [ + "# Get the integration time of the original data\n", + "hd_true = io.HERAData('/lustre/aoc/projects/hera/Validation/test-4.0.0/data/visibilities/2458098/zen.2458098.43124.sum.true.uvh5')\n", + "tint = np.median(np.diff(hd_true.times)) * 24 * 3600" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "ExecuteTime": { + "end_time": "2020-09-30T23:09:41.190968Z", + "start_time": "2020-09-30T23:09:31.024686Z" + } + }, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "936e0f9d985f4c32b7f300ac1a1c1e87", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(FloatProgress(value=0.0, max=1122.0), HTML(value='')))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "divide by zero encountered in true_divide\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "# lists to store estimates of the nosie variance in the LST-binned data products\n", + "all_obs_var = []\n", + "all_predicted_var = []\n", + "all_interleaved_var = []\n", + "all_predicted_binned_var = []\n", + "\n", + "# Loop over baselines\n", + "for bl in tqdm(data.bls()):\n", + " ant1, ant2 = utils.split_bl(bl)\n", + " auto1 = utils.join_bl(ant1, ant1)\n", + " auto2 = utils.join_bl(ant2, ant2) \n", + " if auto1 == auto2:\n", + " continue # ignore autocorrelations in assessing noise\n", + " \n", + " # Flag integrations with fewer than 10 samples\n", + " flags_here = deepcopy(flags[bl])\n", + " flags_here |= flags[auto1] | flags[auto2]\n", + " flags_here |= (nsamples[bl] < 10)\n", + "\n", + " # Predicted night-to-night visibility variance\n", + " predicted_var = noise.predict_noise_variance_from_autos(bl, data, dt=tint)\n", + " predicted_var[flags_here] = np.nan\n", + " all_predicted_var.append(predicted_var)\n", + " \n", + " # Observed night-to-night visibiltiy variance\n", + " obs_var = deepcopy(data_std[bl])**2\n", + " obs_var[flags_here] = np.nan\n", + " obs_nsamples = deepcopy(nsamples_std[bl])\n", + " obs_nsamples[flags_here] = np.nan\n", + " obs_var *= (obs_nsamples / (obs_nsamples - 1))\n", + " all_obs_var.append(obs_var)\n", + "\n", + " # Predicted visibiltiy variance after LST-binning\n", + " predicted_binned_var = noise.predict_noise_variance_from_autos(bl, data, dt=tint, nsamples=nsamples)\n", + " predicted_binned_var[flags_here] = np.nan\n", + " all_predicted_binned_var.append(predicted_binned_var) \n", + " \n", + " # Observed visibiltiy variance after LST-binning\n", + " data_here = deepcopy(data[bl])\n", + " data_here[flags_here] = np.nan\n", + " interleaved_variance = noise.interleaved_noise_variance_estimate(data_here, kernel=[[-.5,1,-.5]])\n", + " all_interleaved_var.append(interleaved_variance)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "ExecuteTime": { + "end_time": "2020-09-30T23:09:46.968258Z", + "start_time": "2020-09-30T23:09:41.193176Z" + } + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Mean of empty slice\n", + "Mean of empty slice\n", + "Mean of empty slice\n", + "Mean of empty slice\n" + ] + } + ], + "source": [ + "# average all visibiltiy variances over times and unflagged antennas\n", + "mean_obs_var = np.nanmean(np.abs(all_obs_var), axis=(0,1))\n", + "mean_predicted_var = np.nanmean(all_predicted_var, axis=(0,1))\n", + "mean_interleaved_var = np.nanmean(np.abs(all_interleaved_var), axis=(0,1))\n", + "mean_predicted_binned_var = np.nanmean(all_predicted_binned_var, axis=(0,1))" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "ExecuteTime": { + "end_time": "2020-09-30T23:09:47.418163Z", + "start_time": "2020-09-30T23:09:46.970132Z" + } + }, + "outputs": [ + { + "data": { + "application/javascript": [ + "/* Put everything inside the global mpl namespace */\n", + "window.mpl = {};\n", + "\n", + "\n", + "mpl.get_websocket_type = function() {\n", + " if (typeof(WebSocket) !== 'undefined') {\n", + " return WebSocket;\n", + " } else if (typeof(MozWebSocket) !== 'undefined') {\n", + " return MozWebSocket;\n", + " } else {\n", + " alert('Your browser does not have WebSocket support. ' +\n", + " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", + " 'Firefox 4 and 5 are also supported but you ' +\n", + " 'have to enable WebSockets in about:config.');\n", + " };\n", + "}\n", + "\n", + "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", + " this.id = figure_id;\n", + "\n", + " this.ws = websocket;\n", + "\n", + " this.supports_binary = (this.ws.binaryType != undefined);\n", + "\n", + " if (!this.supports_binary) {\n", + " var warnings = document.getElementById(\"mpl-warnings\");\n", + " if (warnings) {\n", + " warnings.style.display = 'block';\n", + " warnings.textContent = (\n", + " \"This browser does not support binary websocket messages. \" +\n", + " \"Performance may be slow.\");\n", + " }\n", + " }\n", + "\n", + " this.imageObj = new Image();\n", + "\n", + " this.context = undefined;\n", + " this.message = undefined;\n", + " this.canvas = undefined;\n", + " this.rubberband_canvas = undefined;\n", + " this.rubberband_context = undefined;\n", + " this.format_dropdown = undefined;\n", + "\n", + " this.image_mode = 'full';\n", + "\n", + " this.root = $('
');\n", + " this._root_extra_style(this.root)\n", + " this.root.attr('style', 'display: inline-block');\n", + "\n", + " $(parent_element).append(this.root);\n", + "\n", + " this._init_header(this);\n", + " this._init_canvas(this);\n", + " this._init_toolbar(this);\n", + "\n", + " var fig = this;\n", + "\n", + " this.waiting = false;\n", + "\n", + " this.ws.onopen = function () {\n", + " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", + " fig.send_message(\"send_image_mode\", {});\n", + " if (mpl.ratio != 1) {\n", + " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", + " }\n", + " fig.send_message(\"refresh\", {});\n", + " }\n", + "\n", + " this.imageObj.onload = function() {\n", + " if (fig.image_mode == 'full') {\n", + " // Full images could contain transparency (where diff images\n", + " // almost always do), so we need to clear the canvas so that\n", + " // there is no ghosting.\n", + " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", + " }\n", + " fig.context.drawImage(fig.imageObj, 0, 0);\n", + " };\n", + "\n", + " this.imageObj.onunload = function() {\n", + " fig.ws.close();\n", + " }\n", + "\n", + " this.ws.onmessage = this._make_on_message_function(this);\n", + "\n", + " this.ondownload = ondownload;\n", + "}\n", + "\n", + "mpl.figure.prototype._init_header = function() {\n", + " var titlebar = $(\n", + " '
');\n", + " var titletext = $(\n", + " '
');\n", + " titlebar.append(titletext)\n", + " this.root.append(titlebar);\n", + " this.header = titletext[0];\n", + "}\n", + "\n", + "\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", + "\n", + "}\n", + "\n", + "\n", + "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", + "\n", + "}\n", + "\n", + "mpl.figure.prototype._init_canvas = function() {\n", + " var fig = this;\n", + "\n", + " var canvas_div = $('
');\n", + "\n", + " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", + "\n", + " function canvas_keyboard_event(event) {\n", + " return fig.key_event(event, event['data']);\n", + " }\n", + "\n", + " canvas_div.keydown('key_press', canvas_keyboard_event);\n", + " canvas_div.keyup('key_release', canvas_keyboard_event);\n", + " this.canvas_div = canvas_div\n", + " this._canvas_extra_style(canvas_div)\n", + " this.root.append(canvas_div);\n", + "\n", + " var canvas = $('');\n", + " canvas.addClass('mpl-canvas');\n", + " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", + "\n", + " this.canvas = canvas[0];\n", + " this.context = canvas[0].getContext(\"2d\");\n", + "\n", + " var backingStore = this.context.backingStorePixelRatio ||\n", + "\tthis.context.webkitBackingStorePixelRatio ||\n", + "\tthis.context.mozBackingStorePixelRatio ||\n", + "\tthis.context.msBackingStorePixelRatio ||\n", + "\tthis.context.oBackingStorePixelRatio ||\n", + "\tthis.context.backingStorePixelRatio || 1;\n", + "\n", + " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", + "\n", + " var rubberband = $('');\n", + " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", + "\n", + " var pass_mouse_events = true;\n", + "\n", + " canvas_div.resizable({\n", + " start: function(event, ui) {\n", + " pass_mouse_events = false;\n", + " },\n", + " resize: function(event, ui) {\n", + " fig.request_resize(ui.size.width, ui.size.height);\n", + " },\n", + " stop: function(event, ui) {\n", + " pass_mouse_events = true;\n", + " fig.request_resize(ui.size.width, ui.size.height);\n", + " },\n", + " });\n", + "\n", + " function mouse_event_fn(event) {\n", + " if (pass_mouse_events)\n", + " return fig.mouse_event(event, event['data']);\n", + " }\n", + "\n", + " rubberband.mousedown('button_press', mouse_event_fn);\n", + " rubberband.mouseup('button_release', mouse_event_fn);\n", + " // Throttle sequential mouse events to 1 every 20ms.\n", + " rubberband.mousemove('motion_notify', mouse_event_fn);\n", + "\n", + " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", + " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", + "\n", + " canvas_div.on(\"wheel\", function (event) {\n", + " event = event.originalEvent;\n", + " event['data'] = 'scroll'\n", + " if (event.deltaY < 0) {\n", + " event.step = 1;\n", + " } else {\n", + " event.step = -1;\n", + " }\n", + " mouse_event_fn(event);\n", + " });\n", + "\n", + " canvas_div.append(canvas);\n", + " canvas_div.append(rubberband);\n", + "\n", + " this.rubberband = rubberband;\n", + " this.rubberband_canvas = rubberband[0];\n", + " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", + " this.rubberband_context.strokeStyle = \"#000000\";\n", + "\n", + " this._resize_canvas = function(width, height) {\n", + " // Keep the size of the canvas, canvas container, and rubber band\n", + " // canvas in synch.\n", + " canvas_div.css('width', width)\n", + " canvas_div.css('height', height)\n", + "\n", + " canvas.attr('width', width * mpl.ratio);\n", + " canvas.attr('height', height * mpl.ratio);\n", + " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", + "\n", + " rubberband.attr('width', width);\n", + " rubberband.attr('height', height);\n", + " }\n", + "\n", + " // Set the figure to an initial 600x600px, this will subsequently be updated\n", + " // upon first draw.\n", + " this._resize_canvas(600, 600);\n", + "\n", + " // Disable right mouse context menu.\n", + " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", + " return false;\n", + " });\n", + "\n", + " function set_focus () {\n", + " canvas.focus();\n", + " canvas_div.focus();\n", + " }\n", + "\n", + " window.setTimeout(set_focus, 100);\n", + "}\n", + "\n", + "mpl.figure.prototype._init_toolbar = function() {\n", + " var fig = this;\n", + "\n", + " var nav_element = $('
');\n", + " nav_element.attr('style', 'width: 100%');\n", + " this.root.append(nav_element);\n", + "\n", + " // Define a callback function for later on.\n", + " function toolbar_event(event) {\n", + " return fig.toolbar_button_onclick(event['data']);\n", + " }\n", + " function toolbar_mouse_event(event) {\n", + " return fig.toolbar_button_onmouseover(event['data']);\n", + " }\n", + "\n", + " for(var toolbar_ind in mpl.toolbar_items) {\n", + " var name = mpl.toolbar_items[toolbar_ind][0];\n", + " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", + " var image = mpl.toolbar_items[toolbar_ind][2];\n", + " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", + "\n", + " if (!name) {\n", + " // put a spacer in here.\n", + " continue;\n", + " }\n", + " var button = $('