Skip to content

Commit

Permalink
refactor: remove repeated find_floe_matches
Browse files Browse the repository at this point in the history
from tracker.jl
  • Loading branch information
cpaniaguam committed Dec 7, 2024
1 parent 941e722 commit 13dc002
Showing 1 changed file with 0 additions and 89 deletions.
89 changes: 0 additions & 89 deletions src/tracker/tracker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,92 +244,3 @@ function pairfloes(
_pairs = _pairs[:, cols]
return _pairs
end


"""
find_floe_matches(
tracked,
candidate_props,
condition_thresholds,
mc_thresholds
)
Find matches for floes in `tracked` from floes in `candidate_props`.
# Arguments
- `tracked`: dataframe containing floe trajectories.
- `candidate_props`: dataframe containing floe candidate properties.
- `condition_thresholds`: thresholds for deciding whether to match floe `i` from tracked to floe j from `candidate_props`
- `mc_thresholds`: thresholds for area mismatch and psi-s shape correlation
"""
function find_floe_matches(
tracked::T,
candidate_props::T,
condition_thresholds,
mc_thresholds
) where {T<:AbstractDataFrame}
props1 = deepcopy(tracked)
props2 = deepcopy(candidate_props)
match_total = MatchedPairs(props2)
while true # there are no more floes to match in props1
# This routine mutates both props1 and props2.

# Container for props of matched floe pairs and their similarity ratios. Matches will be updated and added to match_total
matched_pairs = MatchedPairs(props2)
for r in 1:nrow(props1) # TODO: consider using eachrow(props1) to iterate over rows
@debug "Matching floe $r in day $dayi"
# 1. Collect preliminary matches for floe r in matching_floes
matching_floes = makeemptydffrom(props2)

for s in 1:nrow(props2) # TODO: consider using eachrow(props2) to iterate over rows
Δt = get_dt(props1, r, props2, s)
@debug "Considering floe $s in day $(dayi+1) for floe $r in day $dayi"
ratios, conditions, dist = compute_ratios_conditions(
(props1, r), (props2, s), Δt, condition_thresholds
)

if callmatchcorr(conditions)
@debug "Getting mismatch and correlation for floe $r in day $dayi and floe $s in day $(dayi+1)"
(area_mismatch, corr) = matchcorr(
props1.mask[r], props2.mask[s], Δt; mc_thresholds.comp...
)

if isfloegoodmatch(
conditions, mc_thresholds.goodness, area_mismatch, corr
)
@debug "names in matching_floes" matching_floes |> names
appendrows!(
matching_floes,
props2[s, :],
(ratios..., area_mismatch, corr),
s,
dist,
)
end
end
end # of s for loop

# 2. Find the best match for floe r
@debug "Finding best match for floe $r in day $dayi"
best_match_idx = getidxmostminimumeverything(matching_floes.ratios)
@debug "Best match index for floe $r in day $dayi: $best_match_idx"
if isnotnan(best_match_idx)
bestmatchdata = getbestmatchdata(
best_match_idx, r, props1, matching_floes
) # might be copying data unnecessarily
addmatch!(matched_pairs, bestmatchdata)
end
end # of for r = 1:nrow(props1)

# exit while loop if there are no more floes to match
isempty(matched_pairs) && break

#= Resolve collisions:
Are there floes in day k+1 paired with more than one
floe in day k? If so, keep the best matching pair and remove all others. =#
resolvecollisions!(matched_pairs)
deletematched!((props1, props2), matched_pairs)
update!(match_total, matched_pairs)
end # of while loop
return match_total
end

0 comments on commit 13dc002

Please sign in to comment.