Skip to content
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

Inaccurate results evaluation.plotting.find_all_upstream #95

Open
steinadio opened this issue Dec 2, 2021 · 1 comment
Open

Inaccurate results evaluation.plotting.find_all_upstream #95

steinadio opened this issue Dec 2, 2021 · 1 comment

Comments

@steinadio
Copy link
Collaborator

The function evaluation.plotting.find_all_upstream in bmorph was recently found to not gather the correct upstream river segments and had some issue with reassigning some global variable (e.g. it appeared to work on first call but not subsequent calls). While I am not certain why this function is not currently working, following is some code from @arbennett that does work, but has yet to be cleaned up and generalized:

def find_all(crbtopo, seg_id):
    # Network topology file
    #crbtopo = xr.open_dataset('columbia_huc12_topology_fixed.nc')

    #seg_id = $YOUR_SEG_ID       # Select the segment you want to search from
    search_seg_id = [seg_id]    # Start a list of seg id's to search through
    all_seg_id = [seg_id]       # Start a list of seg id's to select

    while len(search_seg_id):
        cur_seg_id = search_seg_id.pop()                              # Get the last value out of our search queue
        all_seg_id.append(cur_seg_id)                                 # Put the id we are searching from onto the list to select
        sel_seg = crbtopo['Tosegment'] == cur_seg_id                  # Figure out which upstream segments lead to the current segment
        up_seg_ids = crbtopo['seg'].where(sel_seg, drop=True).values  # Select the seg id's which are upstream
        [search_seg_id.append(i) for i in up_seg_ids]                 # For each of those, put them in the queue to be searched

    sel_hru = crbtopo['seg_hru_id'].isin(all_seg_id)
    all_hru_id = crbtopo['hru'].where(sel_hru, drop=True).values    

    return all_seg_id, all_hru_id
@steinadio
Copy link
Collaborator Author

Update: both that aggregation script and the previously found inaccurate aggregation script can result in duplicate segs being returned. I am not certain the cause of this error, however calling set() on the outputted data will resolve this.

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

No branches or pull requests

1 participant