MCPcopy Index your code
hub / github.com/pydata/xarray / test_curvefit_helpers

Method test_curvefit_helpers

xarray/tests/test_dataarray.py:4910–4943  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

4908 assert "x" not in fit.dims
4909
4910 def test_curvefit_helpers(self) -> None:
4911 def exp_decay(t, n0, tau=1):
4912 return n0 * np.exp(-t / tau)
4913
4914 from xarray.computation.fit import _get_func_args, _initialize_curvefit_params
4915
4916 params, func_args = _get_func_args(exp_decay, [])
4917 assert params == ["n0", "tau"]
4918 param_defaults, bounds_defaults = _initialize_curvefit_params(
4919 params, {"n0": 4}, {"tau": [5, np.inf]}, func_args
4920 )
4921 assert param_defaults == {"n0": 4, "tau": 6}
4922 assert bounds_defaults == {"n0": (-np.inf, np.inf), "tau": (5, np.inf)}
4923
4924 # DataArray as bound
4925 param_defaults, bounds_defaults = _initialize_curvefit_params(
4926 params=params,
4927 p0={"n0": 4},
4928 bounds={"tau": [DataArray([3, 4], coords=[("x", [1, 2])]), np.inf]},
4929 func_args=func_args,
4930 )
4931 assert param_defaults["n0"] == 4
4932 assert (
4933 param_defaults["tau"] == xr.DataArray([4, 5], coords=[("x", [1, 2])])
4934 ).all()
4935 assert bounds_defaults["n0"] == (-np.inf, np.inf)
4936 assert (
4937 bounds_defaults["tau"][0] == DataArray([3, 4], coords=[("x", [1, 2])])
4938 ).all()
4939 assert bounds_defaults["tau"][1] == np.inf
4940
4941 param_names = ["a"]
4942 params, func_args = _get_func_args(np.power, param_names)
4943 assert params == param_names
4944
4945 @requires_scipy
4946 @pytest.mark.parametrize("use_dask", [True, False])

Callers

nothing calls this directly

Calls 4

_get_func_argsFunction · 0.90
DataArrayClass · 0.90
allMethod · 0.45

Tested by

no test coverage detected