Exemple #1
0
        usgs_col = df_usgs_info.ix[i,'flow_col']
        dam_number = df_usgs_info.ix[i,'corresponding_dam_number']
        dam_name = df_usgs_info.ix[i,'corresponding_dam_name']
        print 'Plotting dam {}...'.format(dam_number)
        
        #=== Get USGS data ===#
        df_usgs = my_functions.read_USGS_data(\
                        os.path.join(usgs_data_dir, '{}.txt'.format(usgs_code)), \
                        columns=[usgs_col], names=['flow']) / 1000 # convert to thousand cfs
        s_usgs = df_usgs.ix[:,0]  # convert df to Series

        #=== Get TVA data ===#
        TVA_path = os.path.join(TVA_daily_dir, '{}_{}.daily.1903_2013'.format(lat, lon))
        if os.path.isfile(TVA_path)==False:  # if corresponding dam has no data
            continue
        s_TVA = my_functions.read_Lohmann_route_daily_output(\
                    os.path.join(TVA_daily_dir, '{}_{}.daily.1903_2013'.format(lat, lon)))
        s_TVA = s_TVA / 1000.0  # convert to thousand cfs

        #=== Extract data within common range ===#
        # determine the common range of available data of both data sets
        data_avai_start_date, data_avai_end_date = my_functions.\
                        find_data_common_range([s_usgs, s_TVA])
        if (data_avai_start_date-data_avai_end_date).days>=0: # if no common time range
            print "No common range data available!"
            exit()
        # find the full water years with available data for both data sets
        plot_start_date, plot_end_date = my_functions.\
                find_full_water_years_within_a_range(data_avai_start_date, data_avai_end_date)
        # determine time locator #
        if plot_end_date.year-plot_start_date.year < 5:  # if less than 5 years
            time_locator = ('year', 1)  # time locator on the plot; 'year' for year; 'month' for month. e.g., ('month', 3) for plot one tick every 3 months
Exemple #2
0
# Load data
#========================================================
list_s = []  # list of Series to be plotted
list_plot_style = []  # list of plot style for each time series
list_plot_label = []  # list of plot legend label for each time series
for i in range(cfg['INPUT_CONTROL']['n_ts']):  # Load all time series data
    input_section = 'INPUT_{}'.format(i+1)

    # If from formatted RBM output
    if cfg[input_section]['ts_format']=='RBM_formatted':
        s = my_functions.read_RMB_formatted_output(cfg[input_section]['ts_path'], \
                                             var='flow') / 1000 # convert to thousand cfs

    # If from formatted RBM output
    elif cfg[input_section]['ts_format']=='Lohmann':
        s = my_functions.read_Lohmann_route_daily_output(cfg[input_section]['ts_path'])\
                                                         / 1000 # convert to thousand cfs

    # If USGS data
    elif cfg[input_section]['ts_format']=='USGS':
        if type(cfg[input_section]['usgs_col']) is int:  # if only one needed data column
            df_usgs = my_functions.read_USGS_data(cfg[input_section]['ts_path'], \
                                               columns=[cfg[input_section]['usgs_col']], \
                                               names=['flow']) / 1000 # convert to thousand cfs
            s= df_usgs.ix[:,0]  # convert df to Series

        else:  # if more than one data column needed, take average
            usgs_flow_col_split = cfg[input_section]['usgs_col'].split('&')
            names=[]
            for i in range(len(usgs_flow_col_split)):
                usgs_flow_col_split[i] = int(usgs_flow_col_split[i])
Exemple #3
0
        dict_path[line_split[0]] = [
            line_split[1], line_split[2],
            int(line_split[3])
        ]
    elif cfg['INPUT']['obs_format'] == 'Lohmann':
        dict_path[line_split[0]] = [line_split[1], line_split[2]]
    else:
        print 'Error: unsupported observation data format!'
        exit()
f.close()

# Read in routed streamflow from inverted runoff
dict_Lohmann_routed = {}  # {station_name: pd.Series of daily data} [unit: cfs]
for stn in dict_path:
    # Load data
    s_Lohmann_routed = my_functions.read_Lohmann_route_daily_output(
        dict_path[stn][1])
    dict_Lohmann_routed[stn] = s_Lohmann_routed
    # Select full water years
    start_date_WY, end_date_WY = my_functions.find_full_water_years_within_a_range(\
                                                dict_Lohmann_routed[stn].index[0], \
                                                dict_Lohmann_routed[stn].index[-1])
    dict_Lohmann_routed[stn] = my_functions.select_time_range(dict_Lohmann_routed[stn], \
                                                              start_date_WY, \
                                                              end_date_WY)

