fatiando / choclo

Kernel functions for your geophysical models
https://www.fatiando.org/choclo
BSD 3-Clause "New" or "Revised" License
13 stars 2 forks source link

Discontinuity in magnetic field on lines above horizontal edge of prism #98

Closed santisoler closed 3 weeks ago

santisoler commented 3 weeks ago

Description of the problem:

Today I found that the current forward modelling functions for magnetic fields experience some discontinuities when being evaluated on lines above one of the edges of the prism.

I found this misbehavior when exploring the values of magnetic_e along a N-S profile that falls right above one of the horizontal edges of the prism.

Full code that generated the error

import choclo
import numpy as np
import matplotlib.pyplot as plt

prism = np.array([-10.0, 10, -10, 10, -20, 0])
magnetization = np.array([0.0, 1.0, 0.0])

# Build N-S profile that passes above one of the edges of the prism
size = 10001
center, delta = prism[2], 1e-6
northing = np.linspace(center - delta, center + delta, size)
easting, upward = prism[1], 50.0

# Evaluate magnetic_e on those points
magnetic_e = np.array(
    [
        choclo.prism.magnetic_e(easting, n, upward, *prism, *magnetization)
        for n in northing
    ]
)

# Plot results
plt.plot(northing, magnetic_e)
plt.show()

Output

Figure_1

System information

Output of conda list

