Skip to content

Commit e298a70

Browse files
Merge branch 'main' into js_fix_passed_wells
2 parents 0a11089 + 3053872 commit e298a70

14 files changed

Lines changed: 422 additions & 225 deletions

pcpostprocess/detect_ramp_bounds.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import numpy as np
22

33

4-
def detect_ramp_bounds(times, voltage_sections, ramp_no=0):
4+
def detect_ramp_bounds(times, voltage_sections, ramp_index=0):
55
"""
6-
Extract the the times at the start and end of the nth ramp in the protocol.
6+
Extract the timepoint indices at the start and end of the nth ramp in the protocol.
77
88
@param times: np.array containing the time at which each sample was taken
99
@param voltage_sections 2d np.array where each row describes a segment of the protocol: (tstart, tend, vstart, end)
10-
@param ramp_no: the index of the ramp to select. Defaults to 0 - the first ramp
10+
@param ramp_index: the index of the ramp to select. Defaults to 0 - the first ramp
1111
12-
@returns tstart, tend: the start and end times for the ramp_no+1^nth ramp
12+
@returns istart, iend: the start and end timepoint indices for the specified ramp
1313
"""
1414

1515
ramps = [(tstart, tend, vstart, vend) for tstart, tend, vstart, vend
1616
in voltage_sections if vstart != vend]
1717
try:
18-
ramp = ramps[ramp_no]
18+
ramp = ramps[ramp_index]
1919
except IndexError:
20-
print(f"Requested {ramp_no+1}th ramp (ramp_no={ramp_no}),"
20+
print(f"Requested {ramp_index+1}th ramp (ramp_index={ramp_index}),"
2121
" but there are only {len(ramps)} ramps")
2222

2323
tstart, tend = ramp[:2]

pcpostprocess/directory_builder.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import datetime
2+
import os
3+
import sys
4+
5+
from ._version import __commit_id__, __version__
6+
7+
8+
def get_git_revision_hash():
9+
"""
10+
Get the hash for the git commit currently being used.
11+
12+
@return The most recent commit hash or a suitable message
13+
14+
"""
15+
16+
return __commit_id__
17+
18+
19+
def get_build_type():
20+
if "dev" in __version__:
21+
return "Develop"
22+
else:
23+
return "Release"
24+
25+
26+
def setup_output_directory(dirname: str = None, subdir_name: str = None):
27+
"""
28+
Create an output directory if one doesn't already exist. Place an info
29+
file in this directory which lists the date/time created, the version of
30+
pcpostprocess, the command-line arguments provided, and the most recent git
31+
commit. The two parameters allow for a user specified top-level directory and
32+
a script-defined name for a subdirectory.
33+
34+
@param Optional directory name
35+
@param Optional subdirectory name
36+
37+
@return The path to the created file directory (String)
38+
"""
39+
40+
if dirname is None:
41+
if subdir_name:
42+
dirname = os.path.join("output", f"{subdir_name}")
43+
else:
44+
dirname = os.path.join("output", "output")
45+
46+
if subdir_name is not None:
47+
dirname = os.path.join(dirname, subdir_name)
48+
if not os.path.exists(dirname):
49+
os.makedirs(dirname)
50+
51+
with open(os.path.join(dirname, "pcpostprocess_info.txt"), "w") as description_fout:
52+
git_hash = get_git_revision_hash()
53+
datetimestr = str(datetime.datetime.now())
54+
description_fout.write("pcpostprocess output "
55+
"https://github.com/CardiacModelling/pcpostprocess\n")
56+
description_fout.write(f"Date: {datetimestr}\n")
57+
description_fout.write(f"Version: {__version__}\n")
58+
description_fout.write(f"Build type: {get_build_type()}\n")
59+
description_fout.write(f"Commit: {git_hash}\n")
60+
command = " ".join(sys.argv)
61+
description_fout.write(f"Command: {command}\n")
62+
return dirname
63+

pcpostprocess/infer_reversal.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ def infer_reversal_potential(current, times, voltage_segments, voltages,
3333
"""
3434

3535
# Get ramp bounds, assuming final ramp is the reversal ramp
36-
tstart, tend = detect_ramp_bounds(times, voltage_segments, -1)
37-
38-
istart = np.argmax(times > tstart)
39-
iend = np.argmax(times > tend)
36+
istart, iend = detect_ramp_bounds(times, voltage_segments, -1)
4037

4138
current = current[istart:iend]
4239
voltages = voltages[istart:iend]

pcpostprocess/leak_correct.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def fit_linear_leak(current, voltage, times, ramp_start_index, ramp_end_index,
149149
ax4.plot(times, I_obs, label=r'$I_\mathrm{obs}$')
150150
ax4.plot(times, I_leak, linestyle='--', label=r'$I_\mathrm{L}$')
151151
ax4.plot(times, I_obs - I_leak,
152-
linestyle='--', alpha=0.5, label=r'$I_\mathrm{obs} - I_\mathrm{L}$')
152+
alpha=0.5, label=r'$I_\mathrm{obs} - I_\mathrm{L}$')
153153
ax4.legend(frameon=False)
154154

155155
if not os.path.exists(output_dir):

0 commit comments

Comments
 (0)