{ "cells": [ { "cell_type": "markdown", "id": "9359fc63-3229-4fd3-8631-09c181e6a27b", "metadata": {}, "source": [ "# Aligning Spectra\n", "\n", "This notebook shows how to align spectra before they can be averaged.\n", "\n", "We use an observation with a mixed observing strategy; position switching and frequency switching.\n", "In this case the on and off source observations also switch the signal in the frequency domain between a signal and a reference state, so there are four switching states: signal with the noise diode, signal without the noise diode, reference with the noise diode and reference without the noise diode.\n", "\n", "We will calibrate the signal and reference states independently, using position switching. Then, we'll look at the calibrated spectra as a function of channel and vizualize the shift between the signal and reference states. Finally we will shift the reference state and average it with the signal state.\n", "\n", "## Dysh commands\n", "\n", "The following dysh commands are introduced (leaving out all the function arguments):\n", "\n", " filename = dysh_data()\n", " sdf = GBTFITSLoad()\n", " sb = sdf.getps()\n", " ta = sb.timeaverage()\n", " ta1 = ta.align_to()\n", " ta.average()\n", " p1 = ta.plot()\n", " p1.oshow(ta1)\n", "\n", "## Loading Modules\n", "We start by loading the modules we will use for the data reduction. " ] }, { "cell_type": "code", "execution_count": 1, "id": "e34b86e9-6438-4e84-8503-d6dd1699e243", "metadata": {}, "outputs": [], "source": [ "# These modules are required for the data reduction.\n", "from dysh.fits.gbtfitsload import GBTFITSLoad\n", "from dysh.log import init_logging\n", "from astropy import units as u\n", "\n", "# This module is used for custom plotting.\n", "import matplotlib.pyplot as plt\n", "\n", "# These modules are used for file I/O\n", "from dysh.util.files import dysh_data\n", "from pathlib import Path" ] }, { "cell_type": "markdown", "id": "333aa096-b7dc-4812-a77c-88b07dcc116d", "metadata": {}, "source": [ "## Setup\n", "dysh uses a logger to communicate. If you are working in the command\n", "line, then the logging is setup for you. If you are working in a\n", "jupyter lab instance, then you need to set it up. You can do so using\n", "the init_logging function imported above. As an argument, init_logging\n", "takes a number, the verbosity level. level 0 is for error messages\n", "only, 1 for warning, 2 for info and 3 for debug. Here we set it to\n", "level 2.\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "4b612a07-7193-41dd-b7ed-5a4f695d0b50", "metadata": {}, "outputs": [], "source": [ "init_logging(2)\n", "\n", "# also create a local \"output\" directory where temporary notebook files can be stored.\n", "output_dir = Path.cwd() / \"output\"\n", "output_dir.mkdir(exist_ok=True)" ] }, { "cell_type": "markdown", "id": "74f02c88-5632-4f64-abda-6e70f63ff0fd", "metadata": {}, "source": [ "## Data Retrieval\n", "\n", "Download the example SDFITS data, if necessary." ] }, { "cell_type": "code", "execution_count": 3, "id": "cf801734-2ba0-48cd-a664-3ca15ce58890", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "06:24:09.652 I Resolving example=align -> mixed-fs-ps/data/TGBT24B_613_04.raw.vegas.trim.fits\n", "06:24:09.653 I url: http://www.gb.nrao.edu/dysh//example_data/mixed-fs-ps/data/TGBT24B_613_04.raw.vegas.trim.fits\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Odd-1, did not find /home/teuben/GBT/dysh_data/example_data/mixed-fs-ps/data/TGBT24B_613_04.raw.vegas.trim.fits\n", "TGBT24B_613_04.raw.vegas.trim.fits already downloaded\n" ] } ], "source": [ "filename = dysh_data(example=\"align\")" ] }, { "cell_type": "markdown", "id": "66d69520-58ac-46ac-be99-071c5812217c", "metadata": {}, "source": [ "## Data Loading\n", "\n", "Next, we use `GBTFITSLoad` to load the data, and then its `summary` method to inspect its contents." ] }, { "cell_type": "code", "execution_count": 4, "id": "fb10b18f-4510-4707-ad2a-70a1ec2b4d79", "metadata": {}, "outputs": [], "source": [ "sdf = GBTFITSLoad(filename)" ] }, { "cell_type": "code", "execution_count": 5, "id": "62f47e96-7553-48c9-9dfb-032d2af60897", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| SCAN | \n", "OBJECT | \n", "VELOCITY | \n", "PROC | \n", "PROCSEQN | \n", "RESTFREQ | \n", "DOPFREQ | \n", "# IF | \n", "# POL | \n", "# INT | \n", "# FEED | \n", "AZIMUTH | \n", "ELEVATION | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 35 | \n", "MESSIER32 | \n", "-200.0 | \n", "OnOff | \n", "1 | \n", "1.420406 | \n", "1.420406 | \n", "1 | \n", "1 | \n", "5 | \n", "1 | \n", "73.1155 | \n", "62.2955 | \n", "
| 36 | \n", "MESSIER32 | \n", "-200.0 | \n", "OnOff | \n", "2 | \n", "1.420406 | \n", "1.420406 | \n", "1 | \n", "1 | \n", "5 | \n", "1 | \n", "72.3087 | \n", "59.3225 | \n", "