Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
cigale
CIGALE
Commits
b78e682a
Commit
b78e682a
authored
Sep 06, 2016
by
Yannick Roehlly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a test for the function adjusting data
The test fails so that we can correct the function.
parent
678a4578
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
0 deletions
+66
-0
tests/test_analysis_modules.py
tests/test_analysis_modules.py
+66
-0
No files found.
tests/test_analysis_modules.py
0 → 100644
View file @
b78e682a
# -*- coding: utf-8 -*-
import
numpy
as
np
from
numpy.testing
import
assert_almost_equal
from
pcigale.analysis_modules
import
adjust_data
def
test_adjust_data
():
fluxes
=
np
.
array
([
10.
,
0.
,
-
9999
,
10.
,
10.
,
10.
,
-
10
,
-
10.
,
-
10
])
errors
=
np
.
array
([
0.1
,
0.1
,
0.1
,
-
9999.
,
0
,
-
0.1
,
0.1
,
0.
,
-
0.1
])
adjusted_fluxes
,
adjusted_errors
=
adjust_data
(
fluxes
,
errors
,
tolerance
=
1.e-12
,
lim_flag
=
False
,
default_error
=
0.1
,
systematic_deviation
=
0.1
)
# (10, 0.1) is ok. We just add the systematic deviation.
assert_almost_equal
(
adjusted_fluxes
[
0
],
10.
)
assert_almost_equal
(
adjusted_errors
[
0
],
np
.
sqrt
(
0.1
**
2
+
1
))
# (0., 0.1) is is invalid.
assert
(
np
.
isnan
([
adjusted_fluxes
[
1
],
adjusted_errors
[
1
]]).
all
())
# (-9999, 0.1) is invalid
assert
(
np
.
isnan
([
adjusted_fluxes
[
2
],
adjusted_errors
[
2
]]).
all
())
# (10., -9999.) we use the default error and add the systematic deviation.
assert_almost_equal
(
adjusted_fluxes
[
3
],
10.
)
assert_almost_equal
(
adjusted_errors
[
3
],
np
.
sqrt
(
2
))
# (10., 0.) With error to 0, we use the default error and add the
# systematic deviation.
assert_almost_equal
(
adjusted_fluxes
[
4
],
10.
)
assert_almost_equal
(
adjusted_errors
[
4
],
np
.
sqrt
(
2
))
# (10., -0.1) Negative error is invalid, we use the default error and add
# the systematic deviation.
assert_almost_equal
(
adjusted_fluxes
[
5
],
10.
)
assert_almost_equal
(
adjusted_errors
[
5
],
np
.
sqrt
(
2
))
# With lim_flag set to False, negative fluxes are invalid values
assert
(
np
.
isnan
([
adjusted_fluxes
[
6
],
adjusted_errors
[
6
]]).
all
())
assert
(
np
.
isnan
([
adjusted_fluxes
[
7
],
adjusted_errors
[
7
]]).
all
())
assert
(
np
.
isnan
([
adjusted_fluxes
[
8
],
adjusted_errors
[
8
]]).
all
())
# With lim_flag set to True
adjusted_fluxes
,
adjusted_errors
=
adjust_data
(
fluxes
,
errors
,
tolerance
=
1.e-12
,
lim_flag
=
True
,
default_error
=
0.1
,
systematic_deviation
=
0.1
)
# (-10, 0.1) Upper limit, we add the systematic deviation to the error.
assert_almost_equal
(
adjusted_fluxes
[
6
],
-
10.
)
assert_almost_equal
(
adjusted_errors
[
6
],
np
.
sqrt
(
0.1
**
2
+
1
))
# (-10., 0.) Upper limit, we use the default error and add the systematic
# deviation.
assert_almost_equal
(
adjusted_fluxes
[
7
],
-
10.
)
assert_almost_equal
(
adjusted_errors
[
7
],
np
.
sqrt
(
2
))
# (-10., -9999) Upper limit, we use the default error and add
# the systematic deviation.
assert_almost_equal
(
adjusted_fluxes
[
8
],
-
10.
)
assert_almost_equal
(
adjusted_errors
[
8
],
np
.
sqrt
(
2
))
Write
Preview
Markdown
is supported
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