Skip to content

Commit 4076201

Browse files
committed
No longer changing loggin level except in command line call. Closes #42.
1 parent 5247d7e commit 4076201

4 files changed

Lines changed: 14 additions & 49 deletions

File tree

pcpostprocess/hergQC.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,8 @@ def __init__(self, voltage, sampling_rate=5, removal_time=5, noise_len=200,
7575
self.removal_time = removal_time
7676
self.noise_len = int(noise_len)
7777

78-
# Passing in a plot dir enables debug mode
7978
self._plot_dir = plot_dir
8079
self.logger = logging.getLogger(__name__)
81-
if self._plot_dir is not None:
82-
self.logger.setLevel(logging.DEBUG)
83-
# https://github.com/CardiacModelling/pcpostprocess/issues/42
84-
self._plot_dir = plot_dir
8580

8681
# Define all thresholds
8782

pcpostprocess/scripts/run_herg_qc.py

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
import logging
99
import multiprocessing
1010
import os
11+
import re
1112
import string
1213
import sys
1314

1415
import matplotlib
1516
import matplotlib.pyplot as plt
1617
import numpy as np
1718
import pandas as pd
18-
import regex as re
1919
import scipy
2020
from syncropatch_export.trace import Trace
2121
from syncropatch_export.voltage_protocols import VoltageProtocol
@@ -77,7 +77,7 @@ def run_from_command_line(): # pragma: no cover
7777

7878
parser.add_argument('--figsize', nargs=2, type=int, default=[16, 18])
7979

80-
parser.add_argument('--log_level', default='INFO')
80+
parser.add_argument('--log_level', default='WARNING')
8181

8282
args = parser.parse_args()
8383

@@ -104,14 +104,14 @@ def run_from_command_line(): # pragma: no cover
104104
reversal_spread_threshold=args.reversal_spread_threshold,
105105
max_processes=args.no_cpus,
106106
figure_size=args.figsize,
107-
save_id=export_config.saveID
107+
save_id=export_config.saveID,
108108
)
109109

110110

111111
def run(data_path, output_path, qc_map, wells=None,
112112
write_traces=False, write_failed_traces=False, write_map={},
113113
reversal_potential=-90, reversal_spread_threshold=10,
114-
max_processes=1, figure_size=None, save_id=None):
114+
max_processes=1, figure_size=None, save_id=None, logger=None):
115115
"""
116116
Imports traces and runs QC.
117117
@@ -174,7 +174,6 @@ def run(data_path, output_path, qc_map, wells=None,
174174
# 3. Ends with a code 00.00.00 (where 0 is any number)
175175
#
176176
# TODO: Just want to check that it ends in a 6 digit date code
177-
# TODO: Just use ``re`` instead of ``regex``
178177
protocols_regex = \
179178
r'^([a-z|A-Z|_|0-9| |\-|\(|\)]+)_([0-9][0-9]\.[0-9][0-9]\.[0-9][0-9])$'
180179
protocols_regex = re.compile(protocols_regex)
@@ -235,17 +234,10 @@ def run(data_path, output_path, qc_map, wells=None,
235234
if not readnames:
236235
raise ValueError('No compatible protocols specified.')
237236

238-
n = min(max_processes, len(readnames))
239-
args = zip(
240-
readnames,
241-
savenames,
242-
times_list,
243-
[output_path] * len(readnames),
244-
[data_path] * len(readnames),
245-
[wells] * len(readnames),
246-
[write_traces] * len(readnames),
247-
[save_id] * len(readnames),
248-
)
237+
m = len(readnames)
238+
n = min(max_processes, m)
239+
args = zip(readnames, savenames, times_list, [output_path] * m,
240+
[data_path] * m, [wells] * m, [write_traces] * m, [save_id] * m)
249241
well_selections, qc_dfs = list(zip(*starmap(n, run_qc_for_protocol, args)))
250242

251243
qc_df = pd.concat(qc_dfs, ignore_index=True)
@@ -333,21 +325,11 @@ def run(data_path, output_path, qc_map, wells=None,
333325

334326
logging.info(f"exporting wells {wells}")
335327

336-
no_protocols = len(res_dict)
337-
338-
n = min(max_processes, no_protocols)
339-
args = zip(
340-
readnames,
341-
savenames,
342-
times_list,
343-
[wells_to_export] * len(savenames),
344-
[output_path for i in readnames],
345-
[data_path for i in readnames],
346-
[write_traces for i in readnames],
347-
[figure_size for i in readnames],
348-
[reversal_potential for i in readnames],
349-
[save_id for i in readnames],
350-
)
328+
m = len(readnames)
329+
n = min(max_processes, m)
330+
args = zip(readnames, savenames, times_list, [wells_to_export] * m,
331+
[output_path] * m, [data_path] * m, [write_traces] * m,
332+
[figure_size] * m, [reversal_potential] * m, [save_id] * m)
351333
dfs = starmap(n, extract_protocol, args)
352334

353335
if dfs:
@@ -547,7 +529,7 @@ def agg_func(x):
547529

548530
def extract_protocol(readname, savename, time_strs, selected_wells, savedir,
549531
data_path, write_traces, figure_size, reversal_potential,
550-
save_id):
532+
save_id, logger):
551533
# TODO: Tidy up argument order
552534
"""
553535
???

