Skip to content

Commit

Permalink
Merge pull request #25 from alan-turing-institute/22-fix-commponents-…
Browse files Browse the repository at this point in the history
…typo

replacing commponents with components
  • Loading branch information
MaxBalmus authored Feb 12, 2025
2 parents a3039b6 + fb6e81c commit 5f749dc
Show file tree
Hide file tree
Showing 11 changed files with 276 additions and 276 deletions.
34 changes: 17 additions & 17 deletions ModularCirc/Analysis/BaseAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def plot_t_v(self, component:str, ax=None, time_units:str='s', volume_units:str=
if ax is None:
_, ax = plt.subplots(figsize=(5,5))
ax.plot(self.tsym,
self.model.commponents[component].V.values[self.tind],
self.model.components[component].V.values[self.tind],
linewidth=4,
label=component,
linestyle=linestyle)
Expand All @@ -81,7 +81,7 @@ def plot_t_p(self, component:str, ax=None, time_units:str='s', pressure_units:st
if ax is None:
_, ax = plt.subplots(figsize=(5,5))
ax.plot(self.tsym,
self.model.commponents[component].P.values[self.tind],
self.model.components[component].P.values[self.tind],
linewidth=4,
label=component,
linestyle=linestyle)
Expand All @@ -95,8 +95,8 @@ def plot_p_v_loop(self, component, ax=None, volume_units:str='mL', pressure_unit
if ax is None:
_, ax = plt.subplots(figsize=(5,5))
ax.plot(
self.model.commponents[component].V.values[self.tind],
self.model.commponents[component].P.values[self.tind],
self.model.components[component].V.values[self.tind],
self.model.components[component].P.values[self.tind],
linewidth=4,
)
ax.set_title(component.upper() + ': PV loop')
Expand All @@ -109,7 +109,7 @@ def plot_t_q_out(self, component:str, ax=None, time_units:str='s', volume_units:
_, ax = plt.subplots(figsize=(5,5))
ax.plot(
self.tsym,
self.model.commponents[component].Q_o.values[self.tind],
self.model.components[component].Q_o.values[self.tind],
linewidth=4,
linestyle=linestyle,
label=component,
Expand All @@ -124,23 +124,23 @@ def plot_fluxes(self, component:str, ax=None, time_units:str='s', volume_units:s
_, ax = plt.subplots(figsize=(5,5))
ax.plot(
self.tsym,
self.model.commponents[component].Q_i.values[self.tind] -
self.model.commponents[component].Q_o.values[self.tind],
self.model.components[component].Q_i.values[self.tind] -
self.model.components[component].Q_o.values[self.tind],
linestyle='-',
linewidth=4,
alpha=0.6,
label=f'{component} $dV/dt$'
)
ax.plot(
self.tsym,
self.model.commponents[component].Q_i.values[self.tind],
self.model.components[component].Q_i.values[self.tind],
linestyle=':',
linewidth=4,
label=f'{component} $Q_i$'
)
ax.plot(
self.tsym,
self.model.commponents[component].Q_o.values[self.tind],
self.model.components[component].Q_o.values[self.tind],
linestyle=':',
linewidth=4,
label=f'{component} $Q_o$'
Expand All @@ -157,7 +157,7 @@ def plot_valve_opening(self, component:str, ax=None, time_units:str='s'):
_, ax = plt.subplots(figsize=(5,5))
ax.plot(
self.tsym,
self.model.commponents[component].PHI.values[self.tind],
self.model.components[component].PHI.values[self.tind],
linestyle='-',
linewidth=4,
label=f'{component} $\phi$'
Expand All @@ -182,7 +182,7 @@ def compute_opening_closing_valve(self, component:str, shift:float=0.0):
shift : float
a time shift value which takes into account that the contraction of the atria starts before the ventricles.
"""
valve = self.model.commponents[component]
valve = self.model.components[component]
nshift= int(shift/ self.model.time_object.dt)
self.valves[component] = ValveData(component)

Expand Down Expand Up @@ -214,7 +214,7 @@ def compute_ventricle_volume_limits(self, component:str, vic:int, voc:int)->None
voc : int
the time index corresponding to the outflow valve closing
"""
ventricle = self.model.commponents[component]
ventricle = self.model.components[component]
volume = ventricle.V.values[self.tind]

self.ventricles[component] = VentricleData(component)
Expand All @@ -234,7 +234,7 @@ def compute_cardiac_output(self, component:str)->float:
CO : float
the cardiac ouput value
"""
valve = self.model.commponents[component]
valve = self.model.components[component]
dt = self.model.time_object.dt
T = self.model.time_object.tcycle / 60.0

Expand All @@ -255,7 +255,7 @@ def compute_ejection_fraction(self, component:str)->float:
CO : float
the ejection fraction
"""
ventricle = self.model.commponents[component]
ventricle = self.model.components[component]
edv = ventricle.V.values[self.tind].max()
esv = ventricle.V.values[self.tind].min()
self.EF = (edv - esv) / edv
Expand All @@ -272,7 +272,7 @@ def compute_artery_pressure_range(self, component:str)->tuple[float]:
DP (float) : diastolic pressure
SP (float) : systolic pressure
"""
c = self.model.commponents[component]
c = self.model.components[component]
p = c.P_i.values[self.tind]
return (np.min(p), np.max(p))

Expand All @@ -290,10 +290,10 @@ def compute_end_systolic_pressure(self, component:str, upstream:str):
ESP : float
vessel end systolic pressure
"""
c = self.model.commponents[component]
c = self.model.components[component]
p = c.P_i.values[self.tind]

uc = self.model.commponents[upstream]
uc = self.model.components[upstream]
up = uc.P_i.values[self.tind]

flag = up > p
Expand Down
82 changes: 41 additions & 41 deletions ModularCirc/Models/KPat5MixedModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,96 +41,96 @@ def __init__(self, time_setup_dict, parobj:po=k2006, supress_printing:bool=False
class_ = HC_mixed_elastance
else:
raise Exception(f'Component name {key} not in the model list.')
self.commponents[key] = class_(name=name,
self.components[key] = class_(name=name,
time_object=self.time_object,
**parobj[key].to_dict())
if key not in parobj._valves:
self.set_v_sv(key)
# else:
# self.set_phi_sv(key)
self.commponents[key].setup()
self.components[key].setup()

self.connect_modules(self.commponents['lv'],
self.commponents['ao'],
self.connect_modules(self.components['lv'],
self.components['ao'],
plabel='p_lv',
qlabel='q_ao')
self.connect_modules(self.commponents['ao'],
self.commponents['sas'],
self.connect_modules(self.components['ao'],
self.components['sas'],
plabel='p_sas',
qlabel='q_ao')
self.connect_modules(self.commponents['sas'],
self.commponents['sat'],
self.connect_modules(self.components['sas'],
self.components['sat'],
plabel='p_sat',
qlabel='q_sas')
self.connect_modules(self.commponents['sat'],
self.commponents['svn'],
self.connect_modules(self.components['sat'],
self.components['svn'],
plabel='p_svn',
qlabel='q_sat')
self.connect_modules(self.commponents['svn'],
self.commponents['ra'],
self.connect_modules(self.components['svn'],
self.components['ra'],
plabel='p_ra',
qlabel='q_svn')
self.connect_modules(self.commponents['ra'],
self.commponents['ti'],
self.connect_modules(self.components['ra'],
self.components['ti'],
plabel='p_ra',
qlabel='q_ti')
self.connect_modules(self.commponents['ti'],
self.commponents['rv'],
self.connect_modules(self.components['ti'],
self.components['rv'],
plabel='p_rv',
qlabel='q_ti')
self.connect_modules(self.commponents['rv'],
self.commponents['po'],
self.connect_modules(self.components['rv'],
self.components['po'],
plabel='p_rv',
qlabel='q_po')
self.connect_modules(self.commponents['po'],
self.commponents['pas'],
self.connect_modules(self.components['po'],
self.components['pas'],
plabel='p_pas',
qlabel='q_po')
############################################
self.connect_modules(self.commponents['pas'],
self.commponents['pat0'],
self.connect_modules(self.components['pas'],
self.components['pat0'],
plabel='p_pat0',
qlabel='q_pas')
self.connect_modules(self.commponents['pat0'],
self.commponents['pat1'],
self.connect_modules(self.components['pat0'],
self.components['pat1'],
plabel='p_pat1',
qlabel='q_pat0')
self.connect_modules(self.commponents['pat1'],
self.commponents['pat2'],
self.connect_modules(self.components['pat1'],
self.components['pat2'],
plabel='p_pat2',
qlabel='q_pat1')
self.connect_modules(self.commponents['pat2'],
self.commponents['pat3'],
self.connect_modules(self.components['pat2'],
self.components['pat3'],
plabel='p_pat3',
qlabel='q_pat2')
self.connect_modules(self.commponents['pat3'],
self.commponents['pat4'],
self.connect_modules(self.components['pat3'],
self.components['pat4'],
plabel='p_pat4',
qlabel='q_pat3')
############################################
self.connect_modules(self.commponents['pat4'],
self.commponents['pvn'],
self.connect_modules(self.components['pat4'],
self.components['pvn'],
plabel='p_pvn',
qlabel='q_pat4')
############################################
self.connect_modules(self.commponents['pvn'],
self.commponents['la'],
self.connect_modules(self.components['pvn'],
self.components['la'],
plabel='p_la',
qlabel='q_pvn')
self.connect_modules(self.commponents['la'],
self.commponents['mi'],
self.connect_modules(self.components['la'],
self.components['mi'],
plabel='p_la',
qlabel='q_mi')
self.connect_modules(self.commponents['mi'],
self.commponents['lv'],
self.connect_modules(self.components['mi'],
self.components['lv'],
plabel='p_lv',
qlabel='q_mi')

for component in self.commponents.values():
for component in self.components.values():
component.setup()

# def set_phi_sv(self, comp_key:str) -> None:
# phi_key = 'phi_' + comp_key
# self._state_variable_dict[phi_key] = self.commponents[comp_key]._PHI
# self._state_variable_dict[phi_key] = self.components[comp_key]._PHI
# self._state_variable_dict[phi_key].set_name(phi_key)
# self.all_sv_data[phi_key] = self.commponents[comp_key].PHI
# self.all_sv_data[phi_key] = self.components[comp_key].PHI
68 changes: 34 additions & 34 deletions ModularCirc/Models/KorakianitisMaynardModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,78 +37,78 @@ def __init__(self, time_setup_dict, parobj:po=k2006) -> None:
class_ = HC_constant_elastance
else:
raise Exception(f'Component name {key} not in the model list.')
self.commponents[key] = class_(name=name,
self.components[key] = class_(name=name,
time_object=self.time_object,
**parobj[key].to_dict())
if key not in parobj._valves:
self.set_v_sv(key)
else:
self.set_phi_sv(key)
self.commponents[key].setup()
self.components[key].setup()

self.connect_modules(self.commponents['lv'],
self.commponents['ao'],
self.connect_modules(self.components['lv'],
self.components['ao'],
plabel='p_lv',
qlabel='q_ao')
self.connect_modules(self.commponents['ao'],
self.commponents['sas'],
self.connect_modules(self.components['ao'],
self.components['sas'],
plabel='p_sas',
qlabel='q_ao')
self.connect_modules(self.commponents['sas'],
self.commponents['sat'],
self.connect_modules(self.components['sas'],
self.components['sat'],
plabel='p_sat',
qlabel='q_sas')
self.connect_modules(self.commponents['sat'],
self.commponents['svn'],
self.connect_modules(self.components['sat'],
self.components['svn'],
plabel='p_svn',
qlabel='q_sat')
self.connect_modules(self.commponents['svn'],
self.commponents['ra'],
self.connect_modules(self.components['svn'],
self.components['ra'],
plabel='p_ra',
qlabel='q_svn')
self.connect_modules(self.commponents['ra'],
self.commponents['ti'],
self.connect_modules(self.components['ra'],
self.components['ti'],
plabel='p_ra',
qlabel='q_ti')
self.connect_modules(self.commponents['ti'],
self.commponents['rv'],
self.connect_modules(self.components['ti'],
self.components['rv'],
plabel='p_rv',
qlabel='q_ti')
self.connect_modules(self.commponents['rv'],
self.commponents['po'],
self.connect_modules(self.components['rv'],
self.components['po'],
plabel='p_rv',
qlabel='q_po')
self.connect_modules(self.commponents['po'],
self.commponents['pas'],
self.connect_modules(self.components['po'],
self.components['pas'],
plabel='p_pas',
qlabel='q_po')
self.connect_modules(self.commponents['pas'],
self.commponents['pat'],
self.connect_modules(self.components['pas'],
self.components['pat'],
plabel='p_pat',
qlabel='q_pas')
self.connect_modules(self.commponents['pat'],
self.commponents['pvn'],
self.connect_modules(self.components['pat'],
self.components['pvn'],
plabel='p_pvn',
qlabel='q_pat')
self.connect_modules(self.commponents['pvn'],
self.commponents['la'],
self.connect_modules(self.components['pvn'],
self.components['la'],
plabel='p_la',
qlabel='q_pvn')
self.connect_modules(self.commponents['la'],
self.commponents['mi'],
self.connect_modules(self.components['la'],
self.components['mi'],
plabel='p_la',
qlabel='q_mi')
self.connect_modules(self.commponents['mi'],
self.commponents['lv'],
self.connect_modules(self.components['mi'],
self.components['lv'],
plabel='p_lv',
qlabel='q_mi')

for component in self.commponents.values():
for component in self.components.values():
component.setup()

def set_phi_sv(self, comp_key:str) -> None:
phi_key = 'phi_' + comp_key
self._state_variable_dict[phi_key] = self.commponents[comp_key]._PHI
self._state_variable_dict[phi_key] = self.components[comp_key]._PHI
self._state_variable_dict[phi_key].set_name(phi_key)
self.all_sv_data[phi_key] = self.commponents[comp_key].PHI
self.commponents[comp_key]._PHI._u = self.all_sv_data[phi_key]
self.all_sv_data[phi_key] = self.components[comp_key].PHI
self.components[comp_key]._PHI._u = self.all_sv_data[phi_key]
Loading

0 comments on commit 5f749dc

Please sign in to comment.