# packages in environment at /home/santi/.miniforge3/envs/choclo:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
accessible-pygments       0.0.5              pyhd8ed1ab_0    conda-forge
alabaster                 0.7.16             pyhd8ed1ab_0    conda-forge
alsa-lib                  1.2.12               h4ab18f5_0    conda-forge
astor                     0.8.1              pyh9f0ad1d_0    conda-forge
asttokens                 2.4.1              pyhd8ed1ab_0    conda-forge
attr                      2.5.1                h166bdaf_1    conda-forge
attrs                     23.2.0             pyh71513ae_0    conda-forge
aws-c-auth                0.7.31               h57bd9a3_0    conda-forge
aws-c-cal                 0.7.4                hfd43aa1_1    conda-forge
aws-c-common              0.9.28               hb9d3cd8_0    conda-forge
aws-c-compression         0.2.19               h756ea98_1    conda-forge
aws-c-event-stream        0.4.3                h29ce20c_2    conda-forge
aws-c-http                0.8.10               h5e77a74_0    conda-forge
aws-c-io                  0.14.18             h33ff4e5_10    conda-forge
aws-c-mqtt                0.10.6               h02abb05_0    conda-forge
aws-c-s3                  0.6.6                h834ce55_0    conda-forge
aws-c-sdkutils            0.1.19               h756ea98_3    conda-forge
aws-checksums             0.1.20               h756ea98_0    conda-forge
aws-crt-cpp               0.28.3               h469002c_5    conda-forge
aws-sdk-cpp               1.11.407             h9f1560d_0    conda-forge
azure-core-cpp            1.13.0               h935415a_0    conda-forge
azure-identity-cpp        1.8.0                hd126650_2    conda-forge
azure-storage-blobs-cpp   12.12.0              hd2e3451_0    conda-forge
azure-storage-common-cpp  12.7.0               h10ac4d7_1    conda-forge
azure-storage-files-datalake-cpp 12.11.0              h325d260_1    conda-forge
babel                     2.14.0             pyhd8ed1ab_0    conda-forge
backports                 1.0                pyhd8ed1ab_3    conda-forge
backports.tarfile         1.0.0              pyhd8ed1ab_1    conda-forge
beautifulsoup4            4.12.3             pyha770c72_0    conda-forge
black                     24.4.2          py312h7900ff3_0    conda-forge
bleach                    6.1.0              pyhd8ed1ab_0    conda-forge
bokeh                     3.5.2              pyhd8ed1ab_0    conda-forge
brotli                    1.1.0                hd590300_1    conda-forge
brotli-bin                1.1.0                hd590300_1    conda-forge
brotli-python             1.1.0           py312h30efb56_1    conda-forge
build                     0.7.0              pyhd8ed1ab_0    conda-forge
burocrata                 0.2.0                    pypi_0    pypi
bzip2                     1.0.8                hd590300_5    conda-forge
c-ares                    1.33.1               heb4867d_0    conda-forge
ca-certificates           2024.8.30            hbcca054_0    conda-forge
cairo                     1.18.0               hbb29018_2    conda-forge
certifi                   2024.8.30          pyhd8ed1ab_0    conda-forge
cffi                      1.16.0          py312hf06ca03_0    conda-forge
charset-normalizer        3.3.2              pyhd8ed1ab_0    conda-forge
choclo                    0.2.0                    pypi_0    pypi
click                     8.1.7           unix_pyh707e725_0    conda-forge
cloudpickle               3.0.0              pyhd8ed1ab_0    conda-forge
cmarkgfm                  0.8.0           py312h98912ed_3    conda-forge
colorama                  0.4.6              pyhd8ed1ab_0    conda-forge
comm                      0.2.2              pyhd8ed1ab_0    conda-forge
contourpy                 1.2.1           py312h8572e83_0    conda-forge
coverage                  7.6.0           py312h41a817b_0    conda-forge
cryptography              42.0.8          py312hbcc2302_0    conda-forge
cycler                    0.12.1             pyhd8ed1ab_0    conda-forge
cytoolz                   0.12.3          py312h98912ed_0    conda-forge
dask                      2024.9.0           pyhd8ed1ab_0    conda-forge
dask-core                 2024.9.0           pyhd8ed1ab_0    conda-forge
dask-expr                 1.1.14             pyhd8ed1ab_0    conda-forge
dbus                      1.13.6               h5008d03_3    conda-forge
debugpy                   1.8.2           py312h7070661_0    conda-forge
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
defusedxml                0.7.1              pyhd8ed1ab_0    conda-forge
distributed               2024.9.0           pyhd8ed1ab_0    conda-forge
docutils                  0.20.1          py312h7900ff3_3    conda-forge
entrypoints               0.4                pyhd8ed1ab_0    conda-forge
exceptiongroup            1.2.0              pyhd8ed1ab_2    conda-forge
executing                 2.0.1              pyhd8ed1ab_0    conda-forge
expat                     2.6.2                h59595ed_0    conda-forge
flake8                    7.1.0              pyhd8ed1ab_0    conda-forge
flake8-bugbear            24.4.26            pyhd8ed1ab_0    conda-forge
flake8-builtins           2.5.0              pyhd8ed1ab_0    conda-forge
flake8-functions          0.0.8              pyhd8ed1ab_0    conda-forge
flake8-mutable            1.2.0                      py_1    conda-forge
flake8-rst-docstrings     0.3.0              pyhd8ed1ab_0    conda-forge
flake8-simplify           0.21.0             pyhd8ed1ab_0    conda-forge
flake8-unused-arguments   0.0.13             pyhd8ed1ab_0    conda-forge
font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    conda-forge
font-ttf-inconsolata      3.000                h77eed37_0    conda-forge
font-ttf-source-code-pro  2.038                h77eed37_0    conda-forge
font-ttf-ubuntu           0.83                 h77eed37_2    conda-forge
fontconfig                2.14.2               h14ed4e7_0    conda-forge
fonts-conda-ecosystem     1                             0    conda-forge
fonts-conda-forge         1                             0    conda-forge
fonttools                 4.53.1          py312h41a817b_0    conda-forge
freetype                  2.12.1               h267a509_2    conda-forge
fsspec                    2024.9.0           pyhff2d567_0    conda-forge
gettext                   0.22.5               h59595ed_2    conda-forge
gettext-tools             0.22.5               h59595ed_2    conda-forge
gflags                    2.2.2             h5888daf_1005    conda-forge
glib                      2.80.3               h8a4344b_1    conda-forge
glib-tools                2.80.3               h73ef956_1    conda-forge
glog                      0.7.1                hbabe93e_0    conda-forge
graphite2                 1.3.13            h59595ed_1003    conda-forge
gst-plugins-base          1.24.5               hbaaba92_0    conda-forge
gstreamer                 1.24.5               haf2f30d_0    conda-forge
h2                        4.1.0              pyhd8ed1ab_0    conda-forge
harfbuzz                  8.5.0                hfac3d4d_0    conda-forge
hpack                     4.0.0              pyh9f0ad1d_0    conda-forge
hyperframe                6.0.1              pyhd8ed1ab_0    conda-forge
icu                       73.2                 h59595ed_0    conda-forge
idna                      3.7                pyhd8ed1ab_0    conda-forge
imagesize                 1.4.1              pyhd8ed1ab_0    conda-forge
importlib-metadata        8.0.0              pyha770c72_0    conda-forge
importlib_metadata        8.0.0                hd8ed1ab_0    conda-forge
importlib_resources       6.4.0              pyhd8ed1ab_0    conda-forge
iniconfig                 2.0.0              pyhd8ed1ab_0    conda-forge
ipykernel                 6.29.5             pyh3099207_0    conda-forge
ipython                   8.26.0             pyh707e725_0    conda-forge
ipywidgets                8.1.3              pyhd8ed1ab_0    conda-forge
isort                     5.13.2             pyhd8ed1ab_0    conda-forge
jaraco.classes            3.4.0              pyhd8ed1ab_1    conda-forge
jaraco.context            5.3.0              pyhd8ed1ab_1    conda-forge
jaraco.functools          4.0.0              pyhd8ed1ab_0    conda-forge
jedi                      0.19.1             pyhd8ed1ab_0    conda-forge
jeepney                   0.8.0              pyhd8ed1ab_0    conda-forge
jinja2                    3.1.4              pyhd8ed1ab_0    conda-forge
joblib                    1.4.2              pyhd8ed1ab_0    conda-forge
jsonschema                4.23.0             pyhd8ed1ab_0    conda-forge
jsonschema-specifications 2023.12.1          pyhd8ed1ab_0    conda-forge
jupyter-sphinx            0.5.3              pyha770c72_4    conda-forge
jupyter_client            8.6.2              pyhd8ed1ab_0    conda-forge
jupyter_core              5.7.2           py312h7900ff3_0    conda-forge
jupyterlab_pygments       0.3.0              pyhd8ed1ab_1    conda-forge
jupyterlab_widgets        3.0.11             pyhd8ed1ab_0    conda-forge
keyring                   25.2.1             pyha804496_0    conda-forge
keyutils                  1.6.1                h166bdaf_0    conda-forge
kiwisolver                1.4.5           py312h8572e83_1    conda-forge
krb5                      1.21.3               h659f571_0    conda-forge
lame                      3.100             h166bdaf_1003    conda-forge
lcms2                     2.16                 hb7c19ff_0    conda-forge
ld_impl_linux-64          2.40                 hf3520f5_7    conda-forge
lerc                      4.0.0                h27087fc_0    conda-forge
libabseil                 20240116.2      cxx17_he02047a_1    conda-forge
libarrow                  17.0.0          had3b6fe_16_cpu    conda-forge
libarrow-acero            17.0.0          h5888daf_16_cpu    conda-forge
libarrow-dataset          17.0.0          h5888daf_16_cpu    conda-forge
libarrow-substrait        17.0.0          hf54134d_16_cpu    conda-forge
libasprintf               0.22.5               h661eb56_2    conda-forge
libasprintf-devel         0.22.5               h661eb56_2    conda-forge
libblas                   3.9.0           22_linux64_openblas    conda-forge
libbrotlicommon           1.1.0                hd590300_1    conda-forge
libbrotlidec              1.1.0                hd590300_1    conda-forge
libbrotlienc              1.1.0                hd590300_1    conda-forge
libcap                    2.69                 h0f662aa_0    conda-forge
libcblas                  3.9.0           22_linux64_openblas    conda-forge
libclang-cpp15            15.0.7          default_h127d8a8_5    conda-forge
libclang13                18.1.8          default_h6ae225f_0    conda-forge
libcrc32c                 1.1.2                h9c3ff4c_0    conda-forge
libcups                   2.3.3                h4637d8d_4    conda-forge
libcurl                   8.10.1               hbbe4b11_0    conda-forge
libdeflate                1.20                 hd590300_0    conda-forge
libedit                   3.1.20191231         he28a2e2_2    conda-forge
libev                     4.33                 hd590300_2    conda-forge
libevent                  2.1.12               hf998b51_1    conda-forge
libexpat                  2.6.2                h59595ed_0    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libflac                   1.4.3                h59595ed_0    conda-forge
libgcc                    14.1.0               h77fa898_1    conda-forge
libgcc-ng                 14.1.0               h69a702a_1    conda-forge
libgcrypt                 1.11.0               h4ab18f5_0    conda-forge
libgettextpo              0.22.5               h59595ed_2    conda-forge
libgettextpo-devel        0.22.5               h59595ed_2    conda-forge
libgfortran-ng            14.1.0               h69a702a_0    conda-forge
libgfortran5              14.1.0               hc5f4f2c_0    conda-forge
libglib                   2.80.3               h8a4344b_1    conda-forge
libgomp                   14.1.0               h77fa898_1    conda-forge
libgoogle-cloud           2.29.0               h435de7b_0    conda-forge
libgoogle-cloud-storage   2.29.0               h0121fbd_0    conda-forge
libgpg-error              1.50                 h4f305b6_0    conda-forge
libgrpc                   1.62.2               h15f2491_0    conda-forge
libiconv                  1.17                 hd590300_2    conda-forge
libjpeg-turbo             3.0.0                hd590300_1    conda-forge
liblapack                 3.9.0           22_linux64_openblas    conda-forge
libllvm14                 14.0.6               hcd5def8_4    conda-forge
libllvm15                 15.0.7               hb3ce162_4    conda-forge
libllvm18                 18.1.8               hc9dba70_0    conda-forge
libnghttp2                1.58.0               h47da74e_1    conda-forge
libnsl                    2.0.1                hd590300_0    conda-forge
libogg                    1.3.5                h4ab18f5_0    conda-forge
libopenblas               0.3.27          pthreads_hac2b453_1    conda-forge
libopus                   1.3.1                h7f98852_1    conda-forge
libparquet                17.0.0          h39682fd_16_cpu    conda-forge
libpng                    1.6.43               h2797004_0    conda-forge
libpq                     16.3                 ha72fbe1_0    conda-forge
libprotobuf               4.25.3               hd5b35b9_1    conda-forge
libre2-11                 2023.09.01           h5a48ba9_2    conda-forge
libsndfile                1.2.2                hc60ed4a_1    conda-forge
libsodium                 1.0.18               h36c2ea0_1    conda-forge
libsqlite                 3.46.0               hde9e2c9_0    conda-forge
libssh2                   1.11.0               h0841786_0    conda-forge
libstdcxx                 14.1.0               hc0a3c3a_1    conda-forge
libstdcxx-ng              14.1.0               h4852527_1    conda-forge
libsystemd0               255                  h3516f8a_1    conda-forge
libthrift                 0.20.0               h0e7cc3e_1    conda-forge
libtiff                   4.6.0                h1dd3fc0_3    conda-forge
libutf8proc               2.8.0                h166bdaf_0    conda-forge
libuuid                   2.38.1               h0b41bf4_0    conda-forge
libvorbis                 1.3.7                h9c3ff4c_0    conda-forge
libwebp-base              1.4.0                hd590300_0    conda-forge
libxcb                    1.16                 hd590300_0    conda-forge
libxkbcommon              1.7.0                h2c5496b_1    conda-forge
libxml2                   2.12.7               h4c95cb1_2    conda-forge
libzlib                   1.3.1                h4ab18f5_1    conda-forge
llvmlite                  0.43.0          py312h9c5d478_0    conda-forge
locket                    1.0.0              pyhd8ed1ab_0    conda-forge
lz4                       4.3.3           py312hb3f7f12_1    conda-forge
lz4-c                     1.9.4                hcb278e6_0    conda-forge
make                      4.3                  hd18ef5c_1    conda-forge
markdown-it-py            3.0.0              pyhd8ed1ab_0    conda-forge
markupsafe                2.1.5           py312h98912ed_0    conda-forge
matplotlib                3.9.1           py312h7900ff3_0    conda-forge
matplotlib-base           3.9.1           py312h9201f00_0    conda-forge
matplotlib-inline         0.1.7              pyhd8ed1ab_0    conda-forge
mccabe                    0.7.0              pyhd8ed1ab_0    conda-forge
mdurl                     0.1.2              pyhd8ed1ab_0    conda-forge
mistune                   3.0.2              pyhd8ed1ab_0    conda-forge
more-itertools            10.3.0             pyhd8ed1ab_0    conda-forge
mpg123                    1.32.6               h59595ed_0    conda-forge
mr-proper                 0.0.7              pyhd8ed1ab_0    conda-forge
msgpack-python            1.1.0           py312h68727a3_0    conda-forge
munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
mypy_extensions           1.0.0              pyha770c72_0    conda-forge
mysql-common              8.3.0                hf1915f5_4    conda-forge
mysql-libs                8.3.0                hca2cd23_4    conda-forge
nbclient                  0.10.0             pyhd8ed1ab_0    conda-forge
nbconvert                 7.16.4               hd8ed1ab_1    conda-forge
nbconvert-core            7.16.4             pyhd8ed1ab_1    conda-forge
nbconvert-pandoc          7.16.4               hd8ed1ab_1    conda-forge
nbformat                  5.10.4             pyhd8ed1ab_0    conda-forge
ncurses                   6.5                  h59595ed_0    conda-forge
nest-asyncio              1.6.0              pyhd8ed1ab_0    conda-forge
nh3                       0.2.18          py312hf008fa9_0    conda-forge
nspr                      4.35                 h27087fc_0    conda-forge
nss                       3.102                h593d115_0    conda-forge
numba                     0.60.0          py312h83e6fd3_0    conda-forge
numpy                     2.0.0           py312h22e1c76_0    conda-forge
numpydoc                  1.7.0              pyhd8ed1ab_3    conda-forge
openjpeg                  2.5.2                h488ebb8_0    conda-forge
openssl                   3.3.2                hb9d3cd8_0    conda-forge
orc                       2.0.2                h669347b_0    conda-forge
packaging                 24.1               pyhd8ed1ab_0    conda-forge
pandas                    2.2.3           py312hf9745cd_1    conda-forge
pandoc                    3.2.1                ha770c72_0    conda-forge
pandocfilters             1.5.0              pyhd8ed1ab_0    conda-forge
parso                     0.8.4              pyhd8ed1ab_0    conda-forge
partd                     1.4.2              pyhd8ed1ab_0    conda-forge
pathspec                  0.12.1             pyhd8ed1ab_0    conda-forge
pcre2                     10.44                h0f59acf_0    conda-forge
pep517                    0.13.0             pyhd8ed1ab_0    conda-forge
pep8-naming               0.14.1             pyhd8ed1ab_0    conda-forge
pexpect                   4.9.0              pyhd8ed1ab_0    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    10.4.0          py312h287a98d_0    conda-forge
pip                       24.0               pyhd8ed1ab_0    conda-forge
pixman                    0.43.2               h59595ed_0    conda-forge
pkginfo                   1.10.0             pyhd8ed1ab_0    conda-forge
pkgutil-resolve-name      1.3.10             pyhd8ed1ab_1    conda-forge
platformdirs              4.2.2              pyhd8ed1ab_0    conda-forge
pluggy                    1.5.0              pyhd8ed1ab_0    conda-forge
ply                       3.11               pyhd8ed1ab_2    conda-forge
pooch                     1.8.2              pyhd8ed1ab_0    conda-forge
prompt-toolkit            3.0.47             pyha770c72_0    conda-forge
psutil                    6.0.0           py312h9a8786e_0    conda-forge
pthread-stubs             0.4               h36c2ea0_1001    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pulseaudio-client         17.0                 hb77b528_0    conda-forge
pure_eval                 0.2.2              pyhd8ed1ab_0    conda-forge
pyarrow                   17.0.0          py312h9cebb41_1    conda-forge
pyarrow-core              17.0.0          py312h9cafe31_1_cpu    conda-forge
pyarrow-hotfix            0.6                pyhd8ed1ab_0    conda-forge
pycodestyle               2.12.0             pyhd8ed1ab_0    conda-forge
pycparser                 2.22               pyhd8ed1ab_0    conda-forge
pydata-sphinx-theme       0.15.4             pyhd8ed1ab_0    conda-forge
pyflakes                  3.2.0              pyhd8ed1ab_0    conda-forge
pygments                  2.18.0             pyhd8ed1ab_0    conda-forge
pyparsing                 3.1.2              pyhd8ed1ab_0    conda-forge
pyqt                      5.15.9          py312h949fe66_5    conda-forge
pyqt5-sip                 12.12.2         py312h30efb56_5    conda-forge
pysocks                   1.7.1              pyha2e5f31_6    conda-forge
pytest                    8.3.1              pyhd8ed1ab_0    conda-forge
pytest-cov                5.0.0              pyhd8ed1ab_0    conda-forge
python                    3.12.0          hab00c5b_0_cpython    conda-forge
python-dateutil           2.9.0              pyhd8ed1ab_0    conda-forge
python-fastjsonschema     2.20.0             pyhd8ed1ab_0    conda-forge
python-tzdata             2024.2             pyhd8ed1ab_0    conda-forge
python_abi                3.12                    4_cp312    conda-forge
pytz                      2024.1             pyhd8ed1ab_0    conda-forge
pyyaml                    6.0.2           py312h66e93f0_1    conda-forge
pyzmq                     26.0.3          py312h8fd38d8_0    conda-forge
qhull                     2020.2               h434a139_3    conda-forge
qt-main                   5.15.8              ha2b5568_22    conda-forge
re2                       2023.09.01           h7f4b329_2    conda-forge
readline                  8.2                  h8228510_1    conda-forge
readme_renderer           42.0               pyhd8ed1ab_0    conda-forge
referencing               0.35.1             pyhd8ed1ab_0    conda-forge
requests                  2.32.3             pyhd8ed1ab_0    conda-forge
requests-toolbelt         1.0.0              pyhd8ed1ab_0    conda-forge
restructuredtext_lint     1.4.0              pyhd8ed1ab_0    conda-forge
rfc3986                   2.0.0              pyhd8ed1ab_0    conda-forge
rich                      13.7.1             pyhd8ed1ab_0    conda-forge
rpds-py                   0.19.0          py312hf008fa9_0    conda-forge
ruff                      0.5.1           py312hbe4c86d_0    conda-forge
s2n                       1.5.3                h7b32b05_0    conda-forge
scikit-learn              1.5.2           py312h7a48858_1    conda-forge
scipy                     1.14.1          py312h7d485d2_0    conda-forge
secretstorage             3.3.3           py312h7900ff3_2    conda-forge
setuptools                70.2.0             pyhd8ed1ab_0    conda-forge
sip                       6.7.12          py312h30efb56_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
snappy                    1.2.1                ha2e4443_0    conda-forge
snowballstemmer           2.2.0              pyhd8ed1ab_0    conda-forge
sortedcontainers          2.4.0              pyhd8ed1ab_0    conda-forge
soupsieve                 2.5                pyhd8ed1ab_1    conda-forge
sphinx                    7.2.6              pyhd8ed1ab_0    conda-forge
sphinx-book-theme         1.1.3              pyhd8ed1ab_0    conda-forge
sphinx-copybutton         0.5.2              pyhd8ed1ab_0    conda-forge
sphinx-design             0.5.0              pyhd8ed1ab_0    conda-forge
sphinxcontrib-applehelp   1.0.8              pyhd8ed1ab_0    conda-forge
sphinxcontrib-devhelp     1.0.6              pyhd8ed1ab_0    conda-forge
sphinxcontrib-htmlhelp    2.0.5              pyhd8ed1ab_0    conda-forge
sphinxcontrib-jsmath      1.0.1              pyhd8ed1ab_0    conda-forge
sphinxcontrib-qthelp      1.0.7              pyhd8ed1ab_0    conda-forge
sphinxcontrib-serializinghtml 1.1.10             pyhd8ed1ab_0    conda-forge
stack_data                0.6.2              pyhd8ed1ab_0    conda-forge
stdlib-list               0.10.0             pyhd8ed1ab_0    conda-forge
tabulate                  0.9.0              pyhd8ed1ab_1    conda-forge
tblib                     3.0.0              pyhd8ed1ab_0    conda-forge
threadpoolctl             3.5.0              pyhc1e730c_0    conda-forge
tinycss2                  1.3.0              pyhd8ed1ab_0    conda-forge
tk                        8.6.13          noxft_h4845f30_101    conda-forge
toml                      0.10.2             pyhd8ed1ab_0    conda-forge
tomli                     2.0.1              pyhd8ed1ab_0    conda-forge
toolz                     0.12.1             pyhd8ed1ab_0    conda-forge
tornado                   6.4.1           py312h9a8786e_0    conda-forge
traitlets                 5.14.3             pyhd8ed1ab_0    conda-forge
twine                     5.1.1              pyhd8ed1ab_0    conda-forge
typing-extensions         4.12.2               hd8ed1ab_0    conda-forge
typing_extensions         4.12.2             pyha770c72_0    conda-forge
tzdata                    2024a                h0c530f3_0    conda-forge
urllib3                   2.2.2              pyhd8ed1ab_1    conda-forge
verde                     1.8.1              pyhd8ed1ab_0    conda-forge
wcwidth                   0.2.13             pyhd8ed1ab_0    conda-forge
webencodings              0.5.1              pyhd8ed1ab_2    conda-forge
wheel                     0.43.0             pyhd8ed1ab_1    conda-forge
widgetsnbextension        4.0.11             pyhd8ed1ab_0    conda-forge
xarray                    2024.9.0           pyhd8ed1ab_0    conda-forge
xcb-util                  0.4.1                hb711507_2    conda-forge
xcb-util-image            0.4.0                hb711507_2    conda-forge
xcb-util-keysyms          0.4.1                hb711507_0    conda-forge
xcb-util-renderutil       0.3.10               hb711507_0    conda-forge
xcb-util-wm               0.4.2                hb711507_0    conda-forge
xkeyboard-config          2.42                 h4ab18f5_0    conda-forge
xorg-kbproto              1.0.7             h7f98852_1002    conda-forge
xorg-libice               1.1.1                hd590300_0    conda-forge
xorg-libsm                1.2.4                h7391055_0    conda-forge
xorg-libx11               1.8.9                hb711507_1    conda-forge
xorg-libxau               1.0.11               hd590300_0    conda-forge
xorg-libxdmcp             1.1.3                h7f98852_0    conda-forge
xorg-libxext              1.3.4                h0b41bf4_2    conda-forge
xorg-libxrender           0.9.11               hd590300_0    conda-forge
xorg-renderproto          0.11.1            h7f98852_1002    conda-forge
xorg-xextproto            7.3.0             h0b41bf4_1003    conda-forge
xorg-xf86vidmodeproto     2.3.1             h7f98852_1002    conda-forge
xorg-xproto               7.0.31            h7f98852_1007    conda-forge
xyzservices               2024.9.0           pyhd8ed1ab_0    conda-forge
xz                        5.2.6                h166bdaf_0    conda-forge
yaml                      0.2.5                h7f98852_2    conda-forge
zeromq                    4.3.5                h75354e8_4    conda-forge
zict                      3.0.0              pyhd8ed1ab_0    conda-forge
zipp                      3.19.2             pyhd8ed1ab_0    conda-forge
zlib                      1.3.1                h4ab18f5_1    conda-forge
zstandard                 0.22.0          py312h5b18bf6_1    conda-forge
zstd                      1.5.6                ha6fb4c9_0    conda-forge

