From 16fa9c67b0e9e3d8e6be7e1bd91026b5f91a6da0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dieter=20Werthm=C3=BCller?= Date: Wed, 16 Oct 2024 17:45:16 +0200 Subject: [PATCH] Dev (#228) - improvements from the c-vs-numba comparison exercise. - Add numpy back to the deps, for better visibility. --- CHANGELOG.rst | 13 +++++++---- docs/dev/maintenance.rst | 18 +++++++++++----- docs/manual/installation.rst | 3 ++- empymod/kernel.py | 42 +++++++++++++++++++----------------- pyproject.toml | 15 ++++++------- 5 files changed, 52 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 34dcc14f..9ca41451 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -10,12 +10,17 @@ v2.3.x """""" -latest ------- +v2.3.3 pyproject.toml +--------------------- -- Maintenance: +**2024-10-16** + +Small maintenance release: - - Changed from ``setup.py`` to ``pyproject.toml``. +- Update credits to reflect current situation. +- Changed from ``setup.py`` to ``pyproject.toml``. +- Some maintenance in tests and docs. +- Small modifications to the kernel. v2.3.2: NumPy v2 diff --git a/docs/dev/maintenance.rst b/docs/dev/maintenance.rst index 0469f2df..87977f9a 100644 --- a/docs/dev/maintenance.rst +++ b/docs/dev/maintenance.rst @@ -64,8 +64,16 @@ To check the environment in which the documentation was built. .. ipython:: In [1]: import empymod - ...: empymod.Report( - ...: ['sphinx', 'numpydoc', 'sphinx_design', 'sphinx_numfig', - ...: 'sphinx_gallery', 'memory_profiler', 'pydata_sphinx_theme', - ...: 'sphinx_automodapi', 'ipykernel', ] - ...: ) + ...: empymod.Report([ + ...: "ipympl", + ...: "sphinx", + ...: "numpydoc", + ...: "ipykernel", + ...: "pickleshare", + ...: "sphinx_design", + ...: "sphinx_numfig", + ...: "sphinx_gallery", + ...: "memory_profiler", + ...: "sphinx_automodapi", + ...: "pydata_sphinx_theme", + ...: ]) diff --git a/docs/manual/installation.rst b/docs/manual/installation.rst index 03ea1a48..bd97ac3e 100644 --- a/docs/manual/installation.rst +++ b/docs/manual/installation.rst @@ -13,7 +13,8 @@ or via ``pip``: pip install empymod -Requirements are the modules ``scipy``, ``numba``, and ``libdlf``. +Requirements are the modules ``numpy``, ``scipy``, ``numba``, ``libdlf``, and +``scooby``. The modeller empymod comes with add-ons (``empymod.scripts``). These add-ons provide some very specific, additional functionalities. Some of these add-ons diff --git a/empymod/kernel.py b/empymod/kernel.py index 6fd1e458..df13c487 100644 --- a/empymod/kernel.py +++ b/empymod/kernel.py @@ -241,7 +241,7 @@ def greenfct(zsrc, zrec, lsrc, lrec, depth, etaH, etaV, zetaH, zetaV, lambd, lrecGam = Gam[:, :, lrec, :] # Reflection (coming from below (Rp) and above (Rm) rec) - if depth.size > 1: # Only if more than 1 layer + if nlayer > 1: # Only if more than 1 layer Rp, Rm = reflections(depth, e_zH, Gam, lrec, lsrc) # Field propagators @@ -249,7 +249,7 @@ def greenfct(zsrc, zrec, lsrc, lrec, depth, etaH, etaV, zetaH, zetaV, lambd, Wu = np.zeros_like(lrecGam) Wd = np.zeros_like(lrecGam) - if lrec != depth.size-1: # No upgoing field prop. if rec in last + if lrec != nlayer-1: # No upgoing field prop. if rec in last ddepth = depth[lrec + 1] - zrec for i in range(nfreq): for ii in range(noff): @@ -272,14 +272,14 @@ def greenfct(zsrc, zrec, lsrc, lrec, depth, etaH, etaV, zetaH, zetaV, lambd, # Green's function depending on # (If only one layer, no reflections/fields) - if depth.size > 1 and ab in [13, 23, 31, 32, 14, 24, 15, 25]: + if nlayer > 1 and ab in [13, 23, 31, 32, 14, 24, 15, 25]: for i in range(nfreq): for ii in range(noff): for iv in range(nlambda): green[i, ii, iv] = Pu[i, ii, iv]*Wu[i, ii, iv] green[i, ii, iv] -= Pd[i, ii, iv]*Wd[i, ii, iv] - elif depth.size > 1: + elif nlayer > 1: for i in range(nfreq): for ii in range(noff): for iv in range(nlambda): @@ -313,7 +313,7 @@ def greenfct(zsrc, zrec, lsrc, lrec, depth, etaH, etaV, zetaH, zetaV, lambd, else: # Calculate exponential factor - if lrec == depth.size-1: + if lrec == nlayer-1: ddepth = 0 else: ddepth = depth[lrec+1] - depth[lrec] @@ -436,7 +436,7 @@ def reflections(depth, e_zH, Gam, lrec, lsrc): """ # Get numbers and max/min layer. - nfreq, noff, nlambda = Gam[:, :, 0, :].shape + nfreq, noff, nlayer, nlambda = Gam.shape maxl = max([lrec, lsrc]) minl = min([lrec, lsrc]) @@ -446,7 +446,7 @@ def reflections(depth, e_zH, Gam, lrec, lsrc): # Switches depending if plus or minus if plus: pm = 1 - layer_count = np.arange(depth.size-2, minl-1, -1) + layer_count = np.arange(nlayer-2, minl-1, -1) izout = abs(lsrc-lrec) minmax = pm*maxl else: @@ -458,7 +458,7 @@ def reflections(depth, e_zH, Gam, lrec, lsrc): # If rec in last and rec below src (plus) or # if rec in first and rec above src (minus), shift izout shiftplus = lrec < lsrc and lrec == 0 and not plus - shiftminus = lrec > lsrc and lrec == depth.size-1 and plus + shiftminus = lrec > lsrc and lrec == nlayer-1 and plus if shiftplus or shiftminus: izout -= pm @@ -536,21 +536,21 @@ def fields(depth, Rp, Rm, Gam, lrec, lsrc, zsrc, ab, TM): """ - nfreq, noff, nlambda = Gam[:, :, 0, :].shape + nfreq, noff, nlayer, nlambda = Gam.shape # Variables nlsr = abs(lsrc-lrec)+1 # nr of layers btw and incl. src and rec layer rsrcl = 0 # src-layer in reflection (Rp/Rm), first if down izrange = range(2, nlsr) isr = lsrc - last = depth.size-1 + last = nlayer-1 # Booleans if src in first or last layer; swapped if up=True first_layer = lsrc == 0 - last_layer = lsrc == depth.size-1 + last_layer = lsrc == nlayer-1 # Depths; dp and dm are swapped if up=True - if lsrc != depth.size-1: + if lsrc != nlayer-1: ds = depth[lsrc+1]-depth[lsrc] dp = depth[lsrc+1]-zsrc dm = zsrc-depth[lsrc] @@ -580,7 +580,7 @@ def fields(depth, Rp, Rm, Gam, lrec, lsrc, zsrc, ab, TM): for up in [False, True]: # No upgoing field if rec is in last layer or below src - if up and (lrec == depth.size-1 or lrec > lsrc): + if up and (lrec == nlayer-1 or lrec > lsrc): Pu = np.zeros_like(iGam) continue # No downgoing field if rec is in first layer or above src @@ -654,14 +654,16 @@ def fields(depth, Rp, Rm, Gam, lrec, lsrc, zsrc, ab, TM): P[i, ii, iv] = (p1 + p2) * p3 # If up or down and src is in last but one layer - if up or (not up and lsrc+1 < depth.size-1): + if up or (not up and lsrc+1 < nlayer-1): ddepth = depth[lsrc+1-1*pup]-depth[lsrc-1*pup] - for i in range(nfreq): - for ii in range(noff): - for iv in range(nlambda): - tiRpm = Rpm[i, ii, rsrcl-1*pup, iv] - tiGam = Gam[i, ii, lsrc-1*pup, iv] - P[i, ii, iv] /= 1 + tiRpm*np.exp(-2*tiGam*ddepth) + if np.isfinite(ddepth): + for i in range(nfreq): + for ii in range(noff): + for iv in range(nlambda): + tiRpm = Rpm[i, ii, rsrcl-1*pup, iv] + tiGam = Gam[i, ii, lsrc-1*pup, iv] + fact = tiRpm*np.exp(-2*tiGam*ddepth) + P[i, ii, iv] /= 1 + fact # Second compute P for all other layers if nlsr > 2: diff --git a/pyproject.toml b/pyproject.toml index d76a2e6d..ce2f8f49 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,6 +11,7 @@ authors = [ {name = "The emsig community", email = "info@emsig.xyz"}, ] dependencies = [ + "numpy", "scipy>=1.10", "numba", "libdlf", @@ -33,22 +34,20 @@ Repository = "https://github.com/emsig/empymod" [project.optional-dependencies] docs = [ - "matplotlib", + "ipympl", "sphinx>=7.3", "numpydoc", + "ipykernel", + "matplotlib", + "pickleshare", "sphinx_design", "sphinx_numfig", "sphinx_gallery>=0.16", "memory_profiler", - "pydata_sphinx_theme", "sphinx_automodapi", - "ipykernel", - "ipympl", - "pickleshare", + "pydata_sphinx_theme", ] - tests = [ - "asv", "flake8", "pytest", "coveralls", @@ -57,12 +56,10 @@ tests = [ "flake8-pyproject", "pytest-console-scripts", ] - all = [ "empymod[docs]", "empymod[tests]", ] - build = [ "setuptools_scm>=8", "setuptools>=64",