Location: Bond Graph Circulation @ 3973d8384668 / io_flow_data_into_cellml.py

Author:
finbar <farg967@aucklanduni.ac.nz>
Date:
2021-08-01 15:55:25+12:00
Desc:
created files for modifying cellml files with flow and resistance params
Permanent Source URI:
https://models.physiomeproject.org/workspace/673/rawfile/3973d8384668023c136aca8af28618aa1f4d69f7/io_flow_data_into_cellml.py

import pandas as pd
import re

data = pd.read_csv('df_vessels.csv')

with open('Parameters218.cellml', 'r') as r:
    with open('Parameters218_new.cellml', 'w') as w:
        for line in r:
            for rowNum in range(data.shape[0]):
                flow_name = 'v_nom_' + data.iloc[rowNum, 0]
                flow_val = data.iloc[rowNum,3]
                flow_val_string = 'initial_value=\"{:.8f}e-6\"'.format(flow_val)
                if flow_name in line:
                    line = re.sub('initial_value=\"\d*\.?\d*e?-?\d*\"', flow_val_string, line)
                    break
            w.write(line)