Beispiel #1
0
def add_pi_obj_func(pst, obj_func_dict=None, out_pst_name=None):
    if not isinstance(pst, Pst):
        pst = Pst(pst)
    if obj_func_dict is None:
        obj_func_dict = {name: 1.0 for name in pst.adj_par_names}
    pi_equation = ''
    for name, coef in obj_func_dict.items():
        assert (name in pst.adj_par_names
                ), "obj func component not in adjustable pars:" + name
        if coef < 0.0:
            pi_equation += ' - {0}*{1}'.format(coef, name)
        else:
            pi_equation += ' + {0}*{1}'.format(coef, name)
    pi_equation += ' = 0.0'
    pilbl = "pi_obj_func"
    pi_df = pd.DataFrame(
        {
            "pilbl": pilbl,
            "equation": pi_equation,
            "weight": 0.0,
            "obgnme": pilbl
        },
        index=[pilbl])

    if pst.prior_information.shape[0] == 0:
        pst.prior_information = pi_df
    else:
        assert pilbl not in pst.prior_information.index
        # append by enlargement
        pst.prior_information.loc[pilbl, :] = pi_df.loc[pilbl, :]

    if out_pst_name is not None:
        pst.write(out_pst_name)

    return pst
Beispiel #2
0
def add_pi_obj_func(pst,obj_func_dict=None,out_pst_name=None):
    if not isinstance(pst,Pst):
        pst = Pst(pst)
    if obj_func_dict is None:
        obj_func_dict = {name:1.0 for name in pst.adj_par_names}
    pi_equation = ''
    for name,coef in obj_func_dict.items():
        assert(name in pst.adj_par_names),"obj func component not in adjustable pars:"+name
        if coef < 0.0:
            pi_equation += ' - {0}*{1}'.format(coef,name)
        else:
            pi_equation += ' + {0}*{1}'.format(coef, name)
    pi_equation += ' = 0.0'
    pilbl = "pi_obj_func"
    pi_df = pd.DataFrame({"pilbl":pilbl,"equation":pi_equation,"weight":0.0,"obgnme":pilbl},index=[pilbl])

    if pst.prior_information.shape[0] == 0:
        pst.prior_information = pi_df
    else:
        assert pilbl not in pst.prior_information.index
        # append by enlargement
        pst.prior_information.loc[pilbl,:] = pi_df.loc[pilbl,:]

    if out_pst_name is not None:
        pst.write(out_pst_name)

    return pst
Beispiel #3
0
def load_test():
    import os
    from pyemu import Pst, pst_utils
    pst_dir = os.path.join("pst")
    temp_dir = "temp"
    if not os.path.exists(temp_dir):
        os.mkdir(temp_dir)
    # just testing all sorts of different pst files
    pst_files = os.listdir(pst_dir)
    exceptions = []
    load_fails = []
    for pst_file in pst_files:
        if "pest_tied_tester" not in pst_file:
            continue
        if pst_file.endswith(".pst") and not "comments" in pst_file and \
                not "missing" in pst_file:
            print(pst_file)
            try:
                p = Pst(os.path.join(pst_dir, pst_file))
            except Exception as e:
                exceptions.append(pst_file + " read fail: " + str(e))
                load_fails.append(pst_file)
                continue
            out_name = os.path.join(temp_dir, pst_file)
            print(out_name)
            # p.write(out_name)
            try:
                p.write(out_name)
            except Exception as e:
                exceptions.append(pst_file + " write fail: " + str(e))
                continue
            print(pst_file)
            try:
                p = Pst(out_name)
            except Exception as e:
                exceptions.append(pst_file + " reload fail: " + str(e))
                continue
            print(out_name)
            # p.write(out_name)
            try:
                p.write(out_name, version=2)
            except Exception as e:
                exceptions.append(pst_file + " v2 write fail: " + str(e))
                continue

            p = Pst(out_name)
            try:
                p = Pst(out_name)
            except Exception as e:
                exceptions.append(pst_file + " v2 reload fail: " + str(e))
                continue

    # with open("load_fails.txt",'w') as f:
    #    [f.write(pst_file+'\n') for pst_file in load_fails]
    if len(exceptions) > 0:
        raise Exception('\n'.join(exceptions))
