Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
astro
astrotools
Commits
c636fbb2
Commit
c636fbb2
authored
Dec 05, 2019
by
Marcus Wirtz
Browse files
[simulations] Fix python2 unittest
parent
a1f8c2bd
Changes
2
Hide whitespace changes
Inline
Side-by-side
astrotools/simulations.py
View file @
c636fbb2
...
...
@@ -501,18 +501,14 @@ class SourceBound(BaseSimulation):
elif
isinstance
(
charges
,
str
):
if
charges
==
'first_minimum'
:
gamma
,
log10_cut
=
0.96
,
18.68
charges
=
{
'h'
:
0.
,
'he'
:
0.673
,
'n'
:
0.281
,
'si'
:
0.046
,
'fe'
:
0.
}
self
.
energy_setting
[
'gamma'
],
self
.
energy_setting
[
'
log10_cut
'
]
=
-
0.96
,
18.68
self
.
charge
_weight
s
=
{
'h'
:
0.
,
'he'
:
0.673
,
'n'
:
0.281
,
'si'
:
0.046
,
'fe'
:
0.
}
elif
charges
==
'second_minimum'
:
gamma
,
log10_cut
=
2.04
,
19.88
charges
=
{
'h'
:
0.
,
'he'
:
0.
,
'n'
:
0.798
,
'si'
:
0.202
,
'fe'
:
0.
}
self
.
energy_setting
[
'gamma'
],
self
.
energy_setting
[
'
log10_cut
'
]
=
-
2.04
,
19.88
self
.
charge
_weight
s
=
{
'h'
:
0.
,
'he'
:
0.
,
'n'
:
0.798
,
'si'
:
0.202
,
'fe'
:
0.
}
else
:
raise
Exception
(
'Charge keyword not understood (first_minimum/second_minimum)'
)
self
.
energy_setting
[
'gamma'
]
=
gamma
self
.
energy_setting
[
'log10_cut'
]
=
log10_cut
self
.
energy_setting
[
'rig_cut'
]
=
True
self
.
charge_weights
=
charges
else
:
raise
Exception
(
'Charge type not understood (dictionary or string)'
)
...
...
test/test_simulations.py
View file @
c636fbb2
...
...
@@ -64,10 +64,10 @@ class TestObservedBound(unittest.TestCase):
sim4
=
ObservedBound
(
self
.
nside
,
self
.
nsets
,
self
.
ncrs
)
sim4
.
set_charges
({
'h'
:
0.5
,
'he'
:
0.25
,
'n'
:
0.24
,
'si'
:
0.01
})
self
.
assertTrue
(
np
.
abs
(
np
.
sum
(
sim4
.
crs
[
'charge'
]
==
1
)
/
(
self
.
nsets
*
self
.
ncrs
)
-
0.5
)
<
0.02
)
self
.
assertTrue
(
np
.
abs
(
np
.
sum
(
sim4
.
crs
[
'charge'
]
==
2
)
/
(
self
.
nsets
*
self
.
ncrs
)
-
0.25
)
<
0.02
)
self
.
assertTrue
(
np
.
abs
(
np
.
sum
(
sim4
.
crs
[
'charge'
]
==
7
)
/
(
self
.
nsets
*
self
.
ncrs
)
-
0.25
)
<
0.02
)
self
.
assertTrue
(
np
.
abs
(
np
.
sum
(
sim4
.
crs
[
'charge'
]
==
14
)
/
(
self
.
nsets
*
self
.
ncrs
)
-
0.01
)
<
0.01
)
self
.
assertTrue
(
np
.
abs
(
np
.
sum
(
sim4
.
crs
[
'charge'
]
==
1
)
/
float
(
self
.
nsets
*
self
.
ncrs
)
-
0.5
)
<
0.02
)
self
.
assertTrue
(
np
.
abs
(
np
.
sum
(
sim4
.
crs
[
'charge'
]
==
2
)
/
float
(
self
.
nsets
*
self
.
ncrs
)
-
0.25
)
<
0.02
)
self
.
assertTrue
(
np
.
abs
(
np
.
sum
(
sim4
.
crs
[
'charge'
]
==
7
)
/
float
(
self
.
nsets
*
self
.
ncrs
)
-
0.25
)
<
0.02
)
self
.
assertTrue
(
np
.
abs
(
np
.
sum
(
sim4
.
crs
[
'charge'
]
==
14
)
/
float
(
self
.
nsets
*
self
.
ncrs
)
-
0.01
)
<
0.01
)
def
test_05_set_n_random_sources
(
self
):
n
=
5
...
...
@@ -425,8 +425,8 @@ class TestSourceBound(unittest.TestCase):
def
test_05a_first_minimum
(
self
):
sim
=
SourceBound
(
self
.
nsets
,
1000
)
# sim.set_energy(gamma=-0.96, log10e_min=19.6, log10_cut=18.6
6
, rig_cut=True)
# sim.set_charges(charges={
'h': 0.125,
'he': 0.
586
, 'n': 0.2
46
, 'si': 0.04
3
})
# sim.set_energy(gamma=-0.96, log10e_min=19.6, log10_cut=18.6
8
, rig_cut=True)
# sim.set_charges(charges={'he': 0.
673
, 'n': 0.2
81
, 'si': 0.04
6
})
sim
.
set_energy
(
log10e_min
=
19.6
)
sim
.
set_charges
(
'first_minimum'
)
sim
.
set_sources
(
source_density
=
1e-3
)
...
...
@@ -438,10 +438,10 @@ class TestSourceBound(unittest.TestCase):
def
test_05b_second_minimum
(
self
):
sim
=
SourceBound
(
self
.
nsets
,
1000
)
# sim.set_energy(gamma=-2.04, log10e_min=19.6, log10_cut=19.
9
, rig_cut=True)
# sim.set_charges(charges={'n': 0.8, 'si': 0.2})
# sim.set_energy(gamma=-2.04, log10e_min=19.6, log10_cut=19.
88
, rig_cut=True)
# sim.set_charges(charges={'n': 0.
79
8, 'si': 0.2
02
})
sim
.
set_energy
(
log10e_min
=
19.6
)
sim
.
set_charges
(
'
first
_minimum'
)
sim
.
set_charges
(
'
second
_minimum'
)
sim
.
set_sources
(
source_density
=
1e-3
)
sim
.
attenuate
()
sim
.
smear_sources
(
np
.
deg2rad
(
3
))
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment