Skip to content

Add nearest_neighbor_TMP#28

Merged
stephpenn1 merged 4 commits intomainfrom
nearest
Oct 15, 2025
Merged

Add nearest_neighbor_TMP#28
stephpenn1 merged 4 commits intomainfrom
nearest

Conversation

@bpbond
Copy link
Member

@bpbond bpbond commented Oct 14, 2025

This PR adds a nearest_neighbor_TMP function that lets you easily look up the 'nearest neighbor' grid squares for any location on the TEMPEST grid:

> library(compasstools)
> nearest_neighbor_TMP("C2")
[1] "B1" "C1" "D1" "B2" "C2" "D2" "B3" "C3" "D3"
> nearest_neighbor_TMP("A1") # returns four squares (others are out)
[1] "A1" "B1" "A2" "B2"

The example code also shows how to do this for many locations, e.g. where you're trying to match TEROS sensors to tree locations.

> locations <- c("C2", "F3")
> grid_map <- lapply(locations, function(x) data.frame(location = x, neighbor = nearest_neighbor_TMP(x)))
> dplyr::bind_rows(grid_map)
   location neighbor
1        C2       B1
2        C2       C1
3        C2       D1
4        C2       B2
5        C2       C2
6        C2       D2
7        C2       B3
8        C2       C3
9        C2       D3
10       F3       E2
11       F3       F2
12       F3       G2
13       F3       E3
14       F3       F3
15       F3       G3
16       F3       E4
17       F3       F4
18       F3       G4

Feedback welcome @kendalynnm @peterregier @stephpenn1

Addresses #27

@bpbond bpbond linked an issue Oct 14, 2025 that may be closed by this pull request
@bpbond bpbond requested a review from stephpenn1 October 14, 2025 17:39
@bpbond
Copy link
Member Author

bpbond commented Oct 15, 2025

@kendalynnm Per our discussion the other day, will this fit your needs?

@bpbond bpbond requested a review from kendalynnm October 15, 2025 10:53
@kendalynnm
Copy link

I think this looks good! I'm going to download and give it a try. Won't merge yet, I'll leave that to Data Master Pennington

@bpbond
Copy link
Member Author

bpbond commented Oct 15, 2025

Or "DMP" as we call her 😜

Copy link
Member

@stephpenn1 stephpenn1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome!

@stephpenn1 stephpenn1 merged commit 22e1bb5 into main Oct 15, 2025
6 checks passed
@bpbond bpbond deleted the nearest branch October 15, 2025 19:45
@stephpenn1
Copy link
Member

The DMP has spoken and the PR has been merged.

@kendalynnm
Copy link

kendalynnm commented Oct 16, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a function to compute 'nearest neighbor' for TEMPEST grid?

3 participants