Location: Metabolite-sensitive cross-bridge models of human atria @ 4fceceed40a4 / CellML / piecewise_Ca.py

Author:
JuliaMusgrave <jmus753@aucklanduni.ac.nz>
Date:
2025-07-29 09:52:08+12:00
Desc:
Updated main README and added README to each folder
Permanent Source URI:
https://staging.physiomeproject.org/workspace/d52/rawfile/4fceceed40a42817f103ba12e930abd4cf712580/CellML/piecewise_Ca.py

''' 
Short script to help prepare CellML code with piecewise Calcium as an input.
Reads the csv files containing Ca data and outputs a text file suitable for copying into CellML text editor
Useful if data can not be easily captured with a fitted function.
'''
import csv
import numpy as np

ca_time = []
nd_ca = []
d_ca = []
with open('nd_ca.csv', 'r') as file:
    csv_reader = csv.reader(file)
    next(csv_reader)
    for row in csv_reader:
        ca_time.append(float(row[0]))
        nd_ca.append(float(row[1]))

with open('d_ca.csv', 'r') as file:
    csv_reader = csv.reader(file)
    next(csv_reader)
    for row in csv_reader:
        d_ca.append(float(row[1]))

dt = 0.001 # sampling frequency
T = 1 # period
with open('nd_step.txt', 'w') as fp:
    fp.write("Ca = sel\n")
    for t in np.linspace(0, T, int(T/dt)+1):
        ca_i = np.interp(t, ca_time, nd_ca)
        fp.write(f"case t_twitch < {t+dt/2:.4f}{{second}}:\n"
                 f"    {ca_i:.4f}{{micromolar}};\n")
    fp.write("endsel;\n")

with open('d_step.txt', 'w') as fp:
    fp.write("Ca = sel\n")
    for t in np.linspace(0, T, int(T/dt)+1):
        ca_i = np.interp(t, ca_time, d_ca)
        fp.write(f"case t_twitch < {t+dt/2:.4f}{{second}}:\n"
                 f"    {ca_i:.4f}{{micromolar}};\n")
    fp.write("endsel;\n")