Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

Convert gravmag.prism Cython code to numpy #398

Closed
wants to merge 3 commits into from
Closed

Conversation

leouieda
Copy link
Member

@leouieda leouieda commented May 20, 2017

Following what was done for polyprism in #368 and sphere in #364.
Also implements a regression test using saved data from a simple 1 prism model.

This is the benchmark script used:

from __future__ import division, print_function
import sys
import numpy as np
from fatiando import gridder, utils
from fatiando.mesher import PrismMesh
from fatiando.gravmag import prism
# Get processor information
tmp = !cat /proc/cpuinfo | grep "model name"
processor = tmp[0].split(':')[1].strip()
print(processor)
# Make a model for testing
model = PrismMesh((0, 1000, 0, 2000, 0, 500), (5, 3, 8))
model.addprop('density', 1000*np.ones(model.size))
model.addprop('magnetization', utils.ang2vec(2*np.ones(model.size), 25, -10))
inc, dec = -30, 50
x, y, z = gridder.regular((-500, 500, -500, 500), (50, 50), z=-1)
print('Model size: {}'.format(model.size))
print('Grid size: {}'.format(x.size))
# Time the forward modeling of gravity, gradients and mag
print('Times:')
if len(sys.argv) == 1:
    fields = 'potential gx gy gz gxx gxy gxz gyy gyz gzz tf bz bx by'.split()
else:
    fields = sys.argv[1:]
for field in fields:
    print('  {}: '.format(field), end='')
    if field == 'tf':
        args = (x, y, z, model, inc, dec)
    else:
        args = (x, y, z, model)
    %timeit -n 10 getattr(prism, field)(*args)

These are the results for the master branch:

Intel(R) Core(TM) i5-4200U CPU @ 1.60GHz
Model size: 120
Grid size: 2500
Times:
  potential: 10 loops, best of 3: 776 ms per loop
  gx: 10 loops, best of 3: 435 ms per loop
  gy: 10 loops, best of 3: 443 ms per loop
  gz: 10 loops, best of 3: 420 ms per loop
  gxx: 10 loops, best of 3: 201 ms per loop
  gxy: 10 loops, best of 3: 198 ms per loop
  gxz: 10 loops, best of 3: 220 ms per loop
  gyy: 10 loops, best of 3: 228 ms per loop
  gyz: 10 loops, best of 3: 235 ms per loop
  gzz: 10 loops, best of 3: 221 ms per loop
  tf: 10 loops, best of 3: 769 ms per loop
  bz: 10 loops, best of 3: 408 ms per loop
  bx: 10 loops, best of 3: 420 ms per loop
  by: 10 loops, best of 3: 415 ms per loop

Checklist:

  • Make tests for new code (at least 80% coverage)
  • Create/update docstrings
  • Include relevant equations and citations in docstrings
  • Docstrings follow the style conventions
  • Code follows PEP8 style conventions
  • Code and docs have been spellchecked
  • Include new dependencies in doc/install.rst, environment.yml, ci/requirements.txt.
  • Documentation builds properly (run cd doc; make locally)
  • Changelog entry (leave for last to avoid conflicts)

Uses saved data from a simple 1 prism model to check for regressions in
the code. Same as done for polyprism in #368 and sphere in #364.
@leouieda leouieda added this to the 0.6 milestone May 20, 2017
Need to fix gradient components with singularities.
@MohAbdrabou
Copy link

You can provide me script for calculating gravity due to 3d prism using Plouff or Nagy formula

@leouieda leouieda closed this Jun 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants