Exemplo n.º 1
0
    ueb_df.columns = [
        'ueb_' + name if 'ueb' not in name else name for name in ueb_df.columns
    ]

if os.path.isdir(snow17_dir):
    ts_file_list = [
        os.path.join(snow17_dir, name) for name in os.listdir(snow17_dir)
        if name[-2:] == 'ts'
    ]
    snow17_df = get_sac_ts_dataframe(ts_file_list, sim_skip=snow17_skip)
    snow17_df.columns = [
        'snow17_' + name if 'snow17' not in name else name
        for name in snow17_df.columns
    ]

obs_df = get_obs_dataframe(obs_discharge_path)


# step2 get plots for each water year
def get_discharge_stats(obs, sim):
    nse = 1 - sum(np.power(
        (obs - sim), 2)) / sum(np.power((obs - obs.mean()), 2))
    bias = (sim - obs).mean()
    rmse = np.sqrt(np.mean(np.power((obs - sim), 2)))
    return {'nse': nse, 'bias': bias, 'rmse': rmse}


fig, ax_list = plt.subplots(len(water_year_list),
                            2,
                            figsize=(20, 5 * len(water_year_list)))
snow17_skip = 136
ueb_skip = 121

start_time = '1989-10-1'
end_time = '2005-9-30'
dt = 6

result_dir = os.path.join(
    os.getcwd(), 'discharge_table_analysis_{}_{}'.format(
        watershed, 'all' if end_time == '' else start_time[:4] + end_time[:4]))
if not os.path.isdir(result_dir):
    os.makedirs(result_dir)

# step 1 get discharge data frame  ##############################################
obs_df = get_obs_dataframe(obs_file, start_time, end_time)
ueb_df = get_sim_dataframe(ueb_file,
                           start_time=start_time,
                           end_time=end_time,
                           sim_skip=ueb_skip)
snow17_df = get_sim_dataframe(snow17_file,
                              start_time=start_time,
                              end_time=end_time,
                              sim_skip=snow17_skip)

DF = pd.concat(
    [obs_df, ueb_df, snow17_df], axis=1
)  # obs should be first used by the loop to get the discharge threshold
DF.columns = [
    'obs', 'ueb', 'snow17'
]  # obs should be first used by the loop to get the discharge threshold
Exemplo n.º 3
0
        folder_path = os.path.join(os.getcwd(), output_folder, folder)
        if os.path.isdir(folder_path):
            ts_file_name = [
                x for x in os.listdir(folder_path) if x[-3:] == '.ts'
            ].pop()
            ts_file_path = os.path.join(folder_path, ts_file_name)
            sim = get_sim_dataframe(ts_file_path,
                                    start_time=start_time,
                                    end_time=end_time)
            sim_list.append(sim)
            column_names.append(folder)

    DF = pd.concat(sim_list, axis=1, join='inner')
    DF.columns = column_names

    obs = get_obs_dataframe(obs_file_path)

    # get the statistics for all the options
    stat_result = pd.DataFrame(columns=[
        'rmse',
        'nse',
        'mae',
        'r',
        'bias',
        # 'monthly_bias', 'annual_bias', 'vol_err'
    ])
    for column in column_names:
        df = pd.concat([DF[column], obs], axis=1,
                       join_axes=[DF[column].index]).reset_index()
        df.columns = ['time', 'sim', 'obs']
        rmse, nse, mae, r, bias = get_basic_stats(df)
Exemplo n.º 4
0
    # compare discharge with obs.
    concat_df['discharge_diff'] = concat_df['ueb_discharge'] - concat_df[
        'snow17_discharge']

    fig, ax = plt.subplots(2, 1, figsize=(10, 8))
    concat_df.plot(
        y=['ueb_discharge', 'snow17_discharge'],
        ax=ax[0],
        style=['-', ':'],
        title='Compare discharge between UEB and Snow17',
    )
    ax[0].set_ylabel('discharge(cms)')

    if obs_discharge_path:
        obs_discharge = get_obs_dataframe(obs_discharge_path,
                                          start_time=start_time,
                                          end_time=end_time)
        if len(obs_discharge) != 0:
            obs_discharge.plot.area(ax=ax[0], alpha=0.3)

    concat_df.plot(
        y=['discharge_diff'],
        ax=ax[1],
        title='Difference of discharge between UEB and Snow17',
        legend=False,
    )
    ax[1].legend(['ueb - snow17'])
    ax[1].set_ylabel('discharge(cms)')
    plt.tight_layout()
    fig.savefig(os.path.join(result_dir, 'compare_discharge.png'))