Skip to content

Commit

Permalink
Dev (#228)
Browse files Browse the repository at this point in the history
- improvements from the c-vs-numba comparison exercise.
- Add numpy back to the deps, for better visibility.
  • Loading branch information
prisae authored Oct 16, 2024
1 parent e3b43b6 commit 16fa9c6
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 39 deletions.
13 changes: 9 additions & 4 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 13 additions & 5 deletions docs/dev/maintenance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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",
...: ])
3 changes: 2 additions & 1 deletion docs/manual/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 22 additions & 20 deletions empymod/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@ 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
# (Up- (Wu) and downgoing (Wd), in rec layer); Eq 74
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):
Expand All @@ -272,14 +272,14 @@ def greenfct(zsrc, zrec, lsrc, lrec, depth, etaH, etaV, zetaH, zetaV, lambd,

# Green's function depending on <ab>
# (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):
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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])

Expand All @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
15 changes: 6 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ authors = [
{name = "The emsig community", email = "[email protected]"},
]
dependencies = [
"numpy",
"scipy>=1.10",
"numba",
"libdlf",
Expand All @@ -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",
Expand All @@ -57,12 +56,10 @@ tests = [
"flake8-pyproject",
"pytest-console-scripts",
]

all = [
"empymod[docs]",
"empymod[tests]",
]

build = [
"setuptools_scm>=8",
"setuptools>=64",
Expand Down

0 comments on commit 16fa9c6

Please sign in to comment.