New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 12 commits into from Nov 24, 2014

Conversation

Projects
None yet
2 participants
@leouieda
Member

leouieda commented Nov 20, 2014

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

leouieda added some commits Nov 12, 2014

New Moulder GUI with more interaction
Allows editing points, setting densities, selecting/deleting polygons
and points, etc.
Few plotting bugfixes
Reload the predicted data from file as well.
Set animated=False before saving so that all polygons are plotted on
reload.
Pickle vertices instead of matplotlib polygon
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__.

leouieda added some commits Nov 23, 2014

Removed the fatiando.gui package
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

leouieda added some commits Nov 23, 2014

@coveralls

This comment has been minimized.

coveralls commented Nov 23, 2014

Coverage Status

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

leouieda added some commits Nov 23, 2014

Merge branch 'master' into new-moulder
Conflicts:
	README.md
@coveralls

This comment has been minimized.

coveralls commented Nov 23, 2014

Coverage Status

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

@coveralls

This comment has been minimized.

coveralls commented Nov 23, 2014

Coverage Status

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

@coveralls

This comment has been minimized.

coveralls commented Nov 23, 2014

Coverage Status

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

Fix model out of plot error when resizing the plot
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

This comment has been minimized.

coveralls commented Nov 23, 2014

Coverage Status

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

@leouieda

This comment has been minimized.

Member

leouieda commented Nov 23, 2014

@leouieda

This comment has been minimized.

Member

leouieda commented Nov 23, 2014

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.

Merge branch 'master' into new-moulder
Conflicts:
	doc/changelog.rst

leouieda added a commit that referenced this pull request Nov 24, 2014

Merge pull request #143 from fatiando/new-moulder
Rewrote the Moulder class for interactive 2D gravity modeling

@leouieda leouieda merged commit 26de0d7 into master Nov 24, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details

@leouieda leouieda deleted the new-moulder branch Nov 24, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment