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

Error in estimating magnetization direction with Fatiando #416

Open
IsabelaOM opened this issue Nov 22, 2017 · 7 comments
Open

Error in estimating magnetization direction with Fatiando #416

IsabelaOM opened this issue Nov 22, 2017 · 7 comments

Comments

@IsabelaOM
Copy link

IsabelaOM commented Nov 22, 2017

Hello! I'm trying to run the cookbook code gravmag_magdir_dipolemagdir.py from fatiando 0.3, but I get an error related to the script sphere.py.

That is the code:

"""
GravMag: Use the DipoleMagDir class to estimate the magnetization direction
of dipoles with known centers
"""
import numpy

from fatiando import mesher, gridder
from fatiando.utils import ang2vec, vec2ang, contaminate
from fatiando.gravmag import sphere
from fatiando.vis import mpl
from fatiando.gravmag.magdir import DipoleMagDir
from fatiando.constants import CM

# Make noise-corrupted synthetic data
inc, dec = -10.0, -15.0  # inclination and declination of the Geomagnetic Field
model = [mesher.Sphere(3000, 3000, 1000, 1000,
                       {'magnetization': ang2vec(6.0, -20.0, -10.0)}),
         mesher.Sphere(7000, 7000, 1000, 1000,
                       {'magnetization': ang2vec(10.0, 3.0, -67.0)})]
area = (0, 10000, 0, 10000)
x, y, z = gridder.scatter(area, 1000, z=-150, seed=0)
tf = contaminate(sphere.tf(x, y, z, model, inc, dec), 5.0, seed=0)

# Give the centers of the dipoles
centers = [[3000, 3000, 1000], [7000, 7000, 1000]]

# Estimate the magnetization vectors
solver = DipoleMagDir(x, y, z, tf, inc, dec, centers).fit()

# Print the estimated and true dipole monents, inclinations and declinations
print 'Estimated magnetization (intensity, inclination, declination)'
for e in solver.estimate_:
    print e

# Plot the fit and the normalized histogram of the residuals
mpl.figure(figsize=(14, 5))
mpl.subplot(1, 2, 1)
mpl.title("Total Field Anomaly (nT)", fontsize=14)
mpl.axis('scaled')
nlevels = mpl.contour(y, x, tf, (50, 50), 15, interp=True, color='r',
                      label='Observed', linewidth=2.0)
mpl.contour(y, x, solver.predicted(), (50, 50), nlevels, interp=True,
            color='b', label='Predicted', style='dashed', linewidth=2.0)
mpl.legend(loc='upper left', shadow=True, prop={'size': 13})
mpl.xlabel('East y (m)', fontsize=14)
mpl.ylabel('North x (m)', fontsize=14)
mpl.subplot(1, 2, 2)
residuals_mean = numpy.mean(solver.residuals())
residuals_std = numpy.std(solver.residuals())
# Each residual is subtracted from the mean and the resulting
# difference is divided by the standard deviation
s = (solver.residuals() - residuals_mean) / residuals_std
mpl.hist(s, bins=21, range=None, normed=True, weights=None,
         cumulative=False, bottom=None, histtype='bar', align='mid',
         orientation='vertical', rwidth=None, log=False,
         color=None, label=None)
mpl.xlim(-4, 4)
mpl.title("mean = %.3f    std = %.3f" % (residuals_mean, residuals_std),
          fontsize=14)
mpl.ylabel("P(z)", fontsize=14)
mpl.xlabel("z", fontsize=14)
mpl.show()

And that is the error:

  File "C:\Users\Auriluce\Anaconda2\lib\site-packages\fatiando\gravmag\sphere.py", line 522, in gxx
    _sphere.gxx(xp, yp, zp, sphere.x, sphere.y, sphere.z, sphere.radius,

AttributeError: 'NoneType' object has no attribute 'gxx'

Is there a problem with the code sphere.py?

@leouieda
Copy link
Member

@IsabelaOM thanks for reporting the error!

This error happens when there was a problem installing Fatiando. The sphere code is looking for compiled modules that don't exist. Do you remember all the steps you took to install Fatiando?

@IsabelaOM
Copy link
Author

I have made a mistake in installation... I'll try to fix it now. Thank you!

@leouieda
Copy link
Member

@IsabelaOM please follow these instructions to get v0.5: http://www.fatiando.org/install.html#installing-with-conda

@IsabelaOM
Copy link
Author

I need to install version 0.3, specifically, according to "https://github.com/pinga-lab/Total-magnetization-of-spherical-bodies". How can I do that?
I tried "conda install fatiando==0.3" but the package is not found.

@leouieda
Copy link
Member

Oh, OK. We only started making conda packages after 0.4 so you'll have to install using pip. This requires that you have the Microsoft Visual Studio compiler. See http://www.fatiando.org/install.html#installing-with-pip for instructions for installing using pip on Windows.

@IsabelaOM
Copy link
Author

IsabelaOM commented Nov 23, 2017

I keep getting this error when I try to install Fatiando v0.3:
error: command 'C:\Users\Isabela\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\link.exe' failed with exit status 1

I installed and reinstalled Microsoft Visual C++ for Python, but it did not work.

@leouieda
Copy link
Member

@IsabelaOM I'm sorry that this doesn't work for you. I think that it might be an issue with the versions of some libraries. Though I think tracking this down might be a lot harder than installing fatiando 0.5 and giving it a try. I would wager that most things in that paper will work without any problems. Feel free to ask in the chat if you need more help getting this to work.

This is a lesson for us that in order to get a reproducible environment for computation we really need to record all the versions of dependencies we used. I have been trying that with more recent publications but with this current one we were still experimenting with putting the code on Github. We'll keep this in mind for our newer publications.

Thanks for reporting this and for trying to reproduce the results!

cc @birocoles @santis19

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants