Frequently Asked Question
There are numerous ways how you can use external files to parametrize your models. Using the Model Initialization script, you can import numerous file formats. In this article .csv, .mat, and .json file formats will be covered.
Note: The methods used for importing different types of files shown in this article are not exclusive. Considering the flexibility and rich library support of Python, import of certain file types can be achieved in alternative ways.
How to navigate to the appropriate folder path
Navigating to the appropriate folder path where the desired parametrization file is located can be done using the pathlib library in combination with the get_model_file_path() function, which is a part of Typhoon HIL Schematic API:
from pathlib import Path model_address = mdl.get_model_file_path() root_path = Path(model_address).parents[0]
Importing parameters from CSV files (.csv)
Importing parameters from CSV (Comma separated values) files can be done with the following steps:
1) Specifying the correct path to the desired .csv file.
parameters_file = str(root_path / "parameters.csv")
2) Reading the .csv using the Pandas library and creating an appropriate data structure. A code snippet demonstrating this can be found at the end of this section.
import pandas df = pandas.read_csv(parameters_file) params = df.to_dict()
3) Extracting data from the data structure.
R1 = params['R'][0] L1 = params['L'][0] C1 = params['C'][0]
An example showing this can be found in the attached files: reading csv file.tse, parameters.csv.
Importing parameters from MAT files (.mat)
Importing parameters from MAT files, which are binary MATLAB files that store workspace variables, can be done with the following steps:
1) Specifying the correct path to the desired .mat file.
parameters_file = str(root_path / "parameters.mat")
2) Loading the .mat file using the SciPy library.
import scipy from scipy.io import loadmat params = loadmat(parameters_file)
3) Extracting data from the data structure.
R = params['R'][0] R1 = R[0] L = params['L'][0] L1 = L[0] C = params['C'][0] C1 = C[0]
An example showing this can be found in the attached files: reading mat file.tse, parameters.mat.
Importing parameters from JSON files (.json)
Importing parameters from JSON files, which are files which store simple data structures and objects in JavaScript Object Notation (JSON) format, can be done with the following steps:
1) Specifying the correct path to the desired .json file.
parameters_file = str(root_path / "parameters.json")
2) Loading the .json file using the JSON library.
import json with open(parameters_file) as params: data = json.load(params)
3) Extracting data from the data structure.
R = (data["RLC branch"]["resistance"]) L = (data["RLC branch"]["inductance"]) C = (data["RLC branch"]["capacitance"])
An example showing this can be found in the attached file: reading json file.tse, parameters.json.