def test_study(self): input_file = io_data_path('ChromExampleDataV2.xlsx') obj = load_study_from_excel(input_file, allow_gui=False) expected = ['product', 'is_blank', 'name', 'study_type', 'editable', 'class_metadata', 'study_purpose', 'experiments', 'simulations', 'study_datasource', 'exp_study_filepath', 'analysis_tools'] assert_serial_data_contains(obj, expected)
def setUp(self): fname = "PROD001_Example_Pulse_Injection_Study.xlsx" folder = join(dirname(kromatography.__file__), "data", "tutorial_data") fpath = join(folder, fname) pulse_study = load_study_from_excel(fpath, allow_gui=False) self.exp = pulse_study.search_experiment_by_name("Run_1") # Multi-component product experiment self.exp2 = make_sample_experiment2()
def test_read_input_files_with_release_ds(self): ds = SimpleDataSource.from_data_catalog(DATA_CATALOG) # Make sure that's the external datasource self.assertEqual(len(ds.products), 3) study = load_study_from_excel(self.tutorial_file, datasource=ds, allow_gui=False) self.assert_valid_tutorial_study(study)
def test_read_input_files_with_internal_ds(self): ds = SimpleDataSource() # Make sure that's the internal datasource self.assertGreater(len(ds.products), 5) study = load_study_from_excel(self.tutorial_file, datasource=ds, allow_gui=False) self.assert_valid_tutorial_study(study)
def make_sample_study2(source=DEFAULT_INPUT, add_sims=0, add_transp_bind_models=False, with_ph_bind=False): """ Load an simulation from a standard source file. """ from kromatography.io.study import load_study_from_excel from kromatography.utils.testing_utils import io_data_path from kromatography.model.factories.transport_model import \ create_transport_model from kromatography.model.factories.binding_model import \ create_binding_model from kromatography.model.binding_model import PH_STERIC_BINDING_MODEL, \ STERIC_BINDING_MODEL from kromatography.model.factories.simulation import \ build_simulation_from_experiment filepath = io_data_path(source) test_study = load_study_from_excel(filepath, allow_gui=False) if add_transp_bind_models: study_ds = test_study.study_datasource num_comp = len(test_study.product.product_components) + 1 tr_model = create_transport_model(num_comp) study_ds.set_object_of_type("transport_models", tr_model) if with_ph_bind: bind_model = create_binding_model( num_comp, model_type=PH_STERIC_BINDING_MODEL ) else: bind_model = create_binding_model( num_comp, model_type=STERIC_BINDING_MODEL ) study_ds.set_object_of_type("binding_models", bind_model) else: tr_model = None bind_model = None if isinstance(add_sims, int) and add_sims > 0: for i in range(add_sims): exp = test_study.experiments[i] sim = build_simulation_from_experiment( exp, transport_model=tr_model, binding_model=bind_model ) test_study.simulations.append(sim) elif isinstance(add_sims, basestring): exp = test_study.search_experiment_by_name(add_sims) sim = build_simulation_from_experiment( exp, transport_model=tr_model, binding_model=bind_model ) test_study.simulations.append(sim) return test_study
def make_sample_experiment2_with_strip(exp_name="Run_1", source=DEFAULT_INPUT_WITH_STRIP): from kromatography.utils.api import load_default_user_datasource from kromatography.io.api import load_study_from_excel from kromatography.utils.testing_utils import io_data_path from kromatography.model.factories.product import add_strip_to_product ds = load_default_user_datasource()[0] prod1 = ds.get_object_of_type("products", "Prod000Complex") new_prod, new_comp = add_strip_to_product(prod1, 18.8, 0.75) new_prod.name = "Prod001_with_strip" ds.set_object_of_type("products", new_prod) ds.set_object_of_type("product_components", new_comp) filepath = io_data_path(source) study = load_study_from_excel(filepath, datasource=ds, allow_gui=False) experim = study.search_experiment_by_name(exp_name) return experim
def build_study_from_file(self, filepath, allow_gui=True): """ Build a new task and window from loading an ExperimentalStudy file. Returns ------- TaskWindow Returns the newly created TaskWindow around the provided study. """ from kromatography.io.study import load_study_from_excel study = load_study_from_excel(filepath, datasource=self.datasource, allow_gui=allow_gui) window = self.create_new_task_window(study=study) if study.product_contains_strip: study.request_strip_fraction_tool() return window
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)
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