Skip to content

Commit 9d85b95

Browse files
authored
Merge pull request #26 from comet-toolkit/v1.0.2
V1.0.2
2 parents f71d103 + a51e852 commit 9d85b95

File tree

15 files changed

+163
-74
lines changed

15 files changed

+163
-74
lines changed

.github/workflows/pull_request.yml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,6 @@ jobs:
2929
run: |
3030
pre-commit run -a
3131
32-
test_code_python3p8:
33-
runs-on: ubuntu-latest
34-
strategy:
35-
matrix:
36-
python-version: ["3.8"]
37-
steps:
38-
- uses: actions/checkout@v4
39-
- name: Set up Python ${{ matrix.python-version }}
40-
uses: actions/setup-python@v3
41-
with:
42-
python-version: ${{ matrix.python-version }}
43-
- name: Install dependencies
44-
run: |
45-
python -m pip install --upgrade pip
46-
pip install .[dev]
47-
- name: Test code
48-
run: |
49-
mkdir test_report
50-
tox
51-
52-
5332
test_code_and_coverage_report_python3p11:
5433
runs-on: ubuntu-latest
5534
strategy:

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ coverage.xml
5757
*.cover
5858
.hypothesis/
5959
.pytest_cache/
60-
60+
test_report/
6161
# Translations
6262
*.mo
6363
*.pot

.gitlab-ci.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Default image, if not specified
2-
image: "python:3.8"
2+
image: "python:3.11"
33

44
stages:
55
- Static Analysis
@@ -98,23 +98,15 @@ mypy:
9898
junit: cov_report.xml
9999
expire_in: 1 hour
100100

101-
tox-3.10:
102-
extends: ".tox"
103-
stage: "Test"
104-
image: "python:3.6"
105-
rules:
106-
- if: '$CI_COMMIT_TAG'
107-
when: always
108-
109101
tox-3.11:
110102
extends: ".tox"
111103
stage: "Test"
112104
image: "python:3.11"
113105

114-
tox-3.8:
106+
tox-3.9:
115107
extends: ".tox"
116108
stage: "Test"
117-
image: "python:3.8"
109+
image: "python:3.9"
118110
rules:
119111
- if: '$CI_COMMIT_TAG'
120112
when: always

comet_maths/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.0"
1+
__version__ = "1.0.6"

