# plot_phi_lm.pyΒΆ

plot_phi_lm plots the real and imaginary parts of a given (l, m) mode of one of the $$\Phi_i$$ as measured by a given detector. Here $$\Phi_i$$ are the Newman-Penrose scalars for Maxwell/Proca. They can be computed with the thorn NPScalars_Proca.

#!/usr/bin/env python3
# PYTHON_ARGCOMPLETE_OK

# Copyright (C) 2020-2023 Gabriele Bozzola
#
# This program is free software; you can redistribute it and/or modify it under
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, see <https://www.gnu.org/licenses/>.

import logging

import matplotlib.pyplot as plt

from kuibit import argparse_helper as kah
from kuibit.simdir import SimDir
from kuibit.visualize_matplotlib import (
get_figname,
save_from_dir_filename_ext,
set_axis_limits_from_args,
setup_matplotlib,
)

if __name__ == "__main__":
desc = f"""\
{kah.get_program_name()} plots the multipolar decomposition of one of the Phi
Newman-Penrose constants for Maxwell/Proca as measured by a given detector and
at a given l and m."""

parser = kah.init_argparse(desc)

"--phi-num",
type=int,
choices=[0, 1, 2],
default=1,
help="Why Phi to plot? Phi0, Phi1, or Phi2?",
)

"--detector-num",
"--num-detector",
type=int,
required=True,
help="Number of the spherical surface over which to read Phi.",
)

"--mult-l", type=int, default=0, help="Multipole number l."
)
"--mult-m", type=int, default=0, help="Multipole number m."
)

args = kah.get_args(parser)
setup_matplotlib(rc_par_file=args.mpl_rc_file)

# Parse arguments

logger = logging.getLogger(__name__)

if args.verbose:
logging.basicConfig(format="%(asctime)s - %(message)s")
logger.setLevel(logging.DEBUG)

phi_num = args.phi_num
var_name = f"Phi{phi_num}"

figname = get_figname(
args,
default=f"{var_name}_{args.mult_l}{args.mult_m}_det{args.detector_num}",
)
logger.debug(f"Using figname {figname}")

with SimDir(
pickle_file=args.pickle_file,
) as sim:
logger.debug("Prepared SimDir")

raise ValueError(f"{var_name} not available")

if (args.mult_l, args.mult_m) not in detector.available_lm:
logger.debug(f"Available multipoles {detector.available_lm}")
raise ValueError(
f"Multipole {args.mult_l}, {args.mult_m} not available"
)

phi = detector[args.mult_l, args.mult_m]

logger.debug(f"Plotting {var_name}")

plt.plot(
phi.real(),
label=rf"$\Re \Phi_{phi_num}^{{{args.mult_l}{args.mult_m}}}$",
)
plt.plot(
phi.imag(),
label=rf"$\Im \Phi_{phi_num}^{{{args.mult_l}{args.mult_m}}}$",
)

plt.legend()
plt.xlabel("Time")
plt.ylabel(rf"$r \Phi_{phi_num}$")
set_axis_limits_from_args(args)

f"Det {args.detector_num}", anchor="SW", offset=0.005
)
add_text_to_corner(rf"$r = {radius:.3f}$", anchor="NE", offset=0.005)

logger.debug("Plotted")

logger.debug("Saving")
save_from_dir_filename_ext(
args.outdir,
figname,
args.fig_extension,
tikz_clean_figure=args.tikz_clean_figure,
)
logger.debug("DONE")