generate_snapshot_batch#

TwinModel.generate_snapshot_batch(batch_results, rom_name, on_disk=True, named_selection=None)#

Generate several field snapshots based on historical batch results of the Twin, either in memory or on disk, for the full field or a specific named selection. It returns a list of the field data as an array if in memory, or a list of the paths of the different snapshots written on disk.

Parameters:
batch_resultspandas.DataFrame

Historical output values stored in a Pandas dataframe. It must have a ‘Time’ column and all the time instants for the twin model outputs that you want to post process, with one output per column.

rom_namestr

Name of the TBROM considered to generate the snapshot.

on_diskbool

Whether the snapshot file is saved on disk (True which is the default) or returned in memory (False).

named_selectionstr (optional)

Named selection on which the snasphot has to be generated.

Returns:
list[str] | list[np.ndarray]

List of paths to snapshots written to disk if on_disk == True, else list of arrays of snapshot field data

Raises:
TwinModelError:

If the pytwin.TwinModel.initialize_evaluation() method has not been called before. If rom_name is not included in the Twin’s list of TBROM If TBROM hasn’t its mode coefficients outputs connected to the twin’s outputs. If name_selection is not included in the TBROM’s list of Named Selections

Examples

>>> import pandas as pd
>>> from pytwin import TwinModel
>>> # Instantiate a twin model, initialize it, and evaluate it step by step until you want to save its state
>>> model = TwinModel('model.twin')
>>> inputs_df = pd.DataFrame({'Time': [0., 1., 2.], 'input1': [1., 2., 3.], 'input2': [1., 2., 3.]})
>>> model.initialize_evaluation(inputs={'input1': 1., 'input2': 1.})
>>> romname = model.tbrom_names[0]
>>> nslist = model.get_named_selections(romname)
>>> outputs_df = model.evaluate_batch(inputs_df=inputs_df)
>>> fieldresults = model.generate_snapshot_batch(outputs_df, romname, nslist[0])