pcpostprocess/scripts/summarise_herg_export.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import argparse
2-
import json
32
import os
43
import string
54

65
import matplotlib
76
import matplotlib.pyplot as plt
87
import numpy as np
98
import pandas as pd
10-
import regex as re
119
import scipy
1210
import seaborn as sns
13-
from syncropatch_export.voltage_protocols import VoltageProtocol
1411

1512
from pcpostprocess.directory_builder import setup_output_directory
1613
from pcpostprocess.scripts.run_herg_qc import create_qc_table
@@ -190,7 +187,6 @@ def scatterplot_timescale_E_obs(output_path, df, passed_wells, figsize=None):
190187
plot_dfs.append(plot_df)
191188

192189
plot_df = pd.concat(plot_dfs, ignore_index=True)
193-
print(plot_df)
194190

195191
plot_df['E_leak'] = (plot_df.set_index('well')['E_leak'] - plot_df.groupby('well')
196192
['E_leak'].mean()).reset_index()['E_leak']
@@ -690,7 +686,6 @@ def create_attrition_table(qc_df, subtraction_df):
690686
agg_dict = {crit: 'min' for crit in stage_5_criteria}
691687

692688
qc_df_sc1 = qc_df[qc_df.protocol == 'staircaseramp1']
693-
print(qc_df_sc1.values.shape)
694689
n_stage_1_wells = np.sum(np.all(qc_df_sc1.groupby('well')
695690
.agg(agg_dict)[original_qc_criteria].values,
696691
axis=1))
@@ -717,12 +712,6 @@ def create_attrition_table(qc_df, subtraction_df):
717712
# np.all(qc_df.groupby('well').agg(agg_dict)[stage_6_criteria].values,
718713
# axis=1))
719714

720-
passed_qc_df = qc_df.groupby('well').agg(agg_dict)[stage_5_criteria]
721-
print(passed_qc_df)
722-
passed_wells = [well for well, row in passed_qc_df.iterrows() if np.all(row.values)]
723-
724-
print(f"passed wells = {passed_wells}")
725-
726715
res_dict = {
727716
'stage1': [n_stage_1_wells],
728717
'stage2': [n_stage_2_wells],

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ dependencies = [
3636
'numpy>=1.21',
3737
'matplotlib>=3.4',
3838
'pandas>=1.3',
39-
'regex>=2023.12.25',
4039
'seaborn>=0.12.2',
4140
'jinja2>=3.1.0',
4241
'syncropatch_export @ git+https://github.com/CardiacModelling/syncropatch_export.git'

0 commit comments

Comments
 (0)