From c27a1ba0e73564a4b3c37b9a0b0f208c0224cc81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Thu, 1 Aug 2024 19:16:32 +0200 Subject: [PATCH] apply black+isort; add imports and docs --- examples/01_call_theis.py | 1 + examples/02_call_ext_theis2d.py | 9 ++-- examples/03_call_ext_theis3d.py | 9 ++-- examples/04_call_ext_theis_tpl.py | 9 ++-- examples/05_call_neuman2004.py | 9 ++-- examples/06_compare_extthiem2d_grfsteady.py | 1 + examples/07_compare_extthiem3d_grfsteady.py | 1 + examples/08_compare_extthiem2d_neuman.py | 1 + examples/09_compare_exttheis2d_neuman.py | 5 +- examples/10_convergence_ext_theis_tpl.py | 5 +- examples/11_convergence_ext_grf.py | 5 +- examples/12_compare_theis_quasi_steady.py | 9 ++-- examples/13_self_defined_transmissivity.py | 5 +- examples/14_interval_theis.py | 1 + examples/15_accruing_theis.py | 1 + pyproject.toml | 2 - src/anaflow/__init__.py | 21 ++++++--- src/anaflow/flow/__init__.py | 13 ++++++ src/anaflow/flow/ext_grf_model.py | 5 +- src/anaflow/flow/heterogeneous.py | 51 ++++++--------------- src/anaflow/flow/homogeneous.py | 1 + src/anaflow/flow/laplace.py | 5 +- src/anaflow/tools/__init__.py | 5 +- src/anaflow/tools/coarse_graining.py | 13 +++--- src/anaflow/tools/laplace.py | 19 ++------ src/anaflow/tools/mean.py | 9 ++-- src/anaflow/tools/special.py | 26 +++-------- tests/test_anaflow.py | 24 +++------- 28 files changed, 107 insertions(+), 158 deletions(-) diff --git a/examples/01_call_theis.py b/examples/01_call_theis.py index d7281dc..6bc4a3c 100644 --- a/examples/01_call_theis.py +++ b/examples/01_call_theis.py @@ -7,6 +7,7 @@ Reference: `Theis 1935 `__ """ + import numpy as np from matplotlib import pyplot as plt diff --git a/examples/02_call_ext_theis2d.py b/examples/02_call_ext_theis2d.py index c37490d..769de8b 100644 --- a/examples/02_call_ext_theis2d.py +++ b/examples/02_call_ext_theis2d.py @@ -12,6 +12,7 @@ Reference: `Zech et. al. 2016 `__ """ + import numpy as np from matplotlib import pyplot as plt @@ -51,12 +52,8 @@ label_TG = "Theis($T_G$)" if i == 0 else None label_TH = "Theis($T_H$)" if i == 0 else None label_ef = "extended Theis" if i == 0 else None - plt.plot( - rad, head_TG[i], label=label_TG, color="C" + str(i), linestyle="--" - ) - plt.plot( - rad, head_TH[i], label=label_TH, color="C" + str(i), linestyle=":" - ) + plt.plot(rad, head_TG[i], label=label_TG, color="C" + str(i), linestyle="--") + plt.plot(rad, head_TH[i], label=label_TH, color="C" + str(i), linestyle=":") plt.plot(rad, head_ef[i], label=label_ef, color="C" + str(i)) time_ticks.append(head_ef[i][-1]) diff --git a/examples/03_call_ext_theis3d.py b/examples/03_call_ext_theis3d.py index 19d56bc..af91897 100644 --- a/examples/03_call_ext_theis3d.py +++ b/examples/03_call_ext_theis3d.py @@ -14,6 +14,7 @@ Reference: `Müller 2015 `__ """ + import numpy as np from matplotlib import pyplot as plt @@ -59,12 +60,8 @@ label_TG = "Theis($K_{efu}$)" if i == 0 else None label_TH = "Theis($K_H$)" if i == 0 else None label_ef = "extended Theis 3D" if i == 0 else None - plt.plot( - rad, head_Kefu[i], label=label_TG, color="C" + str(i), linestyle="--" - ) - plt.plot( - rad, head_KH[i], label=label_TH, color="C" + str(i), linestyle=":" - ) + plt.plot(rad, head_Kefu[i], label=label_TG, color="C" + str(i), linestyle="--") + plt.plot(rad, head_KH[i], label=label_TH, color="C" + str(i), linestyle=":") plt.plot(rad, head_ef[i], label=label_ef, color="C" + str(i)) time_ticks.append(head_ef[i][-1]) diff --git a/examples/04_call_ext_theis_tpl.py b/examples/04_call_ext_theis_tpl.py index 82271b0..e234d8a 100755 --- a/examples/04_call_ext_theis_tpl.py +++ b/examples/04_call_ext_theis_tpl.py @@ -13,6 +13,7 @@ Reference: (not yet published) """ + import numpy as np from matplotlib import pyplot as plt @@ -62,12 +63,8 @@ label_TG = "Theis($K_G$)" if i == 0 else None label_TH = "Theis($K_H$)" if i == 0 else None label_ef = "extended Theis TPL 2D" if i == 0 else None - plt.plot( - rad, head_KG[i], label=label_TG, color="C" + str(i), linestyle="--" - ) - plt.plot( - rad, head_KH[i], label=label_TH, color="C" + str(i), linestyle=":" - ) + plt.plot(rad, head_KG[i], label=label_TG, color="C" + str(i), linestyle="--") + plt.plot(rad, head_KH[i], label=label_TH, color="C" + str(i), linestyle=":") plt.plot(rad, head_ef[i], label=label_ef, color="C" + str(i)) time_ticks.append(head_ef[i][-1]) diff --git a/examples/05_call_neuman2004.py b/examples/05_call_neuman2004.py index c35c6cb..02c7de7 100755 --- a/examples/05_call_neuman2004.py +++ b/examples/05_call_neuman2004.py @@ -14,6 +14,7 @@ Reference: `Neuman 2004 `__ """ + import numpy as np from matplotlib import pyplot as plt @@ -61,12 +62,8 @@ label_TG = "Theis($T_G$)" if i == 0 else None label_TH = "Theis($T_H$)" if i == 0 else None label_ef = "transient Neuman [2004]" if i == 0 else None - plt.plot( - rad, head_TG[i], label=label_TG, color="C" + str(i), linestyle="--" - ) - plt.plot( - rad, head_TH[i], label=label_TH, color="C" + str(i), linestyle=":" - ) + plt.plot(rad, head_TG[i], label=label_TG, color="C" + str(i), linestyle="--") + plt.plot(rad, head_TH[i], label=label_TH, color="C" + str(i), linestyle=":") plt.plot(rad, head_ef[i], label=label_ef, color="C" + str(i)) time_ticks.append(head_ef[i][-1]) diff --git a/examples/06_compare_extthiem2d_grfsteady.py b/examples/06_compare_extthiem2d_grfsteady.py index 2540e81..1edae14 100755 --- a/examples/06_compare_extthiem2d_grfsteady.py +++ b/examples/06_compare_extthiem2d_grfsteady.py @@ -11,6 +11,7 @@ - `Schneider & Attinger 2008 `__ - `Zech & Attinger 2016 `__ """ + import numpy as np from matplotlib import pyplot as plt diff --git a/examples/07_compare_extthiem3d_grfsteady.py b/examples/07_compare_extthiem3d_grfsteady.py index 208c273..aa3b4e0 100755 --- a/examples/07_compare_extthiem3d_grfsteady.py +++ b/examples/07_compare_extthiem3d_grfsteady.py @@ -8,6 +8,7 @@ Reference: `Zech et. al. 2012 `__ """ + import numpy as np from matplotlib import pyplot as plt diff --git a/examples/08_compare_extthiem2d_neuman.py b/examples/08_compare_extthiem2d_neuman.py index 4e442c8..67c8da7 100755 --- a/examples/08_compare_extthiem2d_neuman.py +++ b/examples/08_compare_extthiem2d_neuman.py @@ -13,6 +13,7 @@ - `Neuman 2004 `__ - `Zech & Attinger 2016 `__ """ + import numpy as np from matplotlib import pyplot as plt diff --git a/examples/09_compare_exttheis2d_neuman.py b/examples/09_compare_exttheis2d_neuman.py index 25fbd4e..5a14750 100755 --- a/examples/09_compare_exttheis2d_neuman.py +++ b/examples/09_compare_exttheis2d_neuman.py @@ -13,6 +13,7 @@ - `Neuman 2004 `__ - `Zech et. al. 2016 `__ """ + import numpy as np from matplotlib import pyplot as plt @@ -40,9 +41,7 @@ plt.plot(rad, head2[i], label=label2, color="C" + str(i), linestyle="--") time_ticks.append(head1[i][-1]) -plt.title( - "$T_G={}$, $\sigma^2={}$, $\ell={}$, $S={}$".format(TG, var, len_scale, S) -) +plt.title("$T_G={}$, $\sigma^2={}$, $\ell={}$, $S={}$".format(TG, var, len_scale, S)) plt.xlabel("r in [m]") plt.ylabel("h in [m]") plt.legend() diff --git a/examples/10_convergence_ext_theis_tpl.py b/examples/10_convergence_ext_theis_tpl.py index dee18fd..25138fe 100755 --- a/examples/10_convergence_ext_theis_tpl.py +++ b/examples/10_convergence_ext_theis_tpl.py @@ -7,6 +7,7 @@ Reference: (not yet published) """ + import numpy as np from matplotlib import pyplot as plt @@ -25,9 +26,7 @@ S = 1e-4 # storativity rate = -1e-4 # pumping rate -head1 = ext_thiem_tpl( - rad, r_ref, KG, len_scale, hurst, var, dim=dim, rate=rate -) +head1 = ext_thiem_tpl(rad, r_ref, KG, len_scale, hurst, var, dim=dim, rate=rate) head2 = ext_theis_tpl( time, rad, S, KG, len_scale, hurst, var, dim=dim, rate=rate, r_bound=r_ref ) diff --git a/examples/11_convergence_ext_grf.py b/examples/11_convergence_ext_grf.py index 518aed7..ad20f4e 100755 --- a/examples/11_convergence_ext_grf.py +++ b/examples/11_convergence_ext_grf.py @@ -9,6 +9,7 @@ Reference: `Barker 1988 `__ """ + import numpy as np from matplotlib import pyplot as plt @@ -30,9 +31,7 @@ plt.plot(rad, head1, label="Ext GRF steady") plt.plot(rad, head2, label="Ext GRF (t={})".format(time), linestyle="--") -plt.plot( - rad, head3, label="GRF quasi-steady (t={})".format(time), linestyle=":" -) +plt.plot(rad, head3, label="GRF quasi-steady (t={})".format(time), linestyle=":") plt.xlabel("r in [m]") plt.ylabel("h in [m]") diff --git a/examples/12_compare_theis_quasi_steady.py b/examples/12_compare_theis_quasi_steady.py index ea89012..81cf687 100755 --- a/examples/12_compare_theis_quasi_steady.py +++ b/examples/12_compare_theis_quasi_steady.py @@ -5,6 +5,7 @@ The quasi steady is reached, when the radial shape of the drawdown in not changing anymore. """ + import numpy as np from matplotlib import pyplot as plt @@ -21,12 +22,8 @@ transmissivity=1e-4, rate=-1e-4, ) -head1 = ( - theis(time, rad, storage=1e-3, transmissivity=1e-4, rate=-1e-4) - head_ref -) -head2 = theis( - time, rad, storage=1e-3, transmissivity=1e-4, rate=-1e-4, r_bound=r_ref -) +head1 = theis(time, rad, storage=1e-3, transmissivity=1e-4, rate=-1e-4) - head_ref +head2 = theis(time, rad, storage=1e-3, transmissivity=1e-4, rate=-1e-4, r_bound=r_ref) head3 = thiem(rad, r_ref, transmissivity=1e-4, rate=-1e-4) for i, step in enumerate(time): diff --git a/examples/13_self_defined_transmissivity.py b/examples/13_self_defined_transmissivity.py index 72fe491..71899c0 100755 --- a/examples/13_self_defined_transmissivity.py +++ b/examples/13_self_defined_transmissivity.py @@ -15,6 +15,7 @@ Reference: (not yet published) """ + import matplotlib.gridspec as gridspec import numpy as np from matplotlib import pyplot as plt @@ -78,9 +79,7 @@ def cond(rad, K_far, K_well, len_scale): rad_lin = np.linspace(rad[0], rad[-1], 1000) ax1.plot(rad_lin, step_f(rad_lin, R_part, K_part), label="step Conductivity") -ax1.plot( - rad_lin, cond(rad_lin, K_far, K_well, len_scale), label="Conductivity" -) +ax1.plot(rad_lin, cond(rad_lin, K_far, K_well, len_scale), label="Conductivity") ax1.set_yticks([K_well, K_far]) ax1.set_ylabel(r"$K$ in $[\frac{m}{s}]$") plt.setp(ax1.get_xticklabels(), visible=False) diff --git a/examples/14_interval_theis.py b/examples/14_interval_theis.py index ad9be56..084765d 100755 --- a/examples/14_interval_theis.py +++ b/examples/14_interval_theis.py @@ -8,6 +8,7 @@ Unfortunatly the Stehfest algorithm is not suitable for this kind of solution, which is demonstrated in the following script. """ + import numpy as np from matplotlib import pyplot as plt diff --git a/examples/15_accruing_theis.py b/examples/15_accruing_theis.py index 523d041..d285d20 100755 --- a/examples/15_accruing_theis.py +++ b/examples/15_accruing_theis.py @@ -7,6 +7,7 @@ This could be interpreted as that the water pump needs a certain time to reach its constant rate state. """ + import matplotlib.gridspec as gridspec import numpy as np from matplotlib import pyplot as plt diff --git a/pyproject.toml b/pyproject.toml index cb46f56..09a9d75 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -79,11 +79,9 @@ fallback_version = "0.0.0.dev0" [tool.isort] profile = "black" multi_line_output = 3 -line_length = 79 [tool.black] exclude = "_version.py" -line-length = 79 target-version = ["py37"] [tool.coverage] diff --git a/src/anaflow/__init__.py b/src/anaflow/__init__.py index 3f22418..e8ca78b 100644 --- a/src/anaflow/__init__.py +++ b/src/anaflow/__init__.py @@ -39,10 +39,14 @@ ext_thiem_3d ext_thiem_tpl ext_thiem_tpl_3d + ext_thiem_int + ext_thiem_int_3d ext_theis_2d ext_theis_3d ext_theis_tpl ext_thiem_tpl_3d + ext_theis_int + ext_thiem_int_3d neuman2004 neuman2004_steady @@ -78,15 +82,20 @@ specialrange specialrange_cut """ + from anaflow.flow import ( ext_grf, ext_grf_steady, ext_theis_2d, ext_theis_3d, + ext_theis_int, + ext_theis_int_3d, ext_theis_tpl, ext_theis_tpl_3d, ext_thiem_2d, ext_thiem_3d, + ext_thiem_int, + ext_thiem_int_3d, ext_thiem_tpl, ext_thiem_tpl_3d, grf, @@ -95,13 +104,7 @@ theis, thiem, ) -from anaflow.tools import ( - get_lap, - get_lap_inv, - specialrange, - specialrange_cut, - step_f, -) +from anaflow.tools import get_lap, get_lap_inv, specialrange, specialrange_cut, step_f try: from anaflow._version import __version__ @@ -117,10 +120,14 @@ "ext_thiem_3d", "ext_thiem_tpl", "ext_thiem_tpl_3d", + "ext_thiem_int", + "ext_thiem_int_3d", "ext_theis_2d", "ext_theis_3d", "ext_theis_tpl", "ext_theis_tpl_3d", + "ext_theis_int", + "ext_theis_int_3d", "neuman2004", "neuman2004_steady", "grf", diff --git a/src/anaflow/flow/__init__.py b/src/anaflow/flow/__init__.py index 059bb19..417f3e8 100644 --- a/src/anaflow/flow/__init__.py +++ b/src/anaflow/flow/__init__.py @@ -38,10 +38,14 @@ ext_thiem_3d ext_thiem_tpl ext_thiem_tpl_3d + ext_thiem_int + ext_thiem_int_3d ext_theis_2d ext_theis_3d ext_theis_tpl ext_theis_tpl_3d + ext_theis_int + ext_theis_int_3d neuman2004 neuman2004_steady @@ -56,14 +60,19 @@ ext_grf ext_grf_steady """ + from anaflow.flow.ext_grf_model import ext_grf, ext_grf_steady from anaflow.flow.heterogeneous import ( ext_theis_2d, ext_theis_3d, + ext_theis_int, + ext_theis_int_3d, ext_theis_tpl, ext_theis_tpl_3d, ext_thiem_2d, ext_thiem_3d, + ext_thiem_int, + ext_thiem_int_3d, ext_thiem_tpl, ext_thiem_tpl_3d, neuman2004, @@ -78,10 +87,14 @@ "ext_thiem_3d", "ext_thiem_tpl", "ext_thiem_tpl_3d", + "ext_thiem_int", + "ext_thiem_int_3d", "ext_theis_2d", "ext_theis_3d", "ext_theis_tpl", "ext_theis_tpl_3d", + "ext_theis_int", + "ext_theis_int_3d", "neuman2004", "neuman2004_steady", "grf", diff --git a/src/anaflow/flow/ext_grf_model.py b/src/anaflow/flow/ext_grf_model.py index 207c8e3..cd1e744 100644 --- a/src/anaflow/flow/ext_grf_model.py +++ b/src/anaflow/flow/ext_grf_model.py @@ -9,6 +9,7 @@ ext_grf ext_grf_steady """ + # pylint: disable=C0103 import numpy as np from scipy.integrate import quad as integ @@ -200,9 +201,7 @@ def integrand(val): if np.isclose(dim, 2): res = np.log(r_ref / Input.rad) / con else: - res = ( - (r_ref ** (2 - dim) - Input.rad ** (2 - dim)) / (2 - dim) / con - ) + res = (r_ref ** (2 - dim) - Input.rad ** (2 - dim)) / (2 - dim) / con res = Input.reshape(res) # rescale by pumping rate diff --git a/src/anaflow/flow/heterogeneous.py b/src/anaflow/flow/heterogeneous.py index 17a48db..8ecd8e3 100644 --- a/src/anaflow/flow/heterogeneous.py +++ b/src/anaflow/flow/heterogeneous.py @@ -21,6 +21,7 @@ neuman2004 neuman2004_steady """ + # pylint: disable=C0103,C0302 import functools as ft @@ -33,10 +34,10 @@ T_CG, TPL_CG, Int_CG, + Int_CG_error, K_CG_error, T_CG_error, TPL_CG_error, - Int_CG_error, ) from anaflow.tools.mean import annular_hmean from anaflow.tools.special import aniso, neuman2004_trans, specialrange_cut @@ -134,13 +135,9 @@ def ext_thiem_2d( rad = np.array(rad, dtype=float) # check the input if r_ref <= 0.0: - raise ValueError( - "The upper boundary needs to be greater than the wellradius" - ) + raise ValueError("The upper boundary needs to be greater than the wellradius") if np.any(rad <= 0.0): - raise ValueError( - "The given radii need to be greater than the wellradius" - ) + raise ValueError("The given radii need to be greater than the wellradius") if trans_gmean <= 0.0: raise ValueError("The Transmissivity needs to be positive.") if T_well is not None and T_well <= 0.0: @@ -579,13 +576,9 @@ def ext_theis_3d( if parts <= 1: raise ValueError("The numbor of partitions needs to be at least 2") if not 0.0 < far_err < 1.0: - raise ValueError( - "The relative error of Conductivity needs to be within (0,1)" - ) + raise ValueError("The relative error of Conductivity needs to be within (0,1)") # genearte rlast from a given relativ-error to farfield-conductivity - r_last = K_CG_error( - far_err, cond_gmean, var, len_scale, anis, K_well, prop - ) + r_last = K_CG_error(far_err, cond_gmean, var, len_scale, anis, K_well, prop) # generate the partition points if r_last > r_well: R_part = specialrange_cut(r_well, r_bound, parts + 1, r_last) @@ -763,9 +756,7 @@ def ext_theis_tpl( if parts <= 1: raise ValueError("The numbor of partitions needs to be at least 2") if not 0.0 < far_err < 1.0: - raise ValueError( - "The relative error of Conductivity needs to be within (0,1)" - ) + raise ValueError("The relative error of Conductivity needs to be within (0,1)") # genearte rlast from a given relativ-error to farfield-conductivity r_last = TPL_CG_error( far_err, cond_gmean, len_scale, hurst, var, c, 1, dim, K_well, prop @@ -790,9 +781,7 @@ def ext_theis_tpl( K_well=K_well, prop=prop, ) - K_well = TPL_CG( - r_well, cond_gmean, len_scale, hurst, var, c, 1, dim, K_well, prop - ) + K_well = TPL_CG(r_well, cond_gmean, len_scale, hurst, var, c, 1, dim, K_well, prop) return ext_grf( time=time, rad=rad, @@ -942,9 +931,7 @@ def ext_theis_tpl_3d( if parts <= 1: raise ValueError("The numbor of partitions needs to be at least 2") if not 0.0 < far_err < 1.0: - raise ValueError( - "The relative error of Conductivity needs to be within (0,1)" - ) + raise ValueError("The relative error of Conductivity needs to be within (0,1)") # genearte rlast from a given relativ-error to farfield-conductivity r_last = TPL_CG_error( far_err, cond_gmean, len_scale, hurst, var, c, anis, 3, K_well, prop @@ -969,9 +956,7 @@ def ext_theis_tpl_3d( K_well=K_well, prop=prop, ) - K_well = TPL_CG( - r_well, cond_gmean, len_scale, hurst, var, c, anis, 3, K_well, prop - ) + K_well = TPL_CG(r_well, cond_gmean, len_scale, hurst, var, c, anis, 3, K_well, prop) return ext_grf( time=time, rad=rad, @@ -1390,9 +1375,7 @@ def ext_theis_int( if parts <= 1: raise ValueError("The numbor of partitions needs to be at least 2") if not 0.0 < far_err < 1.0: - raise ValueError( - "The relative error of Conductivity needs to be within (0,1)" - ) + raise ValueError("The relative error of Conductivity needs to be within (0,1)") # genearte rlast from a given relativ-error to farfield-conductivity r_last = Int_CG_error( far_err, cond_gmean, var, len_scale, roughness, 1, dim, K_well, prop @@ -1416,9 +1399,7 @@ def ext_theis_int( K_well=K_well, prop=prop, ) - K_well = Int_CG( - r_well, cond_gmean, var, len_scale, roughness, 1, dim, K_well, prop - ) + K_well = Int_CG(r_well, cond_gmean, var, len_scale, roughness, 1, dim, K_well, prop) return ext_grf( time=time, rad=rad, @@ -1564,9 +1545,7 @@ def ext_theis_int_3d( if parts <= 1: raise ValueError("The numbor of partitions needs to be at least 2") if not 0.0 < far_err < 1.0: - raise ValueError( - "The relative error of Conductivity needs to be within (0,1)" - ) + raise ValueError("The relative error of Conductivity needs to be within (0,1)") # genearte rlast from a given relativ-error to farfield-conductivity r_last = Int_CG_error( far_err, cond_gmean, var, len_scale, roughness, anis, 3, K_well, prop @@ -1985,9 +1964,7 @@ def neuman2004( ) -def neuman2004_steady( - rad, r_ref, trans_gmean, var, len_scale, rate=-1e-4, h_ref=0.0 -): +def neuman2004_steady(rad, r_ref, trans_gmean, var, len_scale, rate=-1e-4, h_ref=0.0): """ The steady solution for the apparent transmissivity from [Neuman2004]. diff --git a/src/anaflow/flow/homogeneous.py b/src/anaflow/flow/homogeneous.py index 2fa0865..f1f878c 100644 --- a/src/anaflow/flow/homogeneous.py +++ b/src/anaflow/flow/homogeneous.py @@ -10,6 +10,7 @@ theis grf """ + # pylint: disable=C0103 import numpy as np diff --git a/src/anaflow/flow/laplace.py b/src/anaflow/flow/laplace.py index a7256ce..a47b917 100644 --- a/src/anaflow/flow/laplace.py +++ b/src/anaflow/flow/laplace.py @@ -10,6 +10,7 @@ grf_laplace """ + # pylint: disable=C0103,R0915 import warnings @@ -200,9 +201,7 @@ def grf_laplace( # calculate the head for ri, re in enumerate(rad): if re < R_part[-1]: - res[si, ri] = re**nu * ( - As * kv(nu, Cs * re) + Bs * iv(nu, Cs * re) - ) + res[si, ri] = re**nu * (As * kv(nu, Cs * re) + Bs * iv(nu, Cs * re)) # if there is more than one partition, create an equation system else: diff --git a/src/anaflow/tools/__init__.py b/src/anaflow/tools/__init__.py index 6d9671d..8a3a0dd 100644 --- a/src/anaflow/tools/__init__.py +++ b/src/anaflow/tools/__init__.py @@ -42,6 +42,7 @@ T_CG K_CG TPL_CG + Int_CG Special ~~~~~~~ @@ -68,7 +69,8 @@ get_lap get_lap_inv """ -from anaflow.tools.coarse_graining import K_CG, T_CG, TPL_CG + +from anaflow.tools.coarse_graining import K_CG, T_CG, TPL_CG, Int_CG from anaflow.tools.laplace import get_lap, get_lap_inv from anaflow.tools.mean import ( annular_amean, @@ -101,4 +103,5 @@ "T_CG", "K_CG", "TPL_CG", + "Int_CG", ] diff --git a/src/anaflow/tools/coarse_graining.py b/src/anaflow/tools/coarse_graining.py index dbe7530..c8fbead 100644 --- a/src/anaflow/tools/coarse_graining.py +++ b/src/anaflow/tools/coarse_graining.py @@ -16,7 +16,10 @@ K_CG_error TPL_CG TPL_CG_error + Int_CG + Int_CG_error """ + # pylint: disable=C0103 import numpy as np from scipy.optimize import root @@ -32,6 +35,8 @@ "K_CG_error", "TPL_CG", "TPL_CG_error", + "Int_CG", + "Int_CG_error", ] @@ -225,9 +230,7 @@ def K_CG(rad, cond_gmean, var, len_scale, anis, K_well="KH", prop=1.6): chi = np.log(K_well / K_efu) return K_efu * np.exp( - chi - / np.sqrt(1.0 + (prop * rad / (len_scale * anis ** (1.0 / 3.0))) ** 2) - ** 3 + chi / np.sqrt(1.0 + (prop * rad / (len_scale * anis ** (1.0 / 3.0))) ** 2) ** 3 ) @@ -334,9 +337,7 @@ def K_CG_error(err, cond_gmean, var, len_scale, anis, K_well="KH", prop=1.6): if chi > 0.0: if chi / np.log(1.0 + err) >= 1.0: - return coef * np.sqrt( - (chi / np.log(1.0 + err)) ** (2.0 / 3.0) - 1.0 - ) + return coef * np.sqrt((chi / np.log(1.0 + err)) ** (2.0 / 3.0) - 1.0) # standard value if the error is less then the variation return 0 diff --git a/src/anaflow/tools/laplace.py b/src/anaflow/tools/laplace.py index 467fd78..73d597e 100644 --- a/src/anaflow/tools/laplace.py +++ b/src/anaflow/tools/laplace.py @@ -13,6 +13,7 @@ lap_trans stehfest """ + from math import factorial, floor import numpy as np @@ -131,9 +132,7 @@ def integrand(val): return result -def get_lap_inv( - func, method="stehfest", method_dict=None, arg_dict=None, **kwargs -): +def get_lap_inv(func, method="stehfest", method_dict=None, arg_dict=None, **kwargs): """ Callable Laplace inversion. @@ -295,13 +294,9 @@ def stehfest(func, time, bound=12, arg_dict=None, **kwargs): "The time-values need to be positiv for the stehfest-algorithm" ) if bound <= 1: - raise ValueError( - "The boundary needs to be >1 for the stehfest-algorithm" - ) + raise ValueError("The boundary needs to be >1 for the stehfest-algorithm") if bound % 2 != 0: - raise ValueError( - "The boundary needs to be even for the stehfest-algorithm" - ) + raise ValueError("The boundary needs to be even for the stehfest-algorithm") # get all coefficient factors at once c_fac = c_array(bound) @@ -457,11 +452,7 @@ def _c(i, bound): def _d(k, i, bound): res = ((float(k)) ** (bound / 2 + 1)) * (factorial(2 * k)) - res /= ( - (factorial(bound / 2 - k)) - * (factorial(i - k)) - * (factorial(2 * k - i)) - ) + res /= (factorial(bound / 2 - k)) * (factorial(i - k)) * (factorial(2 * k - i)) res /= factorial(k) ** 2 return res diff --git a/src/anaflow/tools/mean.py b/src/anaflow/tools/mean.py index a06323f..0955f8f 100644 --- a/src/anaflow/tools/mean.py +++ b/src/anaflow/tools/mean.py @@ -14,6 +14,7 @@ annular_hmean annular_pmean """ + # pylint: disable=E1137, C0103 import numpy as np from scipy.integrate import quad as integ @@ -27,9 +28,7 @@ ] -def annular_fmean( - func, val_arr, f_def, f_inv, ann_dim=2, arg_dict=None, **kwargs -): +def annular_fmean(func, val_arr, f_def, f_inv, ann_dim=2, arg_dict=None, **kwargs): r""" Calculating the annular generalized f-mean. @@ -101,9 +100,7 @@ def annular_fmean( if not callable(f_inv): raise ValueError("The inverse f-mean function needs to be callable") if not np.all( - np.isclose( - f_inv(f_def(func(val_arr, **kwargs))), func(val_arr, **kwargs) - ) + np.isclose(f_inv(f_def(func(val_arr, **kwargs))), func(val_arr, **kwargs)) ): raise ValueError("f_def and f_inv need to be inverse to each other") if len(val_arr) < 2: diff --git a/src/anaflow/tools/special.py b/src/anaflow/tools/special.py index 5622f70..a18adb7 100644 --- a/src/anaflow/tools/special.py +++ b/src/anaflow/tools/special.py @@ -20,6 +20,7 @@ tpl_hyp neuman2004_trans """ + # pylint: disable=C0103,R0903 import numpy as np from scipy.special import exp1, expn, gamma, gammaincc, hyp2f1 @@ -77,12 +78,8 @@ def __init__(self, time=0, rad=0, struc_grid=True): self.rad_max = np.max(self.rad) self.time_gz = self.time > 0 - self.time_mat = np.outer( - self.time[self.time_gz], np.ones_like(self.rad) - ) - self.rad_mat = np.outer( - np.ones_like(self.time[self.time_gz]), self.rad - ) + self.time_mat = np.outer(self.time[self.time_gz], np.ones_like(self.rad)) + self.rad_mat = np.outer(np.ones_like(self.time[self.time_gz]), self.rad) if not self.struc_grid and self.rad_shape != self.time_shape: raise ValueError("No struc_grid: shape of time & radius differ") @@ -157,9 +154,7 @@ def specialrange(val_min, val_max, steps, typ="exp"): array([ 1. , 2.53034834, 5.23167968, 10. ]) """ if typ in ["exponential", "exp"]: - rng = np.expm1( - np.linspace(np.log1p(val_min), np.log1p(val_max), steps) - ) + rng = np.expm1(np.linspace(np.log1p(val_min), np.log1p(val_max), steps)) elif typ in ["logarithmic", "log"]: rng = np.log(np.linspace(np.exp(val_min), np.exp(val_max), steps)) elif typ in ["geometric", "geo", "geom"]: @@ -170,9 +165,7 @@ def specialrange(val_min, val_max, steps, typ="exp"): rng = (np.linspace(np.sqrt(val_min), np.sqrt(val_max), steps)) ** 2 elif typ in ["cubic", "cub"]: rng = ( - np.linspace( - np.power(val_min, 1 / 3.0), np.power(val_max, 1 / 3.0), steps - ) + np.linspace(np.power(val_min, 1 / 3.0), np.power(val_max, 1 / 3.0), steps) ) ** 3 elif isinstance(typ, (float, int)): rng = ( @@ -279,12 +272,7 @@ def aniso(e): res = 0.0 else: res = e / (2 * (1.0 - e**2)) - res *= ( - 1.0 - / np.sqrt(1.0 - e**2) - * np.arctan(np.sqrt(1.0 / e**2 - 1.0)) - - e - ) + res *= 1.0 / np.sqrt(1.0 - e**2) * np.arctan(np.sqrt(1.0 / e**2 - 1.0)) - e return res @@ -500,7 +488,7 @@ def inc_gamma(s, x): def tpl_hyp(rad, dim, hurst, corr, prop): """Hyp_2F1 for the TPL CG model.""" x, d = 1 / (1 + (prop * rad / corr) ** 2), dim / 2 - return x ** d * hyp2f1(d, 1, d + 1 + hurst, x) + return x**d * hyp2f1(d, 1, d + 1 + hurst, x) def neuman2004_trans(rad, trans_gmean, var, len_scale): diff --git a/tests/test_anaflow.py b/tests/test_anaflow.py index afa76d3..e723134 100644 --- a/tests/test_anaflow.py +++ b/tests/test_anaflow.py @@ -63,9 +63,7 @@ def test_homogeneous(self): self.assertTrue(inc(rad_arr, self.delta)) for time_arr in transient.T: self.assertTrue(dec(time_arr, self.delta)) - self.assertAlmostEqual( - np.abs(np.max(steady - transient[-1, :])), 0.0, places=4 - ) + self.assertAlmostEqual(np.abs(np.max(steady - transient[-1, :])), 0.0, places=4) def test_ext_2d(self): steady = af.ext_thiem_2d( @@ -93,9 +91,7 @@ def test_ext_2d(self): self.assertTrue(inc(rad_arr, self.delta)) for time_arr in transient.T: self.assertTrue(dec(time_arr, self.delta)) - self.assertAlmostEqual( - np.abs(np.max(steady - transient[-1, :])), 0.0, places=4 - ) + self.assertAlmostEqual(np.abs(np.max(steady - transient[-1, :])), 0.0, places=4) def test_ext_3d(self): steady = af.ext_thiem_3d( @@ -127,9 +123,7 @@ def test_ext_3d(self): self.assertTrue(inc(rad_arr, self.delta)) for time_arr in transient.T: self.assertTrue(dec(time_arr, self.delta)) - self.assertAlmostEqual( - np.abs(np.max(steady - transient[-1, :])), 0.0, places=4 - ) + self.assertAlmostEqual(np.abs(np.max(steady - transient[-1, :])), 0.0, places=4) def test_neuman(self): steady = af.neuman2004_steady( @@ -157,9 +151,7 @@ def test_neuman(self): self.assertTrue(inc(rad_arr, self.delta)) for time_arr in transient.T: self.assertTrue(dec(time_arr, self.delta)) - self.assertAlmostEqual( - np.abs(np.max(steady - transient[-1, :])), 0.0, places=4 - ) + self.assertAlmostEqual(np.abs(np.max(steady - transient[-1, :])), 0.0, places=4) def test_tpl(self): steady = af.ext_thiem_tpl( @@ -193,9 +185,7 @@ def test_tpl(self): self.assertTrue(inc(rad_arr, self.delta)) for time_arr in transient.T: self.assertTrue(dec(time_arr, self.delta)) - self.assertAlmostEqual( - np.abs(np.max(steady - transient[-1, :])), 0.0, places=3 - ) + self.assertAlmostEqual(np.abs(np.max(steady - transient[-1, :])), 0.0, places=3) def test_tpl_3d(self): steady = af.ext_thiem_tpl_3d( @@ -229,9 +219,7 @@ def test_tpl_3d(self): self.assertTrue(inc(rad_arr, self.delta)) for time_arr in transient.T: self.assertTrue(dec(time_arr, self.delta)) - self.assertAlmostEqual( - np.abs(np.max(steady - transient[-1, :])), 0.0, places=2 - ) + self.assertAlmostEqual(np.abs(np.max(steady - transient[-1, :])), 0.0, places=2) # plt.plot(self.rad, steady) # for rad_arr in transient: