-
Notifications
You must be signed in to change notification settings - Fork 10
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
Recurse algorithm #10
Open
cath34
wants to merge
5
commits into
master
Choose a base branch
from
recurse_algorithm
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
41003a3
Added Recurse algorithm
cath34 90fcd40
Fixed pre-commit failures
cath34 6e7cb6a
Added Recurse algorithm
cath34 4dd9f00
Fixed pre-commit errors
cath34 dfc4e71
Merge branch 'recurse_algorithm' of https://github.com/wildlife-dynam…
cath34 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from math import ceil, floor | ||
|
||
import numpy as np | ||
|
||
import ecoscope | ||
|
||
|
||
def get_consecutive_items_number(idxs): | ||
gaps = [[s, e] for s, e in zip(idxs, idxs[1:]) if s + 1 < e] | ||
edges = iter(idxs[:1] + sum(gaps, []) + idxs[-1:]) | ||
return len(list(zip(edges, edges))) | ||
|
||
|
||
def get_recursions(relocations, resolution): | ||
relocations = relocations.reset_index(drop=True) | ||
if not relocations["fixtime"].is_monotonic: | ||
relocations.sort_values("fixtime", inplace=True) | ||
|
||
diameter = ceil(resolution) * 2 | ||
utm_crs = relocations.estimate_utm_crs() | ||
relocations.to_crs(utm_crs, inplace=True) | ||
|
||
geom = relocations["geometry"] | ||
eastings = np.array([geom.iloc[i].x for i in range(len(geom))]).flatten() | ||
northings = np.array([geom.iloc[i].y for i in range(len(geom))]).flatten() | ||
|
||
grid = ecoscope.base.Grid(eastings, northings, diameter) | ||
|
||
grid_cells_dict = {} | ||
for i in range(len(geom)): | ||
point = geom.iloc[i] | ||
grid_cell = grid.inverse_transform * (point.x, point.y) | ||
row, col = floor(grid_cell[0]), ceil(grid_cell[1]) | ||
if (col, row) in grid_cells_dict: | ||
grid_cells_dict[(col, row)].append(i) | ||
else: | ||
grid_cells_dict[(col, row)] = [i] | ||
|
||
for grid_cell in grid_cells_dict: | ||
grid_cells_dict[grid_cell] = get_consecutive_items_number(grid_cells_dict[grid_cell]) | ||
|
||
recursion_values = [] | ||
for i in range(len(geom)): | ||
point = geom.iloc[i] | ||
grid_cell = grid.inverse_transform * (point.x, point.y) | ||
row, col = floor(grid_cell[0]), ceil(grid_cell[1]) | ||
recursion_values.append(grid_cells_dict[(col, row)]) | ||
|
||
return recursion_values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We can avoid for-loop here by using geopandas methods (it's well optimized)