Commit 341ba908 authored by Marcus Wirtz's avatar Marcus Wirtz
Browse files

[simulations] Clarify combined fit minimima default settings. NO PYTHON 2 SUPPORT HERE!

parent c9967b83
Pipeline #340894 passed with stages
in 4 minutes and 51 seconds
...@@ -511,15 +511,15 @@ class SourceBound(BaseSimulation): ...@@ -511,15 +511,15 @@ class SourceBound(BaseSimulation):
self.charge_weights = charges self.charge_weights = charges
elif isinstance(charges, str): elif isinstance(charges, str):
if charges == 'first_minimum': if charges == 'first_minimum_CTG':
self.energy_setting['gamma'], self.energy_setting['log10_cut'] = -0.87, 18.62
self.charge_weights = {'n': 0.88, 'si': 0.12}
elif charges == 'first_minimum_SPG':
self.energy_setting['gamma'], self.energy_setting['log10_cut'] = -0.96, 18.68
self.charge_weights = {'he': 0.673, 'n': 0.281, 'si': 0.046}
elif charges == 'second_minimum':
self.energy_setting['gamma'], self.energy_setting['log10_cut'] = 1.03, 18.21 self.energy_setting['gamma'], self.energy_setting['log10_cut'] = 1.03, 18.21
self.charge_weights = {'h': 0.6794, 'he': 0.31, 'n': 0.01, 'si': 0.0006} self.charge_weights = {'h': 0.6794, 'he': 0.31, 'n': 0.01, 'si': 0.0006}
elif charges == 'second_minimum_CTG':
self.energy_setting['gamma'], self.energy_setting['log10_cut'] = -0.87, 18.62
self.charge_weights = {'n': 0.88, 'si': 0.12}
elif charges == 'first_minimum_CTD':
self.energy_setting['gamma'], self.energy_setting['log10_cut'] = 1.47, 18.15
self.charge_weights = {'h': 0.4494, 'he': 0.52, 'n': 0.03, 'si': 0.0006}
elif charges == 'first_minimum_walz': elif charges == 'first_minimum_walz':
self.energy_setting['gamma'], self.energy_setting['log10_cut'] = -0.62, 18.56 self.energy_setting['gamma'], self.energy_setting['log10_cut'] = -0.62, 18.56
self.charge_weights = {'h': 0.001, 'he': 0.001, 'n': 0.985, 'fe': 0.012} self.charge_weights = {'h': 0.001, 'he': 0.001, 'n': 0.985, 'fe': 0.012}
......
import unittest
import os import os
import sys
import numpy as np import numpy as np
import unittest
from astrotools import coord, gamale, healpytools as hpt from astrotools import coord, gamale, healpytools as hpt
from astrotools.simulations import PATH, ObservedBound, SourceBound from astrotools.simulations import PATH, ObservedBound, SourceBound
...@@ -334,6 +335,7 @@ class TestSourceBound(unittest.TestCase): ...@@ -334,6 +335,7 @@ class TestSourceBound(unittest.TestCase):
dmin = np.min(sim.universe.distances, axis=-1) dmin = np.min(sim.universe.distances, axis=-1)
self.assertTrue((np.median(dmin) > 20)) self.assertTrue((np.median(dmin) > 20))
@unittest.skipIf(sys.version_info < (3, 0), "Simulation libraries work only for python 3.")
def test_03_fluxes(self): def test_03_fluxes(self):
sim = SourceBound(self.nsets, self.ncrs) sim = SourceBound(self.nsets, self.ncrs)
sim.set_energy(gamma=-2, log10e_min=19.6, log10_cut=20.5, rig_cut=False) sim.set_energy(gamma=-2, log10e_min=19.6, log10_cut=20.5, rig_cut=False)
...@@ -402,6 +404,7 @@ class TestSourceBound(unittest.TestCase): ...@@ -402,6 +404,7 @@ class TestSourceBound(unittest.TestCase):
fraction_inside = np.sum(mask_inside_10) / float(sim.ncrs * sim.nsets) fraction_inside = np.sum(mask_inside_10) / float(sim.ncrs * sim.nsets)
self.assertTrue(fraction_inside < 0.2) self.assertTrue(fraction_inside < 0.2)
@unittest.skipIf(sys.version_info < (3, 0), "Simulation libraries work only for python 3.")
def test_04a_shuffle(self): def test_04a_shuffle(self):
sim = SourceBound(self.nsets, self.ncrs) sim = SourceBound(self.nsets, self.ncrs)
sim.set_energy(gamma=-2, log10e_min=19.6) sim.set_energy(gamma=-2, log10e_min=19.6)
...@@ -412,6 +415,7 @@ class TestSourceBound(unittest.TestCase): ...@@ -412,6 +415,7 @@ class TestSourceBound(unittest.TestCase):
src_labels = crs['source_labels'] src_labels = crs['source_labels']
self.assertTrue(np.all(src_labels[sim.signal_label] != -1)) self.assertTrue(np.all(src_labels[sim.signal_label] != -1))
@unittest.skipIf(sys.version_info < (3, 0), "Simulation libraries work only for python 3.")
def test_04b_shuffle(self): def test_04b_shuffle(self):
sim = SourceBound(self.nsets, self.ncrs) sim = SourceBound(self.nsets, self.ncrs)
sim.set_energy(gamma=-2, log10e_min=19.6) sim.set_energy(gamma=-2, log10e_min=19.6)
...@@ -424,12 +428,13 @@ class TestSourceBound(unittest.TestCase): ...@@ -424,12 +428,13 @@ class TestSourceBound(unittest.TestCase):
test2 = np.unique(crs['vecs'] * crs['log10e']) test2 = np.unique(crs['vecs'] * crs['log10e'])
self.assertTrue(np.all(test1 == test2)) self.assertTrue(np.all(test1 == test2))
@unittest.skipIf(sys.version_info < (3, 0), "Simulation libraries work only for python 3.")
def test_05a_first_minimum(self): def test_05a_first_minimum(self):
sim = SourceBound(self.nsets, 1000) sim = SourceBound(self.nsets, 1000)
# sim.set_energy(gamma=-0.96, log10e_min=19.6, log10_cut=18.68, rig_cut=True) # sim.set_energy(gamma=-0.96, log10e_min=19.6, log10_cut=18.68, rig_cut=True)
# sim.set_charges(charges={'he': 0.673, 'n': 0.281, 'si': 0.046}) # sim.set_charges(charges={'he': 0.673, 'n': 0.281, 'si': 0.046})
sim.set_energy(log10e_min=19.6) sim.set_energy(log10e_min=19.6)
sim.set_charges('first_minimum') sim.set_charges('first_minimum_CTG')
sim.set_sources(source_density=1e-3) sim.set_sources(source_density=1e-3)
sim.attenuate() sim.attenuate()
sim.smear_sources(np.deg2rad(3)) sim.smear_sources(np.deg2rad(3))
...@@ -437,12 +442,22 @@ class TestSourceBound(unittest.TestCase): ...@@ -437,12 +442,22 @@ class TestSourceBound(unittest.TestCase):
# sim.plot_spectrum() # sim.plot_spectrum()
# sim.plot_distance() # sim.plot_distance()
sim = SourceBound(self.nsets, 1000)
# sim.set_energy(gamma=-0.96, log10e_min=19.6, log10_cut=18.68, rig_cut=True)
# sim.set_charges(charges={'he': 0.673, 'n': 0.281, 'si': 0.046})
sim.set_energy(log10e_min=19.6)
sim.set_charges('first_minimum_CTD')
sim.set_sources(source_density=1e-3)
sim.attenuate()
sim.smear_sources(np.deg2rad(3))
@unittest.skipIf(sys.version_info < (3, 0), "Simulation libraries work only for python 3.")
def test_05b_second_minimum(self): def test_05b_second_minimum(self):
sim = SourceBound(self.nsets, 1000) sim = SourceBound(self.nsets, 1000)
# sim.set_energy(gamma=-2.04, log10e_min=19.6, log10_cut=19.88, rig_cut=True) # sim.set_energy(gamma=-2.04, log10e_min=19.6, log10_cut=19.88, rig_cut=True)
# sim.set_charges(charges={'n': 0.798, 'si': 0.202}) # sim.set_charges(charges={'n': 0.798, 'si': 0.202})
sim.set_energy(log10e_min=19.6) sim.set_energy(log10e_min=19.6)
sim.set_charges('second_minimum') sim.set_charges('second_minimum_CTG')
sim.set_sources(source_density=1e-3) sim.set_sources(source_density=1e-3)
sim.attenuate() sim.attenuate()
sim.smear_sources(np.deg2rad(3)) sim.smear_sources(np.deg2rad(3))
...@@ -453,6 +468,7 @@ class TestSourceBound(unittest.TestCase): ...@@ -453,6 +468,7 @@ class TestSourceBound(unittest.TestCase):
class TestReweight(unittest.TestCase): class TestReweight(unittest.TestCase):
@unittest.skipIf(sys.version_info < (3, 0), "Simulation libraries work only for python 3.")
def setUp(self): def setUp(self):
self.charge = {'h': 1, 'he': 2, 'n': 7, 'si': 14, 'fe': 26} self.charge = {'h': 1, 'he': 2, 'n': 7, 'si': 14, 'fe': 26}
data = np.load(PATH+'/simulation/crpropa3__emin_18.5__emax_21.0__IRB_Gilmore12.npz', allow_pickle=True) data = np.load(PATH+'/simulation/crpropa3__emin_18.5__emax_21.0__IRB_Gilmore12.npz', allow_pickle=True)
...@@ -460,12 +476,14 @@ class TestReweight(unittest.TestCase): ...@@ -460,12 +476,14 @@ class TestReweight(unittest.TestCase):
self.log10e_bins = data['log10e_bins'] self.log10e_bins = data['log10e_bins']
self.distances = data['distances'] self.distances = data['distances']
@unittest.skipIf(sys.version_info < (3, 0), "Simulation libraries work only for python 3.")
def test_01_dimensions(self): def test_01_dimensions(self):
ne = self.log10e_bins.size - 1 ne = self.log10e_bins.size - 1
nd = self.distances.size nd = self.distances.size
for key in self.charge: for key in self.charge:
self.assertTrue(self.fractions[key].shape == (ne, nd, 5, ne)) self.assertTrue(self.fractions[key].shape == (ne, nd, 5, ne))
@unittest.skipIf(sys.version_info < (3, 0), "Simulation libraries work only for python 3.")
def test_02_no_energy_gain(self): def test_02_no_energy_gain(self):
for key in self.charge: for key in self.charge:
for i, lge in enumerate(self.log10e_bins[:-1]): for i, lge in enumerate(self.log10e_bins[:-1]):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment