{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Options for ionospheric models\n", "\n", "## What are `iono_kwargs`??\n", "\n", "In our top-level functions, we allow generic keyword arguments (`kwargs`) to be passed in and down to our ionospheric models. This will appear as `**iono_kwargs: Any` in a function signature. For example in `get_rm_from_skycoord`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from __future__ import annotations\n", "\n", "import astropy.units as u\n", "import numpy as np\n", "from astropy.coordinates import EarthLocation, SkyCoord\n", "from astropy.time import Time\n", "from spinifex import get_rm\n", "\n", "help(get_rm.get_rm_from_skycoord)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If no options are specified, a set of defaults will be used depending on the model chosen. The available options will also depend on the model. Specifying invalid options will raise an error. For example:" ] }, { "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", "###\n", "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", "\n", "\n", "# Let's intentionally set a bad option to show how the function will fail\n", "try:\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", " bad_option=\"bad_option\",\n", " )\n", "except Exception as e:\n", " print(e)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can inspect the available options using a couple of our helper functions:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pprint import pprint\n", "\n", "from spinifex.ionospheric.models import (\n", " ionospheric_models,\n", " parse_iono_kwargs,\n", " parse_iono_model,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(\"Supported models are: \")\n", "pprint(f\"{list(ionospheric_models.__annotations__.keys())}\")\n", "\n", "for model_name in ionospheric_models.__annotations__:\n", " model = parse_iono_model(model_name)\n", " default_options = parse_iono_kwargs(model)\n", " print(f\"Model {model_name} has default options: \")\n", " pprint(f\"{dict(default_options)}\")" ] } ], "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 }