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

Is there a way to can get the reach type (Weir, Pump, Link)? #23

Open
ThomasTHT opened this issue Dec 19, 2021 · 1 comment
Open

Is there a way to can get the reach type (Weir, Pump, Link)? #23

ThomasTHT opened this issue Dec 19, 2021 · 1 comment
Assignees

Comments

@ThomasTHT
Copy link

ThomasTHT commented Dec 19, 2021

[str(n) for n in res1d.data.Reaches]

may give something like

['Res1DReach: B4.1200l1-1 (0-479.998999014497)',
 'Res1DReach: B4.1502l1-12 (0-209.999271030538)',
 'Res1DReach: B4.1520l1-13 (0-235.000625581015)',
 'Res1DReach: Weir:B4.1480w1-14 (0-1)',
 'Res1DReach: Weir:B4.1510w1-15 (0-1)',
 'Res1DReach: Pump:B4.1510p1-16 (0-80.0006092712283)',
 'Res1DReach: Pump:B4.1510p2-17 (0-80.0006092712283)']

Is there a way to get the reach type, which is named 'Weir' or 'Pump' in the above list, and probably 'Link' for the other lines?

I've created a function, but I don't know which values are possible beside 'Weir' and 'Pump'.

def get_reach_type(reach):
    try:
        # get the full identifier string:
        fullstring = str(reach)

        # get the second part after the ':'
        structureReach = fullstring.split(':')[1].lstrip()

        # if the second part is Pump or Weir, use Pump or Weir:
        if structureReach in ['Pump','Weir']:
            reach_type = structureReach

        # in any other case this must be a normal Link (Pipe or Canal or River)
        else:
            reach_type = 'Link'
    
    except:
        reach_type = None

    return reach_type

I'm thinking of something simpler, similar to ''Reach.Name'', wich extracts the MUID. This is a property important for any further processing.

Thank you,
Thomas

@AL89
Copy link

AL89 commented Mar 6, 2024

@ThomasTHT I know it's been a while since your post.

I just thought there was some issues in your code, so I decided to polish your code a little. Because I agree with you that it should be a little more simple to determine the reach type.

def get_reach_type(reach):
   reach_type = 'Link'     # Predefine the reach as a link.

   reach_lst = reach.split(':')     # Create a list with strings, separated by : (colon)
   if reach_lst[0] in ('Weir','Pump','Orifice'):       # If the first value of the list occurs in the tuple, we know that the reach_type is one of them.
      reach_type = reach_lst[0]
   return reach_type

The input of a reach type string is [Reach type]:[Reach ID].
If there is no [Reach type] and a colon, then the reach type is 'Link' in every case. That's why I predefine the reach_type in the beginning of the function. It will only change if the if statement is true.

@ryan-kipawa ryan-kipawa self-assigned this Sep 24, 2024
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

3 participants