{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Channel Properties - Exploring XRT Instrument Configuration"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We will explore the X-Ray Telescope (XRT) instrument properties using XRTpy's `Channel` object. The Channel object provides convenient methods and attributes to access and analyze various aspects of the XRT instrument configuration.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import the xrtpy package\n",
    "import xrtpy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[xrtpy- X-Ray Filter Channel]: https://xrtpy.readthedocs.io/en/latest/getting_started.html\n",
    "\n",
    "Begin by defining a filter channel by its common abbreviation. In this example we will be exploring the titanium-on-polyimide filter. For detailed information about various filter channels and their characteristics, you can refer to the [xrtpy- X-Ray Filter Channel] section."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define the filter channel abbreviation\n",
    "Filter = \"Ti-poly\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To further explore the properties and characteristics of the defined filter channel, we will create a Channel object using `xrtpy.response.Channel`. By inserting the `Filter` variable as an input to the `xrtpy.response.Channel` object, we can conveniently work with the properties associated with the titanium-on-polyimide filter."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "channel = xrtpy.response.Channel(Filter)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now that we have created our `channel` object, we can delve into the X-Ray Telescope (XRT) instrument and its properties. We will start by examining basic information about the XRT instrument."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Display relevant information about the selected filter, observatory, and instrument\n",
    "print(\"Selected filter:\", channel.name)\n",
    "print(\"\\nObservatory:\", channel.observatory)\n",
    "print(\"Instrument:\", channel.instrument)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### **Note: Instrument Properties**\n",
    "###### It is important to note that most instrument properties of the X-Ray Telescope (XRT) remain the same regardless of the specific filter being used. This means that many characteristics and specifications of the XRT instrument, such as its dimensions, field of view, and detector properties, are independent of the selected filter."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Contents\n",
    "\n",
    "1. [Charge-Coupled Device](#Charge-Coupled-Device-(CCD))\n",
    "2. [Entrance Filter](#Entrance-Filter) \n",
    "3. [Focus-Filter](#Focus-Filter)\n",
    "4. [Geometry](#Geometry)\n",
    "5. [Mirror 1 and 2](#Mirror)\n",
    "6. [Instrument Plotting](#Instrument-Plotting)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Charge-Coupled-Device (CCD)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `channel.ccd` object reviews properties associated with the Charge-Coupled-Device (CCD) camera of the X-Ray Telescope (XRT) instrument.\n",
    "\n",
    "We can explore various characteristics of the CCD camera, such as its quantum_efficiency and pixel size to list a few."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(channel.ccd.ccd_name)\n",
    "\n",
    "print(\"\\nPixel size: \", channel.ccd.ccd_pixel_size)\n",
    "\n",
    "print(\"Full well: \", channel.ccd.ccd_full_well)\n",
    "print(\"Gain left: \", channel.ccd.ccd_gain_left)\n",
    "print(\"Gain right: \", channel.ccd.ccd_gain_right)\n",
    "print(\"eV pre electron: \", channel.ccd.ccd_energy_per_electron)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Entrance Filter"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can explore the XRT entrance filter properties utilizing `channel.entrancefilter` object. \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(channel.entrancefilter.entrancefilter_name)\n",
    "print(\"Material: \", channel.entrancefilter.entrancefilter_material)\n",
    "print(\"Thickness: \", channel.entrancefilter.entrancefilter_thickness)\n",
    "print(\"Density: \", channel.entrancefilter.entrancefilter_density)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Focus-Filter"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "[X-Ray Filter Channel]: https://xrtpy.readthedocs.io/en/latest\n",
    "\n",
    "The XRT data is recorded through nine X-ray filters, which are implemented using two filter wheels. By utilizing the `channel.filter_#` notation, where `#` represents filter wheel 1 or 2, we can explore detailed information about the selected XRT channel filter.\n",
    "\n",
    "We are exploring the titanium-on-polyimide filter located in filter wheel 2, we will be utilizing the `channel.filter_2` object. This enables us to gather specific information about the properties and characteristics of this particular filter.\n",
    "\n",
    "It's worth noting that exploring the other filter will yield the result \"Open,\" as it's not use. For more comprehensive information about the XRT filters, you can refer to the [X-Ray Filter Channel] documentation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(\"Filter Wheel:\", channel.filter_2.filter_name)\n",
    "print(\"\\nFilter material:\", channel.filter_2.filter_material)\n",
    "print(\"Thickness: \", channel.filter_2.filter_thickness)\n",
    "print(\"Density: \", channel.filter_2.filter_density)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Geometry"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can explore geometry factors in the XRT using `channel.geometry`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(channel.geometry.geometry_name)\n",
    "print(\"\\nFocal length:\", channel.geometry.geometry_focal_len)\n",
    "print(\"Aperture Area:\", channel.geometry.geometry_aperture_area)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Mirror"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The XRT is equipped with two mirrors, each having a unique configuration. We can access the properties of these mirrors using the `channel_mirror_#` notation, where `#` represents the first or second mirror surface. In this example, we will explore several XRT properties related to mirror 1 using the `channel_mirror_1` object. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(channel.mirror_1.mirror_name)\n",
    "print(\"Material: \", channel.mirror_1.mirror_material)\n",
    "print(\"Density: \", channel.mirror_1.mirror_density)\n",
    "print(\"Graze_angle: \", channel.mirror_1.mirror_graze_angle)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Instrument Plotting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Plotting XRT properties - Transmittance"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Define the XRT transmission in `channel` by referencing transmission."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "transmission = channel.transmission"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Define the XRT wavelength in `channel` by referencing wavelength."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "wavelength = channel.wavelength"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Create a plotting function that plots the `transmission` versus `wavelength`. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def plot_transmission():\n",
    "    import matplotlib.pyplot as plt\n",
    "\n",
    "    plt.figure(figsize=(10, 6))\n",
    "\n",
    "    plt.plot(wavelength, transmission, label=f\"{channel.name}\")\n",
    "\n",
    "    plt.title(\"X-Ray Telescope\", fontsize=15)\n",
    "    plt.xlabel(r\"$\\lambda$ [Å]\", fontsize=15)\n",
    "    plt.ylabel(r\"Transmittance\", fontsize=15)\n",
    "    plt.legend(fontsize=20)\n",
    "    plt.xlim(-5, 80)\n",
    "    plt.xticks(fontsize=15)\n",
    "    plt.yticks(fontsize=15)\n",
    "\n",
    "    plt.grid(color=\"lightgrey\")\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Run `plot_transmission` function to create the plot."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot_transmission()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
