{ "cells": [ { "attachments": {}, "cell_type": "markdown", "id": "c48993ec-314c-432a-827e-ff6e35502cb7", "metadata": {}, "source": [ "# Spin-weighted spherical harmonics" ] }, { "cell_type": "code", "execution_count": 1, "id": "122d31c5", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "\n", "import few\n", "\n", "# tune few configuration\n", "cfg_set = few.get_config_setter(reset=True)\n", "cfg_set.enable_backends(\"cpu\") # This tutorial only uses CPU\n", "cfg_set.set_log_level(\"info\")\n", "cfg_set.finalize()" ] }, { "cell_type": "code", "execution_count": 2, "id": "06e4ccab-0329-4cdd-b4b2-bf8154137063", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[ 2.17261840e-17+3.54815511e-01j -1.28533838e-17-2.09911687e-01j\n", " 1.24292687e-16-1.24292687e-16j -2.46692086e-01+2.46692086e-01j]\n" ] } ], "source": [ "from few.utils.ylm import GetYlms\n", "\n", "ylm_gen = GetYlms(assume_positive_m=False)\n", "\n", "ls = np.array([2, 3, 4, 5])\n", "ms = np.array([2, 2, 3, 3])\n", "\n", "# viewing angles\n", "theta = np.pi / 3\n", "phi = np.pi / 4\n", "\n", "print(ylm_gen(ls, ms, theta, phi))" ] }, { "attachments": {}, "cell_type": "markdown", "id": "95fd7bdc-1dc6-45ca-84df-54e04e718b63", "metadata": {}, "source": [ "If we assume positive m, it will return -m entries for all +m. The last 5 below are for -m. The final shape will be twice the initial length and will duplicate m=0 so be careful." ] }, { "cell_type": "code", "execution_count": 3, "id": "4fed355a-2b1b-4218-a5b4-32a30cd6c748", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(2,2): (2.1726183986132197e-17+0.3548155109090852j)\n", "(3,2): (-1.285338378442592e-17-0.20991168708193983j)\n", "(4,3): (1.242926870060164e-16-1.2429268700601641e-16j)\n", "(5,3): (-0.24669208642519014+0.2466920864251902j)\n", "(2,0): (0.2897056515173922+0j)\n", "(2,-2): (2.4140204429035754e-18-0.039423945656564985j)\n", "(3,-2): (-9.997076276775717e-18+0.16326464550817543j)\n", "(4,-3): (-0.12119256904280647-0.12119256904280648j)\n", "(5,-3): (0.235727993695182+0.23572799369518202j)\n", "(2,-0): (0.2897056515173922+0j)\n" ] } ], "source": [ "ylm_gen = GetYlms(assume_positive_m=True)\n", "\n", "ls = np.array([2, 3, 4, 5, 2])\n", "ms = np.array([2, 2, 3, 3, 0])\n", "\n", "# viewing angles\n", "theta = np.pi / 3\n", "phi = np.pi / 4\n", "\n", "ylms = ylm_gen(ls, ms, theta, phi)\n", "\n", "for l, m, ylm in zip(ls, ms, ylms[:5]):\n", " print(\"({},{}):\".format(l, m), ylm)\n", "\n", "for l, m, ylm in zip(ls, ms, ylms[5:]):\n", " print(\"({},-{}):\".format(l, m), ylm)" ] } ], "metadata": { "kernelspec": { "display_name": "few-venv", "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.3" } }, "nbformat": 4, "nbformat_minor": 5 }