comet_maths/generate_sample/generate_sample.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,10 @@ def generate_sample_same(MCsteps, param, dtype=None):
212212
:return: generated sample
213213
:rtype: array
214214
"""
215-
tileshape = generate_sample_shape(MCsteps, param)
216-
MC_sample = np.tile(param, tileshape).astype(dtype)
215+
# tileshape = generate_sample_shape(MCsteps, param)
216+
MC_sample = np.repeat(np.array(param)[np.newaxis], MCsteps, axis=0)
217+
if dtype is not None:
218+
MC_sample = MC_sample.astype(dtype)
217219
return MC_sample
218220

219221

@@ -696,33 +698,39 @@ def correlate_sample_corr(
696698
"comet_math.correlate_sample_corr: it is not yet possible to provide a sample with inhomogeneous dimensions."
697699
)
698700

699-
try:
700-
L = np.array(np.linalg.cholesky(corr))
701-
except:
702-
L = cm.nearestPD_cholesky(corr, corr=True)
703-
704-
if maintain_sample_unmodified:
705-
sample_out = copy.deepcopy(sample)
706-
else:
707-
sample_out = sample
708-
709701
if iterate_sample:
710702
sample_out_iter = np.empty(len(sample), dtype=object)
711703
for i in range(len(sample)):
712-
sample_i = np.roll(sample_out, i, axis=0)
704+
sample_i = np.roll(sample, i, axis=0)
713705
if mean is not None:
714706
mean_i = np.roll(mean, i, axis=0)
715707
if std is not None:
716708
std_i = np.roll(std, i, axis=0)
717709
sample_out_iter[i] = np.roll(
718710
correlate_sample_corr(
719-
sample_i, corr, mean_i, std_i, dtype=dtype, iterate_sample=False
711+
sample_i,
712+
corr,
713+
mean_i,
714+
std_i,
715+
dtype=dtype,
716+
iterate_sample=False,
717+
maintain_sample_unmodified=True,
720718
),
721719
-i,
722720
axis=0,
723721
)
724722
return np.mean(sample_out_iter, axis=0)
725723

724+
try:
725+
L = np.array(np.linalg.cholesky(corr))
726+
except:
727+
L = cm.nearestPD_cholesky(corr, corr=True)
728+
729+
if maintain_sample_unmodified:
730+
sample_out = copy.deepcopy(sample)
731+
else:
732+
sample_out = sample
733+
726734
if mean is None:
727735
mean = np.array(
728736
[np.mean(sample[i], axis=0) for i in range(len(sample))],

comet_maths/generate_sample/tests/test_generate_sample.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def test_generate_sample_same(self):
112112
sample = generate_sample_same(100, x0)
113113
npt.assert_equal(sample.shape, (100,))
114114
npt.assert_equal(sample[:-1], sample[1:])
115+
assert sample.dtype == int
115116

116117
sample = generate_sample_same(100, x1)
117118
npt.assert_equal(sample.shape, (100, 20))
@@ -121,7 +122,13 @@ def test_generate_sample_same(self):
121122
npt.assert_equal(sample.shape, (100, 5, 6))
122123
npt.assert_equal(sample[:-1], sample[1:])
123124

125+
sample = generate_sample_same(100, "test")
126+
npt.assert_equal(sample.shape, (100,))
127+
npt.assert_equal(sample[:-1], sample[1:])
128+
assert sample.dtype.type is np.str_
129+
124130
def test_generate_sample_systematic(self):
131+
np.random.seed(123456)
125132
sample = generate_sample_systematic(1000, x0, u_x0)
126133
npt.assert_equal(sample.shape, (1000,))
127134
npt.assert_allclose(u_x0, np.std(sample, axis=0), rtol=0.1)

comet_maths/interpolation/interpolation.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def interpolate_1d(
190190
return_corr: Optional[bool] = False,
191191
include_model_uncertainties: Optional[bool] = True,
192192
add_model_error: Optional[bool] = False,
193-
MCsteps: Optional[int] = 100,
193+
MCsteps: Optional[int] = 50,
194194
parallel_cores: Optional[int] = 4,
195195
interpolate_axis: Optional[int] = 0,
196196
) -> Union[
@@ -402,14 +402,26 @@ def _redo_extrapolation(
402402
:param extrapolate: extrapolation method, which can be set to "extrapolate" (in which case extrapolation is used using interpolation method defined in "method"), "nearest" (in which case nearest values are used for extrapolation), or "linear" (in which case linear extrapolation is used). Defaults to "extrapolate".
403403
:return: interpolated values with correct extrapolation
404404
"""
405-
if extrapolate == "nearest":
406-
y[x < x_i[0]] = y_i[0]
407-
y[x > x_i[-1]] = y_i[-1]
405+
if hasattr(x, "__len__") and len(x) > 1:
406+
if extrapolate == "nearest":
407+
y[x < x_i[0]] = y_i[0]
408+
y[x > x_i[-1]] = y_i[-1]
409+
410+
elif extrapolate == "linear":
411+
f_lin = interp1d(x_i, y_i, kind="linear", fill_value="extrapolate")
412+
y[x < x_i[0]] = f_lin(x[x < x_i[0]])
413+
y[x > x_i[-1]] = f_lin(x[x > x_i[-1]])
414+
else:
415+
if extrapolate == "nearest":
416+
if x < x_i[0]:
417+
y = y_i[0]
418+
elif x > x_i[-1]:
419+
y = y_i[-1]
408420

409-
elif extrapolate == "linear":
410-
f_lin = interp1d(x_i, y_i, kind="linear", fill_value="extrapolate")
411-
y[x < x_i[0]] = f_lin(x[x < x_i[0]])
412-
y[x > x_i[-1]] = f_lin(x[x > x_i[-1]])
421+
elif extrapolate == "linear":
422+
if x < x_i[0] or x > x_i[-1]:
423+
f_lin = interp1d(x_i, y_i, kind="linear", fill_value="extrapolate")
424+
y = f_lin(x)
413425

