def compose_networks(supernetwork_values=None, terminal_code=0, debuglevel=0, verbose=False, showtiming=False): terminal_segments = supernetwork_values[4] circular_segments = supernetwork_values[6] terminal_segments_super = terminal_segments - circular_segments connections = supernetwork_values[0] networks = { terminal_segment: {} for terminal_segment in terminal_segments_super } if verbose: print('verbose output') if verbose: print( f'number of Independent Networks to be analyzed is {len(networks)}' ) if verbose: print(f'Multi-processing will use {multiprocessing.cpu_count()} CPUs') if verbose: print(f'debuglevel is {debuglevel}') init_order = 0 for terminal_segment, network in networks.items(): network.update( network_trace(terminal_segment=terminal_segment, order_iter=init_order, connections=connections, terminal_code=terminal_code, verbose=verbose, debuglevel=debuglevel)[terminal_segment]) up_reaches = networkbuilder.get_up_connections( network['reaches'], terminal_code, network['headwater_reaches'], {network['terminal_reach']}, r'upstream_reaches', r'downstream_reach', verbose=verbose, debuglevel=debuglevel) if debuglevel <= -2: if debuglevel <= -2: print(f'terminal_segment: {terminal_segment}') if debuglevel <= -3: for k, v in network.items(): if type(v) is dict: print(f'{k}:') for k1, v1 in v.items(): print(f'\t{k1}: {v1}') else: print(f'{k}: {v}') if debuglevel <= -1: print( f'Number of networks in the Supernetwork: {len(networks.items())}') return networks
def do_network(geofile_path=None, title_string=None, layer_string=None, driver_string=None, key_col=None, downstream_col=None, length_col=None, terminal_code=None, verbose=False, debuglevel=0): # NOTE: these methods can lose the "connections" and "rows" arguments when # implemented as class methods where those arrays are members of the class. if verbose: print(title_string) if debuglevel <= -1: print( f'reading -- dataset: {geofile_path}; layer: {layer_string}; fiona driver: {driver_string}' ) geofile = gpd.read_file(geofile_path, driver=driver_string, layer=layer_string) if debuglevel <= -1: print(geofile.head()) geofile_rows = geofile.to_numpy() if debuglevel <= -1: geofile.plot() # Kick off recursive call for all connections and keys (connections) = networkbuilder.get_down_connections( rows=geofile_rows, key_col=key_col, downstream_col=downstream_col, length_col=length_col, verbose=verbose, debuglevel=debuglevel) (all_keys, ref_keys, headwater_keys, terminal_keys, terminal_ref_keys, circular_keys) = networkbuilder.determine_keys( connections=connections, key_col=key_col, downstream_col=downstream_col, terminal_code=terminal_code, verbose=verbose, debuglevel=debuglevel) (junction_keys) = networkbuilder.get_up_connections( connections=connections, terminal_code=terminal_code, headwater_keys=headwater_keys, terminal_keys=terminal_keys, verbose=verbose, debuglevel=debuglevel) return connections, all_keys, ref_keys, headwater_keys \ , terminal_keys, terminal_ref_keys \ , circular_keys, junction_keys
def build_connections_object(geo_file_rows=None, mask_set=None, key_col=None, downstream_col=None, length_col=None, terminal_code=None, verbose=False, debuglevel=0): (connections) = networkbuilder.get_down_connections( rows=geo_file_rows, mask_set=mask_set, key_col=key_col, downstream_col=downstream_col, length_col=length_col, verbose=verbose, debuglevel=debuglevel) (all_keys, ref_keys, headwater_keys, terminal_keys, terminal_ref_keys, circular_keys) = networkbuilder.determine_keys( connections=connections, key_col=key_col, downstream_col=downstream_col, terminal_code=terminal_code, verbose=verbose, debuglevel=debuglevel) (junction_keys, visited_keys, visited_terminal_keys, junction_count) = networkbuilder.get_up_connections( connections=connections, terminal_code=terminal_code, headwater_keys=headwater_keys, terminal_keys=terminal_keys, verbose=verbose, debuglevel=debuglevel) return connections, all_keys, ref_keys, headwater_keys \ , terminal_keys, terminal_ref_keys \ , circular_keys, junction_keys \ , visited_keys, visited_terminal_keys \ , junction_count
def build_connections_object( geo_file_rows=None, mask_set=None, key_col=None, downstream_col=None, length_col=None, terminal_code=None, waterbody_col=None, waterbody_null_code=None, verbose=False, debuglevel=0, ): (connections) = networkbuilder.get_down_connections( rows=geo_file_rows, mask_set=mask_set, key_col=key_col, downstream_col=downstream_col, length_col=length_col, verbose=verbose, debuglevel=debuglevel, ) ( all_keys, ref_keys, headwater_keys, terminal_keys, terminal_ref_keys, circular_keys, ) = networkbuilder.determine_keys( connections=connections # , key_col = key_col # , downstream_col = downstream_col , terminal_code=terminal_code, verbose=verbose, debuglevel=debuglevel, ) ( junction_keys, confluence_segment_set, visited_keys, visited_terminal_keys, junction_count, ) = networkbuilder.get_up_connections( connections=connections, terminal_code=terminal_code, headwater_keys=headwater_keys, terminal_keys=terminal_keys, verbose=verbose, debuglevel=debuglevel, ) waterbody_dict = None waterbody_segments = None waterbody_outlet_set = None waterbody_upstreams_set = None waterbody_downstream_set = None # TODO: Set/pass/identify a proper flag value if waterbody_col is not None: ( waterbody_dict, waterbody_segments, waterbody_outlet_set, waterbody_upstreams_set, waterbody_downstream_set, ) = networkbuilder.get_waterbody_segments( connections=connections, terminal_code=terminal_code, waterbody_col=waterbody_col, waterbody_null_code=waterbody_null_code, verbose=verbose, debuglevel=debuglevel # , debuglevel = -3 ) # TODO: change names to reflect type set or dict return ( connections, all_keys, ref_keys, headwater_keys, terminal_keys, terminal_ref_keys, circular_keys, junction_keys, visited_keys, visited_terminal_keys, junction_count, confluence_segment_set, waterbody_dict, waterbody_segments, waterbody_outlet_set, waterbody_upstreams_set, waterbody_downstream_set, )
debuglevel=debuglevel) (test_all_keys, test_ref_keys, test_headwater_keys, test_terminal_keys, test_terminal_ref_keys, test_circular_keys) = networkbuilder.determine_keys( connections=test_connections, key_col=test_key_col, downstream_col=test_downstream_col, terminal_code=test_terminal_code, verbose=True, debuglevel=debuglevel) test_junction_keys = networkbuilder.get_up_connections( connections=test_connections, terminal_code=test_terminal_code, headwater_keys=test_headwater_keys, terminal_keys=test_terminal_keys, verbose=True, debuglevel=debuglevel) recursive_print.print_connections(headwater_keys=test_headwater_keys, down_connections=test_connections, up_connections=test_connections, terminal_code=test_terminal_code, terminal_keys=test_terminal_keys, terminal_ref_keys=test_terminal_ref_keys, debuglevel=debuglevel) recursive_print.print_basic_network_info( connections=test_connections, headwater_keys=test_headwater_keys,
def compose_networks( supernetwork_values=None, terminal_code=0, break_network_at_waterbodies=False, debuglevel=0, verbose=False, showtiming=False, ): terminal_segments = supernetwork_values[4] circular_segments = supernetwork_values[6] confluence_segment_set = supernetwork_values[11] terminal_segments_super = terminal_segments - circular_segments waterbody_outlet_set = supernetwork_values[14] waterbody_upstreams_set = supernetwork_values[15] waterbody_breaking_segments = set() if break_network_at_waterbodies: waterbody_breaking_segments = waterbody_outlet_set.union( waterbody_upstreams_set) terminal_segments_super = terminal_segments_super.union( waterbody_breaking_segments) connections = supernetwork_values[0] networks = { terminal_segment: {} for terminal_segment in terminal_segments_super } if verbose: print("verbose output") if verbose: print( f"number of Independent Networks to be analyzed is {len(networks)}" ) if verbose: print(f"debuglevel is {debuglevel}") init_order = 0 for terminal_segment, network in networks.items(): network.update( network_trace( terminal_segment=terminal_segment, order_iter=init_order, connections=connections, terminal_code=terminal_code, reach_breaking_segments=confluence_segment_set, network_breaking_segments=waterbody_breaking_segments, verbose=verbose, debuglevel=debuglevel, )[terminal_segment]) upstream_reaches = network["headwater_reaches"] if break_network_at_waterbodies: upstream_reaches = upstream_reaches | network["receiving_reaches"] up_reaches = networkbuilder.get_up_connections( network["reaches"], terminal_code, upstream_reaches, {network["terminal_reach"]}, r"upstream_reaches", r"downstream_reach", verbose=False # , verbose = verbose , debuglevel=debuglevel, ) if debuglevel <= -2: if debuglevel <= -2: print(f"terminal_segment: {terminal_segment}") if debuglevel <= -3: for k, v in network.items(): if type(v) is dict: print(f"{k}:") for k1, v1 in v.items(): print(f"\t{k1}: {v1}") else: print(f"{k}: {v}") if debuglevel <= -1: print( f"Number of networks in the Supernetwork: {len(networks.items())}") return networks