# Read in original station obs rmat
dict_obs = {}  # {station_name: pd.Series of daily data} [unit: cfs]
for stn in dict_path:
    # Load data
    filename = dict_path[stn][0]
    if cfg['INPUT']['obs_format'] == 'USGS':
                                          float(line.split()[2])]

#======================================================#
# Load data
#======================================================#
# Load data and select time range needed
dict_df_stn = {}  # a dictionary of station data
                  # {station_code: df}
for stn in list_stn:  # for each gauge station, load data
    # Load data
    filename = '{}/{}'.format(cfg['INPUT']['stn_data_dir'], stn)
    if cfg['INPUT']['data_formst']=='USGS':
        column = dict_stn_info[stn][2]
        dict_df_stn[stn] = my_functions.read_USGS_data(filename, [column], ['Discharge'])
    elif cfg['INPUT']['data_formst']=='Lohmann':
        dict_df_stn[stn] = my_functions.read_Lohmann_route_daily_output(filename)

    # Select time range needed
    dict_df_stn[stn] = my_functions.select_time_range(dict_df_stn[stn], \
                                                      start_date, end_date)
    # Convert data to cfs
    if cfg['PARAM']['input_flow_unit']=='cfs':
        pass

#======================================================#
# Write basin.stn.list and basin.stn.obs
#======================================================#
# Write basin.stn.list
f = open(cfg['OUTPUT']['basin_stn_list_path'], 'w')
for stn in list_stn:
    f.write('1 {} {} {} 1000 1000 1000\n'.format(stn, dict_stn_info[stn][0], \
Exemple #5
0
#======================================================#
# Load data
#======================================================#
# Load data and select time range needed
dict_df_stn = {}  # a dictionary of station data
# {station_code: df}
for stn in list_stn:  # for each gauge station, load data
    # Load data
    filename = '{}/{}'.format(cfg['INPUT']['stn_data_dir'], stn)
    if cfg['INPUT']['data_formst'] == 'USGS':
        column = dict_stn_info[stn][2]
        dict_df_stn[stn] = my_functions.read_USGS_data(filename, [column],
                                                       ['Discharge'])
    elif cfg['INPUT']['data_formst'] == 'Lohmann':
        dict_df_stn[stn] = my_functions.read_Lohmann_route_daily_output(
            filename)

    # Select time range needed
    dict_df_stn[stn] = my_functions.select_time_range(dict_df_stn[stn], \
                                                      start_date, end_date)
    # Convert data to cfs
    if cfg['PARAM']['input_flow_unit'] == 'cfs':
        pass

#======================================================#
# Write basin.stn.list and basin.stn.obs
#======================================================#
# Write basin.stn.list
f = open(cfg['OUTPUT']['basin_stn_list_path'], 'w')
for stn in list_stn:
    f.write('1 {} {} {} 1000 1000 1000\n'.format(stn, dict_stn_info[stn][0], \
Exemple #6
0
# Load data
#========================================================
list_s = []  # list of Series to be plotted
list_plot_style = []  # list of plot style for each time series
list_plot_label = []  # list of plot legend label for each time series
for i in range(cfg['INPUT_CONTROL']['n_ts']):  # Load all time series data
    input_section = 'INPUT_{}'.format(i + 1)

    # If from formatted RBM output
    if cfg[input_section]['ts_format'] == 'RBM_formatted':
        s = my_functions.read_RMB_formatted_output(cfg[input_section]['ts_path'], \
                                             var='flow') / 1000 # convert to thousand cfs

    # If from formatted RBM output
    elif cfg[input_section]['ts_format'] == 'Lohmann':
        s = my_functions.read_Lohmann_route_daily_output(cfg[input_section]['ts_path'])\
                                                         / 1000 # convert to thousand cfs

    # If USGS data
    elif cfg[input_section]['ts_format'] == 'USGS':
        if type(cfg[input_section]
                ['usgs_col']) is int:  # if only one needed data column
            df_usgs = my_functions.read_USGS_data(cfg[input_section]['ts_path'], \
                                               columns=[cfg[input_section]['usgs_col']], \
                                               names=['flow']) / 1000 # convert to thousand cfs
            s = df_usgs.ix[:, 0]  # convert df to Series

        else:  # if more than one data column needed, take average
            usgs_flow_col_split = cfg[input_section]['usgs_col'].split('&')
            names = []
            for i in range(len(usgs_flow_col_split)):