Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ift
NIFTy
Commits
94d27fd0
Commit
94d27fd0
authored
Jul 14, 2021
by
Philipp Arras
Browse files
Minisanity: Add possibility to disable terminal colors
parent
496cc7c1
Changes
2
Hide whitespace changes
Inline
Side-by-side
ChangeLog.md
View file @
94d27fd0
Changes since NIFTy 7
Changes since NIFTy 7
=====================
=====================
Minisanity
----------
Terminal colors can be disabled in order to make the output of
`ift.extra.minisanity`
more readable when written to a file.
Jax interface
Jax interface
-------------
-------------
...
...
src/extra.py
View file @
94d27fd0
...
@@ -408,7 +408,8 @@ def _jac_vs_finite_differences(op, loc, tol, ntries, only_r_differentiable):
...
@@ -408,7 +408,8 @@ def _jac_vs_finite_differences(op, loc, tol, ntries, only_r_differentiable):
atol
=
tol
**
2
,
rtol
=
tol
**
2
)
atol
=
tol
**
2
,
rtol
=
tol
**
2
)
def
minisanity
(
data
,
metric_at_pos
,
modeldata_operator
,
mean
,
samples
=
None
):
def
minisanity
(
data
,
metric_at_pos
,
modeldata_operator
,
mean
,
samples
=
None
,
terminal_colors
=
True
):
"""Log information about the current fit quality and prior compatibility.
"""Log information about the current fit quality and prior compatibility.
Log a table with fitting information for the likelihood and the prior.
Log a table with fitting information for the likelihood and the prior.
...
@@ -446,6 +447,10 @@ def minisanity(data, metric_at_pos, modeldata_operator, mean, samples=None):
...
@@ -446,6 +447,10 @@ def minisanity(data, metric_at_pos, modeldata_operator, mean, samples=None):
samples : iterable of Field or MultiField, optional
samples : iterable of Field or MultiField, optional
Residual samples around `mean`. Default: no samples.
Residual samples around `mean`. Default: no samples.
terminal_colors : bool, optional
Setting this to false disables terminal colors. This may be useful if
the output of minisanity is written to a file. Default: True
Note
Note
----
----
For computing the reduced chi^2 values and the normalized residuals, the
For computing the reduced chi^2 values and the normalized residuals, the
...
@@ -459,6 +464,7 @@ def minisanity(data, metric_at_pos, modeldata_operator, mean, samples=None):
...
@@ -459,6 +464,7 @@ def minisanity(data, metric_at_pos, modeldata_operator, mean, samples=None):
and
is_fieldlike
(
mean
)
and
is_fieldlike
(
mean
)
):
):
raise
TypeError
raise
TypeError
colors
=
bool
(
terminal_colors
)
keylen
=
18
keylen
=
18
for
dom
in
[
data
.
domain
,
mean
.
domain
]:
for
dom
in
[
data
.
domain
,
mean
.
domain
]:
if
isinstance
(
dom
,
MultiDomain
):
if
isinstance
(
dom
,
MultiDomain
):
...
@@ -486,8 +492,8 @@ def minisanity(data, metric_at_pos, modeldata_operator, mean, samples=None):
...
@@ -486,8 +492,8 @@ def minisanity(data, metric_at_pos, modeldata_operator, mean, samples=None):
xscmean
[
aa
][
kk
].
add
(
np
.
nanmean
(
rr
[
kk
].
val
))
xscmean
[
aa
][
kk
].
add
(
np
.
nanmean
(
rr
[
kk
].
val
))
xndof
[
aa
][
kk
]
=
rr
[
kk
].
size
-
np
.
sum
(
np
.
isnan
(
rr
[
kk
].
val
))
xndof
[
aa
][
kk
]
=
rr
[
kk
].
size
-
np
.
sum
(
np
.
isnan
(
rr
[
kk
].
val
))
s0
=
_tableentries
(
xredchisq
[
0
],
xscmean
[
0
],
xndof
[
0
],
keylen
)
s0
=
_tableentries
(
xredchisq
[
0
],
xscmean
[
0
],
xndof
[
0
],
keylen
,
colors
)
s1
=
_tableentries
(
xredchisq
[
1
],
xscmean
[
1
],
xndof
[
1
],
keylen
)
s1
=
_tableentries
(
xredchisq
[
1
],
xscmean
[
1
],
xndof
[
1
],
keylen
,
colors
)
f
=
logger
.
info
f
=
logger
.
info
n
=
38
+
keylen
n
=
38
+
keylen
...
@@ -504,14 +510,14 @@ def minisanity(data, metric_at_pos, modeldata_operator, mean, samples=None):
...
@@ -504,14 +510,14 @@ def minisanity(data, metric_at_pos, modeldata_operator, mean, samples=None):
f
(
n
*
"="
)
f
(
n
*
"="
)
class
_bcolors
:
def
_tableentries
(
redchisq
,
scmean
,
ndof
,
keylen
,
colors
):
WARNING
=
"
\033
[33m"
FAIL
=
"
\033
[31m"
ENDC
=
"
\033
[0m"
BOLD
=
"
\033
[1m"
class
_bcolors
:
WARNING
=
"
\033
[33m"
if
colors
else
""
FAIL
=
"
\033
[31m"
if
colors
else
""
ENDC
=
"
\033
[0m"
if
colors
else
""
BOLD
=
"
\033
[1m"
if
colors
else
""
def
_tableentries
(
redchisq
,
scmean
,
ndof
,
keylen
):
out
=
""
out
=
""
for
kk
in
redchisq
.
keys
():
for
kk
in
redchisq
.
keys
():
if
len
(
kk
)
>
keylen
:
if
len
(
kk
)
>
keylen
:
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment