Skip to content
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

Lambert projection #214

Merged
merged 60 commits into from
Sep 15, 2020
Merged

Lambert projection #214

merged 60 commits into from
Sep 15, 2020

Conversation

friedkitteh
Copy link
Collaborator

@friedkitteh friedkitteh commented Sep 10, 2020

Description of the change

Continuation of the Gnomonic and Spherical projections already implemented.
Allows for the transformation of a vector from Cartesian coordiantes to the Lambert projection.
Also allows for transformation both ways between Gnomonic and Lambert projections.

Progress of the PR

Minimal example of the bug fix or new feature

>>> from kikuchipy.projections.lambert_projection import LambertProjection
>>># From Cartesian to Lambert
>>>my_cartesian_vector = np.array((1,1,1))
>>>my_lambert_vector = LambertProjection.project(my_cartesian_vector)
>>>
>>># From Lambert to Cartesian
>>>my_lambert_vector = np.array((1,1))
>>>my_cartesian_vector = LambertProjection.iproject(my_lambert_vector)
>>>
>>># From Lambert to Gnomonic
>>>my_lambert_vector = np.array((1,1))
>>>my_gnomonic_vector = LambertProjection.lambert_to_gnomonic(my_lambert_vector)
>>>
>>># From Gnomonic to Lambert
>>>my_gnomonic_vector = np.array((1,1))
>>>my_lambert_vector = LambertProjection.gnomonic_to_lambert(my_gnomonic_vector)
>>>

For reviewers

  • Check that the PR title is short, concise, and will make sense 1 year
    later.
  • Check that new functions are imported in corresponding __init__.py.
  • Check that new features, API changes, and deprecations are mentioned in
    the unreleased section in doc/changelog.rst.

…jection.project to a class method. Might not be ok as is!!
…ection.project to a class method. Might not be ok as is!!
@friedkitteh friedkitteh added bug Something isn't working enhancement New feature or request work in progress labels Sep 10, 2020
@friedkitteh friedkitteh added this to the v0.3.0 milestone Sep 10, 2020
@friedkitteh friedkitteh marked this pull request as draft September 10, 2020 12:35
@hakonanes
Copy link
Member

hakonanes commented Sep 10, 2020

This is a great addition to the projection capabilities, thanks for this @friedkitteh!

Good catch with the ".py" endings in __init__.py, and the need for GnomonicProjection.project() to be a classmethod.

Let me know when you need feedback.

@friedkitteh
Copy link
Collaborator Author

Ok, finally! I think I am pretty happy with how it turned out now - it is (imo) a lot more compact, neat and clear and should be ready for review! 👍

@friedkitteh
Copy link
Collaborator Author

I can also add that it passed all 8 tests in 0.15s, I did not want to wake Travis for now..

Updated methods to follow PEP8
Swapped some test methods with numpy.allclose(). Pytest.approx() still used mostly due to simplicity.

[skip ci]
@friedkitteh
Copy link
Collaborator Author

Numpy.where()
Vectors: 990
26 function calls in 0.002 seconds

Ordered by: standard name

ncalls tottime percall cumtime percall filename:lineno(function)
3 0.000 0.000 0.000 0.000 <array_function internals>:2(where)
1 0.000 0.000 0.002 0.002 :1()
3 0.000 0.000 0.000 0.000 multiarray.py:311(where)
4 0.000 0.000 0.000 0.000 temp_test_file_ignore.py:19(_eq_c)
1 0.000 0.000 0.002 0.002 temp_test_file_ignore.py:6(mA)
6 0.000 0.000 0.000 0.000 {built-in method builtins.abs}
1 0.000 0.000 0.002 0.002 {built-in method builtins.exec}
1 0.000 0.000 0.000 0.000 {built-in method builtins.len}
1 0.000 0.000 0.000 0.000 {built-in method builtins.print}
1 0.001 0.001 0.001 0.001 {built-in method numpy.array}
3 0.000 0.000 0.000 0.000 {built-in method numpy.core._multiarray_umath.implement_array_function}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}

For-loop
Vectors: 990
4961 function calls in 0.032 seconds