414426
return y
415427

@@ -628,7 +640,7 @@ def interpolate_1d_along_example(
628640
include_model_uncertainties: Optional[bool] = True,
629641
add_model_error: Optional[bool] = False,
630642
plot_residuals: Optional[bool] = False,
631-
MCsteps: Optional[int] = 100,
643+
MCsteps: Optional[int] = 50,
632644
parallel_cores: Optional[int] = 4,
633645
) -> Union[
634646
np.ndarray, Tuple[np.ndarray, np.ndarray], Tuple[np.ndarray, np.ndarray, np.ndarray]

comet_maths/interpolation/tests/test_interpolation.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,33 @@ def test_interpolation_1d(self):
145145
fig2.colorbar(p2)
146146
fig2.savefig("interpolation_test_1d_corrs.png", bbox_inches="tight")
147147

148+
def test_interpolation_1d(self):
149+
xi = np.arange(0, 3.0, 0.2)
150+
yi = function1(xi)
151+
u_yi = 0.05 * np.abs(yi)
152+
# yi = cm.generate_sample(1, yi, u_yi, corr_x="rand")
153+
154+
x = np.array([0.33333, 0.666666, 1, 1.33333, 1.66666, 2.00, 2.3333])
155+
# t1=time.time()
156+
y = cm.interpolate_1d(xi, yi, x, method="cubic")
157+
y2 = cm.interpolate_1d(xi, yi, x, method="quadratic")
158+
159+
y, u_y, corr_y = cm.interpolate_1d(
160+
xi,
161+
yi,
162+
x,
163+
u_y_i=u_yi,
164+
corr_y_i="syst",
165+
method="linear",
166+
return_uncertainties=True,
167+
return_corr=True,
168+
MCsteps=20000,
169+
include_model_uncertainties=False,
170+
)
171+
172+
print(u_y / y)
173+
print(u_y, u_yi)
174+
148175
def test_interpolation_1d_along_example(self):
149176
np.random.seed(1234567)
150177
xi = np.arange(0, 3.0, 0.2)
@@ -296,7 +323,7 @@ def test_interpolation_1d_along_example_unc(self):
296323

297324
# npt.assert_allclose(y_hr_gpr,y_hr_gpr2,atol=0.01)
298325

299-
mcprop = punpy.MCPropagation(100, parallel_cores=4)
326+
mcprop = punpy.MCPropagation(50, parallel_cores=1)
300327

301328
inp2 = cm.Interpolator(
302329
relative=False,

quality_documentation/QualityDocumentation.tex

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,14 @@ \section{Test report}\label{testreport}
110110
\clearpage
111111
}
112112

113-
\part*{User Manual}
114-
\phantomsection
115-
\addcontentsline{toc}{part}{User Manual}
116-
\appendix
117-
\label{UserManual}
118-
\def\maketitle{}
119-
\def\tableofcontents{}
120-
\input{./latex/user_manual.tex}
113+
%\part*{User Manual}
114+
%\usepackage{./latex/sphinxmanual}
115+
%\phantomsection
116+
%\addcontentsline{toc}{part}{User Manual}
117+
%\appendix
118+
%\label{UserManual}
119+
%\def\maketitle{}
120+
%\def\tableofcontents{}
121+
%\input{./latex/user_manual.tex}
121122

122123
\end{document}

quality_documentation/base/CookiecutterMacros.tex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
\verbdef\authorname{Pieter De Vis}
55
\verbdef\authoremail{[email protected]}
66
\newcommand{\packagedescription}{Mathematical algorithms and tools to use within CoMet toolkit.}
7-
\newcommand{\sil}{sil3}
7+
\newcommand{\sil}{sil3}
8+
\newcommand{\sphinxAtStartPar}{\hspace{0}}

0 commit comments

Comments
 (0)