{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# How to use `get_rm_from_skycoord`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This example script shows how to get ionospheric rotation measures for a give source,\n", "observer location and array of times. This script uses the default ionospheric settings,\n", "which are good for most purposes." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from __future__ import annotations\n", "\n", "import astropy.units as u\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "from astropy.coordinates import EarthLocation, SkyCoord\n", "from astropy.time import Time\n", "from astropy.visualization import quantity_support, time_support\n", "from spinifex import get_rm" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "### Required to load local data for example - not needed for normal use\n", "from importlib import resources\n", "\n", "with resources.as_file(resources.files(\"spinifex.data.tests\")) as datapath:\n", " spinifex_data = datapath\n", "###" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "times = Time(\"2020-01-08T01:00:00\") + np.arange(10) * 25 * u.min\n", "# create source object\n", "source = SkyCoord(ra=350.85 * u.deg, dec=58.815 * u.deg)\n", "# create Earth Location\n", "lon = 6.367 * u.deg\n", "lat = 52.833 * u.deg\n", "dwingeloo = EarthLocation(lon=lon, lat=lat, height=0 * u.km)\n", "# get rotation measures\n", "rm = get_rm.get_rm_from_skycoord(\n", " loc=dwingeloo,\n", " times=times,\n", " source=source,\n", " # We set these options to use the data packaged with spinifex\n", " # Unsetting them will cause the function to download the data from the internet\n", " prefix=\"cod\",\n", " output_directory=spinifex_data,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# print to screen\n", "rotation_measures = rm.rm\n", "rm_times = rm.times\n", "elevations = rm.elevation\n", "azimuths = rm.azimuth\n", "print(\"time RM (rad/lambda^2) azimuth (deg) elevation (deg)\")\n", "for myrm, tm, az, el in zip(rotation_measures, rm_times, azimuths, elevations):\n", " print(f\"{tm.isot} {myrm} {az:3.2f} {el:2.2f}\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "with time_support(), quantity_support():\n", " fig, ax = plt.subplots()\n", " im = ax.errorbar(rm.times.datetime, rm.rm, rm.rm_error, fmt=\".\")\n", " ax.set_ylabel(\"RM / rad/m$^2$\")\n", " plt.xticks(rotation=20)" ] } ], "metadata": { "kernelspec": { "display_name": "spinifex", "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.12.9" } }, "nbformat": 4, "nbformat_minor": 2 }