From 1be57046c1e6792c57240a7438e0fa9da8958353 Mon Sep 17 00:00:00 2001 From: Dhruv Sondhi Date: Thu, 22 Jul 2021 20:35:37 +0530 Subject: [PATCH] Added the based config file in py --- tardis/io/logger/montecarlo_tracking.py | 66 +++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 tardis/io/logger/montecarlo_tracking.py diff --git a/tardis/io/logger/montecarlo_tracking.py b/tardis/io/logger/montecarlo_tracking.py new file mode 100644 index 00000000000..2d0c08014ad --- /dev/null +++ b/tardis/io/logger/montecarlo_tracking.py @@ -0,0 +1,66 @@ +import logging + +from numba import objmode +from numba.core import dispatcher + +from tardis.montecarlo import ( + montecarlo_configuration as montecarlo_configuration, +) + +logger = logging.getLogger("tardis_montecarlo") +logger.setLevel(logging.DEBUG) + +# if montecarlo_configuration.packet_tracking: +# logging.basicConfig( +# filename="montecarlolog.log", +# filemode="w", +# level=logger.getEffectiveLevel(), +# ) + +file_handler = logging.FileHandler("montecarlo_packet_properties.csv", mode="w") +# file_rotator = logging.handlers.RotatingFileHandler( +# "montecarlo_log.log", maxBytes=2000, backupCount=10 +# ) +logger.addHandler(file_handler) +# logger.addHandler(file_rotator) +logger.info( + "seed, index, status, nu, mu, r, energy, current_shell, interaction, distance" +) + + +def montecarlo_tracker(r_packet, distance, last_run): + if last_run: + if ( + montecarlo_configuration.packet_seed + and r_packet.seed == montecarlo_configuration.packet_seed + ): + if ( + len(montecarlo_configuration.packet_indices) != 0 + and r_packet.index in montecarlo_configuration.packet_indices + ): + packet_tracking(r_packet, distance) + else: + packet_tracking(r_packet, distance) + + elif ( + len(montecarlo_configuration.packet_indices) != 0 + and r_packet.index in montecarlo_configuration.packet_indices + ): + packet_tracking(r_packet, distance) + + +def packet_tracking(r_packet, distance): + logger.info( + "{seed}, {index}, {status}, {nu:.3g}, {mu:.3g}, {r:.3g}, {energy:.3g}, {current_shell}, {interaction:.3g}, {distance:.3g}".format( + status=r_packet.status, + nu=r_packet.nu, + mu=r_packet.mu, + r=r_packet.r, + index=r_packet.index, + energy=r_packet.energy, + current_shell=r_packet.current_shell_id, + seed=r_packet.seed, + interaction=r_packet.last_interaction_type, + distance=distance, + ) + )