Skip to content

Inaccurate results evaluation.plotting.find_all_upstream #95

@steinadio

Description

@steinadio

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions