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

Add copy method to mesher classes#301

Merged
leouieda merged 13 commits into
fatiando:masterfrom
PiotrKurnik:copy_of_Square
Aug 31, 2016
Merged

Add copy method to mesher classes#301
leouieda merged 13 commits into
fatiando:masterfrom
PiotrKurnik:copy_of_Square

Conversation

@PiotrKurnik
Copy link
Copy Markdown
Member

@PiotrKurnik PiotrKurnik commented Jul 17, 2016

Fixes #284

I added copy method to Square. Also I wrote some tests. This is for a try, if OK I will make further changes.

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, requirements.txt, environment.yml, ci/requirements-conda.txt and ci/requirements-pip.txt.
  • Documentation builds properly (run cd doc; make locally)
  • Changelog entry (leave for last to avoid conflicts)
  • Firt-time contributor? Add yourself to doc/contributors.rst (leave for last to avoid conflicts)

@leouieda
Copy link
Copy Markdown
Member

Thank you for doing this! The code and tests are looking pretty good! I don't think there is much else to do but a few minor changes and documentation.

The reason Travis CI is failing is because of the style check (PEP8). See here for the error log. You just have one too many lines after the copy method. You can run make pep8 locally to check this.

One other thing I would ask is that you rename your test file to test_square.py because it will contain only the tests for Square.


def test_square_copy():
orig = Square([0, 1, 2, 4], {'density': 750})
cp = orig.copy()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another check you do is to check is an object is the same reference as another using the is comparison: cp is not orig.

Two objects might be equal but not be the same object.

@leouieda leouieda added this to the 0.5 milestone Jul 18, 2016
@leouieda
Copy link
Copy Markdown
Member

@PiotrKurnik let me know when you make some of these changes so that I can take a look. No pressure and no hurry 😄

One things I forgot to mention is that the copy method needs a docstring. Please try to follow the style of the others. See http://www.fatiando.org/dev/develop.html#documentation for a specification.

@PiotrKurnik
Copy link
Copy Markdown
Member Author

@leouieda I have added copy to other classes and I have written a few more tests. It's not finished yet, just wanted to see if Travis will pass the tests. It shouldn't take long to complete this.

@leouieda
Copy link
Copy Markdown
Member

@PiotrKurnik OK! Let me know when you're finished and I'll review the code to see if there is anything else needed.

Great job on this!


def test_prism_mesh_copy():
p1 = PrismMesh((0, 1, 0, 2, 0, 3), (1, 2, 2))
p1.addprop('density', 3200)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the mesh classes in Fatiando, the physical properties are arrays of values (one for each cell in the mesh). Could you test this using arrays? You can create the array with something like p1.addprop('density', 3200 + np.zeros(p1.size))

@leouieda
Copy link
Copy Markdown
Member

leouieda commented Aug 4, 2016

@PiotrKurnik one thing I just remembered, all basic geometric types (Square, Prism etc but not PrismMesh etc) inherit from GeometricElemennt. So you can implement the copy method there and they will all get it through inheritance. Sorry it took me so long to spot this. I've haven't looked at the mesher code for quite some time.

@PiotrKurnik
Copy link
Copy Markdown
Member Author

@leouieda Good spot! I have pushed the code. Let's see if it's any closer now.

@leouieda leouieda modified the milestones: 0.5, 0.6 Aug 23, 2016
Comment thread fatiando/mesher.py Outdated
def copy(self):
""" Return a deep copy of the current instance."""
return cp.deepcopy(self)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this one since Polygon will inherit it from GeometricElement.

@leouieda
Copy link
Copy Markdown
Member

@PiotrKurnik all looks good! Just made a few minor comments. Once those are done let me know and I'll hapilly merge this. Thank you for putting time into this!

@PiotrKurnik
Copy link
Copy Markdown
Member Author

Thanks @leouieda. I am sorry it took so long.

Comment thread doc/contributors.rst Outdated
* `Martin Bentley`_ - Nelson Mandela Metropolitan University, South Africa and AEON, South Africa
* `Victor Almeida`_ - UERJ, Brazil.
* `M. Andy Kass`_ - United States Geological Survey, USA
* `Piotr Kurnik`_ - United Kingdom
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to link your name to some page (a personal page, github profile, etc)? If so, add the link to the lines below like the other contributors. If not, you can remove the back tics and the underline.

Sorry that I didn't see this before.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the back ticks.

@leouieda
Copy link
Copy Markdown
Member

@PiotrKurnik no problem! We're all busy with other work and I'm the last one that can complain.

Comment thread doc/changelog.rst Outdated
the `Python Packaging User Guide <https://packaging.python.org/>`__.
(`PR 294 <https://github.com/fatiando/fatiando/pull/294>`__)
* Enable ``fatiando.mesher.PointGrid`` to have points at different depths by
* Enable ``fatiando.mesher.PointGrid`a` to have points at different depths by
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like an a was inserted here by mistake. Could you please delete it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no idea where it came from ....

@leouieda
Copy link
Copy Markdown
Member

@PiotrKurnik everything builds properly on my machine and we're ready to merge!

@leouieda leouieda modified the milestones: 0.5, 0.6 Aug 31, 2016
@leouieda leouieda changed the title Copy of square Add copy method to mesher classes Aug 31, 2016
@leouieda leouieda merged commit 84d511e into fatiando:master Aug 31, 2016
@leouieda
Copy link
Copy Markdown
Member

@PiotrKurnik merged! Congratulations on your first contribution (of many I hope)!

@leouieda leouieda mentioned this pull request Sep 13, 2016
10 tasks
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.

2 participants