Beispiel #4
0
def pst_manip_test():
    import os
    from pyemu import Pst
    pst_dir = os.path.join('..', 'tests', "pst")
    org_path = os.path.join(pst_dir, "pest.pst")
    new_path = os.path.join(pst_dir, "pest1.pst")
    pst = Pst(org_path)
    pst.control_data.pestmode = "regularisation"
    pst.write(new_path)
    pst = Pst(new_path)

    pst.write(new_path, update_regul=True)
Beispiel #5
0
def pst_manip_test():
    import os
    from pyemu import Pst
    pst_dir = os.path.join('..','tests',"pst")
    org_path = os.path.join(pst_dir,"pest.pst")
    new_path = os.path.join(pst_dir,"pest1.pst")
    pst = Pst(org_path)
    pst.control_data.pestmode = "regularisation"
    pst.write(new_path)
    pst = Pst(new_path)

    pst.write(new_path,update_regul=True)
Beispiel #6
0
def pst_manip_test():
    import os
    from pyemu import Pst
    pst_dir = os.path.join("pst")
    org_path = os.path.join(pst_dir, "pest.pst")
    new_path = os.path.join("temp", "pest1.pst")
    pst = Pst(org_path)
    pst.control_data.pestmode = "regularisation"
    pst.write(new_path)
    pst = Pst(new_path)
    pst.svd_data.maxsing = 1
    pst.write(new_path)
Beispiel #7
0
def flex_load_test():
    import os
    from pyemu import Pst, pst_utils
    pst_dir = os.path.join("pst")
    temp_dir = "temp"
    if not os.path.exists(temp_dir):
        os.mkdir(temp_dir)
    # just testing all sorts of different pst files
    pst_files = os.listdir(pst_dir)
    exceptions = []
    load_fails = []
    for pst_file in pst_files:
        if pst_file.endswith(".pst") and not "missing" in pst_file:
            # if not pst_file.startswith("LPR"):
            #    continue
            print(pst_file)
            p = Pst(os.path.join(pst_dir, pst_file), flex=True)
            out_name = os.path.join(temp_dir, pst_file)
            print("write")
            p.write(out_name, update_regul=True)
            p = Pst(out_name)
        #  try:
        #      p = Pst(os.path.join(pst_dir,pst_file),flex=True)
        #  except Exception as e:
        #      exceptions.append(pst_file + " read fail: " + str(e))
        #      load_fails.append(pst_file)
        #      continue
        #  out_name = os.path.join(temp_dir,pst_file)
        #  print(out_name)
        # #p.write(out_name,update_regul=True)
        #  try:
        #      p.write(out_name,update_regul=True)
        #  except Exception as e:
        #      exceptions.append(pst_file + " write fail: " + str(e))
        #      continue
        #  print(pst_file)
        #  try:
        #      p = Pst(out_name)
        #  except Exception as e:
        #      exceptions.append(pst_file + " reload fail: " + str(e))
        #      continue

    # with open("load_fails.txt",'w') as f:
    #    [f.write(pst_file+'\n') for pst_file in load_fails]
    if len(exceptions) > 0:
        raise Exception('\n'.join(exceptions))
