-
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
Set default value for n_closest
for finding nearest neighbors with get_closest_points_to_point
#51
Comments
The default for If we make We cannot omit So, the only two options I see are:
Since, I expect that most people do not want |
Maybe @lepetersson could have a look at this discussion before the meeting today. |
Would it make sense to set |
I think it would be more intutitive to not have to set n_closest, but rather (for example) loop through the stations and the distance matrix and create a xr dataset where the neighbour list per station is stored. In this way the user don't need to care about selecting n_closest. Perhaps you can look for the highest number of neighbours first and then set n_closest to that. Let's discuss later. Referring to this documentation |
Conclusion based on discussion today:
|
n_closest
for finding nearest neighbors with get_closest_points_to_point
Adding some thoughts to the discussion: One workaround using current code could be to select the station you want to find all neighbors to like this: closest_neigbors = plg.spatial.get_closest_points_to_point(
ds_points=ds_pws,
ds_points_neighbors=ds_pws.sel(id = pws_id),
max_distance=max_distance,
n_closest=1, # not relevant, we select the first station regardless
).isel(n_closest = 0) Then all closest neighbors to station "pws_id" can be found like this: neighbor_ids = closest_neigbors.where(closest_neigbors.neighbor_id != None, drop = True).id
ds_pws_neighbors = ds_pws.sel(id=neighbor_ids)
plt.scatter(ds_pws_neighbors.x, ds_pws_neighbors.y, c="C0", s=30) Its not the most intuitive syntax and for it to work you would have to loop through all the PWSs, at the cost of computational time. Another potential option could be to use the kd_tree.query_ball_point like I do in #43, possibly by calculating all distances at once or by looking through all stations... If the behavior of get_closest_points_to_point is changed we should consider adapting the output in #43 to be similar? |
n_closest is a required input for the plg.spatial.get_closest_points_to_point function. I would suggest to make it optional since the number of neighbouring stations might be irrelevant for some calculations, e.g. the indicator correlation. Optionally, the number could be set to a very high number...
PS: I wanted to label this as "discussion" but I don't know how that works....
The text was updated successfully, but these errors were encountered: