Пример #1
0
def test_generate_full_mc(tmpdir):
    """Test generation of full monte carlo"""
    inputfile = TESTDATA / "config/design_input_mc_with_correls.xlsx"
    input_dict = excel2dict_design(inputfile)

    design = DesignMatrix()
    design.generate(input_dict)

    # Checking dimensions of design matrix
    assert design.designvalues.shape == (500, 16)

    # Checking reproducibility from distribution_seed
    assert design.designvalues["PARAM1"].sum() == 17.419

    # Write to disk and check some validity
    tmpdir.chdir()
    design.to_xlsx("designmatrix.xlsx")
    assert Path("designmatrix.xlsx").exists
    diskdesign = pd.read_excel("designmatrix.xlsx",
                               sheet_name="DesignSheet01",
                               engine="openpyxl")
    assert "REAL" in diskdesign
    assert "SENSNAME" in diskdesign
    assert "SENSCASE" in diskdesign
    assert not diskdesign.empty

    diskdefaults = pd.read_excel("designmatrix.xlsx",
                                 sheet_name="DefaultValues",
                                 engine="openpyxl")
    assert not diskdefaults.empty
    assert len(diskdefaults.columns) == 2
Пример #2
0
def test_generate_onebyone(tmpdir):
    """Test generation of onebyone design"""

    inputfile = TESTDATA / "config/design_input_example1.xlsx"
    input_dict = excel2dict_design(inputfile)

    design = DesignMatrix()
    design.generate(input_dict)
    # Checking dimensions of design matrix
    assert design.designvalues.shape == (80, 10)

    # Write to disk and check some validity
    tmpdir.chdir()
    design.to_xlsx("designmatrix.xlsx")
    assert Path("designmatrix.xlsx").exists
    diskdesign = pd.read_excel("designmatrix.xlsx", engine="openpyxl")
    assert "REAL" in diskdesign
    assert "SENSNAME" in diskdesign
    assert "SENSCASE" in diskdesign
    assert not diskdesign.empty

    diskdefaults = pd.read_excel("designmatrix.xlsx",
                                 sheet_name="DefaultValues",
                                 engine="openpyxl")
    assert not diskdefaults.empty
    assert len(diskdefaults.columns) == 2
Пример #3
0
def test_generate_full_mc(tmpdir):
    """Test generation of full monte carlo"""
    if "__file__" in globals():
        # Easen up copying test code into interactive sessions
        testdir = os.path.dirname(os.path.abspath(__file__))
    else:
        testdir = os.path.abspath(".")

    inputfile = (testdir + "/data/sensitivities/config/" +
                 "design_input_mc_with_correls.xlsx")
    input_dict = excel2dict_design(inputfile)

    design = DesignMatrix()
    design.generate(input_dict)

    # Checking dimensions of design matrix
    assert design.designvalues.shape == (500, 16)

    # Checking reproducibility from distribution_seed
    assert design.designvalues["PARAM1"].sum() == 17.419

    # Write to disk and check some validity
    tmpdir.chdir()
    design.to_xlsx("designmatrix.xlsx")
    assert os.path.exists("designmatrix.xlsx")
    diskdesign = pd.read_excel("designmatrix.xlsx", sheet_name="DesignSheet01")
    assert "REAL" in diskdesign
    assert "SENSNAME" in diskdesign
    assert "SENSCASE" in diskdesign
    assert not diskdesign.empty

    diskdefaults = pd.read_excel("designmatrix.xlsx",
                                 sheet_name="DefaultValues")
    assert not diskdefaults.empty
    assert len(diskdefaults.columns) == 2