Beispiel #8
0
def flex_load_test():
    import os
    from pyemu import Pst,pst_utils
    pst_dir = os.path.join("pst")
    temp_dir = "temp"
    if not os.path.exists(temp_dir):
        os.mkdir(temp_dir)
    # just testing all sorts of different pst files
    pst_files = os.listdir(pst_dir)
    exceptions = []
    load_fails = []
    for pst_file in pst_files:
        if pst_file.endswith(".pst") and not "missing" in pst_file:
            #if not pst_file.startswith("LPR"):
            #    continue
            print(pst_file)
            p = Pst(os.path.join(pst_dir, pst_file), flex=True)
            out_name = os.path.join(temp_dir, pst_file)
            print("write")
            p.write(out_name, update_regul=True)
            p = Pst(out_name)
           #  try:
           #      p = Pst(os.path.join(pst_dir,pst_file),flex=True)
           #  except Exception as e:
           #      exceptions.append(pst_file + " read fail: " + str(e))
           #      load_fails.append(pst_file)
           #      continue
           #  out_name = os.path.join(temp_dir,pst_file)
           #  print(out_name)
           # #p.write(out_name,update_regul=True)
           #  try:
           #      p.write(out_name,update_regul=True)
           #  except Exception as e:
           #      exceptions.append(pst_file + " write fail: " + str(e))
           #      continue
           #  print(pst_file)
           #  try:
           #      p = Pst(out_name)
           #  except Exception as e:
           #      exceptions.append(pst_file + " reload fail: " + str(e))
           #      continue

    #with open("load_fails.txt",'w') as f:
    #    [f.write(pst_file+'\n') for pst_file in load_fails]
    if len(exceptions) > 0:
        raise Exception('\n'.join(exceptions))
Beispiel #9
0
def load_test():
    import os
    from pyemu import Pst, pst_utils
    pst_dir = os.path.join('..', 'tests', "pst")
    temp_dir = "temp"
    if not os.path.exists(temp_dir):
        os.mkdir(temp_dir)
    # just testing all sorts of different pst files
    pst_files = os.listdir(pst_dir)
    exceptions = []
    load_fails = []
    for pst_file in pst_files:
        if pst_file.endswith(".pst"):
            print(pst_file)
            try:
                p = Pst(os.path.join(pst_dir, pst_file))
            except Exception as e:
                exceptions.append(pst_file + " read fail: " + str(e))
                load_fails.append(pst_file)
                continue
            out_name = os.path.join(temp_dir, pst_file)
            #p.write(out_name,update_regul=True)
            try:
                p.write(out_name, update_regul=True)
            except Exception as e:
                exceptions.append(pst_file + " write fail: " + str(e))
                continue
            try:
                p = Pst(out_name)
            except Exception as e:
                exceptions.append(pst_file + " reload fail: " + str(e))
                continue

    #with open("load_fails.txt",'w') as f:
    #    [f.write(pst_file+'\n') for pst_file in load_fails]
    if len(exceptions) > 0:
        raise Exception('\n'.join(exceptions))
Beispiel #10
0
def load_test():
    import os
    from pyemu import Pst,pst_utils
    pst_dir = os.path.join('..','tests',"pst")
    temp_dir = "temp"
    if not os.path.exists(temp_dir):
        os.mkdir(temp_dir)
    # just testing all sorts of different pst files
    pst_files = os.listdir(pst_dir)
    exceptions = []
    load_fails = []
    for pst_file in pst_files:
        if pst_file.endswith(".pst"):
            print(pst_file)
            try:
                p = Pst(os.path.join(pst_dir,pst_file))
            except Exception as e:
                exceptions.append(pst_file + " read fail: " + str(e))
                load_fails.append(pst_file)
                continue
            out_name = os.path.join(temp_dir,pst_file)
           #p.write(out_name,update_regul=True)
            try:
                p.write(out_name,update_regul=True)
            except Exception as e:
                exceptions.append(pst_file + " write fail: " + str(e))
                continue
            try:
                p = Pst(out_name)
            except Exception as e:
                exceptions.append(pst_file + " reload fail: " + str(e))
                continue

    #with open("load_fails.txt",'w') as f:
    #    [f.write(pst_file+'\n') for pst_file in load_fails]
    if len(exceptions) > 0:
        raise Exception('\n'.join(exceptions))