{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Smoothing and coordinate transformation\n",
    "\n",
    "Smoothing and coordinate transforms are combined because they are both performed in spherical harmonics space, so we can have a single transform to and from $a_{lm}$.\n",
    "\n",
    "Currently they are implemented as an indepent function `pysm.apply_smoothing_and_coord_transform` which takes an input map and returns another map either smoothed or coordinate-transformed or both.\n",
    "Usually it operates on maps created with `pysm.Sky.get_emission` but it would work even with other inputs."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "nbsphinx": "hidden"
   },
   "outputs": [],
   "source": [
    "import pysm\n",
    "import pysm.units as u\n",
    "import healpy as hp\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sky = pysm.Sky(nside=128, preset_strings=[\"d1\", \"s1\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "map_100GHz = sky.get_emission(100 * u.GHz)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def plot_map(m):\n",
    "    \"\"\"Utility function to plot Mollweide view of a map\"\"\"\n",
    "    hp.mollview(m[0], min=0, max=1e2, title=\"I map\", unit=m.unit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "map_100GHz_smoothed = pysm.apply_smoothing_and_coord_transform(map_100GHz, fwhm=2*u.deg) \n",
    "plot_map(map_100GHz_smoothed)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "map_100GHz_rotated = pysm.apply_smoothing_and_coord_transform(map_100GHz, rot=hp.Rotator(coord=\"GE\")) \n",
    "plot_map(map_100GHz_rotated)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "map_100GHz_smoothed_rotated = pysm.apply_smoothing_and_coord_transform(map_100GHz, rot=hp.Rotator(coord=\"GE\"), fwhm=2*u.deg)\n",
    "plot_map(map_100GHz_smoothed_rotated)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "PySM 3",
   "language": "python",
   "name": "pysm3"
  },
  "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.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
