def test_char_map_number_of_dimensions(): cmp_char.char_map(x=[0, 1, 2], y=[[1, 2, 3, 4], [1, 2, 3, 4]])
def test_char_map_missing_key(): cmp_char.char_map(a=6)
def test_char_map_number_of_points(): cmp_char.char_map(x=[0, 1, 2], y=[[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3]])
def construct_comps(c, *args): r""" Creates TESPy component from class name provided in the .csv-file and specifies its parameters. Parameters ---------- c : pandas.core.series.Series Component information from .csv-file. args[0] : pandas.core.frame.DataFrame DataFrame containing the x and y data of characteristic functions. args[1] : pandas.core.frame.DataFrame DataFrame containing the x, y, z1 and z2 data of characteristic maps. Returns ------- instance : tespy.components.components.component TESPy component object. """ if c.interface: instance = cmp.subsys_interface(c.label, num_inter=1) else: target_class = getattr(cmp, c.cp) instance = target_class(c.label) kwargs = {} # basic properties for key in ['mode', 'design', 'offdesign']: kwargs[key] = c[key] for key, value in instance.attr().items(): if key in c: # component parameters if isinstance(value, hlp.dc_cp): dc = hlp.dc_cp(val=c[key], is_set=c[key + '_set'], is_var=c[key + '_var']) kwargs[key] = dc # component parameters if isinstance(value, hlp.dc_simple): dc = hlp.dc_simple(val=c[key], val_set=c[key + '_set']) kwargs[key] = dc # component characteristics elif isinstance(value, hlp.dc_cc): # finding x and y values of the characteristic function values = args[0]['id'] == c[key] try: x = args[0][values].x.values[0] y = args[0][values].y.values[0] except IndexError: # if characteristics are missing (for compressor map atm) x = cmp_char.characteristics().x y = cmp_char.characteristics().y msg = 'Could not find x and y values for characteristic line, using defaults instead for function ' + key + ' at component ' + c.label + '.' logging.warning(msg) char = cmp_char.characteristics(x=x, y=y, method=c[key + '_method'], comp=instance.component()) dc = hlp.dc_cc(is_set=c[key + '_set'], method=c[key + '_method'], param=c[key + '_param'], func=char, x=x, y=y) kwargs[key] = dc # component characteristics elif isinstance(value, hlp.dc_cm): # finding x and y values of the characteristic function values = args[1]['id'] == c[key] try: x = list(args[1][values].x.values[0]) y = list(args[1][values].y.values[0]) z1 = list(args[1][values].z1.values[0]) z2 = list(args[1][values].z2.values[0]) except IndexError: # if characteristics are missing (for compressor map atm) x = cmp_char.char_map().x y = cmp_char.char_map().y z1 = cmp_char.char_map().z1 z2 = cmp_char.char_map().z2 msg = 'Could not find x, y, z1 and z2 values for characteristic map, using defaults instead.' logging.warning(msg) char_map = cmp_char.char_map(x=x, y=y, z1=z1, z2=z2, method=c[key + '_method'], comp=instance.component()) dc = hlp.dc_cm(is_set=c[key + '_set'], method=c[key + '_method'], param=c[key + '_param'], func=char_map, x=x, y=y, z1=z1, z2=z2) kwargs[key] = dc # grouped component parameters elif isinstance(value, hlp.dc_gcp): dc = hlp.dc_gcp(method=c[key]) kwargs[key] = dc instance.set_attr(**kwargs) return instance