{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Antenna response to galactic radio emission" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "import sys\n", "from radiocalibrationtoolkit import *" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import matplotlib.animation as animation\n", "from IPython.display import HTML\n", "\n", "%config InlineBackend.print_figure_kwargs = {'bbox_inches':None}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# some global plot settings\n", "plt.rcParams[\"axes.labelweight\"] = \"bold\"\n", "plt.rcParams[\"font.weight\"] = \"bold\"\n", "plt.rcParams['font.size'] = 16\n", "plt.rcParams['legend.fontsize']= 14\n", "\n", "plt.rcParams['xtick.major.width']= 2\n", "plt.rcParams['ytick.major.width']= 2\n", "\n", "plt.rcParams['xtick.major.size']= 5\n", "plt.rcParams['ytick.major.size']= 5\n", "\n", "plt.rcParams['xtick.labelsize']= 14\n", "plt.rcParams['ytick.labelsize']= 14" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# this will be further on constant\n", "frequency_MHz = 45 \n", "LATITUDE = -35.206667" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hw_file_path = './antenna_setup_files/HardwareProfileList_realistic.xml'\n", "hw_dict = read_hw_file(hw_file_path)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hw_dict" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# calculate power received by the antenna\n", "antenna_inst = AntennaPattern(\"./antenna_setup_files/SALLA_EW.xml\")\n", "galactic_map_inst = GlobalSkyModel2016(freq_unit=\"MHz\")\n", "\n", "impedance_func = hw_dict['IImpedance']['antenna_EW']\n", "\n", "lst_range = range(24)\n", "\n", "update_antenna_conventions = {\n", " 'shift_phi': -90,\n", " 'flip_theta': True,\n", " 'flip_phi': False,\n", " 'in_degrees': True,\n", " 'add_invisible_sky': True\n", "}\n", "\n", "power_density_DF = calculate_power_spectral_density(\n", " antenna_inst=antenna_inst,\n", " galactic_map_inst=galactic_map_inst,\n", " lst_range=lst_range,\n", " freq_Mhz_range=[frequency_MHz, frequency_MHz + 1],\n", " latitude=LATITUDE,\n", " update_antenna_conventions=update_antenna_conventions,\n", " impedance_func=impedance_func)\n", "\n", "power_DF = integrate_spectral_density(\n", " power_density_DF, integrated_MHz_bands=power_density_DF.columns.values)\n", "power_DF.iloc[:, :] = power_DF.values * 1e12" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# create figures: antenna gain in gal. coordinates, galactic radio emission, antenna response to galactic emission\n", "\n", "galactic_map = hp.ma(\n", " hp.pixelfunc.ud_grade(galactic_map_inst.generate(frequency_MHz), NSIDE)\n", " ).copy()\n", "image_list = []\n", "\n", "lst_range = range(24)\n", "\n", "for lst in lst_range:\n", " rotation_parameters = create_rotation_parameters(lst, LATITUDE)\n", " rotator = Rotator(coord=['G','C'], rot=rotation_parameters)\n", "\n", " antenna_map_inst = antenna_inst.convert2hp(frequency=frequency_MHz, quantity='absolute', **update_antenna_conventions)\n", " antenna_map = antenna_map_inst.get_map(rotator=rotator)\n", " mask = create_local_mask(NSIDE, rotation_parameters)\n", " # Test\n", " galactic_map.mask = mask\n", " cmap = 'jet'\n", "\n", " projview(\n", " antenna_map**2,\n", " # norm=\"log\",\n", " # coord=[\"G\",'C'],\n", " # rot=False,\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=\"VEL [$m^2$]\",\n", " xlabel=\"RA\",\n", " ylabel=\"DEC\",\n", " cb_orientation=\"vertical\",\n", " min=0,\n", " max=3,\n", " # max=550000,\n", " latitude_grid_spacing=30,\n", " xtick_label_color=\"white\",\n", " title='Antenna gain',\n", " cmap=cmap,\n", " sub=(2, 2, 1),\n", " # projection_type='cart'\n", " )\n", "\n", " projview(\n", " galactic_map,\n", " norm=\"log\",\n", " # coord=[\"G\",'C'],\n", " # rot=False,\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=\"Temperature [K]\",\n", " xlabel=\"RA\",\n", " ylabel=\"DEC\",\n", " cb_orientation=\"vertical\",\n", " min=3500,\n", " max=30000,\n", " # max=550000,\n", " latitude_grid_spacing=30,\n", " xtick_label_color=\"white\",\n", " title='Galactic radio emission',\n", " cmap=cmap,\n", " sub=(2, 2, 2),\n", " # projection_type='cart'\n", " )\n", "\n", " projview(\n", " galactic_map*antenna_map**2,\n", " norm=\"log\",\n", " # coord=[\"G\",'C'],\n", " # rot=False,\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=\"[$m^2$K]\",\n", " xlabel=\"RA\",\n", " ylabel=\"DEC\",\n", " cb_orientation=\"vertical\",\n", " min=3500,\n", " # max=30000,\n", " max=25000,\n", " latitude_grid_spacing=30,\n", " xtick_label_color=\"white\",\n", " title='Antenna response to gal.emission',\n", " cmap=cmap,\n", " sub=(2, 2, 3),\n", " # projection_type='cart'\n", " )\n", "\n", " fig = plt.gcf()\n", " fig.autolayout=False\n", " ax = fig.add_subplot(2,2,4)\n", " ax.plot(power_DF.index.values, power_DF[frequency_MHz].values)\n", " ax.scatter(lst, power_DF.loc[lst, frequency_MHz], color='red', s=75)\n", " ax.set_title('Integrated sky by antenna')\n", " ax.set_xlabel('LST')\n", " ax.set_ylabel('power [pW]')\n", " fig.subplots_adjust(left=0.075, bottom=0.1, wspace=0.35)\n", " plt.close()\n", " image_list.append(fig_to_image(fig))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# animate\n", "\n", "def animate(i):\n", " ax.ravel()[0].imshow(image_list[i], animated=True)\n", " ax.ravel()[0].axis(\"off\")\n", " ax.ravel()[0].set_title(\"\\n frequency: {} MHz LST: {:02d}:00\".format(frequency_MHz, i))\n", "\n", "fig, ax = plt.subplots(figsize=(6, 4.5), dpi=160, squeeze=False)\n", "fig.subplots_adjust(left=0, right=1)\n", "\n", "dynamic_figs = animation.FuncAnimation(\n", " fig, animate, frames=len(image_list), interval=100, repeat_delay=100\n", ")\n", "plt.close()\n", "\n", "# Show the animation\n", "HTML(dynamic_figs.to_html5_video())\n", "\n", "# save\n", "# dynamic_figs.save('dynamic_images.mp4')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# In the local coordinate system" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# create figures: antenna gain in gal. coordinates, galactic radio emission, antenna response to galactic emission\n", "\n", "image_list = []\n", "\n", "antenna_hpmap_inst = antenna_inst.convert2hp(frequency_MHz, **update_antenna_conventions)\n", "antenna_map = antenna_hpmap_inst.get_map()\n", "galactic_map = hp.pixelfunc.ud_grade(galactic_map_inst.generate(frequency_MHz), 64)\n", "\n", "for lst in lst_range:\n", " galactic_map_rotated = rotate_default_hpmap_array_from_galactic2local_coordinates(galactic_map, lst, LATITUDE)\n", " cmap = 'jet'\n", "\n", " projview(\n", " antenna_map**2,\n", " # norm=\"log\",\n", " # coord=[\"G\",'C'],\n", " # rot=False,\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=\"VEL [$m^2$]\",\n", " xlabel=\"azimuth\",\n", " ylabel=\"altitude\",\n", " cb_orientation=\"vertical\",\n", " min=0,\n", " max=3,\n", " # max=550000,\n", " latitude_grid_spacing=30,\n", " xtick_label_color=\"white\",\n", " title='Antenna gain',\n", " cmap=cmap,\n", " sub=(2, 2, 1),\n", " # projection_type='cart'\n", " )\n", "\n", " projview(\n", " galactic_map_rotated,\n", " norm=\"log\",\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=\"Temperature [K]\",\n", " xlabel=\"azimuth\",\n", " ylabel=\"altitude\",\n", " cb_orientation=\"vertical\",\n", " min=3500,\n", " max=30000,\n", " # max=550000,\n", " latitude_grid_spacing=30,\n", " xtick_label_color=\"white\",\n", " title='Galactic radio emission',\n", " cmap=cmap,\n", " sub=(2, 2, 2),\n", " # projection_type='cart'\n", " )\n", "\n", " projview(\n", " galactic_map_rotated*antenna_map**2,\n", " norm=\"log\",\n", " # coord=[\"G\",'C'],\n", " # rot=False,\n", " graticule=True,\n", " graticule_labels=True,\n", " unit=\"[$m^2$K]\",\n", " xlabel=\"azimuth\",\n", " ylabel=\"altitude\",\n", " cb_orientation=\"vertical\",\n", " min=3500,\n", " # max=30000,\n", " max=25000,\n", " latitude_grid_spacing=30,\n", " xtick_label_color=\"white\",\n", " title='Antenna response to gal.emission',\n", " cmap=cmap,\n", " sub=(2, 2, 3),\n", " # projection_type='cart'\n", " )\n", "\n", " fig = plt.gcf()\n", " fig.autolayout=False\n", " ax = fig.add_subplot(2,2,4)\n", " ax.plot(power_DF.index.values, power_DF[frequency_MHz].values)\n", " ax.scatter(lst, power_DF.loc[lst, frequency_MHz], color='red', s=75)\n", " ax.set_title('Integrated sky by antenna')\n", " ax.set_xlabel('LST')\n", " ax.set_ylabel('power [pW]')\n", " fig.subplots_adjust(left=0.075, bottom=0.1, wspace=0.35)\n", " plt.close()\n", " image_list.append(fig_to_image(fig))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# animate\n", "\n", "def animate(i):\n", " ax.ravel()[0].imshow(image_list[i], animated=True)\n", " ax.ravel()[0].axis(\"off\")\n", " ax.ravel()[0].set_title(\"\\n frequency: {} MHz LST: {:02d}:00\".format(frequency_MHz, i))\n", "\n", "fig, ax = plt.subplots(figsize=(6, 4.5), dpi=160, squeeze=False)\n", "fig.subplots_adjust(left=0, right=1)\n", "\n", "dynamic_figs = animation.FuncAnimation(\n", " fig, animate, frames=len(image_list), interval=100, repeat_delay=100\n", ")\n", "plt.close()\n", "\n", "# Show the animation\n", "HTML(dynamic_figs.to_html5_video())\n", "\n", "# save\n", "# dynamic_figs.save('dynamic_images_local.mp4')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.10.6" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false }, "vscode": { "interpreter": { "hash": "e7370f93d1d0cde622a1f8e1c04877d8463912d04d973331ad4851f04de6915a" } } }, "nbformat": 4, "nbformat_minor": 2 }