a function to apply boundary condition multiplier parameters.  Used to implement
    the parameterization constructed by PstFromFlopyModel during a forward run

    Note
    ----
    requires either "temporal_list_pars.csv" or "spatial_list_pars.csv"

    should be added to the forward_run.py script

def apply_list_pars():
    """ a function to apply boundary condition multiplier parameters.  Used to implement
    the parameterization constructed by PstFromFlopyModel during a forward run

    Note
    ----
    requires either "temporal_list_pars.csv" or "spatial_list_pars.csv"

    should be added to the forward_run.py script

    """
    temp_file = "temporal_list_pars.dat"
    spat_file = "spatial_list_pars.dat"

    temp_df,spat_df = None,None
    if os.path.exists(temp_file):
        temp_df = pd.read_csv(temp_file, delim_whitespace=True)
        temp_df.loc[:,"split_filename"] = temp_df.filename.apply(lambda x: os.path.split(x)[-1])
        org_dir = temp_df.list_org.iloc[0]
        model_ext_path = temp_df.model_ext_path.iloc[0]
    if os.path.exists(spat_file):
        spat_df = pd.read_csv(spat_file, delim_whitespace=True)
        spat_df.loc[:,"split_filename"] = spat_df.filename.apply(lambda x: os.path.split(x)[-1])
        mlt_dir = spat_df.list_mlt.iloc[0]
        org_dir = spat_df.list_org.iloc[0]
        model_ext_path = spat_df.model_ext_path.iloc[0]
    if temp_df is None and spat_df is None:
        raise Exception("apply_list_pars() - no key dfs found, nothing to do...")
    # load the spatial mult dfs
    sp_mlts = {}
    if spat_df is not None:

        for f in os.listdir(mlt_dir):
            pak = f.split(".")[0].lower()
            df = pd.read_csv(os.path.join(mlt_dir,f),index_col=0, delim_whitespace=True)
            #if pak != 'hfb6':
            df.index = df.apply(lambda x: "{0:02.0f}{1:04.0f}{2:04.0f}".format(x.k,x.i,x.j),axis=1)
            # else:
            #     df.index = df.apply(lambda x: "{0:02.0f}{1:04.0f}{2:04.0f}{2:04.0f}{2:04.0f}".format(x.k, x.irow1, x.icol1,
            #                                                                      x.irow2, x.icol2), axis = 1)
            if pak in sp_mlts.keys():
                raise Exception("duplicate multplier csv for pak {0}".format(pak))
            if df.shape[0] == 0:
                raise Exception("empty dataframe for spatial list file: {0}".format(f))
            sp_mlts[pak] = df

    org_files = os.listdir(org_dir)
    #for fname in df.filename.unique():
    for fname in org_files:
        # need to get the PAK name to handle stupid horrible expceptions for HFB...
        # try:
        #     pakspat = sum([True if fname in i else False for i in spat_df.filename])
        #     if pakspat:
        #         pak = spat_df.loc[spat_df.filename.str.contains(fname)].pak.values[0]
        #     else:
        #         pak = 'notHFB'
        # except:
        #     pak = "notHFB"

        names = None
        if temp_df is not None and fname in temp_df.split_filename.values:
            temp_df_fname = temp_df.loc[temp_df.split_filename==fname,:]
            if temp_df_fname.shape[0] > 0:
                names = temp_df_fname.dtype_names.iloc[0].split(',')
        if spat_df is not None and fname in spat_df.split_filename.values:
            spat_df_fname = spat_df.loc[spat_df.split_filename == fname, :]
            if spat_df_fname.shape[0] > 0:
                names = spat_df_fname.dtype_names.iloc[0].split(',')
        if names is not None:

            df_list = pd.read_csv(os.path.join(org_dir, fname),
                                  delim_whitespace=True, header=None, names=names)
            df_list.loc[:, "idx"] = df_list.apply(lambda x: "{0:02.0f}{1:04.0f}{2:04.0f}".format(x.k-1, x.i-1, x.j-1), axis=1)


            df_list.index = df_list.idx
            pak_name = fname.split('_')[0].lower()
            if pak_name in sp_mlts:
                mlt_df = sp_mlts[pak_name]
                mlt_df_ri = mlt_df.reindex(df_list.index)
                for col in df_list.columns:
                    if col in ["k","i","j","inode",'irow1','icol1','irow2','icol2','idx']:
                        continue
                    if col in mlt_df.columns:
                       # print(mlt_df.loc[mlt_df.index.duplicated(),:])
                       # print(df_list.loc[df_list.index.duplicated(),:])
                        df_list.loc[:,col] *= mlt_df_ri.loc[:,col].values

            if temp_df is not None and fname in temp_df.split_filename.values:
                temp_df_fname = temp_df.loc[temp_df.split_filename == fname, :]
                for col,val in zip(temp_df_fname.col,temp_df_fname.val):
                     df_list.loc[:,col] *= val
            fmts = ''
            for name in names:
                if name in ["i","j","k","inode",'irow1','icol1','irow2','icol2']:
                    fmts += " %9d"
                else:
                    fmts += " %9G"
        np.savetxt(os.path.join(model_ext_path, fname), df_list.loc[:, names].values, fmt=fmts)