コード例 #1
0
def load_default_experiment_simulation(expt_id='Run_1'):
    """ Load a default experiment and already run simulation.

    DEPRECATED: use
    kromatography.model.tests.sample_data_factories.make_sample_experiment2
    instead.
    """
    # Load the experiment
    input_file = io_data_path('ChromExampleDataV2.xlsx')
    study = load_exp_study_from_excel(input_file,
                                      datasource=None,
                                      allow_gui=False)
    expt = study.search_experiment_by_name(expt_id)

    # Build and load the simulation
    sim = build_simulation_from_experiment(expt)
    build_cadet_input(sim)
    output_file = io_data_path('Chrom_Example_Run_1_cadet_simulation.h5')
    update_simulation_results(sim, output_file)
    return expt, sim
コード例 #2
0
def create_cadet_file_for_sim(sim):
    """ Create

    Parameters
    ----------
    sim : Simulation
        Simulation for which to create the CADET file.

    Returns
    -------
    str
        File path created for the simulation.
    """
    cadet_input = build_cadet_input(sim)
    output_file = sim.cadet_filepath
    write_to_h5(output_file, cadet_input, root='/input', overwrite=True)
    return output_file
コード例 #3
0
    def write_sim_to_input_file_and_check(self, sim):
        cadet_input = build_cadet_input(sim)
        output_file = "test.h5"
        with temp_fname(output_file):
            write_to_h5(output_file,
                        cadet_input,
                        root='/input',
                        overwrite=True)
            self.assertTrue(exists(output_file))
            with h5py.File(F1NAME, "r") as h5:
                self.assertEqual(h5.keys(), [u"input"])
                expected = [
                    u'CHROMATOGRAPHY_TYPE', u'discretization', u'model',
                    u'sensitivity', u'solver'
                ]
                self.assertEqual(set(h5[u"input"].keys()), set(expected))

            data_found = read_from_h5(output_file)
            return data_found
コード例 #4
0
    def setUpClass(cls):
        input_file = io_data_path('ChromExampleDataV2.xlsx')
        cls.study = load_study_from_excel(input_file, allow_gui=False)

        # Building and running simulation for only 1 experiment
        expt = cls.study.experiments[0]
        output_file = "{}_{}_{}.h5".format(cls.study.name, expt.name,
                                           'cadet_simulation')
        output_file = string2filename(output_file)
        sim = build_simulation_from_experiment(expt)
        cls.study.simulations.append(sim)

        # create the CADET inputs
        cadet_input = build_cadet_input(sim)

        # write the CADET inputs
        write_to_h5(output_file, cadet_input, root='/input', overwrite=True)
        # run simulation to generate outputs
        run_cadet_simulator(output_file)
        update_simulation_results(sim, output_file)
コード例 #5
0
    def test_build_simulation(self):
        # Setup
        self.sim_builder.column_name = 'CP_001'
        self.sim_builder.method_name = 'Run_1'
        self.sim_builder.first_simulated_step_name = 'Load'
        self.sim_builder.last_simulated_step_name = 'Strip'
        self.sim_builder.transport_model_name = DEFAULT_TRANSPORT_MODEL_NAME
        self.sim_builder.binding_model_name = DEFAULT_BINDING_MODEL_NAME
        sim = self.sim_builder.to_simulation()
        self.assertIsInstance(sim, Simulation)

        # init buffer:
        self.assertEqual(self.sim_builder.initial_buffer_name, '')

        exp1 = self.study.search_experiment_by_name("Run_1")
        equil_buffer = exp1.method.method_steps[1].solutions[0].name
        self.assertEqual(sim.method.initial_buffer.name, equil_buffer)
        # the simulation has to be valid enough that it can be converted to a
        # CADET input...
        cadet_input = build_cadet_input(sim)
        self.assertIsInstance(cadet_input, CADETInput)
コード例 #6
0
def run_chromatography_simulation(input_file,
                                  output_file=None,
                                  expt_id="Run_1",
                                  skip_cadet=False,
                                  skip_plot=False,
                                  skip_animation=False,
                                  binding_model=None,
                                  transport_model=None,
                                  allow_gui=True):
    """ Run chromatography simulation for the inputs given in `input_file`
    and plot the results.

    Parameters
    ----------
    input_file : str (file path)
        The file path for the excel file containing the experiment/simulation
        input data.

    output_file : str (file path)
        The file path for the CADET output h5 file. If None, then a default
        name is chosen based on the study and experiment ids.

    expt_id : str
        The name of the exeperiment to use for intializing the CADET
        simulation. If None, the first experiment in the study is chosen.

    skip_cadet : bool
        If True, the CADET simulation is not run but instead the output
        file is directly loaded (assuming one already exists). The main usecase
        here is for testing.

    skip_plot : bool
        If True, the chromatogram plot is not generated. This is useful for
        testing.

    Returns
    -------
    study : Study
        The Study instance containing the experiment and the simulation data.
    """
    study = load_study_from_excel(input_file, allow_gui=allow_gui)

    # lets just pick a single experiment
    if expt_id is None:
        expt = study.experiments[0]
    else:
        expt = study.search_experiment_by_name(expt_id)

    logger.info('Running simulation for experiment : {!r}'.format(expt_id))

    if output_file is None:
        output_file = ("{}_{}_{}.h5".format(study.name, expt.name,
                                            'cadet_simulation'))
        output_file = string2filename(output_file)

    # create a simulation object from an experiment
    # FIXME: how to identify related expt and simulations !
    sim = build_simulation_from_experiment(expt,
                                           binding_model=binding_model,
                                           transport_model=transport_model)

    study.simulations.append(sim)

    # create the CADET inputs
    cadet_input = build_cadet_input(sim)

    # NOTE: This is primarily used for testing/debugging workflow when the
    # CADET simulation doesn't need to be run everytime.
    if not skip_cadet:
        # write the CADET inputs
        write_to_h5(output_file, cadet_input, root='/input', overwrite=True)
        logger.info("Output file {} was generated".format(output_file))

        # run simulation to generate outputs
        run_cadet_simulator(output_file)

    update_simulation_results(sim, output_file)

    if not skip_plot:
        plot_chromatogram(expt, sim)

    if not skip_animation:
        column_animation(sim)

    return study