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

Displacement has lon and lat the wrong way around #913

Closed
jc-harrison opened this issue Jun 10, 2019 · 3 comments · Fixed by #914
Closed

Displacement has lon and lat the wrong way around #913

jc-harrison opened this issue Jun 10, 2019 · 3 comments · Fixed by #914
Labels
bug Something isn't working FlowMachine Issues related to FlowMachine

Comments

@jc-harrison
Copy link
Member

Describe the bug
In Displacement._make_query, the SQL string to calculate distance is created as

dist_string = get_dist_string("lat_home_loc", "lon_home_loc", "lat", "lon")

However, the calling signature of get_dist_string (as defined in utils.py) is

get_dist_string(lo1, la1, lo2, la2)

Displacement is passing lat and lon values the wrong way around, so distances will be incorrect.

Product
FlowMachine

Additional context
There is some inconsistency more generally around the ordering of "lat" and "lon" in FlowMachine (e.g. "versioned-site" level has columns ["site_id", "version", "lon", "lat"], but "lat-lon" level has columns ["lat", "lon"]). This is mostly not a problem, since the values are usually in columns referenced by name, but more consistency around this would reduce the chance of these bugs popping up. I'm attempting to make this consistent as part of my spatial unit refactoring, choosing ["lon", "lat"] ordering for consistency with the order required by ST_Point().

@jc-harrison jc-harrison added bug Something isn't working FlowMachine Issues related to FlowMachine labels Jun 10, 2019
@jc-harrison jc-harrison mentioned this issue Jun 10, 2019
8 tasks
@maxalbert
Copy link
Contributor

I think at the very least we should enforce always passing lon/lat values as named keyword args.

Probably better would be to have Point or Geolocation class so that we don't need to pass the values around individually.

If this fits naturally with the spatial unit refactoring then would be great to roll it in, but also happy to keep it as a separate PR because it probably requires a lot of little changes all over the place.

@maxalbert
Copy link
Contributor

Just to note that this is not just an issue within our code base - different third-party packages also use different orderings for lon/lat, so it's even more important to enforce the correct values by name and/or a dedicated object.

@jc-harrison
Copy link
Member Author

Yes, I like the idea of a Point class. In the interest of keeping the spatial unit refactoring PR from getting too much larger than it's already going to be, I think it's probably best to keep this as a separate PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working FlowMachine Issues related to FlowMachine
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants