From 2d4f5dac658e67fb7bf3f778328bede169ed96a9 Mon Sep 17 00:00:00 2001 From: vinferrer Date: Tue, 16 Jun 2020 17:11:42 +0200 Subject: [PATCH 01/24] create extra folder after creating output folder --- phys2bids/phys2bids.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phys2bids/phys2bids.py b/phys2bids/phys2bids.py index 06d74fd65..ab88b2bdb 100644 --- a/phys2bids/phys2bids.py +++ b/phys2bids/phys2bids.py @@ -132,7 +132,8 @@ def phys2bids(filename, info=False, indir='.', outdir='.', heur_file=None, # #!# This can probably be done while parsing? outdir = utils.check_input_dir(outdir) utils.path_exists_or_make_it(outdir) - + # generate extra path + utils.path_exists_or_make_it(outdir + "/extra") # Create logfile name basename = 'phys2bids_' extension = 'tsv' From 5ad6bd8feb56be8589482f77fd3fcd0b192db079 Mon Sep 17 00:00:00 2001 From: vinferrer Date: Tue, 16 Jun 2020 17:24:58 +0200 Subject: [PATCH 02/24] change logger outdir --- phys2bids/phys2bids.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phys2bids/phys2bids.py b/phys2bids/phys2bids.py index ab88b2bdb..4f73c5c4a 100644 --- a/phys2bids/phys2bids.py +++ b/phys2bids/phys2bids.py @@ -133,12 +133,13 @@ def phys2bids(filename, info=False, indir='.', outdir='.', heur_file=None, outdir = utils.check_input_dir(outdir) utils.path_exists_or_make_it(outdir) # generate extra path - utils.path_exists_or_make_it(outdir + "/extra") + extra = outdir + "/extra" + utils.path_exists_or_make_it(extra) # Create logfile name basename = 'phys2bids_' extension = 'tsv' isotime = datetime.datetime.now().strftime('%Y-%m-%dT%H%M%S') - logname = os.path.join(outdir, (basename + isotime + '.' + extension)) + logname = os.path.join(extra, (basename + isotime + '.' + extension)) # Set logging format log_formatter = logging.Formatter( From 1378aa49368386c324c7a8e75b3cbe33c4693a06 Mon Sep 17 00:00:00 2001 From: vinferrer Date: Tue, 16 Jun 2020 17:42:29 +0200 Subject: [PATCH 03/24] change test logger outdir --- phys2bids/tests/test_integration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phys2bids/tests/test_integration.py b/phys2bids/tests/test_integration.py index cb50eda93..88f2e4460 100644 --- a/phys2bids/tests/test_integration.py +++ b/phys2bids/tests/test_integration.py @@ -32,14 +32,14 @@ def test_logger(multifreq_lab_file): test_chtrig = 3 test_ntp = 1 test_outdir = test_path - + extra_dir = test_path + "/extra/" # Phys2bids call through terminal subprocess.run(f'phys2bids -in {test_filename} -indir {test_path} ' f'-chtrig {test_chtrig} -ntp {test_ntp} -outdir {test_outdir}', shell=True, check=True) # Read logger file - logger_file = glob.glob(os.path.join(test_path, '*phys2bids*'))[0] + logger_file = glob.glob(os.path.join(extra_dir, '*phys2bids*'))[0] with open(logger_file) as logger_info: logger_info = logger_info.readlines() From ab6647376551d04b9118371f5ebb5661921adb18 Mon Sep 17 00:00:00 2001 From: vinferrer Date: Tue, 16 Jun 2020 17:46:40 +0200 Subject: [PATCH 04/24] change test logger outdir for the removes and last tests --- phys2bids/tests/test_integration.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/phys2bids/tests/test_integration.py b/phys2bids/tests/test_integration.py index 88f2e4460..a14ab41ae 100644 --- a/phys2bids/tests/test_integration.py +++ b/phys2bids/tests/test_integration.py @@ -138,7 +138,7 @@ def test_integration_acq(samefreq_full_acq_file): 'MR TRIGGER - Custom, HLT100C - A 5', 'PPG100C', 'CO2', 'O2'] # Remove generated files - for filename in glob.glob(os.path.join(test_path, 'phys2bids*')): + for filename in glob.glob(os.path.join(extra_dir, 'phys2bids*')): os.remove(filename) for filename in glob.glob(os.path.join(test_path, 'Test_belt_pulse_samefreq*')): os.remove(filename) @@ -279,7 +279,7 @@ def test_integration_multifreq(multifreq_lab_file): assert json_data['Columns'] == ['time', 'Trigger'] # Remove generated files - for filename in glob.glob(os.path.join(test_path, 'phys2bids*')): + for filename in glob.glob(os.path.join(extra_dir, 'phys2bids*')): os.remove(filename) for filename in glob.glob(os.path.join(test_path, 'Test_belt_pulse_multifreq*')): os.remove(filename) @@ -337,7 +337,7 @@ def test_integration_heuristic(samefreq_short_txt_file): assert json_data['Columns'] == ['time', 'RESP - RSP100C', 'MR TRIGGER - Custom, HLT100C - A 5'] # Remove generated files - for filename in glob.glob(os.path.join(test_path, 'phys2bids*')): + for filename in glob.glob(os.path.join(extra_dir, 'phys2bids*')): os.remove(filename) for filename in glob.glob(os.path.join(test_path, 'Test_belt_pulse_samefreq*')): os.remove(filename) @@ -371,7 +371,7 @@ def test_integration_info(samefreq_short_txt_file): assert os.path.isfile('Test_belt_pulse_samefreq_short.png') # Read logger file - logger_file = glob.glob(os.path.join(test_path, '*phys2bids*'))[0] + logger_file = glob.glob(os.path.join(extra_dir, '*phys2bids*'))[0] with open(logger_file) as logger_info: logger_info = logger_info.readlines() @@ -380,5 +380,5 @@ def test_integration_info(samefreq_short_txt_file): '02. MR TRIGGER - Custom, HLT100C - A 5; sampled at', '10000.0') # Remove generated files - for filename in glob.glob(os.path.join(test_path, 'phys2bids*')): + for filename in glob.glob(os.path.join(extra_dir, 'phys2bids*')): os.remove(filename) From d1807e7a1db15efb4ad6e16aa58274d41826df5a Mon Sep 17 00:00:00 2001 From: vinferrer Date: Tue, 16 Jun 2020 17:48:34 +0200 Subject: [PATCH 05/24] add extra to the last test function --- phys2bids/tests/test_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phys2bids/tests/test_integration.py b/phys2bids/tests/test_integration.py index a14ab41ae..4fb7eca12 100644 --- a/phys2bids/tests/test_integration.py +++ b/phys2bids/tests/test_integration.py @@ -356,7 +356,7 @@ def test_integration_info(samefreq_short_txt_file): test_ntp = 158 test_tr = 1.2 test_thr = 0.735 - + extra_dir = test_path + "/extra/" # Move into folder subprocess.run(f'cd {test_path}', shell=True, check=True) # Phys2bids call through terminal From 585bf56bbe7a2b6883c98c074499118472f29561 Mon Sep 17 00:00:00 2001 From: vinferrer Date: Tue, 16 Jun 2020 17:55:58 +0200 Subject: [PATCH 06/24] add extra to the rest of functions --- phys2bids/tests/test_integration.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/phys2bids/tests/test_integration.py b/phys2bids/tests/test_integration.py index 4fb7eca12..feb3963b6 100644 --- a/phys2bids/tests/test_integration.py +++ b/phys2bids/tests/test_integration.py @@ -104,7 +104,8 @@ def test_integration_acq(samefreq_full_acq_file): test_path, test_filename = os.path.split(samefreq_full_acq_file) test_chtrig = 3 - + extra_dir = test_path + "/extra/" + phys2bids(filename=test_filename, indir=test_path, outdir=test_path, chtrig=test_chtrig, num_timepoints_expected=1) @@ -151,6 +152,7 @@ def test_integration_multifreq(multifreq_lab_file): test_path, test_filename = os.path.split(multifreq_lab_file) test_chtrig = 3 + extra_dir = test_path + "/extra/" phys2bids(filename=test_filename, indir=test_path, outdir=test_path, chtrig=test_chtrig, num_timepoints_expected=1) @@ -294,6 +296,7 @@ def test_integration_heuristic(samefreq_short_txt_file): test_full_path = os.path.join(test_path, test_filename) test_chtrig = 1 test_outdir = test_path + extra_dir = test_path + "/extra/" test_ntp = 158 test_tr = 1.2 test_thr = 0.735 From 9cb54e85eb98529e906c2266aef2fe0530206ccc Mon Sep 17 00:00:00 2001 From: vinferrer Date: Wed, 17 Jun 2020 09:14:07 +0200 Subject: [PATCH 07/24] linting problem --- phys2bids/tests/test_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phys2bids/tests/test_integration.py b/phys2bids/tests/test_integration.py index feb3963b6..de33e8cf6 100644 --- a/phys2bids/tests/test_integration.py +++ b/phys2bids/tests/test_integration.py @@ -105,7 +105,7 @@ def test_integration_acq(samefreq_full_acq_file): test_path, test_filename = os.path.split(samefreq_full_acq_file) test_chtrig = 3 extra_dir = test_path + "/extra/" - + phys2bids(filename=test_filename, indir=test_path, outdir=test_path, chtrig=test_chtrig, num_timepoints_expected=1) From c832dcb470fa8b4334f63581b98e789a58fc0b2c Mon Sep 17 00:00:00 2001 From: vinferrer Date: Wed, 17 Jun 2020 09:21:43 +0200 Subject: [PATCH 08/24] viz plot is now created in the extra folder --- phys2bids/phys2bids.py | 11 +++++------ phys2bids/viz.py | 6 +++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/phys2bids/phys2bids.py b/phys2bids/phys2bids.py index 4f73c5c4a..06d704713 100644 --- a/phys2bids/phys2bids.py +++ b/phys2bids/phys2bids.py @@ -133,13 +133,13 @@ def phys2bids(filename, info=False, indir='.', outdir='.', heur_file=None, outdir = utils.check_input_dir(outdir) utils.path_exists_or_make_it(outdir) # generate extra path - extra = outdir + "/extra" - utils.path_exists_or_make_it(extra) + extra_dir = outdir + "/extra" + utils.path_exists_or_make_it(extra_dir) # Create logfile name basename = 'phys2bids_' extension = 'tsv' isotime = datetime.datetime.now().strftime('%Y-%m-%dT%H%M%S') - logname = os.path.join(extra, (basename + isotime + '.' + extension)) + logname = os.path.join(extra_dir, (basename + isotime + '.' + extension)) # Set logging format log_formatter = logging.Formatter( @@ -194,9 +194,8 @@ def phys2bids(filename, info=False, indir='.', outdir='.', heur_file=None, LGR.info('Reading infos') phys_in.print_info(filename) # #!# Here the function viz.plot_channel should be called - if chplot != '' or info: - viz.plot_all(phys_in.ch_name, phys_in.timeseries, phys_in.units, - phys_in.freq, infile, chplot) + viz.plot_all(phys_in.ch_name, phys_in.timeseries, phys_in.units, + phys_in.freq, infile, extra_dir) # If only info were asked, end here. if info: return diff --git a/phys2bids/viz.py b/phys2bids/viz.py index 38abd32e6..6ac55e158 100644 --- a/phys2bids/viz.py +++ b/phys2bids/viz.py @@ -128,7 +128,7 @@ def ntr2time(x): plt.close() -def plot_all(ch_name, timeseries, units, freq, infile, outfile='', dpi=SET_DPI, size=FIGSIZE): +def plot_all(ch_name, timeseries, units, freq, infile, outfile, dpi=SET_DPI, size=FIGSIZE): """ Plot all the channels for visualizations and saves them in outfile. @@ -179,7 +179,7 @@ def plot_all(ch_name, timeseries, units, freq, infile, outfile='', dpi=SET_DPI, ax[row].xlim = 30 * 60 * freq[0] # maximum display of half an hour ax[row].grid() ax[row].set_xlabel("seconds") - if outfile == '': - outfile = os.path.splitext(os.path.basename(infile))[0] + '.png' + outfile = os.path.join(outfile, os.path.splitext(os.path.basename(infile))[0] + '.png') + print(outfile) LGR.info(f'saving channel plot to {outfile}') fig.savefig(outfile, dpi=dpi, bbox_inches='tight') From 6047f6b96029b1c679c3acafce17e5110d642f28 Mon Sep 17 00:00:00 2001 From: vinferrer Date: Wed, 17 Jun 2020 09:23:28 +0200 Subject: [PATCH 09/24] eliminate -chplot option --- phys2bids/cli/run.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/phys2bids/cli/run.py b/phys2bids/cli/run.py index 8b9118ccd..e29c0b140 100644 --- a/phys2bids/cli/run.py +++ b/phys2bids/cli/run.py @@ -120,11 +120,6 @@ def _get_parser(): type=str, help='Column header (for json file output).', default=[]) - optional.add_argument('-chplot', '--channels-plot', - dest='chplot', - type=str, - help='full path to store channels plot ', - default='') optional.add_argument('-debug', '--debug', dest='debug', action='store_true', From 3ee7ca36258d2ef9d8a0b80f4dd61465e54458c9 Mon Sep 17 00:00:00 2001 From: vinferrer Date: Wed, 17 Jun 2020 09:28:49 +0200 Subject: [PATCH 10/24] chplot eliminated as input to phys2bids function --- phys2bids/phys2bids.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phys2bids/phys2bids.py b/phys2bids/phys2bids.py index 06d704713..e037fa0b7 100644 --- a/phys2bids/phys2bids.py +++ b/phys2bids/phys2bids.py @@ -112,7 +112,7 @@ def print_json(outfile, samp_freq, time_offset, ch_name): def phys2bids(filename, info=False, indir='.', outdir='.', heur_file=None, sub=None, ses=None, chtrig=0, chsel=None, num_timepoints_expected=0, - tr=1, thr=None, ch_name=[], chplot='', debug=False, quiet=False): + tr=1, thr=None, ch_name=[], debug=False, quiet=False): """ Main workflow of phys2bids. From 001002cc27ee3ebd3752711fd0a98d31a1074fd3 Mon Sep 17 00:00:00 2001 From: vinferrer Date: Wed, 17 Jun 2020 09:43:05 +0200 Subject: [PATCH 11/24] fix new plot path in test --- phys2bids/tests/test_viz.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/phys2bids/tests/test_viz.py b/phys2bids/tests/test_viz.py index 65b444af7..d1e3e4245 100644 --- a/phys2bids/tests/test_viz.py +++ b/phys2bids/tests/test_viz.py @@ -8,9 +8,8 @@ def test_plot_all(samefreq_full_acq_file): chtrig = 3 test_path, test_filename = os.path.split(samefreq_full_acq_file) phys_obj = acq.populate_phys_input(samefreq_full_acq_file, chtrig) - out = os.path.join(test_path, 'Test_belt_pulse_samefreq.png') viz.plot_all(phys_obj.ch_name, phys_obj.timeseries, phys_obj.units, - phys_obj.freq, test_filename, outfile=out) + phys_obj.freq, test_filename, outfile=test_path) assert os.path.isfile(out) From 34687c1d369d3367b6633399aeac788d7011c29d Mon Sep 17 00:00:00 2001 From: vinferrer Date: Wed, 17 Jun 2020 09:47:37 +0200 Subject: [PATCH 12/24] correct plot path in integration test --- phys2bids/tests/test_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phys2bids/tests/test_integration.py b/phys2bids/tests/test_integration.py index de33e8cf6..537f3db2e 100644 --- a/phys2bids/tests/test_integration.py +++ b/phys2bids/tests/test_integration.py @@ -371,7 +371,7 @@ def test_integration_info(samefreq_short_txt_file): subprocess.run(command_str, shell=True, check=True) # Check that plot all file is generated - assert os.path.isfile('Test_belt_pulse_samefreq_short.png') + assert os.path.isfile(os.path.join(test_outdir, 'extra/Test_belt_pulse_samefreq_short.png')) # Read logger file logger_file = glob.glob(os.path.join(extra_dir, '*phys2bids*'))[0] From d0956ffbfef73558386e16e9b1cf1abc3ccec668 Mon Sep 17 00:00:00 2001 From: vinferrer Date: Wed, 17 Jun 2020 09:51:22 +0200 Subject: [PATCH 13/24] change trigger plot dir to extra --- phys2bids/phys2bids.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phys2bids/phys2bids.py b/phys2bids/phys2bids.py index e037fa0b7..ef6650fe7 100644 --- a/phys2bids/phys2bids.py +++ b/phys2bids/phys2bids.py @@ -207,7 +207,7 @@ def phys2bids(filename, info=False, indir='.', outdir='.', heur_file=None, # #!# Get option of no trigger! (which is wrong practice or Respiract) phys_in.check_trigger_amount(thr, num_timepoints_expected, tr) LGR.info('Plot trigger') - plot_path = os.path.join(outdir, + plot_path = os.path.join(extra_dir, os.path.splitext(os.path.basename(filename))[0]) if sub: plot_path += f'_sub-{sub}' From 6b8b93ce245d7a0cd435dce9e2d8f37edf451e83 Mon Sep 17 00:00:00 2001 From: vinferrer Date: Wed, 17 Jun 2020 09:56:14 +0200 Subject: [PATCH 14/24] correct assert path --- phys2bids/tests/test_viz.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phys2bids/tests/test_viz.py b/phys2bids/tests/test_viz.py index d1e3e4245..d7109508b 100644 --- a/phys2bids/tests/test_viz.py +++ b/phys2bids/tests/test_viz.py @@ -10,7 +10,8 @@ def test_plot_all(samefreq_full_acq_file): phys_obj = acq.populate_phys_input(samefreq_full_acq_file, chtrig) viz.plot_all(phys_obj.ch_name, phys_obj.timeseries, phys_obj.units, phys_obj.freq, test_filename, outfile=test_path) - assert os.path.isfile(out) + assert os.path.isfile(os.path.join(test_path, + os.path.splitext(os.path.basename(test_filename))[0] + '.png')) def test_plot_trigger(samefreq_full_acq_file): From dae88c64b0ecef96c106fe40f997b71273377c3f Mon Sep 17 00:00:00 2001 From: vinferrer Date: Wed, 17 Jun 2020 10:09:42 +0200 Subject: [PATCH 15/24] print summary in extra folder --- phys2bids/phys2bids.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phys2bids/phys2bids.py b/phys2bids/phys2bids.py index ef6650fe7..a9d1b372f 100644 --- a/phys2bids/phys2bids.py +++ b/phys2bids/phys2bids.py @@ -295,7 +295,7 @@ def phys2bids(filename, info=False, indir='.', outdir='.', heur_file=None, phys_out[uniq_freq].ch_name) print_summary(filename, num_timepoints_expected, phys_in.num_timepoints_found, uniq_freq, - phys_out[uniq_freq].start_time, outfile) + phys_out[uniq_freq].start_time, os.path.join(extra_dir, os.path.splitext(os.path.basename(outfile))[0])) def _main(argv=None): From aeab76c54276ef1f87fa3609f79e73c32172293e Mon Sep 17 00:00:00 2001 From: vinferrer Date: Wed, 17 Jun 2020 10:25:25 +0200 Subject: [PATCH 16/24] eliminate print --- phys2bids/viz.py | 1 - 1 file changed, 1 deletion(-) diff --git a/phys2bids/viz.py b/phys2bids/viz.py index 6ac55e158..190a61aa8 100644 --- a/phys2bids/viz.py +++ b/phys2bids/viz.py @@ -180,6 +180,5 @@ def plot_all(ch_name, timeseries, units, freq, infile, outfile, dpi=SET_DPI, siz ax[row].grid() ax[row].set_xlabel("seconds") outfile = os.path.join(outfile, os.path.splitext(os.path.basename(infile))[0] + '.png') - print(outfile) LGR.info(f'saving channel plot to {outfile}') fig.savefig(outfile, dpi=dpi, bbox_inches='tight') From dc455409a243a5d93164b43528a045598020f101 Mon Sep 17 00:00:00 2001 From: vinferrer Date: Wed, 17 Jun 2020 10:52:20 +0200 Subject: [PATCH 17/24] solved integration tests paths --- phys2bids/tests/test_integration.py | 52 +++++++++++++++++++---------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/phys2bids/tests/test_integration.py b/phys2bids/tests/test_integration.py index 537f3db2e..237ff5e92 100644 --- a/phys2bids/tests/test_integration.py +++ b/phys2bids/tests/test_integration.py @@ -3,6 +3,7 @@ import math import os import re +import shutil import subprocess from pkg_resources import resource_filename @@ -58,16 +59,21 @@ def test_integration_txt(samefreq_short_txt_file): test_path, test_filename = os.path.split(samefreq_short_txt_file) test_chtrig = 2 + extra_dir = test_path + "/extra/" phys2bids(filename=test_filename, indir=test_path, outdir=test_path, chtrig=test_chtrig, num_timepoints_expected=1) # Check that files are generated - for suffix in ['.log', '.json', '.tsv.gz', '_trigger_time.png']: + for suffix in ['.json', '.tsv.gz']: assert os.path.isfile(os.path.join(test_path, 'Test_belt_pulse_samefreq_short' + suffix)) + # Check files in extra are generated + for suffix in ['.log', '_trigger_time.png']: + assert os.path.isfile(os.path.join(extra_dir, 'Test_belt_pulse_samefreq_short' + suffix)) + # Read log file (note that this file is not the logger file) - with open(os.path.join(test_path, 'Test_belt_pulse_samefreq_short.log')) as log_info: + with open(os.path.join(extra_dir, 'Test_belt_pulse_samefreq_short.log')) as log_info: log_info = log_info.readlines() # Check timepoints expected @@ -95,6 +101,7 @@ def test_integration_txt(samefreq_short_txt_file): os.remove(filename) for filename in glob.glob(os.path.join(test_path, 'Test_belt_pulse_samefreq_short*')): os.remove(filename) + shutil.rmtree(extra_dir) def test_integration_acq(samefreq_full_acq_file): @@ -110,11 +117,15 @@ def test_integration_acq(samefreq_full_acq_file): chtrig=test_chtrig, num_timepoints_expected=1) # Check that files are generated - for suffix in ['.log', '.json', '.tsv.gz', '_trigger_time.png']: + for suffix in ['.json', '.tsv.gz']: assert os.path.isfile(os.path.join(test_path, 'Test_belt_pulse_samefreq' + suffix)) + # Check files in extra are generated + for suffix in ['.log', '_trigger_time.png']: + assert os.path.isfile(os.path.join(extra_dir, 'Test_belt_pulse_samefreq' + suffix)) + # Read log file (note that this file is not the logger file) - with open(os.path.join(test_path, 'Test_belt_pulse_samefreq.log')) as log_info: + with open(os.path.join(extra_dir, 'Test_belt_pulse_samefreq.log')) as log_info: log_info = log_info.readlines() # Check timepoints expected @@ -143,6 +154,7 @@ def test_integration_acq(samefreq_full_acq_file): os.remove(filename) for filename in glob.glob(os.path.join(test_path, 'Test_belt_pulse_samefreq*')): os.remove(filename) + shutil.rmtree(extra_dir) def test_integration_multifreq(multifreq_lab_file): @@ -158,25 +170,28 @@ def test_integration_multifreq(multifreq_lab_file): chtrig=test_chtrig, num_timepoints_expected=1) # Check that files are generated - for suffix in ['.log', '.json', '.tsv.gz']: + for suffix in ['.json', '.tsv.gz']: assert os.path.isfile(os.path.join(test_path, 'Test1_multifreq_onescan_40.0' + suffix)) - for suffix in ['.log', '.json', '.tsv.gz']: + for suffix in ['.json', '.tsv.gz']: assert os.path.isfile(os.path.join(test_path, 'Test1_multifreq_onescan_100.0' + suffix)) - for suffix in ['.log', '.json', '.tsv.gz']: + for suffix in ['.json', '.tsv.gz']: assert os.path.isfile(os.path.join(test_path, 'Test1_multifreq_onescan_500.0' + suffix)) - for suffix in ['.log', '.json', '.tsv.gz']: + for suffix in ['.json', '.tsv.gz']: assert os.path.isfile(os.path.join(test_path, 'Test1_multifreq_onescan_1000.0' + suffix)) - assert os.path.isfile(os.path.join(test_path, 'Test1_multifreq_onescan_trigger_time.png')) + for freq in ['40', '100', '500', '1000']: + assert os.path.isfile(os.path.join(extra_dir, + 'Test1_multifreq_onescan_' + freq + '.log')) + assert os.path.isfile(os.path.join(extra_dir, 'Test1_multifreq_onescan_trigger_time.png')) """ Checks 40 Hz output """ # Read log file of frequency 625 (note that this file is not the logger file) - with open(os.path.join(test_path, 'Test1_multifreq_onescan_40.0.log')) as log_info: + with open(os.path.join(extra_dir, 'Test1_multifreq_onescan_40.log')) as log_info: log_info = log_info.readlines() # Check timepoints expected @@ -203,7 +218,7 @@ def test_integration_multifreq(multifreq_lab_file): Checks 100 Hz output """ # Read log file of frequency 625 (note that this file is not the logger file) - with open(os.path.join(test_path, 'Test1_multifreq_onescan_100.0.log')) as log_info: + with open(os.path.join(extra_dir, 'Test1_multifreq_onescan_100.log')) as log_info: log_info = log_info.readlines() # Check timepoints expected @@ -230,7 +245,7 @@ def test_integration_multifreq(multifreq_lab_file): Checks 500 Hz output """ # Read log file of frequency 625 (note that this file is not the logger file) - with open(os.path.join(test_path, 'Test1_multifreq_onescan_500.0.log')) as log_info: + with open(os.path.join(extra_dir, 'Test1_multifreq_onescan_500.log')) as log_info: log_info = log_info.readlines() # Check timepoints expected @@ -254,10 +269,10 @@ def test_integration_multifreq(multifreq_lab_file): assert json_data['Columns'] == ['Belt'] """ - Checks 100 Hz output + Checks 1000 Hz output """ # Read log file of frequency 625 (note that this file is not the logger file) - with open(os.path.join(test_path, 'Test1_multifreq_onescan_1000.0.log')) as log_info: + with open(os.path.join(extra_dir, 'Test1_multifreq_onescan_1000.log')) as log_info: log_info = log_info.readlines() # Check timepoints expected @@ -285,6 +300,7 @@ def test_integration_multifreq(multifreq_lab_file): os.remove(filename) for filename in glob.glob(os.path.join(test_path, 'Test_belt_pulse_multifreq*')): os.remove(filename) + shutil.rmtree(extra_dir) def test_integration_heuristic(samefreq_short_txt_file): @@ -310,12 +326,12 @@ def test_integration_heuristic(samefreq_short_txt_file): # Check that files are generated base_filename = 'sub-006_ses-01_task-test_rec-biopac_run-01_physio' - for suffix in ['.log', '.json', '.tsv.gz']: + for suffix in ['.json', '.tsv.gz']: assert os.path.isfile(os.path.join(test_path_output, base_filename + suffix)) - + assert os.path.isfile(os.path.join(extra_dir, base_filename + '.log')) # Read log file (note that this file is not the logger file) log_filename = 'sub-006_ses-01_task-test_rec-biopac_run-01_physio.log' - with open(os.path.join(test_path_output, log_filename)) as log_info: + with open(os.path.join(extra_dir, log_filename)) as log_info: log_info = log_info.readlines() # Check timepoints expected @@ -346,6 +362,7 @@ def test_integration_heuristic(samefreq_short_txt_file): os.remove(filename) for filename in glob.glob(os.path.join(test_path_output, '*')): os.remove(filename) + shutil.rmtree(extra_dir) def test_integration_info(samefreq_short_txt_file): @@ -385,3 +402,4 @@ def test_integration_info(samefreq_short_txt_file): # Remove generated files for filename in glob.glob(os.path.join(extra_dir, 'phys2bids*')): os.remove(filename) + shutil.rmtree(extra_dir) From ceed240d16fb24080c022ed4b8ddc17399726f6d Mon Sep 17 00:00:00 2001 From: vinferrer Date: Wed, 17 Jun 2020 10:55:30 +0200 Subject: [PATCH 18/24] correct linting --- phys2bids/phys2bids.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phys2bids/phys2bids.py b/phys2bids/phys2bids.py index a9d1b372f..01608259a 100644 --- a/phys2bids/phys2bids.py +++ b/phys2bids/phys2bids.py @@ -295,7 +295,8 @@ def phys2bids(filename, info=False, indir='.', outdir='.', heur_file=None, phys_out[uniq_freq].ch_name) print_summary(filename, num_timepoints_expected, phys_in.num_timepoints_found, uniq_freq, - phys_out[uniq_freq].start_time, os.path.join(extra_dir, os.path.splitext(os.path.basename(outfile))[0])) + phys_out[uniq_freq].start_time, + os.path.join(extra_dir, os.path.splitext(os.path.basename(outfile))[0])) def _main(argv=None): From 016b21474effad8a1e99fd50ba61faced103316b Mon Sep 17 00:00:00 2001 From: vinferrer Date: Wed, 17 Jun 2020 12:38:28 +0200 Subject: [PATCH 19/24] restart tests From 9fc8608709adecda3ed4b3adeab632b396585fdc Mon Sep 17 00:00:00 2001 From: vinferrer Date: Wed, 17 Jun 2020 17:18:44 +0200 Subject: [PATCH 20/24] change extra folder name to bids_ignore --- phys2bids/phys2bids.py | 2 +- phys2bids/tests/test_integration.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/phys2bids/phys2bids.py b/phys2bids/phys2bids.py index 01608259a..cc6e05a5e 100644 --- a/phys2bids/phys2bids.py +++ b/phys2bids/phys2bids.py @@ -133,7 +133,7 @@ def phys2bids(filename, info=False, indir='.', outdir='.', heur_file=None, outdir = utils.check_input_dir(outdir) utils.path_exists_or_make_it(outdir) # generate extra path - extra_dir = outdir + "/extra" + extra_dir = outdir + "/bids_ignore" utils.path_exists_or_make_it(extra_dir) # Create logfile name basename = 'phys2bids_' diff --git a/phys2bids/tests/test_integration.py b/phys2bids/tests/test_integration.py index 237ff5e92..e5c766495 100644 --- a/phys2bids/tests/test_integration.py +++ b/phys2bids/tests/test_integration.py @@ -33,7 +33,7 @@ def test_logger(multifreq_lab_file): test_chtrig = 3 test_ntp = 1 test_outdir = test_path - extra_dir = test_path + "/extra/" + extra_dir = test_path + "/bids_ignore/" # Phys2bids call through terminal subprocess.run(f'phys2bids -in {test_filename} -indir {test_path} ' f'-chtrig {test_chtrig} -ntp {test_ntp} -outdir {test_outdir}', @@ -59,7 +59,7 @@ def test_integration_txt(samefreq_short_txt_file): test_path, test_filename = os.path.split(samefreq_short_txt_file) test_chtrig = 2 - extra_dir = test_path + "/extra/" + extra_dir = test_path + "/bids_ignore/" phys2bids(filename=test_filename, indir=test_path, outdir=test_path, chtrig=test_chtrig, num_timepoints_expected=1) @@ -111,7 +111,7 @@ def test_integration_acq(samefreq_full_acq_file): test_path, test_filename = os.path.split(samefreq_full_acq_file) test_chtrig = 3 - extra_dir = test_path + "/extra/" + extra_dir = test_path + "/bids_ignore/" phys2bids(filename=test_filename, indir=test_path, outdir=test_path, chtrig=test_chtrig, num_timepoints_expected=1) @@ -164,7 +164,7 @@ def test_integration_multifreq(multifreq_lab_file): test_path, test_filename = os.path.split(multifreq_lab_file) test_chtrig = 3 - extra_dir = test_path + "/extra/" + extra_dir = test_path + "/bids_ignore/" phys2bids(filename=test_filename, indir=test_path, outdir=test_path, chtrig=test_chtrig, num_timepoints_expected=1) @@ -312,7 +312,7 @@ def test_integration_heuristic(samefreq_short_txt_file): test_full_path = os.path.join(test_path, test_filename) test_chtrig = 1 test_outdir = test_path - extra_dir = test_path + "/extra/" + extra_dir = test_path + "/bids_ignore/" test_ntp = 158 test_tr = 1.2 test_thr = 0.735 @@ -376,7 +376,7 @@ def test_integration_info(samefreq_short_txt_file): test_ntp = 158 test_tr = 1.2 test_thr = 0.735 - extra_dir = test_path + "/extra/" + extra_dir = test_path + "/bids_ignore/" # Move into folder subprocess.run(f'cd {test_path}', shell=True, check=True) # Phys2bids call through terminal @@ -388,7 +388,7 @@ def test_integration_info(samefreq_short_txt_file): subprocess.run(command_str, shell=True, check=True) # Check that plot all file is generated - assert os.path.isfile(os.path.join(test_outdir, 'extra/Test_belt_pulse_samefreq_short.png')) + assert os.path.isfile(os.path.join(test_outdir, 'bids_ignore/Test_belt_pulse_samefreq_short.png')) # Read logger file logger_file = glob.glob(os.path.join(extra_dir, '*phys2bids*'))[0] From a5eeb7c12c1f49f89c7ba3ea940f896a89c1c9ca Mon Sep 17 00:00:00 2001 From: vinferrer Date: Wed, 17 Jun 2020 17:25:43 +0200 Subject: [PATCH 21/24] single commas --- phys2bids/phys2bids.py | 2 +- phys2bids/tests/test_integration.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phys2bids/phys2bids.py b/phys2bids/phys2bids.py index cc6e05a5e..600bfd4d1 100644 --- a/phys2bids/phys2bids.py +++ b/phys2bids/phys2bids.py @@ -133,7 +133,7 @@ def phys2bids(filename, info=False, indir='.', outdir='.', heur_file=None, outdir = utils.check_input_dir(outdir) utils.path_exists_or_make_it(outdir) # generate extra path - extra_dir = outdir + "/bids_ignore" + extra_dir = outdir + '/bids_ignore' utils.path_exists_or_make_it(extra_dir) # Create logfile name basename = 'phys2bids_' diff --git a/phys2bids/tests/test_integration.py b/phys2bids/tests/test_integration.py index e5c766495..42e4bb8f7 100644 --- a/phys2bids/tests/test_integration.py +++ b/phys2bids/tests/test_integration.py @@ -376,7 +376,7 @@ def test_integration_info(samefreq_short_txt_file): test_ntp = 158 test_tr = 1.2 test_thr = 0.735 - extra_dir = test_path + "/bids_ignore/" + extra_dir = test_path + '/bids_ignore/' # Move into folder subprocess.run(f'cd {test_path}', shell=True, check=True) # Phys2bids call through terminal From d3281f478d93296e3c4254f183e7ed8e9313e7d1 Mon Sep 17 00:00:00 2001 From: vinferrer Date: Wed, 17 Jun 2020 17:25:59 +0200 Subject: [PATCH 22/24] single commas --- phys2bids/tests/test_integration.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/phys2bids/tests/test_integration.py b/phys2bids/tests/test_integration.py index 42e4bb8f7..6f379428d 100644 --- a/phys2bids/tests/test_integration.py +++ b/phys2bids/tests/test_integration.py @@ -33,7 +33,7 @@ def test_logger(multifreq_lab_file): test_chtrig = 3 test_ntp = 1 test_outdir = test_path - extra_dir = test_path + "/bids_ignore/" + extra_dir = test_path + '/bids_ignore/' # Phys2bids call through terminal subprocess.run(f'phys2bids -in {test_filename} -indir {test_path} ' f'-chtrig {test_chtrig} -ntp {test_ntp} -outdir {test_outdir}', @@ -59,7 +59,7 @@ def test_integration_txt(samefreq_short_txt_file): test_path, test_filename = os.path.split(samefreq_short_txt_file) test_chtrig = 2 - extra_dir = test_path + "/bids_ignore/" + extra_dir = test_path + '/bids_ignore/' phys2bids(filename=test_filename, indir=test_path, outdir=test_path, chtrig=test_chtrig, num_timepoints_expected=1) @@ -111,7 +111,7 @@ def test_integration_acq(samefreq_full_acq_file): test_path, test_filename = os.path.split(samefreq_full_acq_file) test_chtrig = 3 - extra_dir = test_path + "/bids_ignore/" + extra_dir = test_path + '/bids_ignore/' phys2bids(filename=test_filename, indir=test_path, outdir=test_path, chtrig=test_chtrig, num_timepoints_expected=1) @@ -164,7 +164,7 @@ def test_integration_multifreq(multifreq_lab_file): test_path, test_filename = os.path.split(multifreq_lab_file) test_chtrig = 3 - extra_dir = test_path + "/bids_ignore/" + extra_dir = test_path + '/bids_ignore/' phys2bids(filename=test_filename, indir=test_path, outdir=test_path, chtrig=test_chtrig, num_timepoints_expected=1) @@ -312,7 +312,7 @@ def test_integration_heuristic(samefreq_short_txt_file): test_full_path = os.path.join(test_path, test_filename) test_chtrig = 1 test_outdir = test_path - extra_dir = test_path + "/bids_ignore/" + extra_dir = test_path + '/bids_ignore/' test_ntp = 158 test_tr = 1.2 test_thr = 0.735 From e49a2963e5cfa1dfe7f5c7534b057e2d89032ce8 Mon Sep 17 00:00:00 2001 From: vinferrer Date: Thu, 18 Jun 2020 09:17:24 +0200 Subject: [PATCH 23/24] use os.path.join instead of + --- phys2bids/phys2bids.py | 2 +- phys2bids/tests/test_integration.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/phys2bids/phys2bids.py b/phys2bids/phys2bids.py index 7eb949a46..2eb56e07e 100644 --- a/phys2bids/phys2bids.py +++ b/phys2bids/phys2bids.py @@ -133,7 +133,7 @@ def phys2bids(filename, info=False, indir='.', outdir='.', heur_file=None, outdir = utils.check_input_dir(outdir) utils.path_exists_or_make_it(outdir) # generate extra path - extra_dir = outdir + '/bids_ignore' + extra_dir = os.path.join(outdir, 'bids_ignore') utils.path_exists_or_make_it(extra_dir) # Create logfile name basename = 'phys2bids_' diff --git a/phys2bids/tests/test_integration.py b/phys2bids/tests/test_integration.py index 51d4edbe6..0c949fd66 100644 --- a/phys2bids/tests/test_integration.py +++ b/phys2bids/tests/test_integration.py @@ -34,7 +34,7 @@ def test_logger(multifreq_lab_file): test_chtrig = 3 test_ntp = 1 test_outdir = test_path - extra_dir = test_path + '/bids_ignore/' + extra_dir = os.path.join(test_path, 'bids_ignore') # Phys2bids call through terminal subprocess.run(f'phys2bids -in {test_filename} -indir {test_path} ' f'-chtrig {test_chtrig} -ntp {test_ntp} -outdir {test_outdir}', @@ -60,7 +60,7 @@ def test_integration_txt(samefreq_short_txt_file): test_path, test_filename = os.path.split(samefreq_short_txt_file) test_chtrig = 2 - extra_dir = test_path + '/bids_ignore/' + extra_dir = os.path.join(test_path, 'bids_ignore') phys2bids(filename=test_filename, indir=test_path, outdir=test_path, chtrig=test_chtrig, num_timepoints_expected=1) @@ -112,7 +112,7 @@ def test_integration_acq(samefreq_full_acq_file): test_path, test_filename = os.path.split(samefreq_full_acq_file) test_chtrig = 3 - extra_dir = test_path + '/bids_ignore/' + extra_dir = os.path.join(test_path, 'bids_ignore') phys2bids(filename=test_filename, indir=test_path, outdir=test_path, chtrig=test_chtrig, num_timepoints_expected=1) @@ -165,7 +165,7 @@ def test_integration_multifreq(multifreq_lab_file): test_path, test_filename = os.path.split(multifreq_lab_file) test_chtrig = 3 - extra_dir = test_path + '/bids_ignore/' + extra_dir = os.path.join(test_path, 'bids_ignore') phys2bids(filename=test_filename, indir=test_path, outdir=test_path, chtrig=test_chtrig, num_timepoints_expected=1) @@ -313,7 +313,7 @@ def test_integration_heuristic(samefreq_short_txt_file): test_full_path = os.path.join(test_path, test_filename) test_chtrig = 1 test_outdir = test_path - extra_dir = test_path + '/bids_ignore/' + extra_dir = os.path.join(test_path, 'bids_ignore') test_ntp = 158 test_tr = 1.2 test_thr = 0.735 @@ -390,7 +390,7 @@ def test_integration_info(samefreq_short_txt_file): test_ntp = 158 test_tr = 1.2 test_thr = 0.735 - extra_dir = test_path + '/bids_ignore/' + extra_dir = os.path.join(test_path, 'bids_ignore') # Move into folder subprocess.run(f'cd {test_path}', shell=True, check=True) # Phys2bids call through terminal From 9360aaa5dcd8901c4ecaee61d166b4c4014c9b0a Mon Sep 17 00:00:00 2001 From: vinferrer Date: Thu, 18 Jun 2020 09:19:41 +0200 Subject: [PATCH 24/24] linting problems --- phys2bids/tests/test_integration.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/phys2bids/tests/test_integration.py b/phys2bids/tests/test_integration.py index 0c949fd66..4cf18972a 100644 --- a/phys2bids/tests/test_integration.py +++ b/phys2bids/tests/test_integration.py @@ -358,8 +358,8 @@ def test_integration_heuristic(samefreq_short_txt_file): # Check that participant.tsv gets updated phys2bids(filename=test_full_path, chtrig=test_chtrig, outdir=test_outdir, - num_timepoints_expected=test_ntp, tr=test_tr, thr=test_thr, sub='002', - ses='01', heur_file=test_heur) + num_timepoints_expected=test_ntp, tr=test_tr, thr=test_thr, sub='002', + ses='01', heur_file=test_heur) counter = 0 subject_list = ['participant_id', '006', '002'] @@ -402,7 +402,8 @@ def test_integration_info(samefreq_short_txt_file): subprocess.run(command_str, shell=True, check=True) # Check that plot all file is generated - assert os.path.isfile(os.path.join(test_outdir, 'bids_ignore/Test_belt_pulse_samefreq_short.png')) + assert os.path.isfile(os.path.join(test_outdir, + 'bids_ignore/Test_belt_pulse_samefreq_short.png')) # Read logger file logger_file = glob.glob(os.path.join(extra_dir, '*phys2bids*'))[0]