Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
PeakOTron
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
UHHDetLab
SiPM
PeakOTron
Commits
38abbbcd
Commit
38abbbcd
authored
2 years ago
by
Jack Christopher Hutchinson Rolph
Browse files
Options
Downloads
Patches
Plain Diff
Delete HelperFunctions.py
parent
e4ba6b13
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
HelperFunctions.py
+0
-154
0 additions, 154 deletions
HelperFunctions.py
with
0 additions
and
154 deletions
HelperFunctions.py
deleted
100644 → 0
+
0
−
154
View file @
e4ba6b13
from
itertools
import
chain
from
iminuit
import
Minuit
from
numba
import
njit
from
iminuit.util
import
describe
from
scipy.interpolate
import
interp1d
import
numpy
as
np
from
scipy.stats
import
skew
as
sc_skew
import
matplotlib.pyplot
as
plt
#HELPER FUNCTIONS
class
FakeFuncCode
:
def
__init__
(
self
,
f
,
prmt
=
None
,
dock
=
0
,
append
=
None
):
#f can either be tuple or function object
self
.
co_varnames
=
describe
(
f
)
self
.
co_argcount
=
len
(
self
.
co_varnames
)
self
.
co_argcount
-=
dock
self
.
co_varnames
=
self
.
co_varnames
[
dock
:]
if
prmt
is
not
None
:
#rename parameters from the front
for
i
,
p
in
enumerate
(
prmt
):
self
.
co_varnames
[
i
]
=
p
if
isinstance
(
append
,
str
):
append
=
[
append
]
if
append
is
not
None
:
old_count
=
self
.
co_argcount
self
.
co_argcount
+=
len
(
append
)
self
.
co_varnames
=
tuple
(
list
(
self
.
co_varnames
[:
old_count
])
+
append
+
list
(
self
.
co_varnames
[
old_count
:]))
def
LatexFormat
(
value
,
scirange
=
[
0.01
,
1000
]):
if
(
np
.
abs
(
value
)
>
scirange
[
0
]
and
np
.
abs
(
value
)
<
scirange
[
1
]):
float_str
=
r
"
${:3.3f}$
"
.
format
(
value
)
else
:
try
:
float_str
=
"
{:3.3E}
"
.
format
(
value
)
base
,
exponent
=
float_str
.
split
(
"
E
"
)
float_str
=
r
"
${0} \times 10^{{{1}}}$
"
.
format
(
base
,
int
(
exponent
))
except
:
float_str
=
str
(
value
)
return
float_str
@njit
def
SelectRangeNumba
(
array
,
low_lim
,
hi_lim
):
index
=
(
array
>=
low_lim
)
&
(
array
<=
hi_lim
)
return
array
[
index
]
def
EmpiricalPPF
(
data
):
x
=
np
.
sort
(
data
)
n
=
x
.
size
y
=
np
.
arange
(
1
,
n
+
1
)
/
n
ppf
=
interp1d
(
y
,
x
,
fill_value
=
"
extrapolate
"
)
return
ppf
def
EmpiricalCDF
(
data
):
x
=
np
.
sort
(
data
)
n
=
x
.
size
y
=
np
.
arange
(
1
,
n
+
1
)
/
n
ppf
=
interp1d
(
x
,
y
,
fill_value
=
"
extrapolate
"
)
return
ppf
def
Logify
(
y
):
log_y
=
np
.
log
(
y
)
min_log_y
=
np
.
min
(
log_y
[
y
>
0
])
return
np
.
where
(
y
>
0
,
log_y
,
min_log_y
)
def
Linear
(
x
,
m
,
c
):
return
m
*
x
+
c
def
GetStats
(
data
):
return
np
.
mean
(
data
),
np
.
std
(
data
),
sc_skew
(
data
)
def
GP_lbda
(
mu
,
sigma
,
gamma
):
lbda
=
0.5
*
(((
mu
*
gamma
)
/
(
sigma
))
-
1
)
return
lbda
def
GP_gain
(
mu
,
sigma
,
gamma
):
lbda
=
GP_lbda
(
mu
,
sigma
,
gamma
)
gain
=
(
sigma
**
2
/
mu
)
*
((
1
-
lbda
)
**
2
)
return
gain
def
GP_muGP
(
mu
,
sigma
,
gamma
):
lbda
=
GP_lbda
(
mu
,
sigma
,
gamma
)
mu_gp
=
(
1
/
(
1
-
lbda
))
*
(
mu
**
2
/
sigma
**
2
)
return
mu_gp
def
FormatExponent
(
ax
,
axis
=
'
y
'
):
# Change the ticklabel format to scientific format
ax
.
ticklabel_format
(
axis
=
axis
,
style
=
'
sci
'
,
scilimits
=
(
-
2
,
2
))
# Get the appropriate axis
if
axis
==
'
y
'
:
ax_axis
=
ax
.
yaxis
x_pos
=
0.0
y_pos
=
1.0
horizontalalignment
=
'
left
'
verticalalignment
=
'
bottom
'
else
:
ax_axis
=
ax
.
xaxis
x_pos
=
1.0
y_pos
=
-
0.05
horizontalalignment
=
'
right
'
verticalalignment
=
'
top
'
# Run plt.tight_layout() because otherwise the offset text doesn't update
plt
.
tight_layout
()
##### THIS IS A BUG
##### Well, at least it's sub-optimal because you might not
##### want to use tight_layout(). If anyone has a better way of
##### ensuring the offset text is updated appropriately
##### please comment!
# Get the offset value
offset
=
ax_axis
.
get_offset_text
().
get_text
()
if
len
(
offset
)
>
0
:
# Get that exponent value and change it into latex format
minus_sign
=
u
'
\u2212
'
expo
=
np
.
float
(
offset
.
replace
(
minus_sign
,
'
-
'
).
split
(
'
e
'
)[
-
1
])
offset_text
=
r
'
x$\mathregular{10^{%d}}$
'
%
expo
# Turn off the offset text that's calculated automatically
ax_axis
.
offsetText
.
set_visible
(
False
)
# Add in a text box at the top of the y axis
ax
.
text
(
x_pos
,
y_pos
,
offset_text
,
transform
=
ax
.
transAxes
,
horizontalalignment
=
horizontalalignment
,
verticalalignment
=
verticalalignment
)
return
ax
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment