{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"HAWC+ Data Inspection\n",
"=============\n",
"* **Aim**: Basic inspection and analysis.
\n",
"* **Data**: Level 4 imaging polarimetry data for 30 Dor
\n",
"* **Tools**: astropy
\n",
"* **Instrument**: HAWC+
\n",
"* **Documentation**: [HAWC+ DRP user's manual](https://irsa.ipac.caltech.edu/data/SOFIA/docs/sites/default/files/2022-12/hawc_users_revL.pdf)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Goals\n",
"---------\n",
"* Load and plot stokes I, Q and U data\n",
"* Create polarized intensity and polization fraction maps\n",
"* Overplot polization vectors\n",
"* Create all polization maps"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Introduction\n",
"--------------\n",
"\n",
"This recipe provides an overview and sample python code for inspecting and plotting HAWC+ data. The data used in this example come from a SOFIA press release ([SOFIA Reveals Never-Before-Seen Magnetic Field Details](https://irsa.ipac.caltech.edu/data/SOFIA/docs/publications/science-results-archive/sofia-reveals-never-seen-magnetic-field-details/index.html)) and the data are publicly available. We will go through the inital steps for loading the level 4 polarization and creating polarization maps. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Imports\n",
"-----------"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2023-09-21T00:21:10.295149Z",
"iopub.status.busy": "2023-09-21T00:21:10.294808Z",
"iopub.status.idle": "2023-09-21T00:21:11.745562Z",
"shell.execute_reply": "2023-09-21T00:21:11.744781Z"
}
},
"outputs": [],
"source": [
"import numpy as np\n",
"from astropy.io import fits\n",
"import matplotlib.pyplot as plt\n",
"from aplpy import FITSFigure\n",
"import warnings\n",
"warnings.simplefilter('ignore')\n",
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Ingredients\n",
"----------------\n",
"\n",
"Downloading HAWC+ Data\n",
"\n",
"- Fill in the following fields\n",
"- Spatial constraints:\n",
" - Coordinates or object name: `30 Dor` from drop-down menu\n",
" - Radius: `600 arcseconds`\n",
"- Click on the arrow next to Observation Constraints to open the drop-down options. \n",
"- Observation Constraints:\n",
" - Observation Date: From: `2018-01-01` To: `2019-01-01`\n",
"- Instrument Constraints\n",
" - Select `HAWC+`\n",
"- Data Product Constraints:\n",
" - Processing Level: `Level 4`\n",
" - Click the `Search` button\n",
"- After the results load, select the checkboxes next to the Column header AOR ID to select all data files. All files should now have a blue check indicating selection. \n",
"- Click `Prepare Download`\n",
"- Fill in Title as `HAWC+_example_data`\n",
"- Click `Prepare Download`\n",
"- After a few minutes, the data will be downloaded locally.\n",
"- For more information, consult the [HAWC+ user's manual](https://irsa.ipac.caltech.edu/data/SOFIA/docs/sites/default/files/2022-12/hawc_users_revL.pdf).\n",
"\n",
"#### You can download the example data directly [here](https://zenodo.org/record/6574619/files/hawc-sample-data.zip?download=1)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"SOFIA Data Organization\n",
"-----------------\n",
"\n",
"After downloading the SOFIA data to your working directory you will want to unzip it, which will produce a directory structure like this:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```console\n",
".\n",
"└── HAWC+_example_data\n",
" ├── level4\n",
" │ └── p5813\n",
" │ └── F0484_HA_POL_7600018_HAWCHWPC_PMP_022-114.fits\n",
" └── missions\n",
" ├── 2018-07-05_HA_F481\n",
" │ └── p5827\n",
" │ └── F0481_HA_POL_7600012_HAWDHWPD_PMP_050-083.fits\n",
" ├── 2018-07-07_HA_F483\n",
" │ └── p5646\n",
" │ └── F0483_HA_POL_7600014_HAWCHWPC_PMP_022-065.fits\n",
" ├── 2018-07-11_HA_F484\n",
" │ └── p5648\n",
" │ └── F0484_HA_POL_7600017_HAWCHWPC_PMP_065-114.fits\n",
" └── 2018-07-12_HA_F485\n",
" └── p5658\n",
" ├── g1\n",
" │ └── F0485_HA_POL_76000110_HAWAHWPA_PMP_043-052.fits\n",
" └── g2\n",
" └── F0485_HA_POL_7600019_HAWEHWPE_PMP_055-075.fits\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note the following features of this data bundle.\n",
"\n",
"- Each `fits` file in the 'missions' directory corresponds to data from a single AOR (or a different filter element) obtained on a single flight\n",
"- Each subdirectory under missions corresponds to a single flight\n",
"- `fits` files under 'level4' correspond to data combined from several flights\n",
"- If multiple filters were observed on the same flight, they will be further divided into subdirectories (g1/g2 on the last line)\n",
"\n",
"Note that two observations were made with the same filter (HAWC C, $89\\,\\mathrm{\\mu m}$). These files, `F0483_HA_POL_7600014_HAWCHWPC_PMP_022-065.fits` and `F0484_HA_POL_7600017_HAWCHWPC_PMP_065-114.fits`, were combined into one:\n",
"\n",
"`level4->p5813->F0484_HA_POL_7600018_HAWCHWPC_PMP_022-114.fits`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can choose to keep the `fits` files nested, or copy them into one directory."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For the purpose of this basic analysis, though, let us dump all the files into one `sofia_data` directory:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```console\n",
".\n",
"└── sofia_data\n",
" ├── F0481_HA_POL_7600012_HAWDHWPD_PMP_050-083.fits\n",
" ├── F0483_HA_POL_7600014_HAWCHWPC_PMP_022-065.fits\n",
" ├── F0484_HA_POL_7600017_HAWCHWPC_PMP_065-114.fits\n",
" ├── F0484_HA_POL_7600018_HAWCHWPC_PMP_022-114.fits\n",
" ├── F0485_HA_POL_76000110_HAWAHWPA_PMP_043-052.fits\n",
" └── F0485_HA_POL_7600019_HAWEHWPE_PMP_055-075.fits\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"30 Dor data\n",
"-----------\n",
"\n",
"The Strategic Director's Discretionary Time (S-DDT) for SOFIA is aimed at providing the astronomical community with data sets of high scientific interest over a broadrange of potential research topics without any proprietary period. These observingsessions allow the general user community access to high-level data products that aremeant not only for general understanding of SOFIA data and its packaging but also for inclusion in published scientific work. The S-DDT target have been selected on a non-interference basis with existing programs and in terms of SOFIA flight planning.\n",
"\n",
"The 76_0001 program, \"Community Science: HAWC+ Polarimetry of 30 Dor,\" was designed and scheduled to provide the community with SOFIA polarimetry data of an important and relatively bright source. The observing strategy also provided significantly increased scheduling efficiency for the OC6I (HAWC+) flights in July 2018. The west-bound observing legs for 30 Doradus allowed a larger fraction of the highest ranked Cycle 6 targets, predominantly in the inner Galaxy, to be scheduled and flown.\n",
"\n",
"This cookbook recipe follows the SOFIA press release of 30 Doradus observations: [SOFIA Reveals Never-Before-Seen Magnetic Field Details](https://irsa.ipac.caltech.edu/data/SOFIA/docs/publications/science-results-archive/sofia-reveals-never-seen-magnetic-field-details/index.html). The Level 4 reduced data from this program has been released immediately to the public and is available on the Infrared Science Archive [(IRSA)](https://irsa.ipac.caltech.edu/Missions/sofia.html).\n",
"\n",
"To enhance the scientific exploitation of these data products, we present here an overview of the observations, visualizations of the data, and preliminary analysis of their quality."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Data Structure\n",
"--------------\n",
"\n",
"For this analysis, we require the standard [numpy/scipy/matplotlib stack](https://scipy.org/install.html) as well the [astropy](http://docs.astropy.org/en/stable/) and [aplpy](https://aplpy.readthedocs.io/en/stable/index.html) modules.\n",
"\n",
"With just a few lines of code, we can explore the HAWC+ `fits` data cubes and plot the images."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"execution": {
"iopub.execute_input": "2023-09-21T00:21:11.748617Z",
"iopub.status.busy": "2023-09-21T00:21:11.748395Z",
"iopub.status.idle": "2023-09-21T00:21:11.770788Z",
"shell.execute_reply": "2023-09-21T00:21:11.769905Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Filename: example_data/HAWC/F0485_HA_POL_76000110_HAWAHWPA_PMP_043-052.fits\n",
"No. Name Ver Type Cards Dimensions Format\n",
" 0 STOKES I 1 PrimaryHDU 572 (94, 114) float64 \n",
" 1 ERROR I 1 ImageHDU 27 (94, 114) float64 \n",
" 2 STOKES Q 1 ImageHDU 18 (94, 114) float64 \n",
" 3 ERROR Q 1 ImageHDU 18 (94, 114) float64 \n",
" 4 STOKES U 1 ImageHDU 18 (94, 114) float64 \n",
" 5 ERROR U 1 ImageHDU 18 (94, 114) float64 \n",
" 6 IMAGE MASK 1 ImageHDU 27 (94, 114) float64 \n",
" 7 PERCENT POL 1 ImageHDU 18 (94, 114) float64 \n",
" 8 DEBIASED PERCENT POL 1 ImageHDU 18 (94, 114) float64 \n",
" 9 ERROR PERCENT POL 1 ImageHDU 18 (94, 114) float64 \n",
" 10 POL ANGLE 1 ImageHDU 18 (94, 114) float64 \n",
" 11 ROTATED POL ANGLE 1 ImageHDU 18 (94, 114) float64 \n",
" 12 ERROR POL ANGLE 1 ImageHDU 18 (94, 114) float64 \n",
" 13 POL FLUX 1 ImageHDU 18 (94, 114) float64 \n",
" 14 ERROR POL FLUX 1 ImageHDU 18 (94, 114) float64 \n",
" 15 DEBIASED POL FLUX 1 ImageHDU 18 (94, 114) float64 \n",
" 16 MERGED DATA 1 BinTableHDU 234 8R x 67C [1J, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1E, 1J, 1J, 1E, 1K, 1K, 1J, 1E, 1E, 1J, 1E, 1E, 1E, 1E, 1E, 1E, 1B, 1E, 1E, 1E, 1E, 1E, 1E, 1D, 1D, 1D, 1D, 1D, 1D, 1D, 1D, 1D, 1D, 1D, 1D, 1D, 1D, 1D, 1J, 1D, 1J, 1D, 1D, 1D, 1J, 1J, 1J, 2624E, 2624E, 1E, 1J, 2624E, 2624E, 2624E, 2624E, D, D, D, 49A] \n",
" 17 POL DATA 1 BinTableHDU 34 10716R x 10C [J, J, D, D, D, D, D, D, D, D] \n",
" 18 FINAL POL DATA 1 BinTableHDU 30 84R x 8C [D, D, D, D, D, D, D, D] \n"
]
}
],
"source": [
"path = 'example_data/HAWC/'\n",
"efile = path+'F0485_HA_POL_7600019_HAWEHWPE_PMP_055-075.fits'\n",
"dfile = path+'F0481_HA_POL_7600012_HAWDHWPD_PMP_050-083.fits'\n",
"cfile = path+'F0484_HA_POL_7600018_HAWCHWPC_PMP_022-114.fits'\n",
"\n",
"afile = path+'F0485_HA_POL_76000110_HAWAHWPA_PMP_043-052.fits'\n",
"hawc = fits.open(afile)\n",
"hawc.info()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can see above the data structure of the multi-extension `fits` files. Each file contains 19 extensions which encapsulates all of the measurable Stokes parameters, derived polarization information, and associated errors in a single package.\n",
"