Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cardiac tutorial #233

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Cardiac tutorial #233

wants to merge 9 commits into from

Conversation

aranas
Copy link
Collaborator

@aranas aranas commented Aug 13, 2024

this PR is a work in progress on the tutorial showcasing how autoemulate can be embedded into an end-to-end cardiac modelling pipeline including sensitivity analysis.

This tutorial still requires some improvements

  • add explanations to every step
  • add plot that showcases value of autoemulate in the context of sensitivity analysis more specifically

@aranas aranas self-assigned this Aug 13, 2024
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

blackfmt

[blackfmt] reported by reviewdog 🐶

fig, ax = plt.subplots(ncols=2, figsize = (10, 5))


[blackfmt] reported by reviewdog 🐶

ax[0].plot(self.res.t, self.res.y[2*i,:] , 'r', alpha=0.1 + (1.-i/self.ncomp) *0.9)
ax[1].plot(self.res.t, self.res.y[2*i+1,:] , 'r', alpha=0.1 + (1.-i/self.ncomp) *0.9)
ax[0].set_title('Pressure')
ax[1].set_title('Flow rate')
ax[0].set_xlabel('Time (s)')
ax[1].set_xlabel('Time (s)')
ax[0].set_ylabel('mmHg')
ax[1].set_ylabel('$ml\cdot s^{-1}$')
return (fig, ax)

autoemulate/simulations/flow_functions.py Outdated Show resolved Hide resolved
import numpy as np
import matplotlib.pyplot as plt

class FlowProblem:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blackfmt] reported by reviewdog 🐶

Suggested change
class FlowProblem:
class FlowProblem:

Comment on lines 8 to 12
self,
T=1.0,
td=0.2,
amp=900.0,
dt=0.001,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blackfmt] reported by reviewdog 🐶

Suggested change
self,
T=1.0,
td=0.2,
amp=900.0,
dt=0.001,
self,
T=1.0,
td=0.2,
amp=900.0,
dt=0.001,

Comment on lines 14 to 21
ncomp = 10,
C = 38.,
R = 0.06,
L = 0.0017,
R_o = 0.025,
p_o = 10.,
) -> None :
'''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blackfmt] reported by reviewdog 🐶

Suggested change
ncomp = 10,
C = 38.,
R = 0.06,
L = 0.0017,
R_o = 0.025,
p_o = 10.,
) -> None :
'''
ncomp=10,
C=38.0,
R=0.06,
L=0.0017,
R_o=0.025,
p_o=10.0,
) -> None:
"""

Comment on lines 33 to 38
'''

assert td < T, f'td should be smaller than T but {td} >= {T}.'

self._td = td
self._T = T
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blackfmt] reported by reviewdog 🐶

Suggested change
'''
assert td < T, f'td should be smaller than T but {td} >= {T}.'
self._td = td
self._T = T
"""
assert td < T, f"td should be smaller than T but {td} >= {T}."
self._td = td
self._T = T

Comment on lines 115 to 117
out[i,0] = (Q_in(t%self.T) - y_temp[i,1]) / Cn
if i < self.ncomp-1:
out[i,1] = (-y_temp[i+1, 0] + y_temp[i, 0] - Rn * y_temp[i, 1]) / Ln
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blackfmt] reported by reviewdog 🐶

Suggested change
out[i,0] = (Q_in(t%self.T) - y_temp[i,1]) / Cn
if i < self.ncomp-1:
out[i,1] = (-y_temp[i+1, 0] + y_temp[i, 0] - Rn * y_temp[i, 1]) / Ln
out[i, 0] = (Q_in(t % self.T) - y_temp[i, 1]) / Cn
if i < self.ncomp - 1:
out[i, 1] = (-y_temp[i + 1, 0] + y_temp[i, 0] - Rn * y_temp[i, 1]) / Ln

