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

Error when using PrismMesh.carvetopo because of matplotlib.mlab.griddata #146

Closed
hbueno opened this issue Nov 24, 2014 · 5 comments
Closed
Assignees
Labels
Milestone

Comments

@hbueno
Copy link
Member

hbueno commented Nov 24, 2014

The topography/relief defined to mask (remove) prisms from the mesh need to be interpolated. The mesher.carvetopo use by default the Natural Neighbor interpolation in matplotlib.mlab.griddata. However, when I try to run, for example, the cookbook mesher_prismmesh_topo.py, a RuntimeError suggests to intall natgrid or change the interpolation method to linear.

Traceback (most recent call last):
  File "mesher_prismmesh_topo.py", line 18, in <module>
    mesh.carvetopo(x, y, height)
  File "/Users/hbueno/src/fatiando/fatiando/mesher.py", line 1205, in carvetopo
   topo = matplotlib.mlab.griddata(x, y, height, XC, YC).ravel()
  File "/Users/hbueno/anaconda/lib/python2.7/site-packages/matplotlib/mlab.py", line 3443, in griddata
   raise RuntimeError("To use interp='nn' (Natural Neighbor "
RuntimeError: To use interp='nn' (Natural Neighbor interpolation) in griddata, natgrid must be installed.  Either install it from http://sourceforge.net/projects/matplotlib/files/matplotlib-toolkits, or use interp='linear' instead.

I've installed Fatiando with conda as well as all the dependencies and passed in all tests.

@hbueno
Copy link
Member Author

hbueno commented Nov 24, 2014

I was using matplotlib=1.4. A possible solution to fix the RuntimeError it was to downgrade to matplotlib=1.3.1 (and consequently to numpy-1.8.2).

@leouieda
Copy link
Member

Copying text by @hbueno from #147 here:

@leouieda I'm opening this issue to "discuss" about some dependencies of Fatiando. To be sincere I don't know if it's the case to open another issue or not, but I'm trying to be more organized (and you always can close it!).

As I pointed in this issue #146, I was using matplotlib=1.4 and its dependencies (all installed with conda) without problems until I needed to use the mesher.carvetopo.

Two "possible" solutions I've found:

  1. to downgrade to matplotlib=1.3.1 which requires numpy-1.8.2.
  2. to install natgrid which requires a separate installation of the natgrid toolkit from the sourceforge download page.

I chose (1) to be easily done with conda and because I don't know another alternative. Anyway, let's suppose this is right, I think we should change the list of Fatiando dependencies. For example, where is matplotlib >= 1.3 change to matplotlib = 1.3 (removing >), or maybe put some temporary warning for who intend to use the matplotlib >= 1.3. Anyway, I'm writing because I've failed when I tried to install natgrid with conda (I now I know why) and as I know, for Fatiando it's interesting that all the dependencies be quickly installed with conda. But please, let me know if you think I'm talking nonsense or doing something wrong ;)

@leouieda
Copy link
Member

The problem seems to be that matplotlib no longer ships natgrid with it. I don't know why this only happens in MacOS (I'm using on Ubuntu and it works fine).

Since the problem is the matplotlib.mlab.griddata functions, we can just replace it by scipy.interpolate.griddata. It has no Nearest Neighbors but that is not a very good interpolation for geophysics anyways. That would actually make the code in fatiando.gridder.interp cleaner. It already uses scipy instead of mlab for all other methods and only calls mlab if `algorithm='nn' (which is not the default anymore).

Fixing would be a simple case of replacing all calls to matplotlib.mlab.griddata with the appropriate call to scipy.interpolate.griddata.

@hbueno, do you want to try to fix this?

@leouieda leouieda added this to the 0.4 milestone Nov 24, 2014
@leouieda leouieda changed the title RuntimeError in mesher.carvetopo Error when using PrismMesh.carvetopo because of matplotlib.mlab.griddata Nov 24, 2014
@hbueno
Copy link
Member Author

hbueno commented Nov 24, 2014

Sure, I can try.

@leouieda
Copy link
Member

leouieda commented Dec 9, 2014

#148 fixed this.

@leouieda leouieda closed this as completed Dec 9, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants