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

Rewrote the Moulder class for interactive 2D gravity modeling #143

Merged
merged 12 commits into from Nov 24, 2014

Conversation

leouieda
Copy link
Member

The fatiando.gui.simple.Moulder class created an interactive matplotlib window for drawing polygons and calculating their gravitational effect (using fatiando.gravmag.talwani). The functionality was very limited: could not edit polygons after they were drawn, orresume the app once the window was closed, or save the app state for loading later, etc.

I have rewritten the Moulder class to allow all of this. You can now:

  • Move the polygon and its vertices
  • Change the density
  • Delete polygons and vertices
  • Save the app state to a pickle file (Moulder.save)
  • Save the predicted data to a text (XYZ) file (Moulder.save_predicted)
  • Create a new instance of Moulder from the pickled state (Moulder.load)
  • Insert a plot of the data and model into the IPython notebook (`Moulder.plot)

You can see this class in action in the 5th practical class of Geofísica 1: pratica5.ipynb. You'll to have this branch active on your local clone to run the notebook.

Here is a screenshot of the GUI window.

figure 1_001

Problems and discussion

The new code breaks the BasinTri and BasinTrap classes that relied on the old Moulder.

I'm inclined to delete these classes (and the Lasagne class as well) because they can be easily replaced (and improved) by IPython widgets.

This raises the question: Should we even keep the fatiando.gui package? It is a tiny and virtually unused package. Things in it could easily be moved to other packages (Moulder could go into a fatiando.gravmag).

I think a better package structure would be to have interactive modules in the method packages (e.g., gravmag.interactive) where the GUIs and widgets could live.

I'd like some input on this, please, @birocoles, @eusoubrasileiro, @hbueno.

TODO

  • There is a problem when resizing the window and then calling plot.
    Polygons get left out of the scene. Maybe make a "window close" callback that
    removes the animate flags and redraws the scene?
  • Add IPython as a dependency

Checklist

  • Make tests for new code (haven't figured out a way to test interactive code)
  • Create/update docstrings
  • Code follows PEP8 style conventions
  • Code and docs have been spell-checked
  • Changelog entry
  • Documentation builds properly
  • All tests pass
  • Can be merged

Allows editing points, setting densities, selecting/deleting polygons
and points, etc.
Reload the predicted data from file as well.
Set animated=False before saving so that all polygons are plotted on
reload.
Was having trouble under windows to pickle the
matplotlib.patches.Polygon. So storing the vertices in the pickle and
recreating the polygons and lines in __init__.
Moved the Moulder class to gravmag.interactive. Deleted the other
classes and their respective cookbook recipes.

Updated docs accordingly.
@leouieda leouieda added this to the 0.4 milestone Nov 23, 2014
@coveralls
Copy link

Coverage Status

Coverage decreased (-2.87%) when pulling a71e20b on new-moulder into 3918e9d on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.87%) when pulling 14fe7f3 on new-moulder into 32af5c0 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 14fe7f3 on new-moulder into 32af5c0 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling fd00e0a on new-moulder into 32af5c0 on master.

When the plot window was resized during modeling, the 'plot'  method was
drawing polygons out of the modelax borders. The same was happening when
calling 'run' again.
Fixed by recreating the polygon and line objects on figure_setup.
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 8efe5e3 on new-moulder into 32af5c0 on master.

@leouieda
Copy link
Member Author

I have made a tutorial notebook using the new Moulder class: http://nbviewer.ipython.org/github/fatiando/tutorials/blob/master/Interactive_gravmag_modeling.ipynb

@leouieda
Copy link
Member Author

So in the end I've deleted the fatiando.gui package in favor of package specific interactive modules, like gravmag.interactive. The only class I've kept is Moulder. The others will be replaced by IPython widgets if the need arises.

Conflicts:
	doc/changelog.rst
leouieda added a commit that referenced this pull request Nov 24, 2014
Rewrote the Moulder class for interactive 2D gravity modeling
@leouieda leouieda merged commit 26de0d7 into master Nov 24, 2014
@leouieda leouieda deleted the new-moulder branch November 24, 2014 16:01
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