diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 3f12fa9..43c6583 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -24,7 +24,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install .[dev] + pip install .[dev,interpolation] - name: Analysing the code with pre-commit lint checks run: | pre-commit run -a @@ -43,7 +43,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install .[dev] + pip install .[dev,interpolation] - name: Test code run: | mkdir test_report diff --git a/.github/workflows/push_branch.yml b/.github/workflows/push_branch.yml index 3bb316b..5b0c374 100644 --- a/.github/workflows/push_branch.yml +++ b/.github/workflows/push_branch.yml @@ -21,7 +21,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install .[dev] + pip install .[dev,interpolation] - name: Test code run: | tox diff --git a/comet_maths/_version.py b/comet_maths/_version.py index 382021f..9e604c0 100644 --- a/comet_maths/_version.py +++ b/comet_maths/_version.py @@ -1 +1 @@ -__version__ = "1.0.6" +__version__ = "1.0.7" diff --git a/comet_maths/interpolation/interpolation.py b/comet_maths/interpolation/interpolation.py index cdd50a7..4f94b32 100644 --- a/comet_maths/interpolation/interpolation.py +++ b/comet_maths/interpolation/interpolation.py @@ -11,7 +11,6 @@ import matplotlib.pyplot as plt import numpy as np -import punpy import comet_maths as cm @@ -204,7 +203,7 @@ def interpolate_1d( :param x: Independent variable quantity x for which we are trying to obtain the measurand y :param method: interpolation method to be used, defaults to linear :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. - :param u_y_i: uncertainties on y_i, defaults to None + :param u_y_i: uncertainties on y_i, defaults to None. Using uncertainties requires the punpy module. :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 :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 :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,8 @@ def interpolate_1d( y_corr = None else: + import punpy + prop = punpy.MCPropagation(MCsteps, parallel_cores=1) intp = Interpolator( unc_methods=unc_methods, add_model_error=include_model_uncertainties @@ -485,7 +486,7 @@ def gaussian_process_regression( :param x_i: Independent variable quantity x (coordinate data of y_i) :param y_i: measured variable quantity y (data to interpolate) :param x: Independent variable quantity x for which we are trying to obtain the measurand y - :param u_y_i: uncertainties on y_i, defaults to None + :param u_y_i: uncertainties on y_i, defaults to None. Using non-trivial uncertainties requires the punpy module. :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 :param kernel: kernel to be used in the gpr interpolation. Defaults to "RBF". :param min_scale: minimum bound on the scale parameter in the gaussian process regression. Defaults to 0.01 @@ -542,6 +543,8 @@ def gaussian_process_regression( u_y_out = cm.uncertainty_from_covariance(cov_simple) else: + import punpy + prop = punpy.MCPropagation(MCsteps, parallel_cores=parallel_cores) intp = Interpolator( method="gpr", @@ -661,7 +664,7 @@ def interpolate_1d_along_example( :param method_hr: String to indicate which interpolation method should be used to interpolate between high resolution measurements. Defaults to cubic spline interpolation. :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. :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. - :param u_y_i: uncertainties on y_i, defaults to None + :param u_y_i: uncertainties on y_i, defaults to None. Using uncertainties requires the punpy module. :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 :param u_y_hr: uncertainties on y_hr, defaults to None :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 +738,8 @@ def interpolate_1d_along_example( return y_out else: + import punpy + prop = punpy.MCPropagation(MCsteps, parallel_cores=parallel_cores) intp = Interpolator( relative=relative, diff --git a/requirements.txt b/requirements.txt index 65ab733..fd07b47 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,3 +12,6 @@ sphinx_design ipython sphinx_autosummary_accessors sphinx_book_theme + +# for interpolations with uncertainties +punpy>=1.0.0 diff --git a/setup.py b/setup.py index 46dacf7..dfa511f 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,6 @@ def read(filename): "scikit-learn>=1.6.1", "numdifftools", "scipy>=1.15.2", - "punpy>=1.0.4", "matplotlib>=3.10.1", ], extras_require={ @@ -43,6 +42,9 @@ def read(filename): "ipython", "sphinx_autosummary_accessors", ], + "interpolation": [ + "punpy>=1.0.4", + ], }, classifiers=[ "Development Status :: 2 - Pre-Alpha", diff --git a/tox.ini b/tox.ini index 2aa8cfe..ac0d865 100644 --- a/tox.ini +++ b/tox.ini @@ -7,5 +7,6 @@ passenv = * deps = pytest-html pytest-cov + .[interpolation] commands = pytest --html=test_report/report.html --cov-report html:test_report/cov_report --cov=comet_maths