Skip to content

Commit 21f3ae6

Browse files
authored
Merge pull request #27 from doronbehar/optional-punpy
Make punpy an optional dependency
2 parents 9d85b95 + c6f9b30 commit 21f3ae6

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

comet_maths/interpolation/interpolation.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import matplotlib.pyplot as plt
1313
import numpy as np
14-
import punpy
1514

1615
import comet_maths as cm
1716

@@ -204,7 +203,7 @@ def interpolate_1d(
204203
:param x: Independent variable quantity x for which we are trying to obtain the measurand y
205204
:param method: interpolation method to be used, defaults to linear
206205
:param unc_methods: interpolation methods to use in the calculation of the model error. Not used for gpr. Defaults to None, in which case a standard list is used for each interpolation method.
207-
:param u_y_i: uncertainties on y_i, defaults to None
206+
:param u_y_i: uncertainties on y_i, defaults to None. Using non-trivial uncertainties requires the punpy module.
208207
:param corr_y_i: error correlation matrix (can be "rand" for random, "syst" for systematic, or a custom 2D error correlation matrix), defaults to None
209208
:param min_scale: minimum bound on the scale parameter in the gaussian process regression. Only used if gpr is selected as method. Defaults to 0.3
210209
: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".
@@ -326,6 +325,7 @@ def interpolate_1d(
326325
y_corr = None
327326

328327
else:
328+
import punpy
329329
prop = punpy.MCPropagation(MCsteps, parallel_cores=1)
330330
intp = Interpolator(
331331
unc_methods=unc_methods, add_model_error=include_model_uncertainties
@@ -485,7 +485,7 @@ def gaussian_process_regression(
485485
:param x_i: Independent variable quantity x (coordinate data of y_i)
486486
:param y_i: measured variable quantity y (data to interpolate)
487487
:param x: Independent variable quantity x for which we are trying to obtain the measurand y
488-
:param u_y_i: uncertainties on y_i, defaults to None
488+
:param u_y_i: uncertainties on y_i, defaults to None. Using non-trivial uncertainties requires the punpy module.
489489
:param corr_y_i: error correlation matrix (can be "rand" for random, "syst" for systematic, or a custom 2D error correlation matrix), defaults to None
490490
:param kernel: kernel to be used in the gpr interpolation. Defaults to "RBF".
491491
:param min_scale: minimum bound on the scale parameter in the gaussian process regression. Defaults to 0.01
@@ -542,6 +542,7 @@ def gaussian_process_regression(
542542
u_y_out = cm.uncertainty_from_covariance(cov_simple)
543543

544544
else:
545+
import punpy
545546
prop = punpy.MCPropagation(MCsteps, parallel_cores=parallel_cores)
546547
intp = Interpolator(
547548
method="gpr",
@@ -661,7 +662,7 @@ def interpolate_1d_along_example(
661662
:param method_hr: String to indicate which interpolation method should be used to interpolate between high resolution measurements. Defaults to cubic spline interpolation.
662663
:param unc_methods: interpolation methods to use in the calculation of the model error for interpolation between normalised data. Not used for gpr. Defaults to None, in which case a standard list is used for each interpolation method.
663664
:param unc_methods_hr: interpolation methods to use in the calculation of the model error for interpolation between high resolution measurements. Not used for gpr. Defaults to None, in which case a standard list is used for each interpolation method.
664-
:param u_y_i: uncertainties on y_i, defaults to None
665+
:param u_y_i: uncertainties on y_i, defaults to None. Using non-trivial uncertainties requires the punpy module.
665666
:param corr_y_i: error correlation matrix for u_y_i (can be "rand" for random, "syst" for systematic, or a custom 2D error correlation matrix), defaults to None
666667
:param u_y_hr: uncertainties on y_hr, defaults to None
667668
:param corr_y_hr: error correlation matrix for u_y_hr (can be "rand" for random, "syst" for systematic, or a custom 2D error correlation matrix), defaults to None
@@ -735,6 +736,7 @@ def interpolate_1d_along_example(
735736
return y_out
736737

737738
else:
739+
import punpy
738740
prop = punpy.MCPropagation(MCsteps, parallel_cores=parallel_cores)
739741
intp = Interpolator(
740742
relative=relative,

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ sphinx_design
1212
ipython
1313
sphinx_autosummary_accessors
1414
sphinx_book_theme
15+
16+
# for interpolations with uncertainties
17+
punpy>=1.0.0

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def read(filename):
3030
"scikit-learn>=1.6.1",
3131
"numdifftools",
3232
"scipy>=1.15.2",
33-
"punpy>=1.0.4",
3433
"matplotlib>=3.10.1",
3534
],
3635
extras_require={
@@ -43,6 +42,9 @@ def read(filename):
4342
"ipython",
4443
"sphinx_autosummary_accessors",
4544
],
45+
"interpolation": [
46+
"punpy>=1.0.4",
47+
],
4648
},
4749
classifiers=[
4850
"Development Status :: 2 - Pre-Alpha",

0 commit comments

Comments
 (0)