Skip to content

Commit

Permalink
Quick fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jlazar17 committed Apr 29, 2024
1 parent 1d479bd commit 53af0dd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
45 changes: 36 additions & 9 deletions taurunner/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
from taurunner.particle import Particle
from taurunner.utils.make_track import make_track

from typing import Union

def str_or_float(v: str) -> Union[str, float]:
try:
return float(v)
except ValueError:
return v

def initialize_parser(): # pragma: no cover
r'''
Helper function to parse command-line arguments
Expand Down Expand Up @@ -49,7 +57,8 @@ def initialize_parser(): # pragma: no cover
parser.add_argument(
'-e',
dest='energy',
default='',
type=str_or_float,
required=True,
help='Energy in GeV if numerical value greater than 0 passed.\n\
Sprectral index if numerical value less than or equal to 0 passed.\n\
Else path to CDF to sample from.'
Expand All @@ -71,7 +80,8 @@ def initialize_parser(): # pragma: no cover
parser.add_argument(
'-t',
dest='theta',
default='',
required=True,
type=str_or_float,
help='nadir angle in degrees if numerical value(0 is through the core).\n\
"range" if you want to sample from a range of thetas. Use --th_min and --th_max to specify lims.'
)
Expand Down Expand Up @@ -329,30 +339,47 @@ def run_MC(

# Make an array of injected energies
from taurunner.utils.make_initial_e import make_initial_e
eini = make_initial_e(TR_specs['nevents'], TR_specs['energy'],
e_min=TR_specs['e_min'], e_max=TR_specs['e_max'], rand=rand)
eini = make_initial_e(
TR_specs['nevents'],
TR_specs['energy'],
e_min=TR_specs['e_min'],
e_max=TR_specs['e_max']
)

# Make an array of injected incident angles
from taurunner.utils.make_initial_thetas import make_initial_thetas
if(TR_specs['theta']=='range'):
theta = (TR_specs['th_min'], TR_specs['th_max'])
else:
theta = TR_specs['theta']
thetas = make_initial_thetas(TR_specs['nevents'], theta, rand=rand, track_type=TR_specs['track'])
thetas = make_initial_thetas(
TR_specs['nevents'],
theta,
track_type=TR_specs['track']
)
sorter = np.argsort(thetas)
thetas = thetas[sorter]

xs = CrossSections(getattr(XSModel, TR_specs['xs_model'].upper()))

prop = make_propagator(TR_specs['flavor'] - np.sign(TR_specs["flavor"]), body, TR_specs['xs_model'])
#prop = make_propagator(TR_specs['flavor'] - np.sign(TR_specs["flavor"]), body, TR_specs['xs_model'])
if args.e_cut:
condition = lambda particle: (particle.energy <= args.e_cut*units.GeV and abs(particle.ID) in [12,14,16])
else:
condition = None

result = run_MC(eini, thetas, body, xs, prop, rand=rand,
no_secondaries=TR_specs['no_secondaries'], no_losses=TR_specs['no_losses'],
flavor=TR_specs['flavor'], condition=condition, depth=TR_specs['depth'], track_type=TR_specs['track'])
result = run_MC(
eini,
thetas,
body,
xs,
no_secondaries=TR_specs['no_secondaries'],
no_losses=TR_specs['no_losses'],
flavor=TR_specs['flavor'],
condition=condition,
depth=TR_specs['depth'],
track_type=TR_specs['track']
)

if TR_specs['save']:
if '.npy' not in TR_specs['save']:
Expand Down
4 changes: 2 additions & 2 deletions taurunner/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
from .construct_body import construct_body
from .setup_outdir import setup_outdir
from .sample_powerlaw import sample_powerlaw
from .make_propagator import make_propagator
from .file_lock import FileLock
from .make_initial_thetas import make_initial_thetas
from .make_initial_e import make_initial_e
from .make_initial_e import make_initial_e

0 comments on commit 53af0dd

Please sign in to comment.