out[i,1] = (-y_temp[i+1, 0] + y_temp[i, 0] - Rn * y_temp[i, 1]) / Ln
pass
else:
out[i,1] = (-self.p_o + y_temp[i, 0] - (Rn + self.R_o) * y_temp[i, 1]) / Ln
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blackfmt] reported by reviewdog 🐶

Suggested change
out[i,1] = (-self.p_o + y_temp[i, 0] - (Rn + self.R_o) * y_temp[i, 1]) / Ln
out[i, 1] = (
-self.p_o + y_temp[i, 0] - (Rn + self.R_o) * y_temp[i, 1]
) / Ln

else:
out[i,1] = (-self.p_o + y_temp[i, 0] - (Rn + self.R_o) * y_temp[i, 1]) / Ln
return out.reshape((-1,))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blackfmt] reported by reviewdog 🐶

Suggested change

return out.reshape((-1,))

def solve(self):
dfdt_fd_spec = lambda t, y : self.dfdt_fd(t=t, y=y, Q_in=self.Q_mi_lambda)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blackfmt] reported by reviewdog 🐶

Suggested change
dfdt_fd_spec = lambda t, y : self.dfdt_fd(t=t, y=y, Q_in=self.Q_mi_lambda)
dfdt_fd_spec = lambda t, y: self.dfdt_fd(t=t, y=y, Q_in=self.Q_mi_lambda)

Comment on lines 126 to 134
dfdt_fd_spec,
[0.0, self.T * self.ncycles],
y0 = np.zeros(self.ncomp*2),
method='BDF',
max_step=self.dt
)
self.res.y = self.res.y[:,self.res.t >= self.T*(self.ncycles-1)]
self.res.t = self.res.t[self.res.t >= self.T*(self.ncycles-1)]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blackfmt] reported by reviewdog 🐶

Suggested change
dfdt_fd_spec,
[0.0, self.T * self.ncycles],
y0 = np.zeros(self.ncomp*2),
method='BDF',
max_step=self.dt
)
self.res.y = self.res.y[:,self.res.t >= self.T*(self.ncycles-1)]
self.res.t = self.res.t[self.res.t >= self.T*(self.ncycles-1)]
dfdt_fd_spec,
[0.0, self.T * self.ncycles],
y0=np.zeros(self.ncomp * 2),
method="BDF",
max_step=self.dt,
)
self.res.y = self.res.y[:, self.res.t >= self.T * (self.ncycles - 1)]
self.res.t = self.res.t[self.res.t >= self.T * (self.ncycles - 1)]

Copy link
Contributor

Coverage report

This PR does not seem to contain any modification to coverable code.

@codecov-commenter
Copy link

codecov-commenter commented Aug 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.54%. Comparing base (2f1d439) to head (c2700e5).
Report is 46 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #233      +/-   ##
==========================================
+ Coverage   91.14%   91.54%   +0.40%     
==========================================
  Files          45       51       +6     
  Lines        2393     2816     +423     
==========================================
+ Hits         2181     2578     +397     
- Misses        212      238      +26     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@aranas
Copy link
Collaborator Author

aranas commented Aug 13, 2024

@MaxBalmus I managed to transfer our original commits into the autoemulate repo, I think it makes more sense to work here directly, so that Martin can chip in where appropriate.
for example, I have now transferred Max's custom flow functions into the simulations file, but I realized that the other files contain functions, not classes @mastoffel, is this something we should adapt for consistency?

@mastoffel
Copy link
Collaborator

@MaxBalmus I managed to transfer our original commits into the autoemulate repo, I think it makes more sense to work here directly, so that Martin can chip in where appropriate. for example, I have now transferred Max's custom flow functions into the simulations file, but I realized that the other files contain functions, not classes @mastoffel, is this something we should adapt for consistency?

@MaxBalmus @aranas: This is great! It would be best to make the simulation a function to be consistent with the other simulations eventually, but this isn't urgent. Let me know when I should have a look at it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants