def do_print(): recursive_print.print_basic_network_info(connections=connections_NHD, headwater_keys=headwater_keys_NHD, junction_keys=junction_keys_NHD, terminal_keys=terminal_keys_NHD, terminal_code=terminal_code_NHD, verbose=True) if 1 == 0: #THE RECURSIVE PRINT IS NOT A GOOD IDEA WITH LARGE NETWORKS!!! recursive_print.print_connections( headwater_keys=headwater_keys_NHD, down_connections=connections_NHD, up_connections=connections_NHD, terminal_code=terminal_code_NHD, terminal_keys=terminal_keys_NHD, terminal_ref_keys=terminal_ref_keys_NHD, debuglevel=-2)
def main(): # find the path of the test scripts, several levels above the script path root = os.path.dirname( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) test_folder = os.path.join(root, r'test') supernetworks = {} supernetworks.update({arg4: {}}) # supernetworks.update({'Pocono_TEST1':{}}) # supernetworks.update({'LowerColorado_Conchos_FULL_RES':{}}) # supernetworks.update({'Brazos_LowerColorado_ge5':{}}) ##NHD Subset (Brazos/Lower Colorado)""" # supernetworks.update({'Brazos_LowerColorado_FULL_RES':{}}) # supernetworks.update({'Brazos_LowerColorado_Named_Streams':{}}) # supernetworks.update({'CONUS_ge5':{}}) ##NHD CONUS order 5 and greater""" # supernetworks.update({'Mainstems_CONUS':{}}) # supernetworks.update({'CONUS_Named_Streams':{}}) # supernetworks.update({'CONUS_FULL_RES_v20':{}}) # = False debuglevel = arg1 verbose = arg2 showtiming = arg3 supernetwork = arg4 for supernetwork in supernetworks: supernetworks[supernetwork] = nnu.set_supernetwork_data( supernetwork=supernetwork, geo_input_folder=os.path.join(test_folder, r'input', r'geo'), debuglevel=debuglevel, verbose=verbose) if debuglevel <= -1: if verbose: print(f'\n\nSupernetwork:') print(f'{supernetwork}') if debuglevel <= -2: if verbose: print(r'All items in the above supernetwork:') for k, v in supernetworks[supernetwork].items(): print(f"{{'{k}' : {v}}}") if showtiming: start_time = time.time() network_out_values = \ nnu.get_nhd_connections( supernetworks[supernetwork] , debuglevel = debuglevel , verbose = verbose ) recursive_print.print_basic_network_info( connections=network_out_values[0], headwater_keys=network_out_values[3], junction_keys=network_out_values[7], terminal_keys=network_out_values[4], terminal_code=supernetworks[supernetwork]['terminal_code'], verbose=verbose) if debuglevel <= -3: # THE RECURSIVE PRINT IS NOT A GOOD IDEA WITH LARGE NETWORKS!!! # The `Pocono_TEST1` supernetwork is a good test case to run with # the debuglevel set at -3. recursive_print.print_connections( headwater_keys=network_out_values[3], down_connections=network_out_values[0], up_connections=network_out_values[0], terminal_code=supernetworks[supernetwork]['terminal_code'], terminal_keys=network_out_values[4], terminal_ref_keys=network_out_values[5], debuglevel=debuglevel) if showtiming: print( f"Supernetwork `{supernetwork}` read and traversed\n... in %s seconds.\n\n" % (time.time() - start_time)) print(printout1)
def main(): """##TEST""" print("") print("Executing Test") # Test data debuglevel = -3 verbose = True test_rows = [ [50, 178, 51, 0], [51, 178, 50, 0], [60, 178, 61, 0], [61, 178, 62, 0], [62, 178, 60, 0], [70, 178, 71, 0], [71, 178, 72, 0], [72, 178, 73, 0], [73, 178, 70, 0], [80, 178, 81, 0], [81, 178, 82, 0], [82, 178, 83, 0], [83, 178, 84, 0], [84, 178, 80, 0], [0, 456, -999, 0], [1, 178, 4, 0], [2, 394, 0, 0], [3, 301, 2, 0], [4, 798, 0, 0], [5, 679, 4, 0], [6, 523, 0, 0], [7, 815, 2, 0], [8, 841, -999, 0], [9, 514, 8, 0], [10, 458, 9, 0], [11, 832, 10, 0], [12, 543, 11, 0], [13, 240, 12, 0], [14, 548, 13, 0], [15, 920, 14, 0], [16, 920, 15, 401], [17, 514, 16, 401], [18, 458, 17, 0], [180, 458, 17, 0], [181, 458, 180, 0], [19, 832, 18, 0], [20, 543, 19, 0], [21, 240, 16, 401], [22, 548, 21, 0], [23, 920, 22, 0], [24, 240, 23, 0], [25, 548, 12, 0], [26, 920, 25, 0], [27, 920, 26, 0], [28, 920, 27, 0], ] test_key_col = 0 test_downstream_col = 2 test_length_col = 1 test_terminal_code = -999 test_waterbody_col = 3 test_waterbody_null_code = 0 (test_connections) = get_down_connections( rows=test_rows, key_col=test_key_col, mask_set={row[test_key_col] for row in test_rows}, downstream_col=test_downstream_col, length_col=test_length_col, verbose=verbose, debuglevel=debuglevel, ) ( test_all_keys, test_ref_keys, test_headwater_keys, test_terminal_keys, test_terminal_ref_keys, test_circular_keys, ) = determine_keys( connections=test_connections, terminal_code=test_terminal_code, verbose=verbose, debuglevel=debuglevel, ) ( test_junction_keys, test_confluence_segment_set, test_visited_keys, test_visited_terminal_keys, test_junction_count, ) = get_up_connections( connections=test_connections, terminal_code=test_terminal_code, headwater_keys=test_headwater_keys, terminal_keys=test_terminal_keys, verbose=verbose, debuglevel=debuglevel, ) # TODO: Set/pass/identify a proper flag value if test_waterbody_col is not None: ( test_waterbody_dict, test_waterbody_segments, test_waterbody_outlet_set, test_waterbody_upstreams_set, test_waterbody_downstream_set, ) = get_waterbody_segments( connections=test_connections, terminal_code=test_terminal_code, waterbody_col=test_waterbody_col, waterbody_null_code=test_waterbody_null_code, verbose=verbose, 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, junction_keys=test_junction_keys, terminal_keys=test_terminal_keys, terminal_code=test_terminal_code, verbose=verbose, debuglevel=debuglevel, )
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, junction_keys=test_junction_keys, terminal_keys=test_terminal_keys, terminal_code=test_terminal_code, verbose=True, debuglevel=debuglevel) # if __name__ == "__main__": # main() """######Header cell to permit folding""" #parallel compute import time import multiprocessing terminal_keys = CONUS_ge5_values[4] circular_keys = CONUS_ge5_values[6] terminal_keys_super = terminal_keys - circular_keys
def main(): """##TEST""" print("") print('Executing Test') # Test data test_rows = [ [50, 178, 51, 0], [51, 178, 50, 0], [60, 178, 61, 0], [61, 178, 62, 0], [62, 178, 60, 0], [70, 178, 71, 0], [71, 178, 72, 0], [72, 178, 73, 0], [73, 178, 70, 0], [80, 178, 81, 0], [81, 178, 82, 0], [82, 178, 83, 0], [83, 178, 84, 0], [84, 178, 80, 0], [0, 456, -999, 0], [1, 178, 4, 0], [2, 394, 0, 0], [3, 301, 2, 0], [4, 798, 0, 0], [5, 679, 4, 0], [6, 523, 0, 0], [7, 815, 2, 0], [8, 841, -999, 0], [9, 514, 8, 0], [10, 458, 9, 0], [11, 832, 10, 0], [12, 543, 11, 0], [13, 240, 12, 0], [14, 548, 13, 0], [15, 920, 14, 0], [16, 920, 15, 0], [17, 514, 16, 0], [18, 458, 17, 0], [19, 832, 18, 0], [20, 543, 19, 0], [21, 240, 16, 0], [22, 548, 21, 0], [23, 920, 22, 0], [24, 240, 23, 0], [25, 548, 12, 0], [26, 920, 25, 0], [27, 920, 26, 0], [28, 920, 27, 0], ] test_key_col = 0 test_downstream_col = 2 test_length_col = 1 test_terminal_code = -999 (test_connections) = get_down_connections( rows=test_rows, key_col=test_key_col, mask_set={row[test_key_col] for row in test_rows}, downstream_col=test_downstream_col, length_col=test_length_col, verbose=True, debuglevel=-2) (test_all_keys, test_ref_keys, test_headwater_keys, test_terminal_keys, test_terminal_ref_keys, test_circular_keys) = determine_keys(connections=test_connections, key_col=test_key_col, downstream_col=test_downstream_col, terminal_code=test_terminal_code, verbose=True, debuglevel=-2) test_junction_keys = get_up_connections(connections=test_connections, terminal_code=test_terminal_code, headwater_keys=test_headwater_keys, terminal_keys=test_terminal_keys, verbose=True, debuglevel=-2) 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=-2) recursive_print.print_basic_network_info( connections=test_connections, headwater_keys=test_headwater_keys, junction_keys=test_junction_keys, terminal_keys=test_terminal_keys, terminal_code=test_terminal_code, verbose=True, debuglevel=-2)