Ordered by: standard name

ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.032 0.032 :1()
1980 0.012 0.000 0.012 0.000 temp_test_file_ignore.py:19(_eq_c)
1 0.002 0.002 0.032 0.032 temp_test_file_ignore.py:24(mB)
990 0.015 0.000 0.028 0.000 temp_test_file_ignore.py:51(_setCartesian)
1980 0.000 0.000 0.000 0.000 {built-in method builtins.abs}
1 0.000 0.000 0.032 0.032 {built-in method builtins.exec}
2 0.000 0.000 0.000 0.000 {built-in method builtins.len}
1 0.000 0.000 0.000 0.000 {built-in method builtins.print}
1 0.002 0.002 0.002 0.002 {built-in method numpy.array}
3 0.000 0.000 0.000 0.000 {built-in method numpy.zeros}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}

##############################################################################################
An increase from 990 vectors to 2970 vectors:
##############################################################################################

Numpy.where()
Vectors: 2970
26 function calls in 0.043 seconds

Ordered by: standard name

ncalls tottime percall cumtime percall filename:lineno(function)
3 0.000 0.000 0.000 0.000 <array_function internals>:2(where)
1 0.000 0.000 0.043 0.043 :1()
3 0.000 0.000 0.000 0.000 multiarray.py:311(where)
4 0.000 0.000 0.000 0.000 temp_test_file_ignore.py:19(_eq_c)
1 0.001 0.001 0.043 0.043 temp_test_file_ignore.py:6(mA)
6 0.000 0.000 0.000 0.000 {built-in method builtins.abs}
1 0.000 0.000 0.043 0.043 {built-in method builtins.exec}
1 0.000 0.000 0.000 0.000 {built-in method builtins.len}
1 0.000 0.000 0.000 0.000 {built-in method builtins.print}
1 0.042 0.042 0.042 0.042 {built-in method numpy.array}
3 0.000 0.000 0.000 0.000 {built-in method numpy.core._multiarray_umath.implement_array_function}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}

For-loop
Vectors: 2970
14861 function calls in 0.586 seconds

Ordered by: standard name

ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.586 0.586 :1()
5940 0.190 0.000 0.190 0.000 temp_test_file_ignore.py:19(_eq_c)
1 0.009 0.009 0.586 0.586 temp_test_file_ignore.py:24(mB)
2970 0.380 0.000 0.571 0.000 temp_test_file_ignore.py:51(_setCartesian)
5940 0.002 0.000 0.002 0.000 {built-in method builtins.abs}
1 0.000 0.000 0.586 0.586 {built-in method builtins.exec}
2 0.000 0.000 0.000 0.000 {built-in method builtins.len}
1 0.000 0.000 0.000 0.000 {built-in method builtins.print}
1 0.005 0.005 0.005 0.005 {built-in method numpy.array}
3 0.000 0.000 0.000 0.000 {built-in method numpy.zeros}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}

@hakonanes
Copy link
Member

Great that you timed it! Is this ready for review? I think you should be allowed to request a review from me under the "Reviewers" part of the sidebar?

Copy link
Member

@hakonanes hakonanes left a comment

Choose a reason for hiding this comment

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

Nice implementation of the Lambert projection from Callahan and De Graef (2013)! This will be used a lot. Also thankful for your fixes of other typos in the other projections.

I have three suggestions for improvements: adding a reference to the above mentioned paper, a change which might save some microseconds, and a correction of a "syntax wording". See more detailed comments below.

I have in addition some minor style comments which are unimportant and you can do with as you see fit.

After this we'll merge and I will set up a "Projections" user guide page, which you might want to add to later if you want, or I can do it if not.

kikuchipy/projections/lambert_projection.py Outdated Show resolved Hide resolved
kikuchipy/projections/lambert_projection.py Show resolved Hide resolved
kikuchipy/projections/lambert_projection.py Outdated Show resolved Hide resolved
kikuchipy/projections/lambert_projection.py Outdated Show resolved Hide resolved
kikuchipy/projections/lambert_projection.py Outdated Show resolved Hide resolved
kikuchipy/projections/lambert_projection.py Outdated Show resolved Hide resolved
kikuchipy/projections/tests/test_lambert_projection.py Outdated Show resolved Hide resolved
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
@hakonanes
Copy link
Member

@friedkitteh, I just added a commit, so you need to pull this commit before pushing I think.

I added your full name in the credits, please change if you want.

Copy link
Member

@hakonanes hakonanes left a comment

Choose a reason for hiding this comment

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

Great! Will merge after Travis passes all builds.

@hakonanes hakonanes merged commit 80b98a9 into pyxem:master Sep 15, 2020
@hakonanes
Copy link
Member

Congratulations on, and thanks a lot for, your first contribution, @friedkitteh! 🎊

@friedkitteh friedkitteh deleted the lambert_projection branch January 6, 2021 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request tests This relates to the tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants