Skip to content

Commit

Permalink
Do not add NoiseModel to Model-class by default anymore (#678)
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulcollenteur committed Apr 15, 2024
2 parents eedba33 + a7b4223 commit 8ec2944
Show file tree
Hide file tree
Showing 46 changed files with 432 additions and 238 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install wheel twine build
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python3 -m build
python3 -m twine upload --repository pypi dist/*
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
78 changes: 40 additions & 38 deletions doc/benchmarks/armamodel.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion doc/benchmarks/autocorrelation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.10.12"
},
"vscode": {
"interpreter": {
Expand Down
2 changes: 1 addition & 1 deletion doc/benchmarks/check_response_functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.10.12"
},
"vscode": {
"interpreter": {
Expand Down
12 changes: 6 additions & 6 deletions doc/benchmarks/noisemodel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"\n",
"$$\\upsilon(t_i) = r(t_i) - r(t_{i-1}) \\text{e}^{-\\Delta t_i / \\alpha}$$\n",
"\n",
"where $\\upsilon$ is the noise, $\\Delta t_i$ the time step between the residuals ($r$), and $\\alpha$ [days] the AR parameter of the model. The model is named `NoiseModel` and can be found in `noisemodel.py`. This is the default noise model that is added to a Pastas model, but it can also be added manually as follows: `ml.add_noisemodel(ps.NoiseModel())`\n",
"where $\\upsilon$ is the noise, $\\Delta t_i$ the time step between the residuals ($r$), and $\\alpha$ [days] the AR parameter of the model. The model is named `NoiseModel` and can be found in `noisemodel.py`. It can be added to a Pastas model as follows: `ml.add_noisemodel(ps.ArNoiseModel())`\n",
"\n",
"## 2. Generate synthetic head time series"
]
Expand Down Expand Up @@ -169,9 +169,9 @@
"ml = ps.Model(head_noise)\n",
"sm = ps.StressModel(rain, ps.Gamma(), name=\"recharge\", settings=\"prec\")\n",
"ml.add_stressmodel(sm)\n",
"ml.add_noisemodel(ps.NoiseModel())\n",
"ml.add_noisemodel(ps.ArNoiseModel())\n",
"\n",
"ml.solve(tmin=\"1991\", tmax=\"2015-06-29\", noise=True, report=False)\n",
"ml.solve(tmin=\"1991\", tmax=\"2015-06-29\", report=False)\n",
"\n",
"# Plot the results\n",
"axes = ml.plots.results(figsize=(10, 5))\n",
Expand Down Expand Up @@ -295,14 +295,14 @@
"ml = ps.Model(head_irregular)\n",
"sm = ps.StressModel(rain, ps.Gamma(cutoff=0.99), name=\"recharge\", settings=\"prec\")\n",
"ml.add_stressmodel(sm)\n",
"ml.add_noisemodel(ps.NoiseModel())\n",
"ml.add_noisemodel(ps.ArNoiseModel())\n",
"\n",
"# ml.set_parameter(\"noise_alpha\", 9.5, vary=False)\n",
"# ml.set_parameter(\"recharge_A\", 800, vary=False)\n",
"# ml.set_parameter(\"recharge_n\", 1.2, vary=False)\n",
"# ml.set_parameter(\"recharge_a\", 200, vary=False)\n",
"\n",
"ml.solve(tmin=\"1991\", tmax=\"2015-06-29\", noise=True, report=False)\n",
"ml.solve(tmin=\"1991\", tmax=\"2015-06-29\", report=False)\n",
"axes = ml.plots.results(figsize=(10, 5))\n",
"axes[-2].plot(ps.Gamma().step([Atrue, ntrue, atrue]))\n",
"\n",
Expand Down Expand Up @@ -376,7 +376,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.10.12"
},
"vscode": {
"interpreter": {
Expand Down
10 changes: 6 additions & 4 deletions doc/benchmarks/pastas_synthetic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
"ml = ps.Model(head)\n",
"sm = ps.StressModel(rain, ps.Gamma(), name=\"recharge\", settings=\"prec\")\n",
"ml.add_stressmodel(sm)\n",
"ml.solve(noise=False, ftol=1e-8)\n",
"ml.solve(ftol=1e-8)\n",
"ml.plots.results();"
]
},
Expand Down Expand Up @@ -345,9 +345,10 @@
],
"source": [
"ml2 = ps.Model(head_noise)\n",
"ml2.add_noisemodel(ps.ArNoiseModel())\n",
"sm2 = ps.StressModel(rain, ps.Gamma(), name=\"recharge\", settings=\"prec\")\n",
"ml2.add_stressmodel(sm2)\n",
"ml2.solve(noise=True)\n",
"ml2.solve()\n",
"ml2.plots.results();"
]
},
Expand Down Expand Up @@ -465,9 +466,10 @@
],
"source": [
"ml3 = ps.Model(head_noise_corr)\n",
"ml3.add_noisemodel(ps.ArNoiseModel())\n",
"sm3 = ps.StressModel(rain, ps.Gamma(), name=\"recharge\", settings=\"prec\")\n",
"ml3.add_stressmodel(sm3)\n",
"ml3.solve(noise=True)\n",
"ml3.solve()\n",
"ml3.plots.results();"
]
},
Expand Down Expand Up @@ -524,7 +526,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"type": "fontawesome", # Default is fontawesome
}
],
"announcement": "The default behavior for adding and solving with noisemodels has changed from Pastas 1.5. <a href='https://github.com/pastas/pastas/issues/735'>Find more information here</a>",
}

html_context = {
Expand Down
5 changes: 3 additions & 2 deletions doc/examples/adding_rivers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"outputs": [],
"source": [
"ml = ps.Model(oseries.resample(\"D\").mean().dropna(), name=\"River\")\n",
"ml.add_noisemodel(ps.ArNoiseModel())\n",
"\n",
"sm = ps.RechargeModel(rain, evap, rfunc=ps.Exponential(), name=\"recharge\")\n",
"ml.add_stressmodel(sm)\n",
Expand Down Expand Up @@ -103,7 +104,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "pastas_dev",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -117,7 +118,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.15 | packaged by conda-forge | (main, Nov 22 2022, 08:41:22) [MSC v.1929 64 bit (AMD64)]"
"version": "3.10.12"
},
"vscode": {
"interpreter": {
Expand Down
14 changes: 9 additions & 5 deletions doc/examples/adding_trends.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@
"\n",
"# Create a Pastas model\n",
"ml = ps.Model(head)\n",
"ml.add_noisemodel(ps.ArNoiseModel())\n",
"\n",
"# Add a recharge model\n",
"rch = ps.rch.FlexModel()\n",
"rm = ps.RechargeModel(rain, evap, recharge=rch, rfunc=ps.Exponential(), name=\"rch\")\n",
"ml.add_stressmodel(rm)\n",
"\n",
"# Solve and plot the model\n",
"ml.solve(noise=False, tmin=\"1990\", report=False) # Get better initial estimated first\n",
"ml.solve(noise=True, tmin=\"1990\", initial=False, report=False)\n",
"ml.solve(tmin=\"1990\", report=False) # Get better initial estimated first\n",
"ml.add_noisemodel(ps.ArNoiseModel())\n",
"ml.solve(tmin=\"1990\", initial=False, report=False)\n",
"ml.plots.results(figsize=(10, 6));"
]
},
Expand All @@ -76,8 +78,7 @@
"ml.add_stressmodel(tm)\n",
"\n",
"# Solve the model\n",
"ml.solve(noise=False, tmin=\"1990\", report=False) # Get better initial estimated first\n",
"ml.solve(noise=True, tmin=\"1990\", initial=False, report=False)\n",
"ml.solve(tmin=\"1990\", initial=False, report=False)\n",
"ml.plots.results(figsize=(10, 6));"
]
},
Expand All @@ -103,6 +104,7 @@
"h = pd.read_csv(\"data/nb18_head.csv\", index_col=0, parse_dates=True).squeeze()\n",
"\n",
"ml = ps.Model(h.iloc[::10])\n",
"ml.add_noisemodel(ps.ArNoiseModel())\n",
"\n",
"sm = ps.RechargeModel(\n",
" p, e, name=\"recharge\", rfunc=ps.Exponential(), recharge=ps.rch.Linear()\n",
Expand Down Expand Up @@ -191,6 +193,7 @@
"source": [
"# method 1\n",
"ml_before = ps.Model(h.iloc[::10][:\"2012-07-01\"])\n",
"ml_before.add_noisemodel(ps.ArNoiseModel())\n",
"\n",
"sm = ps.RechargeModel(\n",
" p, e, name=\"recharge\", rfunc=ps.Exponential(), recharge=ps.rch.Linear()\n",
Expand All @@ -216,6 +219,7 @@
"source": [
"# method 2\n",
"ml_after = ps.Model(h.iloc[::10][pd.Timestamp(\"2012-07-01\") :])\n",
"ml_after.add_noisemodel(ps.ArNoiseModel())\n",
"\n",
"sm = ps.RechargeModel(\n",
" p, e, name=\"recharge\", rfunc=ps.Exponential(), recharge=ps.rch.Linear()\n",
Expand Down Expand Up @@ -265,7 +269,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
"version": "3.11.3"
}
},
"nbformat": 4,
Expand Down
5 changes: 3 additions & 2 deletions doc/examples/adding_wells.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@
"source": [
"# Create the time series model\n",
"ml = ps.Model(head, name=\"groundwater\")\n",
"ml.add_noisemodel(ps.ArNoiseModel())\n",
"\n",
"# Add the stres model for the net recharge\n",
"rm = ps.RechargeModel(\n",
" rain, evap, name=\"recharge\", rfunc=ps.Exponential(), recharge=ps.rch.Linear()\n",
")\n",
"ml.add_stressmodel(rm)\n",
"ml.solve(noise=True)\n",
"ml.solve()\n",
"ml.plot(figsize=(10, 4))\n",
"\n",
"# Let's store the simulated values to compare later\n",
Expand Down Expand Up @@ -165,7 +166,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
6 changes: 3 additions & 3 deletions doc/examples/basic_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"metadata": {},
"source": [
"### 4. Solve the model\n",
"The next step is to compute the optimal model parameters. The default solver uses a non-linear least squares method for the optimization. The python package `scipy` is used (info on `scipy's` least_squares solver can be found [here](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.least_squares.html)). Some standard optimization statistics are reported along with the optimized parameter values and correlations."
"The next step is to compute the optimal model parameters. The default solver uses a non-linear least squares method for the optimization. The python package `scipy` is used (info on `scipy's` least_squares solver can be found [here](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.least_squares.html)). Some standard optimization statistics are reported along with the optimized parameter values and correlations."
]
},
{
Expand Down Expand Up @@ -248,7 +248,7 @@
},
"anaconda-cloud": {},
"kernelspec": {
"display_name": "pastas_dev",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -262,7 +262,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.15"
"version": "3.10.12"
},
"vscode": {
"interpreter": {
Expand Down
20 changes: 11 additions & 9 deletions doc/examples/calibration_options.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"outputs": [],
"source": [
"ml = ps.Model(head)\n",
"ml.add_noisemodel(ps.ArNoiseModel())\n",
"rch = ps.rch.FlexModel()\n",
"rm = ps.RechargeModel(rain, evap, recharge=rch, rfunc=ps.Gamma(), name=\"rch\")\n",
"ml.add_stressmodel(rm)"
Expand Down Expand Up @@ -142,6 +143,7 @@
"outputs": [],
"source": [
"ml = ps.Model(head)\n",
"ml.add_noisemodel(ps.ArNoiseModel())\n",
"rch = ps.rch.FlexModel()\n",
"rm = ps.RechargeModel(\n",
" rain * 1e3, evap * 1e3, recharge=rch, rfunc=ps.Gamma(), name=\"rch\"\n",
Expand Down Expand Up @@ -172,7 +174,7 @@
"outputs": [],
"source": [
"ml.set_parameter(\"rch_n\", initial=15) # Clearly wrong, just for educational purposes\n",
"ml.solve(noise=True, tmin=\"1986\", tmax=\"2003\", report=True)"
"ml.solve(tmin=\"1986\", tmax=\"2003\", report=True)"
]
},
{
Expand All @@ -190,12 +192,12 @@
"metadata": {},
"outputs": [],
"source": [
"ml.solve(\n",
" noise=False, report=False, tmin=\"1986\", tmax=\"2003\"\n",
") # First solve without noise model\n",
"ml.solve(\n",
" noise=True, initial=False, tmin=\"1986\", tmax=\"2003\", report=True\n",
") # Then solve with noise model, but do not initialize the parameters\n",
"# First solve without noise model\n",
"ml.del_noisemodel()\n",
"ml.solve(report=False, tmin=\"1986\", tmax=\"2003\")\n",
"# Then solve with noise model, but do not initialize the parameters\n",
"ml.add_noisemodel(ps.ArNoiseModel())\n",
"ml.solve(initial=False, tmin=\"1986\", tmax=\"2003\", report=True)\n",
"axes = ml.plots.results(figsize=(10, 6))"
]
},
Expand Down Expand Up @@ -257,7 +259,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "pastas_dev",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -271,7 +273,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.15"
"version": "3.10.12"
},
"vscode": {
"interpreter": {
Expand Down
13 changes: 8 additions & 5 deletions doc/examples/changing_responses.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,18 @@
"source": [
"# Normal Model\n",
"ml = ps.Model(head, name=\"linear\")\n",
"ml.add_noisemodel(ps.ArNoiseModel())\n",
"\n",
"sm = ps.StressModel(river, ps.Exponential(), name=\"test\")\n",
"step = ps.StepModel(\"2012-01-01\", rfunc=ps.One(), name=\"step\")\n",
"\n",
"ml.add_stressmodel([sm, step])\n",
"ml.solve(report=False, tmin=\"2004\", tmax=\"2017-12-31\", noise=True)\n",
"ml.solve(report=False, tmin=\"2004\", tmax=\"2017-12-31\")\n",
"ml.plots.results(figsize=(10, 6))\n",
"\n",
"# ChangeModel\n",
"ml2 = ps.Model(head, name=\"linear\")\n",
"ml2.add_noisemodel(ps.ArNoiseModel())\n",
"\n",
"cm = ps.ChangeModel(\n",
" river,\n",
Expand All @@ -131,7 +133,7 @@
")\n",
"\n",
"ml2.add_stressmodel([cm, step])\n",
"ml2.solve(report=False, tmin=\"2004\", tmax=\"2017-12-31\", noise=True)\n",
"ml2.solve(report=False, tmin=\"2004\", tmax=\"2017-12-31\")\n",
"ml2.plots.results(figsize=(10, 6));"
]
},
Expand Down Expand Up @@ -210,6 +212,7 @@
"outputs": [],
"source": [
"ml3 = ps.Model(head, name=\"linear\")\n",
"ml3.add_noisemodel(ps.ArNoiseModel())\n",
"\n",
"river1 = river.copy()\n",
"river1.loc[\"2012\":] = 0\n",
Expand All @@ -222,7 +225,7 @@
"step = ps.StepModel(\"2012-01-01\", rfunc=ps.One(), name=\"step\")\n",
"\n",
"ml3.add_stressmodel([r1, r2, step])\n",
"ml3.solve(report=False, tmin=\"2004\", tmax=\"2017-12-31\", noise=True)\n",
"ml3.solve(report=False, tmin=\"2004\", tmax=\"2017-12-31\")\n",
"ml3.plots.results(figsize=(10, 6));"
]
},
Expand Down Expand Up @@ -278,7 +281,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "pastas_dev",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -292,7 +295,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.15"
"version": "3.10.12"
},
"vscode": {
"interpreter": {
Expand Down

0 comments on commit 8ec2944

Please sign in to comment.