santisoler commented 3 weeks ago

I think I tracked down what's going on with this. The issue is coming when evaluating the kernel_en function, and particularly the safe_log, and due to machine precision.

The issue arises when evaluating the kernel on the two prism vertices that fall below the observation point (the two nodes marked in green circles):

Untitled-2024-10-01-0908

When the observation point falls exactly above the nodes, the kernels are well evaluated and the result is correct.

But when the observation point is slightly away from it, then the evaluation on the nodes falls into a problem:

This leads to evaluate the kernels on this two nodes using different branches of the safe_log function and therefore creating this discontinuity.

I'll think how we can solve this and comment back with some ideas.

santisoler commented 3 weeks ago

I think I arrived to a solution for it.

The issue is generated when two independent calls to _safe_log interpret that the observation point is not above one of the nodes (the closest one to it), while it interprets that it is above the other one. This is because for the first one the r is not equal to x (x could be equal to -50.0 and r will be something like 50.00000001 -just a minor difference in in machine precision). But for the other node, r and x have the same absolute value (e.g. x is -70.0 and r is 70.0).

This triggers that two different branches of the safe_log function are being executed: one that evaluates the actual log function, and the other one that evaluates one of the terms of the limits of the kernel function. This creates an inconsistency: their difference is not the value of the analytic solution on that point.

One way to solve this would be to make _safe_log to not only take the x and the r, but all the shifted coordinates. This way we can ensure that $|x| = r$ by checking if y == 0 and z == 0. This way, even if r and |x| have the same value up to machine precision, we will not neglect the non-zero values of the other components.

Moreover, since we are taking y and z as arguments, we can use the form of the log function that Fukushima suggests for cases in which $x < 0, r \ne |x|$:

$$ \ln(x + r) = \ln \left( \frac{y^2 + z^2}{r - x} \right) \quad x < 0, r \ne |x|$$

This form avoid some floating point errors that appear when trying to evaluate the log on x + r.

I'll open a PR with the bugfix.