Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
buffer = QBuffer()
buffer.open(QIODevice.WriteOnly)
pixmap.save(buffer, "PNG", quality=100)
image = bytes(buffer.data().toBase64()).decode()
html = '<img src="data:image/png;base64,{}">'.format(image)
self.ui.modelImageLabel.setToolTip(html)
# show a scaled preview in "Model Info"
pixmap = pixmap.scaled(200, 200, Qt.KeepAspectRatio, Qt.SmoothTransformation)
self.ui.modelImageLabel.setPixmap(pixmap)
except:
self.ui.modelImageLabel.setPixmap(QPixmap())
self.ui.modelImageLabel.setToolTip(None)
self.filename = filename
platforms = supported_platforms(self.filename)
self.variables.clear()
self.selectedVariables.clear()
self.startValues.clear()
for v in md.modelVariables:
self.variables[v.name] = v
if v.causality == 'output':
self.selectedVariables.add(v)
fmi_types = []
if md.coSimulation:
fmi_types.append('Co-Simulation')
if md.modelExchange:
fmi_types.append('Model Exchange')
# check the input file
input = None
if input_variables:
in_path = os.path.join(root, fmu_name + '_in.csv')
input, in_csv_cell = check_csv_file(filename=in_path, variables=input_variables)
else:
in_csv_cell = '<span class="label label-default">n/a</span>'
# check the reference file
ref_path = os.path.join(root, fmu_name + '_ref.csv')
reference, ref_csv_cell = check_csv_file(filename=ref_path, variables=output_variables)
supported_platforms = fmpy.supported_platforms(fmu_filename)
# this will remove any trailing (back)slashes
fmus_dir = os.path.normpath(args.fmus_dir)
model_path = fmu_filename[len(fmus_dir) + 1:]
model_path = os.path.dirname(model_path)
fmu_simple_filename = os.path.basename(fmu_filename)
model_name, _ = os.path.splitext(fmu_simple_filename)
# build the filenames
result = None
##############
# SIMULATION #
##############
def skip_simulation():
def compilePlatformBinary(self):
""" Compile the platform binary """
from ..util import compile_platform_binary
platforms = supported_platforms(self.filename)
if fmpy.platform in platforms:
button = QMessageBox.question(self, "Platform binary already exists", "The FMU already contains a binary for the current platform. Do you want to compile and overwrite the existing binary?")
if button == QMessageBox.No:
return
try:
compile_platform_binary(self.filename)
except Exception as e:
QMessageBox.critical(self, "Failed to compile platform binaries", str(e))
return
self.load(self.filename)
def fmu_info(filename, causalities=['input', 'output']):
""" Dump the info for an FMU """
from .model_description import read_model_description
from . import supported_platforms
md = read_model_description(filename, validate=False)
platforms = supported_platforms(filename)
fmi_types = []
if md.modelExchange is not None:
fmi_types.append('Model Exchange')
if md.coSimulation is not None:
fmi_types.append('Co-Simulation')
l = []
l.append("")
l.append("Model Info")
l.append("")
l.append(" FMI Version %s" % md.fmiVersion)
l.append(" FMI Type %s" % ', '.join(fmi_types))
l.append(" Model Name %s" % md.modelName)
l.append(" Description %s" % md.description)
debug_logging enable the FMU's debug logging
visible interactive mode (True) or batch mode (False)
fmi_call_logger callback function to log FMI calls
logger callback function passed to the FMU (experimental)
step_finished callback to interact with the simulation (experimental)
model_description the previously loaded model description (experimental)
fmu_instance the previously instantiated FMU (experimental)
Returns:
result a structured numpy array that contains the result
"""
from fmpy import supported_platforms
from fmpy.model_description import read_model_description
platforms = supported_platforms(filename)
# use 32-bit DLL remoting
use_remoting = platform == 'win64' and 'win64' not in platforms and 'win32' in platforms
if fmu_instance is None and platform not in platforms and not use_remoting:
raise Exception("The current platform (%s) is not supported by the FMU." % platform)
if model_description is None:
model_description = read_model_description(filename, validate=validate)
else:
model_description = model_description
if fmi_type is None:
if fmu_instance is not None:
# determine FMI type from the FMU instance
fmi_type = 'CoSimulation' if type(fmu_instance) in [FMU1Slave, FMU2Slave, fmi3.FMU3Slave] else 'ModelExchange'