Skip to content

Conversation

@TheBB
Copy link
Collaborator

@TheBB TheBB commented Sep 2, 2016

It was deemed “out of scope” in #18 but it's actually very simple to do and doubtless a useful feature. For people like me who are working with heightmaps with thousands of points in each direction in different coordinate systems, converting coordinate pairs one-by-one is unacceptably slow.

In principle, the numpy module implements all the functions that are needed from math, and they work transparently for arrays as well as floats, so it's a drop-in replacement.

Exceptions:

  • Bounds checking, I delegated this to a helper function that catches all cases.
  • Possibly ambiguous input in the zone calculation in from_latlon. Here I just use the first point to compute the zone, assuming that the user is careful enough to have all points in the same zone (or that they will be fine with having input points in one zone converted to UTM coordinates in another).
  • Mixed north/south latitudes in from_latlon. Right now the code throws an exception in this case. However now that I think about it, I assume it would be correct to add 10e6 northing to every point with a southern latitude and to not change the northern latitude points? If so I can modify this to work without throwing an error.

I wrote the tests to require numpy since it's safer. Not sure what Travis will think of this so let's see…

I'm already using this modified version in my code so it's not critical to me that this is merged, but I'm fairly sure this would be useful to others.

@Turbo87
Copy link
Owner

Turbo87 commented Sep 2, 2016

@TheBB nice work! I'm wondering if we could adjust the TravisCI config to test both cases though to make sure one doesn't break the other without noticing.

@taylorsansom
Copy link

@TheBB this is great! I just blasted through a conversion of about 80 million points in a matter of seconds. This saved me days if not weeks of processing time!

@Turbo87
Copy link
Owner

Turbo87 commented May 7, 2017

@TheBB I'd really like to merge this, but we need to be testing both code paths, otherwise I can't accept this PR...

@TheBB
Copy link
Collaborator Author

TheBB commented May 19, 2017

Yes, I saw that. I'm not sure how best to implement such a thing.

@astrojuanlu
Copy link
Collaborator

astrojuanlu commented Jun 23, 2017

If there is still interest on this, I can work on the .travis.yml file to add two cases for each Python version: with and without NumPy. The tests are already very quick so there should be no problem. What do you think?

@Turbo87
Copy link
Owner

Turbo87 commented Jun 23, 2017

@Juanlu001 sounds good, thanks for looking into this! :)

@TheBB TheBB force-pushed the numpy branch 3 times, most recently from 61d9c83 to b2ce6fb Compare June 23, 2017 14:44
@codecov
Copy link

codecov bot commented Jun 23, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@4c7c13f). Click here to learn what that means.
The diff coverage is 95.91%.

Impacted file tree graph

@@           Coverage Diff            @@
##             master     #24   +/-   ##
========================================
  Coverage          ?   93.5%           
========================================
  Files             ?       3           
  Lines             ?     154           
  Branches          ?       0           
========================================
  Hits              ?     144           
  Misses            ?      10           
  Partials          ?       0
Impacted Files Coverage Δ
utm/conversion.py 93.33% <95.91%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4c7c13f...235bc6b. Read the comment docs.

@astrojuanlu
Copy link
Collaborator

The tests finally passed! There is no report to comparate against because we just introduced it :) So @Turbo87, ready for review!

TheBB and others added 2 commits June 23, 2017 16:57
All of the actual mathematical tools can be used from the numpy module
instead of the math module, and they will work transparently for arrays
as well as floats. This version works both with and without numpy; and
it should behave as before if numpy is not installed, or if it is
installed and the inputs are floats. The only issues involved are
related to bounds checking and other inequalities.

Bounds checking is done with the utility function in_bounds which checks
if ALL elements satisfy the conditions.

For calculating the zone letters and numbers, only one element is
used: the first one. It is assumed to be caller’s responsibility that
all points lie in the same zone. Forcing the zone may be useful for
numpy users, therefore added a force_zone_letter argument to
from_latlon, to make the zone fully forceable.

The only other caveat is that the south/north check in from_latlon may
cause problems if the input latitude has mixed signs. This is therefore
checked and may raise a ValueError.

Tests do assume that numpy is installed, however.
@TheBB
Copy link
Collaborator Author

TheBB commented Jun 23, 2017

Thanks @Juanlu001. I actually just pushed to your branch before I saw you close it, but we can use this one too.

@danni
Copy link

danni commented Jun 24, 2018

What has happened to this? It would be nice to crunch all of my values in one go.

@astrojuanlu
Copy link
Collaborator

I think it's only missing a review by @Turbo87, the functionality and tests are there!

@Turbo87
Copy link
Owner

Turbo87 commented Jun 25, 2018

@TheBB @Juanlu001 sorry, for taking so long. I don't use numpy and currently do very little Python myself, but I've just sent you an invite to the repo so you can help maintain the project if you want to. feel free to merge this PR if you think it's ready :)

if you want to release a new version you only need to update the changelog, bump the version and push a tag to GitHub, and Travis CI will then take care of publishing the package to PyPI.

@astrojuanlu
Copy link
Collaborator

Thanks for the invitation @Turbo87, I hope I will do a good job as a maintainer :)

I will proceed and merge this, and hopefully we can prepare a release this week or the following one.

@astrojuanlu
Copy link
Collaborator

(I restarted the build just in case, since it's been a while)

@astrojuanlu astrojuanlu merged commit 81883cc into Turbo87:master Jun 26, 2018
@astrojuanlu
Copy link
Collaborator

And by "this week or the following one" I actually meant... Next one 🤞

@Turbo87 Turbo87 mentioned this pull request Aug 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants