def create_basin_csvs(basin_ls, gdrive, folder): """Determines if a basin csv exists. This function Parameters: nabd_dams (pandas.DataFrame): Returns: """ ## If the specified basin csv does not exist, extract it os.chdir(gdrive+folder) read_flag = False for basin in basin_ls: if os.path.isfile(basin+'.csv'): #does it exist? #Read specified basin print(basin + ': Exists') else: if read_flag == False: flowlines, dams = read.read_lines_dams(gdrive) read_flag = True print('\n', basin + ': Does not exist') nabd_nhd = ex.join_dams_flowlines(basin, flowlines, dams)
def create_basin_csvs(basin_ls, gdrive, folder): """Determines if a basin csv exists and create it if needed. This function passes in a list of basins and determines if a csv with each basin name exists. If the csv does not exist, it is created with read.py. The read_flag ensures that read.py is only executed once. Parameters: basin_ls (List): List of basins to be analyzed. gdrive (string): Location on the Google Drive to save the csvs. folder (string): Folder on the Google Drive where csvs will be saved. read_flag (boolean): If False, flowlines and dams will be read in with read.py. If True, flowlines and dams will not be read in because they already have been. flowlines (pandas.DataFrame): Dataframe containing all NHD flowlines from read.py. dams (pandas.DataFrame): Dataframe containing all dams from read.py. Returns: Csvs for each of the basins listed in basin_ls in a specified folder on the Google Drive. """ ## If the specified basin csv does not exist, extract it os.chdir(gdrive + folder) read_flag = False for basin in basin_ls: if os.path.isfile(basin + '.csv'): #does it exist? #Read specified basin print(basin + ': Exists') else: if read_flag == False: flowlines, dams = read.read_lines_dams(gdrive) read_flag = True print('\n', basin + ': Does not exist') ex.join_dams_flowlines(basin, flowlines, dams)
# function = ex.my_function() # If the specified basin csv does not exist, extract it if os.path.isfile(run_name + '.csv'): #does it exist? #Read specified basin print('exists') segments = pd.read_csv(run_name + '.csv', usecols=[ 'Hydroseq', 'UpHydroseq', 'DnHydroseq', 'LENGTHKM', 'StartFlag', 'Coordinates', 'DamID', 'DamCount' ]) else: print('does not exist') nabd_nhd = ex.join_dams_flowlines(run_name) filtered_join = ex.filter_join(nabd_nhd, run_name) #filter the joined data segments = ex.filter_join(nabd_nhd, run_name) #filter the joined data # segments = pd.read_csv(run_name+'.csv', usecols=['Hydroseq', 'UpHydroseq', # 'DnHydroseq', 'LENGTHKM', # 'StartFlag','Coordinates', # 'DamID', 'DamCount']) #%% # STEP1: Make Fragments segments = bfc.make_fragments(segments, exit_id=99900000) # STEP 2: Making a fragment data frame and aggregated by fragment fragments = bfc.agg_by_frag(segments) # STEP 3: Map Upstream Fragments
# %% # Read in data ## If the specified basin csv does not exist, extract it if os.path.isfile(run_name + '.csv'): #does it exist? #Read specified basin print('Exists') segments = pd.read_csv(run_name + 'test.csv', usecols=[ 'Hydroseq', 'UpHydroseq', 'DnHydroseq', 'LENGTHKM', 'StartFlag', 'Coordinates', 'DamID', 'DamCount' ]) else: print('Does not exist') nabd_nhd = ex.join_dams_flowlines(flowlines, run_name, nabd) segments = pd.read_csv(run_name + 'test.csv', usecols=[ 'Hydroseq', 'UpHydroseq', 'DnHydroseq', 'LENGTHKM', 'StartFlag', 'Coordinates', 'DamID', 'DamCount' ]) #%% from time import time t1 = time() # STEP1: Make Fragments segments = bfup.make_fragments(segments, exit_id=99900000) t2 = time() print("Make Fragments:", (t2 - t1))
flowlines['REACHCODE'] = flowlines['REACHCODE'] / ( 10**12) #convert Reachcode to HUC 2 format # flowlines['REACHCODE'] = flowlines['REACHCODE']/(10**10) #convert Reachcode to HUC 4 format flowlines['REACHCODE'] = flowlines['REACHCODE'].apply( np.floor) #round down to integer #round the hydroseq values because of bug flowlines[['UpHydroseq', 'DnHydroseq', 'Hydroseq']] = flowlines[['UpHydroseq', 'DnHydroseq', 'Hydroseq']].round(decimals=0) # flowlines = flowlines[flowlines['FTYPE']!= 'Coastline'] #filter out coastlines # %% # Read in data # basin_ls = ['Red'] # basin_ls = ['California', 'Colorado', 'Columbia', 'Great Basin', 'Great Lakes', # 'Gulf Coast','Mississippi', 'North Atlantic', 'Red', 'Rio Grande','South Atlantic'] basin_ls = ['Columbia'] ## If the specified basin csv does not exist, extract it for basin in basin_ls: if os.path.isfile(basin + '.csv'): #does it exist? #Read specified basin print(basin + ' Exists') else: print(basin + ' Does not exist') nabd_nhd = ex.join_dams_flowlines(flowlines, basin, nabd) # %%