Skip to content

Commit

Permalink
Added the based config file in py
Browse files Browse the repository at this point in the history
  • Loading branch information
DhruvSondhi committed Jul 22, 2021
1 parent 4e97ed5 commit 1be5704
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tardis/io/logger/montecarlo_tracking.py
Original file line number Diff line number Diff line change
@@ -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,
)
)

0 comments on commit 1be5704

Please sign in to comment.