Пример #4
0
def test_generate_onebyone(tmpdir):
    """Test generation of onebyone design"""

    if "__file__" in globals():
        # Easen up copying test code into interactive sessions
        testdir = os.path.dirname(os.path.abspath(__file__))
    else:
        testdir = os.path.abspath(".")

    inputfile = testdir + "/data/sensitivities/config/" + "design_input_example1.xlsx"
    input_dict = excel2dict_design(inputfile)

    design = DesignMatrix()
    design.generate(input_dict)
    # Checking dimensions of design matrix
    assert design.designvalues.shape == (80, 10)

    # Write to disk and check some validity
    tmpdir.chdir()
    design.to_xlsx("designmatrix.xlsx")
    assert os.path.exists("designmatrix.xlsx")
    diskdesign = pd.read_excel("designmatrix.xlsx")
    assert "REAL" in diskdesign
    assert "SENSNAME" in diskdesign
    assert "SENSCASE" in diskdesign
    assert not diskdesign.empty

    diskdefaults = pd.read_excel("designmatrix.xlsx",
                                 sheet_name="DefaultValues")
    assert not diskdefaults.empty
    assert len(diskdefaults.columns) == 2
Пример #5
0
def main():
    """fmudesign is a command line utility for generating design matrices

    Wrapper for the the fmu.tools.sensitivities module"""

    parser = get_parser()
    args = parser.parse_args()

    # Defaulted options should be reset to None, so that the other
    # defaulting level inside _excel2dict can do its work.
    if args.designinput == parser.get_default("designinput"):
        args.designinput = None
    if args.defaultvalues == parser.get_default("defaultvalues"):
        args.defaultvalues = None
    if args.general_input == parser.get_default("general_input"):
        args.general_input = None

    sheetnames = dict()
    if args.designinput:
        sheetnames["designinput"] = args.designinput
    if args.defaultvalues:
        sheetnames["defaultvalues"] = args.defaultvalues
    if args.general_input:
        sheetnames["general_input"] = args.general_input

    if sheetnames:
        print("Worksheets changed from default:")
        print(sheetnames)

    if isinstance(args.config, str):
        if not Path(args.config).is_file():
            raise IOError("Input file {} does not exist".format(args.config))
        input_dict = excel2dict_design(args.config, sheetnames)

    if args.config == args.destination:
        raise IOError('Identical name "{}" have been provided for the input'
                      "file and the output file. "
                      " Exiting.....".format(args.config))

    design = DesignMatrix()

    design.generate(input_dict)

    Path(args.destination).parent.mkdir(exist_ok=True, parents=True)

    design.to_xlsx(args.destination)
Пример #6
0
def main(args=None):
    """fmudesign is a command line utility for generating design matrices

    Wrapper for the the fmu.tools.sensitivities module"""

    args = _do_parse_args(args)

    sheetnames = dict()
    if args.designinput:
        sheetnames["designinput"] = args.designinput
    if args.defaultvalues:
        sheetnames["defaultvalues"] = args.defaultvalues
    if args.general_input:
        sheetnames["general_input"] = args.general_input

    if sheetnames:
        print("Worksheets changed from default:")
        print(sheetnames)

    if isinstance(args.config, str):
        if not os.path.isfile(args.config):
            raise IOError("Input file {} does not exist".format(args.config))
        input_dict = excel2dict_design(args.config, sheetnames)

    if args.config == args.destination:
        raise IOError('Identical name "{}" have been provided for the input'
                      "file and the output file. "
                      " Exiting.....".format(args.config))

    design = DesignMatrix()

    design.generate(input_dict)

    folder = os.path.dirname(args.destination)

    if folder and not os.path.exists(folder):
        os.makedirs(folder)

    design.to_xlsx(args.destination)
Пример #7
0
#    input_dict=yaml.load(input_file)

path = "./tests/data/sensitivities/config/"
prefix = "design_input_"
postfix = ".xlsx"
config = [
    "example1",
    "example2",
    "example_velocities",
    "singlereference",
    "singlereference_and_seed",
    "default_no_seed",
    "onebyone",
    "background_no_seed",
    "background_extseeds",
    "mc_with_correls",
    "montecarlo_full",
    "mc_corr_depend",
]

for input in range(len(config)):
    filename = path + prefix + config[input] + postfix
    print("Reading {}".format(filename))
    input_dict = excel2dict_design(filename)
    # input_dict.to_yaml(input_dict, 'examples/output/'+config[input]+'.yaml')
    design = DesignMatrix()
    design.generate(input_dict)
    design.to_xlsx("examples/output/design_" + config[input] + postfix)
    # if design.backgroundvalues is not None:
    # design.background_to_excel('examples/output/background.xlsx')