{ "cells": [ { "cell_type": "markdown", "id": "4c9b95e3", "metadata": {}, "source": [ "# Isoplane320 Wavelength Calibration Test" ] }, { "cell_type": "markdown", "id": "249f4847", "metadata": {}, "source": [ "Configure the matplotlib backend for high-resolution retina display." ] }, { "cell_type": "markdown", "id": "926413a8", "metadata": {}, "source": [ "Import necessary libraries, including `kspecdr` modules for instrument handling, IO, preprocessing, tramline mapping, extraction, and calibration. Also define the working directory and resource paths." ] }, { "cell_type": "code", "execution_count": 1, "id": "78560f4e", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/hbahk/miniconda3/envs/twodfdr/lib/python3.12/site-packages/rascal/calibrator.py:9: TqdmExperimentalWarning: Using `tqdm.autonotebook.tqdm` in notebook mode. Use `tqdm.tqdm` instead to force console mode (e.g. in jupyter console)\n", " from tqdm.autonotebook import tqdm\n" ] } ], "source": [ "from pathlib import Path\n", "import numpy as np\n", "from astropy.io import fits\n", "from astropy.table import Table\n", "from matplotlib import pyplot as plt\n", "from scipy.signal import find_peaks_cwt, find_peaks\n", "from rascal.util import refine_peaks\n", "from matplotlib.lines import Line2D\n", "from mpl_toolkits.axes_grid1.inset_locator import inset_axes, mark_inset\n", "\n", "from kspecdr.inst.isoplane import convert_isoplane_header, add_fiber_table\n", "from kspecdr.io.image import ImageFile\n", "from kspecdr.preproc.make_im import make_im\n", "from kspecdr.tlm.make_tlm import read_instrument_data, make_tlm\n", "from kspecdr.extract.make_ex import make_ex\n", "from kspecdr.extract.reduce_arc import reduce_arcs\n", "from kspecdr.wavecal.arc_io import read_arc_file\n", "\n", "plt.rcParams[\"figure.dpi\"] = 300\n", "\n", "WD = Path(\"/data1/hbahk/kspec/kspecdr\")\n", "RESOURCES = WD / \"resources\"\n", "TESTDIR = RESOURCES / \"isoplane_arctest_20251224\"" ] }, { "cell_type": "markdown", "id": "662d74fb", "metadata": {}, "source": [ "Load a raw fiber flat field image. Since the raw data from the laboratory might not have the standard headers expected by the pipeline, we convert the header using `convert_isoplane_header`, add a dummy fiber table using `add_fiber_table`, and save the result as a new FITS file suitable for processing." ] }, { "cell_type": "code", "execution_count": 2, "id": "1dc513a6", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Filename: /data1/hbahk/kspec/kspecdr/resources/isoplane_arctest_20251224/flat_150_490_1sec 2025-12-24.fits\n", "No. Name Ver Type Cards Dimensions Format\n", " 0 PRIMARY 1 PrimaryHDU 188 (1340, 1300) uint16 \n", " 1 FIBRES 1 BinTableHDU 13 16R x 2C ['1A', '20A'] \n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "WARNING: TimeDeltaMissingUnitWarning: Numerical value without unit or explicit format passed to TimeDelta, assuming days [astropy.time.core]\n" ] } ], "source": [ "hdul = fits.open(TESTDIR / \"flat_150_490_1sec 2025-12-24.fits\")\n", "hdr = hdul[0].header\n", "# cleaned_hdr = sanitize_header_drop_unparsable(hdr)\n", "new_hdr = convert_isoplane_header(hdr, ndfclass=\"MFFFF\")\n", "\n", "# add fiber table\n", "add_fiber_table(hdul, n_fibers=16)\n", "\n", "# just use the first frame for now\n", "hdul[0].data = hdul[0].data[0]\n", "# make new fits file with new header and fiber table\n", "new_hdr[\"NAXIS\"] = 2\n", "new_hdr.remove(\"NAXIS3\")\n", "hdul[0].header = new_hdr\n", "\n", "new_fpath = TESTDIR / \"flat_150_490_1sec_converted.fits\"\n", "hdul.writeto(new_fpath, overwrite=True)\n", "hdul.info()" ] }, { "cell_type": "markdown", "id": "c7450ea3", "metadata": {}, "source": [ "Inspect the fiber table extension of the converted FITS file to ensure the fiber definitions are correct." ] }, { "cell_type": "code", "execution_count": 3, "id": "3d612eb4", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| TYPE | NAME |
|---|---|
| str1 | str20 |
| P | Fiber 1 |
| P | Fiber 2 |
| P | Fiber 3 |
| P | Fiber 4 |
| P | Fiber 5 |
| P | Fiber 6 |
| P | Fiber 7 |
| P | Fiber 8 |
| P | Fiber 9 |
| P | Fiber 10 |
| P | Fiber 11 |
| P | Fiber 12 |
| P | Fiber 13 |
| P | Fiber 14 |
| P | Fiber 15 |
| P | Fiber 16 |