-
Notifications
You must be signed in to change notification settings - Fork 62
multiple grids #94
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
base: master
Are you sure you want to change the base?
multiple grids #94
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,17 +7,22 @@ | |
|
|
||
| def get_map_center(): | ||
| """Returns center of the map""" | ||
| lat = (config.MAP_END[0] + config.MAP_START[0]) / 2 | ||
| lon = (config.MAP_END[1] + config.MAP_START[1]) / 2 | ||
| return lat, lon | ||
| if isinstance(config.GRID[0], (int, long, float, complex)): | ||
| lat = (config.MAP_END[0] + config.MAP_START[0]) / 2 | ||
| lon = (config.MAP_END[1] + config.MAP_START[1]) / 2 | ||
| return lat, lon | ||
| else: | ||
| lat = (config.MAP_END[0][0] + config.MAP_START[0][0]) / 2 | ||
| lon = (config.MAP_END[0][1] + config.MAP_START[0][1]) / 2 | ||
| return lat, lon | ||
|
|
||
|
|
||
| def get_scan_area(): | ||
| def get_scan_area_single(GRID, MAP_START, MAP_END): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those are not constants, use lowercase. |
||
| """Returns the square kilometers for configured scan area""" | ||
| lat1 = config.MAP_START[0] | ||
| lat2 = config.MAP_END[0] | ||
| lon1 = config.MAP_START[1] | ||
| lon2 = config.MAP_END[1] | ||
| lat1 = MAP_START[0] | ||
| lat2 = MAP_END[0] | ||
| lon1 = MAP_START[1] | ||
| lon2 = MAP_END[1] | ||
| p1 = Point(lat1, lon1) | ||
| p2 = Point(lat1, lon2) | ||
| p3 = Point(lat1, lon1) | ||
|
|
@@ -28,19 +33,20 @@ def get_scan_area(): | |
| area = int(width * height) | ||
| return area | ||
|
|
||
| def get_scan_area(): | ||
| if isinstance(config.GRID[0], (int, long, float, complex)): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again - better convert config.GRID to list early and have a single version of this function. |
||
| return get_scan_area_single(config.GRID, config.MAP_START, config.MAP_END) | ||
| else: | ||
| area = 0 | ||
| for i in range(len(config.GRID)): | ||
| area = area + get_scan_area_single(config.GRID[i], config.MAP_START[i], config.MAP_END[i]) | ||
| return area | ||
|
|
||
|
|
||
| def get_start_coords(worker_no): | ||
| def get_start_coords(p): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| """Returns center of square for given worker""" | ||
| grid = config.GRID | ||
| total_workers = grid[0] * grid[1] | ||
| per_column = total_workers / grid[0] | ||
| column = worker_no % per_column | ||
| row = worker_no / per_column | ||
| part_lat = (config.MAP_END[0] - config.MAP_START[0]) / float(grid[0]) | ||
| part_lon = (config.MAP_END[1] - config.MAP_START[1]) / float(grid[1]) | ||
| start_lat = config.MAP_START[0] + part_lat * row + part_lat / 2 | ||
| start_lon = config.MAP_START[1] + part_lon * column + part_lon / 2 | ||
| return start_lat, start_lon | ||
| center = [sum(y) / len(y) for y in zip(*p)] | ||
| return center[0], center[1] | ||
|
|
||
|
|
||
| def float_range(start, end, step): | ||
|
|
@@ -55,39 +61,46 @@ def float_range(start, end, step): | |
| start += step | ||
|
|
||
|
|
||
| def get_points_per_worker(): | ||
| def get_points_per_worker_single(GRID, MAP_START, MAP_END): | ||
| """Returns all points that should be visited for whole grid""" | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Obsolete docstring. |
||
| total_workers = config.GRID[0] * config.GRID[1] | ||
| total_workers = GRID[0] * GRID[1] | ||
| lat_gain = getattr(config, 'LAT_GAIN', 0.0015) | ||
| lon_gain = getattr(config, 'LON_GAIN', 0.0025) | ||
| points = [[] for _ in range(total_workers)] | ||
| total_rows = math.ceil( | ||
| abs(config.MAP_START[0] - config.MAP_END[0]) / lat_gain | ||
| abs(MAP_START[0] - MAP_END[0]) / lat_gain | ||
| ) | ||
| total_columns = math.ceil( | ||
| abs(config.MAP_START[1] - config.MAP_END[1]) / lon_gain | ||
| abs(MAP_START[1] - MAP_END[1]) / lon_gain | ||
| ) | ||
| for map_row, lat in enumerate( | ||
| float_range(config.MAP_START[0], config.MAP_END[0], lat_gain) | ||
| float_range(MAP_START[0], MAP_END[0], lat_gain) | ||
| ): | ||
| for map_col, lon in enumerate( | ||
| float_range(config.MAP_START[1], config.MAP_END[1], lon_gain) | ||
| float_range(MAP_START[1], MAP_END[1], lon_gain) | ||
| ): | ||
| # Figure out which worker this should go to | ||
| grid_row = int(map_row / float(total_rows) * config.GRID[0]) | ||
| grid_col = int(map_col / float(total_columns) * config.GRID[1]) | ||
| worker_no = grid_row * config.GRID[1] + grid_col | ||
| grid_row = int(map_row / float(total_rows) * GRID[0]) | ||
| grid_col = int(map_col / float(total_columns) * GRID[1]) | ||
| worker_no = grid_row * GRID[1] + grid_col | ||
| points[worker_no].append((lat, lon)) | ||
| points = [ | ||
| sort_points_for_worker(p, i) | ||
| for i, p in enumerate(points) | ||
| ] | ||
| points = [sort_points_for_worker(p) for p in points] | ||
| return points | ||
|
|
||
| def get_points_per_worker(): | ||
| if isinstance(config.GRID[0], (int, long, float, complex)): | ||
| return get_points_per_worker_single(config.GRID, config.MAP_START, config.MAP_END) | ||
| else: | ||
| points = [] | ||
| for i in range(len(config.GRID)): | ||
| points.extend(get_points_per_worker_single(config.GRID[i], config.MAP_START[i], config.MAP_END[i])) | ||
| return points | ||
|
|
||
|
|
||
|
|
||
| def sort_points_for_worker(points, worker_no): | ||
| center = get_start_coords(worker_no) | ||
| return sorted(points, key=lambda p: get_distance(p, center)) | ||
| def sort_points_for_worker(p): | ||
| center = get_start_coords(p) | ||
| return sorted(p, key=lambda p: get_distance(p, center)) | ||
|
|
||
|
|
||
| def get_distance(p1, p2): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of checking everywhere whether config value is an int, or a list. It's better to convert old value to new format in a single place.
Moreover, if GRID can be a list, then GRID[0] may raise an IndexError.