From a1c0579a495f2053b6d6e409b598d7bdbdd85086 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo <36234686+cosimolupo@users.noreply.github.com> Date: Fri, 22 Mar 2024 14:27:55 +0100 Subject: [PATCH] Fixing typos and alignments/spacings (#61) * Fixing typos and alignments/spacings * Adjusting indentation in CLI args definition * Further changing indentation * Fix * Adding help for CLI args where still missing * Rolling back to previous naming convention Postponing this change to a future PR --- cobrawap/pipeline/Snakefile | 2 +- .../scripts/enter_data_template.py | 36 +++++++------- .../stage01_data_entry/scripts/plot_traces.py | 10 ++-- .../pipeline/stage02_processing/Snakefile | 2 +- .../configs/config_template.yaml | 2 +- .../scripts/background_subtraction.py | 16 +++---- .../stage02_processing/scripts/check_input.py | 2 +- .../stage02_processing/scripts/detrending.py | 16 +++---- .../scripts/frequency_filter.py | 16 +++---- .../scripts/logMUA_estimation.py | 38 +++++++-------- .../scripts/normalization.py | 10 ++-- .../scripts/phase_transform.py | 4 +- .../scripts/plot_power_spectrum.py | 16 +++---- .../scripts/plot_processed_trace.py | 16 +++---- .../scripts/roi_selection.py | 18 +++---- .../scripts/spatial_downsampling.py | 16 +++---- .../stage02_processing/scripts/subsampling.py | 10 ++-- .../stage02_processing/scripts/z_score.py | 6 +-- .../stage03_trigger_detection/Snakefile | 7 +-- .../scripts/calc_thresholds_fitted.py | 20 ++++---- .../scripts/calc_thresholds_fixed.py | 7 +-- .../scripts/check_input.py | 4 +- .../scripts/hilbert_phase.py | 20 ++++---- .../scripts/minima.py | 28 +++++------ .../scripts/plot_trigger_times.py | 14 +++--- .../scripts/remove_short_states.py | 10 ++-- .../scripts/threshold.py | 6 +-- .../pipeline/stage04_wave_detection/Snakefile | 10 ++-- .../configs/config_template.yaml | 2 +- .../scripts/check_input.py | 4 +- .../scripts/critical_points.py | 4 +- .../scripts/merge_wave_definitions.py | 7 +-- .../scripts/optical_flow.py | 19 ++++---- .../scripts/plot_clustering.py | 10 ++-- .../scripts/plot_critical_points.py | 8 ++-- .../scripts/plot_movie_frames.py | 26 ++++++---- .../scripts/plot_waves.py | 18 ++++--- .../scripts/time_slice.py | 8 ++-- .../scripts/trigger_clustering.py | 12 ++--- .../scripts/wave_mode_clustering.py | 48 +++++++++---------- .../Snakefile | 1 - .../scripts/annotations.py | 14 +++--- .../scripts/check_input.py | 6 +-- .../scripts/direction_local.py | 8 ++-- .../scripts/flow_direction_local.py | 10 ++-- .../scripts/inter_wave_interval_local.py | 10 ++-- .../scripts/merge_dataframes.py | 12 +++-- .../scripts/spatial_derivative.py | 14 +++--- .../scripts/velocity_local.py | 8 ++-- .../stage05_wave_characterization/Snakefile | 2 +- .../scripts/annotations.py | 15 +++--- .../scripts/check_input.py | 6 +-- .../scripts/direction_planar.py | 10 ++-- .../scripts/duration.py | 8 ++-- .../scripts/inter_wave_interval.py | 8 ++-- .../scripts/label_planar.py | 10 ++-- .../scripts/merge_dataframes.py | 12 +++-- .../scripts/number_of_triggers.py | 8 ++-- .../scripts/time_stamp.py | 10 ++-- .../scripts/velocity_planar.py | 8 ++-- .../stageXY_template/scripts/check_input.py | 5 +- .../scripts/minimal_example.py | 4 +- .../scripts/script_template.py | 18 +++---- cobrawap/pipeline/utils/Snakefile | 2 +- cobrawap/pipeline/utils/io_utils.py | 2 +- cobrawap/pipeline/utils/neo_utils.py | 4 +- cobrawap/pipeline/utils/snakefile.py | 2 +- 67 files changed, 384 insertions(+), 361 deletions(-) diff --git a/cobrawap/pipeline/Snakefile b/cobrawap/pipeline/Snakefile index 372dfc7f..b3618186 100644 --- a/cobrawap/pipeline/Snakefile +++ b/cobrawap/pipeline/Snakefile @@ -14,7 +14,7 @@ temp_config = 'working_config.yaml' config_path = Path(get_setting('config_path')) output_path = Path(get_setting('output_path')) -configfile: config_path /'configs' / 'config.yaml' +configfile: config_path / 'configs' / 'config.yaml' report: "report.rst" # Setting the profile diff --git a/cobrawap/pipeline/stage01_data_entry/scripts/enter_data_template.py b/cobrawap/pipeline/stage01_data_entry/scripts/enter_data_template.py index 12a957f3..eacc6816 100644 --- a/cobrawap/pipeline/stage01_data_entry/scripts/enter_data_template.py +++ b/cobrawap/pipeline/stage01_data_entry/scripts/enter_data_template.py @@ -1,5 +1,5 @@ """ -Loads a dataset a brings it into the required data representation (using Neo). +Loads a dataset and brings it into the required data representation (using Neo). """ import argparse @@ -14,29 +14,29 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=Path, required=True, - help="path to input data") + help="path to input data") CLI.add_argument("--output", nargs='?', type=Path, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--data_name", nargs='?', type=str, default='None', - help="chosen name of the dataset") + help="chosen name of the dataset") CLI.add_argument("--sampling_rate", nargs='?', type=none_or_float, - default=None, help="sampling rate in Hz") + default=None, help="sampling rate in Hz") CLI.add_argument("--spatial_scale", nargs='?', type=float, required=True, - help="distance between electrodes or pixels in mm") + help="distance between electrodes or pixels in mm") CLI.add_argument("--t_start", nargs='?', type=none_or_float, default=None, - help="start time, in s, delimits the interval of recordings to be analyzed") + help="start time, in s, delimits the interval of recordings to be analyzed") CLI.add_argument("--t_stop", nargs='?', type=none_or_float, default=None, - help="stop time, in s, delimits the interval of recordings to be analyzed") + help="stop time, in s, delimits the interval of recordings to be analyzed") CLI.add_argument("--orientation_top", nargs='?', type=str, required=True, - help="upward orientation of the recorded cortical region") + help="upward orientation of the recorded cortical region") CLI.add_argument("--orientation_right", nargs='?', type=str, required=True, - help="right-facing orientation of the recorded cortical region") + help="right-facing orientation of the recorded cortical region") CLI.add_argument("--annotations", nargs='+', type=none_or_str, default=None, - help="metadata of the dataset") + help="metadata of the dataset") CLI.add_argument("--array_annotations", nargs='+', type=none_or_str, - default=None, help="channel-wise metadata") + default=None, help="channel-wise metadata") CLI.add_argument("--kwargs", nargs='+', type=none_or_str, default=None, - help="additional optional arguments") + help="additional optional arguments") if __name__ == '__main__': args, unknown = CLI.parse_known_args() @@ -44,25 +44,25 @@ # Load data with Neo IO or custom loading routine block = load_neo(args.data) # If there is no Neo IO for the data type available, - # the data must be loaded conventioally and added to a newly constructed + # the data must be loaded conventionally and added to a newly constructed # Neo block. For building a Neo objects, have a look into the documentation # https://neo.readthedocs.io/ - # In case the dataset is imagaging data and therefore stored as an + # In case the dataset is imaging data and therefore stored as an # ImageSequence object, it needs to be transformed into an AnalogSignal - # object. To do this use the function imagesequence_to_analogsignal in utils/neo.py + # object. To do this use the function imagesequence_to_analogsignal in utils/neo_utils.py asig = block.segments[0].analogsignals[0] asig = time_slice(asig, args.t_start, args.t_stop) - # Add metadata from ANNOTIATION dict + # Add metadata from ANNOTATION dict asig.annotations.update(parse_string2dict(args.annotations)) asig.annotations.update(spatial_scale=args.spatial_scale*pq.mm) asig.annotations.update(orientation_top=args.orientation_top) asig.annotations.update(orientation_right=args.orientation_right) - # Add metadata from ARRAY_ANNOTIATION dict + # Add metadata from ARRAY_ANNOTATION dict asig.array_annotations.update(parse_string2dict(args.array_annotations)) # Do custom metadata processing from KWARGS dict (optional) diff --git a/cobrawap/pipeline/stage01_data_entry/scripts/plot_traces.py b/cobrawap/pipeline/stage01_data_entry/scripts/plot_traces.py index 6e4c9ead..2e1452ad 100644 --- a/cobrawap/pipeline/stage01_data_entry/scripts/plot_traces.py +++ b/cobrawap/pipeline/stage01_data_entry/scripts/plot_traces.py @@ -13,15 +13,15 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=Path, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=Path, required=True, - help="path of output figure") + help="path of output figure") CLI.add_argument("--t_start", nargs='?', type=float, default=0, - help="start time in seconds") + help="start time in seconds") CLI.add_argument("--t_stop", nargs='?', type=float, default=10, - help="stop time in seconds") + help="stop time in seconds") CLI.add_argument("--channels", nargs='+', type=none_or_int, default=0, - help="list of channels to plot") + help="list of channels to plot") def plot_traces(asig, channels): sns.set(style='ticks', palette="deep", context="notebook") diff --git a/cobrawap/pipeline/stage02_processing/Snakefile b/cobrawap/pipeline/stage02_processing/Snakefile index 65f19836..3b1d26ba 100644 --- a/cobrawap/pipeline/stage02_processing/Snakefile +++ b/cobrawap/pipeline/stage02_processing/Snakefile @@ -122,7 +122,7 @@ use rule template as frequency_filter with: params('highpass_frequency', 'lowpass_frequency', 'filter_function', order=config.FILTER_ORDER, config=config) output: - Path('{dir}') / '{rule_name}' / f'frequency_filter.{config.NEO_FORMAT}' + Path('{dir}') / '{rule_name}' / f'frequency_filter.{config.NEO_FORMAT}' use rule template as roi_selection with: diff --git a/cobrawap/pipeline/stage02_processing/configs/config_template.yaml b/cobrawap/pipeline/stage02_processing/configs/config_template.yaml index 8e99217e..3e936b84 100644 --- a/cobrawap/pipeline/stage02_processing/configs/config_template.yaml +++ b/cobrawap/pipeline/stage02_processing/configs/config_template.yaml @@ -44,7 +44,7 @@ RERUN_MODE: True ################################# # No parameters needed -# BLOCK - spatial_smoothig +# BLOCK - spatial_smoothing ################################# MACRO_PIXEL_DIM: 2 diff --git a/cobrawap/pipeline/stage02_processing/scripts/background_subtraction.py b/cobrawap/pipeline/stage02_processing/scripts/background_subtraction.py index 771dec33..c0682dc4 100644 --- a/cobrawap/pipeline/stage02_processing/scripts/background_subtraction.py +++ b/cobrawap/pipeline/stage02_processing/scripts/background_subtraction.py @@ -11,14 +11,14 @@ from utils.parse import none_or_str CLI = argparse.ArgumentParser() -CLI.add_argument("--data", nargs='?', type=Path, required=True, - help="path to input data in neo format") -CLI.add_argument("--output", nargs='?', type=Path, required=True, - help="path of output file") -CLI.add_argument("--output_img", nargs='?', type=none_or_str, - help="path of output image", default=None) -CLI.add_argument("--output_array", nargs='?', type=none_or_str, - help="path of output numpy array", default=None) +CLI.add_argument("--data", nargs='?', type=Path, required=True, + help="path to input data in neo format") +CLI.add_argument("--output", nargs='?', type=Path, required=True, + help="path of output file") +CLI.add_argument("--output_img", nargs='?', type=none_or_str, + help="path of output image", default=None) +CLI.add_argument("--output_array", nargs='?', type=none_or_str, + help="path of output numpy array", default=None) def shape_frame(value_array, xy_coords): dim_x = np.max(xy_coords[:,0]) + 1 diff --git a/cobrawap/pipeline/stage02_processing/scripts/check_input.py b/cobrawap/pipeline/stage02_processing/scripts/check_input.py index 2e67c737..b83a9656 100644 --- a/cobrawap/pipeline/stage02_processing/scripts/check_input.py +++ b/cobrawap/pipeline/stage02_processing/scripts/check_input.py @@ -11,7 +11,7 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") if __name__ == '__main__': args, unknown = CLI.parse_known_args() diff --git a/cobrawap/pipeline/stage02_processing/scripts/detrending.py b/cobrawap/pipeline/stage02_processing/scripts/detrending.py index a3d3ae31..9eb40437 100644 --- a/cobrawap/pipeline/stage02_processing/scripts/detrending.py +++ b/cobrawap/pipeline/stage02_processing/scripts/detrending.py @@ -13,18 +13,18 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--order", nargs='?', type=int, default=1, - help="detrending order") + help="detrending order") CLI.add_argument("--img_dir", nargs='?', type=str, required=True, - help="path of output figure directory") + help="path of output figure directory") CLI.add_argument("--img_name", nargs='?', type=str, - default='processed_trace_channel0.png', - help='example filename for channel 0') + default='processed_trace_channel0.png', + help='example filename for channel 0') CLI.add_argument("--plot_channels", nargs='+', type=none_or_int, default=None, - help="list of channels to plot") + help="list of channels to plot") def detrend(asig, order): if (order != 0) and (order != 1): @@ -72,7 +72,7 @@ def plot_detrend(asig, detrend_asig, channel): for channel in args.plot_channels: plot_detrend(asig, detrend_asig, channel) output_path = os.path.join(args.img_dir, - args.img_name.replace('_channel0', f'_channel{channel}')) + args.img_name.replace('_channel0', f'_channel{channel}')) save_plot(output_path) detrend_asig.name += "" diff --git a/cobrawap/pipeline/stage02_processing/scripts/frequency_filter.py b/cobrawap/pipeline/stage02_processing/scripts/frequency_filter.py index 9ffa1b69..5e64c71c 100644 --- a/cobrawap/pipeline/stage02_processing/scripts/frequency_filter.py +++ b/cobrawap/pipeline/stage02_processing/scripts/frequency_filter.py @@ -10,18 +10,18 @@ from utils.parse import none_or_float CLI = argparse.ArgumentParser() -CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") -CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") +CLI.add_argument("--data", nargs='?', type=str, required=True, + help="path to input data in neo format") +CLI.add_argument("--output", nargs='?', type=str, required=True, + help="path of output file") CLI.add_argument("--highpass_frequency", nargs='?', type=none_or_float, - default=None, help="lower bound of frequency band in Hz") + default=None, help="lower bound of frequency band in Hz") CLI.add_argument("--lowpass_frequency", nargs='?', type=none_or_float, - default=None, help="upper bound of frequency band in Hz") + default=None, help="upper bound of frequency band in Hz") CLI.add_argument("--order", nargs='?', type=int, default=2, - help="order of the filter function") + help="order of the filter function") CLI.add_argument("--filter_function", nargs='?', type=str, default='filtfilt', - help="filterfunction used in the scipy backend") + help="filter function used in the scipy backend") if __name__ == '__main__': args, unknown = CLI.parse_known_args() diff --git a/cobrawap/pipeline/stage02_processing/scripts/logMUA_estimation.py b/cobrawap/pipeline/stage02_processing/scripts/logMUA_estimation.py index ba9e91fd..ab2da023 100644 --- a/cobrawap/pipeline/stage02_processing/scripts/logMUA_estimation.py +++ b/cobrawap/pipeline/stage02_processing/scripts/logMUA_estimation.py @@ -19,30 +19,30 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=Path, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=Path, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--img_dir", nargs='?', type=Path, - default=None, help="path of figure directory") + default=None, help="path of figure directory") CLI.add_argument("--img_name", nargs='?', type=str, - default='minima_channel0.png', - help='example image filename for channel 0') + default='minima_channel0.png', + help='example image filename for channel 0') CLI.add_argument("--highpass_frequency", nargs='?', type=float, default=200, - help="lower bound of frequency band in Hz") + help="lower bound of frequency band in Hz") CLI.add_argument("--lowpass_frequency", nargs='?', type=float, default=1500, - help="upper bound of frequency band in Hz") + help="upper bound of frequency band in Hz") CLI.add_argument("--logMUA_rate", nargs='?', type=none_or_float, default=None, - help="rate of the signal after transformation") + help="rate of the signal after transformation") CLI.add_argument("--psd_overlap", nargs='?', type=float, default=0.5, - help="overlap parameter for Welch's algorithm [0-1]") + help="overlap parameter for Welch's algorithm [0-1]") CLI.add_argument("--fft_slice", nargs='?', type=none_or_float, default=None, - help="time window length used for power spectrum estimate, in s") + help="time window length used for power spectrum estimate, in s") CLI.add_argument("--plot_tstart", nargs='?', type=float, default=0, - help="start time in seconds") + help="start time in seconds") CLI.add_argument("--plot_tstop", nargs='?', type=float, default=10, - help="stop time in seconds") + help="stop time in seconds") CLI.add_argument("--plot_channels", nargs='+', type=none_or_int, default=None, - help="list of channels to plot") + help="list of channels to plot") def logMUA_estimation(asig, highpass_frequency, lowpass_frequency, logMUA_rate, @@ -175,12 +175,12 @@ def plot_logMUA_estimation(asig, logMUA_asig, highpass_frequency, lowpass_freque if args.plot_channels is not None: for channel in args.plot_channels: plot_logMUA_estimation(asig=block.segments[0].analogsignals[0], - logMUA_asig=asig, - highpass_frequency=args.highpass_frequency*pq.Hz, - lowpass_frequency=args.lowpass_frequency*pq.Hz, - t_start=args.plot_tstart, - t_stop=args.plot_tstop, - channel=channel) + logMUA_asig=asig, + highpass_frequency=args.highpass_frequency*pq.Hz, + lowpass_frequency=args.lowpass_frequency*pq.Hz, + t_start=args.plot_tstart, + t_stop=args.plot_tstop, + channel=channel) output_path = args.img_dir \ / args.img_name.replace('_channel0', f'_channel{channel}') save_plot(output_path) diff --git a/cobrawap/pipeline/stage02_processing/scripts/normalization.py b/cobrawap/pipeline/stage02_processing/scripts/normalization.py index 91b5b165..e3a29e78 100644 --- a/cobrawap/pipeline/stage02_processing/scripts/normalization.py +++ b/cobrawap/pipeline/stage02_processing/scripts/normalization.py @@ -11,12 +11,12 @@ from utils.io_utils import write_neo, load_neo CLI = argparse.ArgumentParser() -CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") -CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") +CLI.add_argument("--data", nargs='?', type=str, required=True, + help="path to input data in neo format") +CLI.add_argument("--output", nargs='?', type=str, required=True, + help="path of output file") CLI.add_argument("--normalize_by", nargs='?', type=str, default='mean', - help="division factor: 'max', 'mean', or 'median'") + help="division factor: 'max', 'mean', or 'median'") def normalize(asig, normalize_by): if normalize_by == 'median': diff --git a/cobrawap/pipeline/stage02_processing/scripts/phase_transform.py b/cobrawap/pipeline/stage02_processing/scripts/phase_transform.py index ba3311e0..d09ff5af 100644 --- a/cobrawap/pipeline/stage02_processing/scripts/phase_transform.py +++ b/cobrawap/pipeline/stage02_processing/scripts/phase_transform.py @@ -10,9 +10,9 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") + help="path of output file") if __name__ == '__main__': args, unknown = CLI.parse_known_args() diff --git a/cobrawap/pipeline/stage02_processing/scripts/plot_power_spectrum.py b/cobrawap/pipeline/stage02_processing/scripts/plot_power_spectrum.py index 13448fd8..c066ec3b 100644 --- a/cobrawap/pipeline/stage02_processing/scripts/plot_power_spectrum.py +++ b/cobrawap/pipeline/stage02_processing/scripts/plot_power_spectrum.py @@ -12,18 +12,18 @@ from utils.parse import none_or_float CLI = argparse.ArgumentParser() -CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") -CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output figure") +CLI.add_argument("--data", nargs='?', type=str, required=True, + help="path to input data in neo format") +CLI.add_argument("--output", nargs='?', type=str, required=True, + help="path of output figure") CLI.add_argument("--highpass_frequency", nargs='?', type=none_or_float, - default='None', help="lower bound of frequency band in Hz") + default='None', help="lower bound of frequency band in Hz") CLI.add_argument("--lowpass_frequency", nargs='?', type=none_or_float, - default='None', help="upper bound of frequency band in Hz") + default='None', help="upper bound of frequency band in Hz") CLI.add_argument("--psd_frequency_resolution", nargs='?', type=float, default=5, - help="frequency resolution of the power spectrum in Hz") + help="frequency resolution of the power spectrum in Hz") CLI.add_argument("--psd_overlap", nargs='?', type=float, default=0.5, - help="overlap parameter for Welch's algorithm [0-1]") + help="overlap parameter for Welch's algorithm [0-1]") def plot_psd(frequencies, psd, highpass_frequency, lowpass_frequency): sns.set(style='ticks', palette="deep", context="notebook") diff --git a/cobrawap/pipeline/stage02_processing/scripts/plot_processed_trace.py b/cobrawap/pipeline/stage02_processing/scripts/plot_processed_trace.py index 26bcbc6d..a3a3a97a 100644 --- a/cobrawap/pipeline/stage02_processing/scripts/plot_processed_trace.py +++ b/cobrawap/pipeline/stage02_processing/scripts/plot_processed_trace.py @@ -11,20 +11,20 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--original_data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--img_dir", nargs='?', type=str, required=True, - help="path of output figure directory") + help="path of output figure directory") CLI.add_argument("--img_name", nargs='?', type=str, - default='processed_trace_channel0.png', - help='example filename for channel 0') + default='processed_trace_channel0.png', + help='example filename for channel 0') CLI.add_argument("--t_start", nargs='?', type=float, default=0, - help="start time in seconds") + help="start time in seconds") CLI.add_argument("--t_stop", nargs='?', type=float, default=10, - help="stop time in seconds") + help="stop time in seconds") CLI.add_argument("--channels", nargs='+', type=int, default=0, - help="channel to plot") + help="channel to plot") def plot_traces(original_asig, processed_asig, channel): sns.set(style='ticks', palette="deep", context="notebook") diff --git a/cobrawap/pipeline/stage02_processing/scripts/roi_selection.py b/cobrawap/pipeline/stage02_processing/scripts/roi_selection.py index 6161aeb8..b4df304e 100644 --- a/cobrawap/pipeline/stage02_processing/scripts/roi_selection.py +++ b/cobrawap/pipeline/stage02_processing/scripts/roi_selection.py @@ -14,16 +14,16 @@ from utils.neo_utils import analogsignal_to_imagesequence, imagesequence_to_analogsignal CLI = argparse.ArgumentParser() -CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") -CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") -CLI.add_argument("--output_img", nargs='?', type=none_or_str, - help="path of output image", default=None) +CLI.add_argument("--data", nargs='?', type=str, required=True, + help="path to input data in neo format") +CLI.add_argument("--output", nargs='?', type=str, required=True, + help="path of output file") +CLI.add_argument("--output_img", nargs='?', type=none_or_str, + help="path of output image", default=None) CLI.add_argument("--intensity_threshold", nargs='?', type=float, - help="threshold for mask [0,1]", default=0.5) + help="threshold for mask [0,1]", default=0.5) CLI.add_argument("--crop_to_selection", nargs='?', type=bool, - help="discard frame outside of ROI", default=True) + help="discard frame outside of ROI", default=True) def calculate_contour(img, contour_limit): # Computing the contour lines... @@ -125,7 +125,7 @@ def plot_roi(img, contour): ax.axis('image') ax.set_xticks([]) ax.set_yticks([]) - ax.plot(contour[:, 0], contour[:, 1], linewidth=2) + ax.plot(contour[:,0], contour[:,1], linewidth=2) plt.draw() return ax diff --git a/cobrawap/pipeline/stage02_processing/scripts/spatial_downsampling.py b/cobrawap/pipeline/stage02_processing/scripts/spatial_downsampling.py index 5f2573c8..8358175c 100644 --- a/cobrawap/pipeline/stage02_processing/scripts/spatial_downsampling.py +++ b/cobrawap/pipeline/stage02_processing/scripts/spatial_downsampling.py @@ -13,14 +13,14 @@ from utils.neo_utils import analogsignal_to_imagesequence, imagesequence_to_analogsignal CLI = argparse.ArgumentParser() -CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") -CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") -CLI.add_argument("--output_img", nargs='?', type=none_or_str, - help="path of output image", default=None) -CLI.add_argument("--macro_pixel_dim", nargs='?', type=int, - help="smoothing factor", default=2) +CLI.add_argument("--data", nargs='?', type=str, required=True, + help="path to input data in neo format") +CLI.add_argument("--output", nargs='?', type=str, required=True, + help="path of output file") +CLI.add_argument("--output_img", nargs='?', type=none_or_str, + help="path of output image", default=None) +CLI.add_argument("--macro_pixel_dim", nargs='?', type=int, + help="smoothing factor", default=2) def spatial_smoothing(imgseq, macro_pixel_dim): images_reduced = measure.block_reduce(imgseq.as_array(), diff --git a/cobrawap/pipeline/stage02_processing/scripts/subsampling.py b/cobrawap/pipeline/stage02_processing/scripts/subsampling.py index b533c93f..6300f9c4 100644 --- a/cobrawap/pipeline/stage02_processing/scripts/subsampling.py +++ b/cobrawap/pipeline/stage02_processing/scripts/subsampling.py @@ -10,11 +10,11 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") -CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") -CLI.add_argument("--target_rate", nargs='?', type=float, required=True, - help="rate to subsample to in Hz") + help="path to input data in neo format") +CLI.add_argument("--output", nargs='?', type=str, required=True, + help="path of output file") +CLI.add_argument("--target_rate", nargs='?', type=float, required=True, + help="rate to subsample to in Hz") if __name__ == '__main__': args, unknown = CLI.parse_known_args() diff --git a/cobrawap/pipeline/stage02_processing/scripts/z_score.py b/cobrawap/pipeline/stage02_processing/scripts/z_score.py index 19e5b657..f24b2b08 100644 --- a/cobrawap/pipeline/stage02_processing/scripts/z_score.py +++ b/cobrawap/pipeline/stage02_processing/scripts/z_score.py @@ -9,9 +9,9 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=Path, required=True, - help="path to input data in neo format") -CLI.add_argument("--output", nargs='?', type=Path, required=True, - help="path of output file") + help="path to input data in neo format") +CLI.add_argument("--output", nargs='?', type=Path, required=True, + help="path of output file") if __name__ == '__main__': args, unknown = CLI.parse_known_args() diff --git a/cobrawap/pipeline/stage03_trigger_detection/Snakefile b/cobrawap/pipeline/stage03_trigger_detection/Snakefile index 4b487399..ab9ad706 100644 --- a/cobrawap/pipeline/stage03_trigger_detection/Snakefile +++ b/cobrawap/pipeline/stage03_trigger_detection/Snakefile @@ -1,4 +1,4 @@ -""" +""" # Stage 03 Trigger Detection """ @@ -13,7 +13,7 @@ def filtered_triggers(wildcards): return prev_rule_output(wildcards, rule_list=config.TRIGGER_FILTER, default_input=default_input) -#### UTILTY BLOCKS #### +#### UTILITY BLOCKS #### use rule template_all as all with: input: @@ -102,6 +102,7 @@ use rule template as minima with: 'plot_channels', 'plot_tstart', 'plot_tstop', img_name='minima_channel0.'+config.PLOT_FORMAT, config=config) + #### FILTER BLOCKS (choose any) #### use rule template as remove_short_states with: @@ -112,4 +113,4 @@ use rule template as remove_short_states with: Path('{dir}') / '{rule_name}' / f'remove_short_states.{config.NEO_FORMAT}' params: params('min_up_duration', 'min_down_duration', 'remove_down_first', - config=config) \ No newline at end of file + config=config) diff --git a/cobrawap/pipeline/stage03_trigger_detection/scripts/calc_thresholds_fitted.py b/cobrawap/pipeline/stage03_trigger_detection/scripts/calc_thresholds_fitted.py index 5bf2be02..82727127 100644 --- a/cobrawap/pipeline/stage03_trigger_detection/scripts/calc_thresholds_fitted.py +++ b/cobrawap/pipeline/stage03_trigger_detection/scripts/calc_thresholds_fitted.py @@ -1,4 +1,4 @@ -"""w +""" Determine the threshold between Up and Down states for each channel by fitting the respective amplitude distributions. """ @@ -15,21 +15,21 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output thresholds (numpy array)") + help="path of output thresholds (numpy array)") CLI.add_argument("--img_dir", nargs='?', type=str, default=None, - help="path of output figure directory") + help="path of output figure directory") CLI.add_argument("--img_name", nargs='?', type=str, default=None, - help="example name of output figure for channel 0") + help="example name of output figure for channel 0") CLI.add_argument("--fit_function", nargs='?', type=str, default='Gaussian', - help="function to fit the amplitude distribution") + help="function to fit the amplitude distribution") CLI.add_argument("--sigma_factor", nargs='?', type=float, default=3, - help="sigma_factor x standard deviation = threshold") + help="sigma_factor x standard deviation = threshold") CLI.add_argument("--bin_num", nargs='?', type=int, default=100, - help='number of bins for the amplitude histogram') + help='number of bins for the amplitude histogram') CLI.add_argument("--plot_channels", nargs='+', type=none_or_int, - default=None, help="list of channels to plot") + default=None, help="list of channels to plot") warnings.simplefilter("error", OptimizeWarning) @@ -153,4 +153,4 @@ def fit_amplitude_distribution(signal, sigma_factor, fit_function, args.img_name.replace('_channel0', f'_channel{channel}')) save_plot(output_path) - np.save(args.output, thresholds) \ No newline at end of file + np.save(args.output, thresholds) diff --git a/cobrawap/pipeline/stage03_trigger_detection/scripts/calc_thresholds_fixed.py b/cobrawap/pipeline/stage03_trigger_detection/scripts/calc_thresholds_fixed.py index a2c0c66d..1046d9ec 100644 --- a/cobrawap/pipeline/stage03_trigger_detection/scripts/calc_thresholds_fixed.py +++ b/cobrawap/pipeline/stage03_trigger_detection/scripts/calc_thresholds_fixed.py @@ -8,10 +8,11 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output thresholds (numpy array)") -CLI.add_argument("--threshold", nargs='?', type=float, required=True) + help="path of output thresholds (numpy array)") +CLI.add_argument("--threshold", nargs='?', type=float, required=True, + help="") if __name__ == '__main__': args, unknown = CLI.parse_known_args() diff --git a/cobrawap/pipeline/stage03_trigger_detection/scripts/check_input.py b/cobrawap/pipeline/stage03_trigger_detection/scripts/check_input.py index 127d9954..947df2d9 100644 --- a/cobrawap/pipeline/stage03_trigger_detection/scripts/check_input.py +++ b/cobrawap/pipeline/stage03_trigger_detection/scripts/check_input.py @@ -10,8 +10,8 @@ from utils.io_utils import load_neo CLI = argparse.ArgumentParser() -CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") +CLI.add_argument("--data", nargs='?', type=str, required=True, + help="path to input data in neo format") if __name__ == '__main__': args, unknown = CLI.parse_known_args() diff --git a/cobrawap/pipeline/stage03_trigger_detection/scripts/hilbert_phase.py b/cobrawap/pipeline/stage03_trigger_detection/scripts/hilbert_phase.py index 9abd815d..3d038594 100644 --- a/cobrawap/pipeline/stage03_trigger_detection/scripts/hilbert_phase.py +++ b/cobrawap/pipeline/stage03_trigger_detection/scripts/hilbert_phase.py @@ -1,4 +1,4 @@ -"""w +""" Detect trigger times (i.e., state transition / local wavefronts onsets) by finding crossing of a set phase-value in the channel signals. """ @@ -18,22 +18,22 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=Path, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=Path, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--img_dir", nargs='?', type=Path, - default=None, help="path of figure directory") + default=None, help="path of figure directory") CLI.add_argument("--img_name", nargs='?', type=str, - default='hilbert_phase_channel0.png', - help='example image filename for channel 0') + default='hilbert_phase_channel0.png', + help='example image filename for channel 0') CLI.add_argument("--transition_phase", nargs='?', type=float, default=-1.570796, - help="phase to use as threshold for the upward transition") + help="phase to use as threshold for the upward transition") CLI.add_argument("--plot_channels", nargs='+', type=none_or_int, default=None, - help="list of channels to plot") + help="list of channels to plot") CLI.add_argument("--plot_tstart", nargs='?', type=none_or_float, default=0, - help="start time in seconds") + help="start time in seconds") CLI.add_argument("--plot_tstop", nargs='?', type=none_or_float, default=10, - help="stop time in seconds") + help="stop time in seconds") def detect_transitions(asig, transition_phase): # ToDo: replace with elephant function diff --git a/cobrawap/pipeline/stage03_trigger_detection/scripts/minima.py b/cobrawap/pipeline/stage03_trigger_detection/scripts/minima.py index ee16fc47..c959a503 100644 --- a/cobrawap/pipeline/stage03_trigger_detection/scripts/minima.py +++ b/cobrawap/pipeline/stage03_trigger_detection/scripts/minima.py @@ -18,30 +18,30 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=Path, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=Path, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--num_interpolation_points", nargs='?', type=int, default=0, - help="number of neighboring points to interpolate") + help="number of neighboring points to interpolate") CLI.add_argument("--minima_persistence", nargs='?', type=float, default=0.200, - help="minimum time minima (s)") + help="minimum time minima (s)") CLI.add_argument("--maxima_threshold_fraction", nargs='?', type=float, default=0.5, - help="amplitude fraction to set the threshold detecting local maxima") + help="amplitude fraction to set the threshold detecting local maxima") CLI.add_argument("--maxima_threshold_window", nargs='?', type=int, default=2, - help="time window to use to set the threshold detecting local maxima [s]") + help="time window to use to set the threshold detecting local maxima [s]") CLI.add_argument("--min_peak_distance", nargs='?', type=float, default=0.200, - help="minimum distance between peaks (s)") + help="minimum distance between peaks (s)") CLI.add_argument("--img_dir", nargs='?', type=Path, - default=None, help="path of figure directory") + default=None, help="path of figure directory") CLI.add_argument("--img_name", nargs='?', type=str, - default='minima_channel0.png', - help='example image filename for channel 0') + default='minima_channel0.png', + help='example image filename for channel 0') CLI.add_argument("--plot_channels", nargs='+', type=none_or_int, default=None, - help="list of channels to plot") + help="list of channels to plot") CLI.add_argument("--plot_tstart", nargs='?', type=none_or_float, default=0., - help="start time in seconds") + help="start time in seconds") CLI.add_argument("--plot_tstop", nargs='?', type=none_or_float, default=10., - help="stop time in seconds") + help="stop time in seconds") def filter_minima_order(signal, mins, order=1): filtered_mins = np.array([], dtype=int) @@ -209,4 +209,4 @@ def plot_minima(asig, event, channel, maxima_threshold_window, maxima_threshold_fraction = args.maxima_threshold_fraction, min_peak_distance = args.min_peak_distance) output_path = args.img_dir / args.img_name.replace('_channel0', f'_channel{channel}') - save_plot(output_path) \ No newline at end of file + save_plot(output_path) diff --git a/cobrawap/pipeline/stage03_trigger_detection/scripts/plot_trigger_times.py b/cobrawap/pipeline/stage03_trigger_detection/scripts/plot_trigger_times.py index 94c5c62f..8b6b09db 100644 --- a/cobrawap/pipeline/stage03_trigger_detection/scripts/plot_trigger_times.py +++ b/cobrawap/pipeline/stage03_trigger_detection/scripts/plot_trigger_times.py @@ -12,18 +12,18 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=str, - required=True, help="path of output directory") + required=True, help="path of output directory") CLI.add_argument("--filename", nargs='?', type=str, - default='trigger_times_channel0.png', - help='example filename for channel 0') + default='trigger_times_channel0.png', + help='example filename for channel 0') CLI.add_argument("--plot_tstart", nargs='?', type=none_or_float, default=0, - help="start time in seconds") + help="start time in seconds") CLI.add_argument("--plot_tstop", nargs='?', type=none_or_float, default=10, - help="stop time in seconds") + help="stop time in seconds") CLI.add_argument("--plot_channels", nargs='+', type=none_or_int, default=None, - help="list of channels to plot") + help="list of channels to plot") def plot_trigger_times(asig, event, channel): sns.set(style='ticks', palette="deep", context="notebook") diff --git a/cobrawap/pipeline/stage03_trigger_detection/scripts/remove_short_states.py b/cobrawap/pipeline/stage03_trigger_detection/scripts/remove_short_states.py index 397e207c..923332e5 100644 --- a/cobrawap/pipeline/stage03_trigger_detection/scripts/remove_short_states.py +++ b/cobrawap/pipeline/stage03_trigger_detection/scripts/remove_short_states.py @@ -12,15 +12,15 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path to output data in neo format") + help="path to output data in neo format") CLI.add_argument("--min_up_duration", nargs='?', type=float, default=0.005, - help="minimum duration of UP states in seconds") + help="minimum duration of UP states in seconds") CLI.add_argument("--min_down_duration", nargs='?', type=float, default=0.005, - help="minimum duration of DOWN states in seconds") + help="minimum duration of DOWN states in seconds") CLI.add_argument("--remove_down_first", nargs='?', type=strtobool, default=True, - help="If True, remove short down states first") + help="If True, remove short down states first") def remove_short_states(evt, min_duration, start_label='UP', stop_label='DOWN'): diff --git a/cobrawap/pipeline/stage03_trigger_detection/scripts/threshold.py b/cobrawap/pipeline/stage03_trigger_detection/scripts/threshold.py index 9b86d042..bb4b75ee 100644 --- a/cobrawap/pipeline/stage03_trigger_detection/scripts/threshold.py +++ b/cobrawap/pipeline/stage03_trigger_detection/scripts/threshold.py @@ -11,11 +11,11 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--thresholds", nargs='?', type=str, required=True, - help="path of thresholds (numpy array)") + help="path of thresholds (numpy array)") def threshold(asig, threshold_array): dim_t, channel_num = asig.shape diff --git a/cobrawap/pipeline/stage04_wave_detection/Snakefile b/cobrawap/pipeline/stage04_wave_detection/Snakefile index a8af854a..f761eb0a 100644 --- a/cobrawap/pipeline/stage04_wave_detection/Snakefile +++ b/cobrawap/pipeline/stage04_wave_detection/Snakefile @@ -40,7 +40,7 @@ rule merge_wave_definitions: use rule template_plus_plot_script as trigger_clustering with: input: data = config.STAGE_INPUT, - script = SCRIPTS / 'trigger_clustering.py', + script = SCRIPTS / 'trigger_clustering.py', plot_script = SCRIPTS / 'plot_clustering.py' params: params('metric', 'time_space_ratio', 'neighbour_distance', @@ -71,7 +71,7 @@ use rule template_plus_plot_script as critical_points with: script = SCRIPTS / 'critical_points.py', plot_script = SCRIPTS / 'plot_critical_points.py', params: - params(frame_id = 0, skip_step = 1) + params(frame_id=0, skip_step=1) output: Path('{dir}') / 'critical_points' / f'critical_points.{config.NEO_FORMAT}', img = Path('{dir}') / 'critical_points' / f'critical_points.{config.PLOT_FORMAT}' @@ -112,7 +112,7 @@ use rule template as plot_waves with: params: params(time_window = 0.4, # in s colormap='viridis', - img_name = 'wave_plot_id0.'+config.PLOT_FORMAT) + img_name='wave_plot_id0.'+config.PLOT_FORMAT) output: directory(Path('{dir}') / 'wave_plots') @@ -135,9 +135,9 @@ use rule template as plot_movie_frames with: script = SCRIPTS / 'plot_movie_frames.py' params: params('colormap', 'frame_rate', 'marker_color', 'plot_event', - config=config, frame_name='frame', frame_format='png') + config=config, frame_name='frame', frame_format='png') output: - frame_folder = directory(Path('{dir}') / '{data_name}_frames'), + frame_folder = directory(Path('{dir}') / '{data_name}_frames') rule plot_movie: diff --git a/cobrawap/pipeline/stage04_wave_detection/configs/config_template.yaml b/cobrawap/pipeline/stage04_wave_detection/configs/config_template.yaml index 6e9d4789..8821a544 100644 --- a/cobrawap/pipeline/stage04_wave_detection/configs/config_template.yaml +++ b/cobrawap/pipeline/stage04_wave_detection/configs/config_template.yaml @@ -24,7 +24,7 @@ PLOT_CHANNELS: 'None' # int or None. default 'None' -> randomly selected PLOT_FORMAT: 'png' -# DETECTIION BLOCK +# DETECTION BLOCK ################## # Available Blocks: 'trigger_clustering' DETECTION_BLOCK: 'trigger_clustering' diff --git a/cobrawap/pipeline/stage04_wave_detection/scripts/check_input.py b/cobrawap/pipeline/stage04_wave_detection/scripts/check_input.py index fb8c1b42..6aafa6d3 100644 --- a/cobrawap/pipeline/stage04_wave_detection/scripts/check_input.py +++ b/cobrawap/pipeline/stage04_wave_detection/scripts/check_input.py @@ -11,8 +11,8 @@ from snakemake.logging import logger CLI = argparse.ArgumentParser() -CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") +CLI.add_argument("--data", nargs='?', type=str, required=True, + help="path to input data in neo format") if __name__ == '__main__': args, unknown = CLI.parse_known_args() diff --git a/cobrawap/pipeline/stage04_wave_detection/scripts/critical_points.py b/cobrawap/pipeline/stage04_wave_detection/scripts/critical_points.py index a94c106b..6974eba8 100644 --- a/cobrawap/pipeline/stage04_wave_detection/scripts/critical_points.py +++ b/cobrawap/pipeline/stage04_wave_detection/scripts/critical_points.py @@ -13,9 +13,9 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") + help="path of output file") def detect_critical_points(imgseq, times): frames = imgseq.as_array() diff --git a/cobrawap/pipeline/stage04_wave_detection/scripts/merge_wave_definitions.py b/cobrawap/pipeline/stage04_wave_detection/scripts/merge_wave_definitions.py index b48b7528..9b3c33fd 100644 --- a/cobrawap/pipeline/stage04_wave_detection/scripts/merge_wave_definitions.py +++ b/cobrawap/pipeline/stage04_wave_detection/scripts/merge_wave_definitions.py @@ -9,14 +9,15 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=Path, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--properties", nargs='*', type=Path, default=[], - help="paths to input data in neo format") + help="paths to input data in neo format") CLI.add_argument("--output", nargs='?', type=Path, required=True, - help="path of output file") + help="path of output file") if __name__ == '__main__': args, unknown = CLI.parse_known_args() + waves_block = load_neo(args.data) asig_names = [asig.name for asig in waves_block.segments[0].analogsignals] diff --git a/cobrawap/pipeline/stage04_wave_detection/scripts/optical_flow.py b/cobrawap/pipeline/stage04_wave_detection/scripts/optical_flow.py index d7ad8947..4bee0fa4 100644 --- a/cobrawap/pipeline/stage04_wave_detection/scripts/optical_flow.py +++ b/cobrawap/pipeline/stage04_wave_detection/scripts/optical_flow.py @@ -18,23 +18,23 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--output_img", nargs='?', type=none_or_str, default=None, - help="path of output image file") + help="path of output image file") CLI.add_argument("--alpha", nargs='?', type=float, default=0.001, - help='regularization parameter') + help='regularization parameter') CLI.add_argument("--max_Niter", nargs='?', type=int, default=50, - help='maximum number of iterations') + help='maximum number of iterations') CLI.add_argument("--convergence_limit", nargs='?', type=float, default=10e-3, - help='absolute change at which consider optimization converged') + help='absolute change at which consider optimization converged') CLI.add_argument("--gaussian_sigma", nargs='+', type=float, default=[0,3,3], - help='sigma of gaussian filter in each dimension') + help='sigma of gaussian filter in each dimension') CLI.add_argument("--derivative_filter", nargs='?', type=none_or_str, default=None, - help='Filter kernel to use for calculating spatial derivatives') + help='Filter kernel to use for calculating spatial derivatives') CLI.add_argument("--use_phases", nargs='?', type=strtobool, default=False, - help='whether to use signal phase instead of amplitude') + help='whether to use signal phase instead of amplitude') def horn_schunck_step(frame, next_frame, alpha, max_Niter, convergence_limit, kernelHS, kernelT, kernelX, kernelY, @@ -230,6 +230,7 @@ def is_phase_signal(signal, use_phases): if __name__ == '__main__': args, unknown = CLI.parse_known_args() + block = load_neo(args.data) asig = block.segments[0].analogsignals[0] diff --git a/cobrawap/pipeline/stage04_wave_detection/scripts/plot_clustering.py b/cobrawap/pipeline/stage04_wave_detection/scripts/plot_clustering.py index bf388a88..b5cb3c61 100644 --- a/cobrawap/pipeline/stage04_wave_detection/scripts/plot_clustering.py +++ b/cobrawap/pipeline/stage04_wave_detection/scripts/plot_clustering.py @@ -16,11 +16,13 @@ from utils.neo_utils import time_slice CLI = argparse.ArgumentParser() -CLI.add_argument("--output", nargs='?', type=str) -CLI.add_argument("--data", nargs='?', type=str) +CLI.add_argument("--data", nargs='?', type=str, + help="path to input data in neo format") +CLI.add_argument("--output", nargs='?', type=str, + help="path of output file") CLI.add_argument("--time_slice", nargs='?', type=none_or_float, default=None, - help="length of time_slice in seconds.") - + help="length of time_slice in seconds.") + def plot_clustering(events, ax=None): if ax is None: fig = plt.figure() diff --git a/cobrawap/pipeline/stage04_wave_detection/scripts/plot_critical_points.py b/cobrawap/pipeline/stage04_wave_detection/scripts/plot_critical_points.py index 96e0e687..1f51b82f 100644 --- a/cobrawap/pipeline/stage04_wave_detection/scripts/plot_critical_points.py +++ b/cobrawap/pipeline/stage04_wave_detection/scripts/plot_critical_points.py @@ -11,13 +11,13 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--skip_step", nargs='?', type=int, default=3, - help="skipping every x vector for the plot") + help="skipping every x vector for the plot") CLI.add_argument("--frame_id", nargs='?', type=int, default=0, - help="number of the frame to plot") + help="number of the frame to plot") def plot_frame(frame, ax=None, skip_step=3): dim_y, dim_x = frame.shape diff --git a/cobrawap/pipeline/stage04_wave_detection/scripts/plot_movie_frames.py b/cobrawap/pipeline/stage04_wave_detection/scripts/plot_movie_frames.py index 3898d5bc..2a9bbfbb 100644 --- a/cobrawap/pipeline/stage04_wave_detection/scripts/plot_movie_frames.py +++ b/cobrawap/pipeline/stage04_wave_detection/scripts/plot_movie_frames.py @@ -13,14 +13,22 @@ CLI = argparse.ArgumentParser() -CLI.add_argument("--data", nargs='?', type=str) -CLI.add_argument("--frame_folder",nargs='?', type=str) -CLI.add_argument("--frame_name", nargs='?', type=str) -CLI.add_argument("--frame_format",nargs='?', type=str) -CLI.add_argument("--frame_rate", nargs='?', type=none_or_float) -CLI.add_argument("--colormap", nargs='?', type=str) -CLI.add_argument("--plot_event", nargs='?', type=none_or_str, default=None) -CLI.add_argument("--marker_color",nargs='?', type=str, default='k') +CLI.add_argument("--data", nargs='?', type=str, + help="path to input data in neo format") +CLI.add_argument("--frame_folder", nargs='?', type=str, + help="") +CLI.add_argument("--frame_name", nargs='?', type=str, + help="") +CLI.add_argument("--frame_format", nargs='?', type=str, + help="") +CLI.add_argument("--frame_rate", nargs='?', type=none_or_float, + help="") +CLI.add_argument("--colormap", nargs='?', type=str, + help="") +CLI.add_argument("--plot_event", nargs='?', type=none_or_str, default=None, + help="") +CLI.add_argument("--marker_color", nargs='?', type=str, default='k', + help="") def get_events(events, frame_times, event_name='transitions'): @@ -161,4 +169,4 @@ def plot_vectorfield(frame, skip_step=3, ax=None): args.frame_format)), transparent=True) plt.close() - \ No newline at end of file + diff --git a/cobrawap/pipeline/stage04_wave_detection/scripts/plot_waves.py b/cobrawap/pipeline/stage04_wave_detection/scripts/plot_waves.py index 81eeeffe..24a82bb0 100644 --- a/cobrawap/pipeline/stage04_wave_detection/scripts/plot_waves.py +++ b/cobrawap/pipeline/stage04_wave_detection/scripts/plot_waves.py @@ -11,12 +11,16 @@ from utils.neo_utils import analogsignal_to_imagesequence CLI = argparse.ArgumentParser() -CLI.add_argument("--data", nargs='?', type=str) -CLI.add_argument("--output", nargs='?', type=str) -CLI.add_argument("--img_name", nargs='?', type=str) +CLI.add_argument("--data", nargs='?', type=str, + help="path to input data in neo format") +CLI.add_argument("--output_dir", nargs='?', type=str, + help="path to output directory") +CLI.add_argument("--img_name", nargs='?', type=str, + help="") CLI.add_argument("--time_window", nargs='?', type=float, default=0.4, - help="size of the plotted window in seconds.") -CLI.add_argument("--colormap", nargs='?', type=str, default='viridis') + help="size of the plotted window in seconds.") +CLI.add_argument("--colormap", nargs='?', type=str, default='viridis', + help="") def plot_wave(wave_id, waves_event, asig, frames, vec_frames, time_window=0.4*pq.s, cmap='virids'): @@ -100,7 +104,7 @@ def plot_wave(wave_id, waves_event, asig, frames, vec_frames, time_window=args.time_window*pq.s, cmap=cmap) - output_path = os.path.join(args.output, - args.img_name.replace('id0', f'id{wave_id}')) + output_path = os.path.join(args.output_dir, + args.img_name.replace('id0', f'id{wave_id}')) save_plot(output_path) plt.close() diff --git a/cobrawap/pipeline/stage04_wave_detection/scripts/time_slice.py b/cobrawap/pipeline/stage04_wave_detection/scripts/time_slice.py index af9143ae..ba4e6963 100644 --- a/cobrawap/pipeline/stage04_wave_detection/scripts/time_slice.py +++ b/cobrawap/pipeline/stage04_wave_detection/scripts/time_slice.py @@ -9,13 +9,13 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--t_start", nargs='?', type=float, default=0, - help="new starting time in s") + help="new starting time in s") CLI.add_argument("--t_stop", nargs='?', type=float, default=10, - help="new stopping time in s") + help="new stopping time in s") if __name__ == '__main__': args, unknown = CLI.parse_known_args() diff --git a/cobrawap/pipeline/stage04_wave_detection/scripts/trigger_clustering.py b/cobrawap/pipeline/stage04_wave_detection/scripts/trigger_clustering.py index c6bec623..4b6b51a9 100644 --- a/cobrawap/pipeline/stage04_wave_detection/scripts/trigger_clustering.py +++ b/cobrawap/pipeline/stage04_wave_detection/scripts/trigger_clustering.py @@ -12,17 +12,17 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--metric", nargs='?', type=str, default='euclidean', - help="parameter for sklearn.cluster.DBSCAN") + help="parameter for sklearn.cluster.DBSCAN") CLI.add_argument("--time_space_ratio", nargs='?', type=float, default=1, - help="factor to apply to time values") + help="factor to apply to time values") CLI.add_argument("--neighbour_distance", nargs='?', type=float, default=30, - help="eps parameter in sklearn.cluster.DBSCAN") + help="eps parameter in sklearn.cluster.DBSCAN") CLI.add_argument("--min_samples", nargs='?', type=int, default=10, - help="minimum number of trigger times to form a wavefront") + help="minimum number of trigger times to form a wavefront") def cluster_triggers(event, metric, neighbour_distance, min_samples, time_space_ratio, sampling_rate): diff --git a/cobrawap/pipeline/stage04_wave_detection/scripts/wave_mode_clustering.py b/cobrawap/pipeline/stage04_wave_detection/scripts/wave_mode_clustering.py index 2ec8defe..6913f934 100644 --- a/cobrawap/pipeline/stage04_wave_detection/scripts/wave_mode_clustering.py +++ b/cobrawap/pipeline/stage04_wave_detection/scripts/wave_mode_clustering.py @@ -23,32 +23,32 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--output_img", nargs='?', type=none_or_str, default=None, - help="path of output image file") + help="path of output image file") CLI.add_argument("--min_trigger_fraction", "--MIN_TRIGGER_FRACTION", - nargs='?', type=float, default=.5, - help="minimum fraction of channels to be involved in a wave") + nargs='?', type=float, default=.5, + help="minimum fraction of channels to be involved in a wave") CLI.add_argument("--num_wave_neighbours", "--NUM_WAVE_NEIGHBOURS", - nargs='?', type=int, default=5, - help="number of similar waves to extrapolate nans from") + nargs='?', type=int, default=5, + help="number of similar waves to extrapolate nans from") CLI.add_argument("--wave_outlier_quantile", "--WAVE_OUTLIER_QUANTILE", - nargs='?', type=float, default=.95, - help="percentage of similar waves to keep") + nargs='?', type=float, default=.95, + help="percentage of similar waves to keep") CLI.add_argument("--pca_dims", "--PCA_DIMS", - nargs='?', type=none_or_int, default=None, - help="reduce wave patterns to n dimensions before kmeans clustering") + nargs='?', type=none_or_int, default=None, + help="reduce wave patterns to n dimensions before kmeans clustering") CLI.add_argument("--num_kmeans_cluster", "--NUM_KMEANS_CLUSTER", - nargs='?', type=int, default=5, - help="number of wave modes to cluster with kmeans") + nargs='?', type=int, default=5, + help="number of wave modes to cluster with kmeans") CLI.add_argument("--interpolation_step_size", "--INTERPOLATION_STEP_SIZE", - nargs='?', type=float, default=.2, - help="grid spacing for interpolation [0,1]") + nargs='?', type=float, default=.2, + help="grid spacing for interpolation [0,1]") CLI.add_argument("--interpolation_smoothing", "--INTERPOLATION_SMOOTHING", - nargs='?', type=float, default=0, - help="0: no smoothing, >0: more smoothing") + nargs='?', type=float, default=0, + help="0: no smoothing, >0: more smoothing") def build_timelag_dataframe(waves_evt, normalize=True): wave_ids = np.unique(waves_evt.labels).astype(int) @@ -329,13 +329,13 @@ def clean_timelag_dataframe(df, min_trigger_fraction=.5, mode_ids = kout.labels_ if len(mode_ids) != len(timelag_df): raise IndexError('Some waves are not assigned to a kmeans cluster!' - + f' {len(mode_ids)} != {len(timelag_df)}') + + f' {len(mode_ids)} != {len(timelag_df)}') mode_labels, mode_counts = np.unique(mode_ids, return_counts=True) mode_dists = calc_cluster_distortions(timelag_matrix_transformed, - cluster_indices=mode_ids, - cluster_centers=kout.cluster_centers_) + cluster_indices=mode_ids, + cluster_centers=kout.cluster_centers_) # calculate the average timelags per mode mode_timelag_df = build_cluster_timelag_dataframe(timelag_df, mode_ids) @@ -351,11 +351,11 @@ def clean_timelag_dataframe(df, min_trigger_fraction=.5, for i, cluster_grid in enumerate(mode_grids): pattern_func = interpolate_grid(cluster_grid, args.interpolation_smoothing) fx, fy, pattern = sample_wave_pattern(pattern_func, - step=args.interpolation_step_size, - dim_x=dim_x, dim_y=dim_y) + step=args.interpolation_step_size, + dim_x=dim_x, dim_y=dim_y) interpolated_mode_grids = np.concatenate((interpolated_mode_grids, - pattern[np.newaxis,:])) \ - if i else pattern[np.newaxis,:] + pattern[np.newaxis,:])) \ + if i else pattern[np.newaxis,:] # add cluster labels as annotation to the wavefronts event evt_id, waves = [(i, evt) for i, evt in enumerate(block.segments[0].events) \ diff --git a/cobrawap/pipeline/stage05_channel_wave_characterization/Snakefile b/cobrawap/pipeline/stage05_channel_wave_characterization/Snakefile index b2f407d3..70a04a19 100644 --- a/cobrawap/pipeline/stage05_channel_wave_characterization/Snakefile +++ b/cobrawap/pipeline/stage05_channel_wave_characterization/Snakefile @@ -25,7 +25,6 @@ def input(wildcards): ruleorder: spatial_derivative > compute_measure - #### UTILITY BLOCKS #### use rule template as all with: diff --git a/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/annotations.py b/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/annotations.py index d6b1341a..e48692fc 100644 --- a/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/annotations.py +++ b/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/annotations.py @@ -14,19 +14,19 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--output_img", nargs='?', type=none_or_str, default=None, - help="path of output image file") + help="path of output image file") CLI.add_argument("--event_name", "--EVENT_NAME", nargs='?', type=str, default='wavefronts', - help="name of neo.Event to analyze (must contain waves)") + help="name of neo.Event to analyze (must contain waves)") CLI.add_argument("--ignore_keys", "--IGNORE_KEYS", nargs='*', type=str, default=[], - help="neo object annotations keys to not include in dataframe") + help="neo object annotations keys to not include in dataframe") CLI.add_argument("--include_keys", "--INCLUDE_KEYS", nargs='*', type=str, default=[], - help="neo object annotations keys to include in dataframe") + help="neo object annotations keys to include in dataframe") CLI.add_argument("--profile", "--PROFILE", nargs='?', type=none_or_str, default=None, - help="profile name") + help="profile name") def add_annotations_to_df(df, annotations, include_keys=[]): use_all_keys = not bool(len(include_keys)) diff --git a/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/check_input.py b/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/check_input.py index d57223ef..d09b0910 100644 --- a/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/check_input.py +++ b/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/check_input.py @@ -14,11 +14,11 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--event_name", "--EVENT_NAME", nargs='?', type=none_or_str, default=None, - help="name of neo.Event to analyze (must contain waves)") + help="name of neo.Event to analyze (must contain waves)") CLI.add_argument("--measures", "--MEASURES", nargs='+', type=none_or_str, default=None, - help="list of measure names to apply") + help="list of measure names to apply") if __name__ == '__main__': args, unknown = CLI.parse_known_args() diff --git a/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/direction_local.py b/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/direction_local.py index 0bf5244d..60ebcdae 100644 --- a/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/direction_local.py +++ b/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/direction_local.py @@ -12,13 +12,13 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to spatial derivative dataframe") + help="path to spatial derivative dataframe") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--output_img", nargs='?', type=none_or_str, default=None, - help="path of output image file") + help="path of output image file") CLI.add_argument("--event_name", "--EVENT_NAME", nargs='?', type=str, default='wavefronts', - help="name of neo.Event to analyze (must contain waves)") + help="name of neo.Event to analyze (must contain waves)") if __name__ == '__main__': args, unknown = CLI.parse_known_args() diff --git a/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/flow_direction_local.py b/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/flow_direction_local.py index 7c7e97a2..b61016e1 100644 --- a/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/flow_direction_local.py +++ b/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/flow_direction_local.py @@ -1,5 +1,5 @@ """ -Calculate the wave directions per wave and channel, +Calculate the wave directions per wave and channel, based on the optical flow at wave trigger times and locations. """ @@ -12,13 +12,13 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to neo object") + help="path to neo object") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--output_img", nargs='?', type=none_or_str, default=None, - help="path of output image file") + help="path of output image file") CLI.add_argument("--event_name", "--EVENT_NAME", nargs='?', type=str, default='wavefronts', - help="name of neo.Event to analyze (must contain waves)") + help="name of neo.Event to analyze (must contain waves)") if __name__ == '__main__': args, unknown = CLI.parse_known_args() diff --git a/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/inter_wave_interval_local.py b/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/inter_wave_interval_local.py index f688cd07..26a8d681 100644 --- a/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/inter_wave_interval_local.py +++ b/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/inter_wave_interval_local.py @@ -12,15 +12,15 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--output_img", nargs='?', type=none_or_str, default=None, - help="path of output image file") + help="path of output image file") CLI.add_argument("--kernel", "--KERNEL", nargs='?', type=none_or_str, default=None, - help="derivative kernel") + help="derivative kernel") CLI.add_argument("--event_name", "--EVENT_NAME", nargs='?', type=str, default='wavefronts', - help="name of neo.Event to analyze (must contain waves)") + help="name of neo.Event to analyze (must contain waves)") def calc_local_wave_intervals(evts): wave_labels = evts.labels.astype(int) diff --git a/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/merge_dataframes.py b/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/merge_dataframes.py index 61566496..77a8b105 100644 --- a/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/merge_dataframes.py +++ b/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/merge_dataframes.py @@ -7,10 +7,14 @@ from copy import deepcopy CLI = argparse.ArgumentParser() -CLI.add_argument("--output", nargs='?', type=str) -CLI.add_argument("--data", nargs='+', type=str) -CLI.add_argument("--output_img",nargs='?', type=str) -CLI.add_argument("--merge_key", nargs='+', type=str) +CLI.add_argument("--data", nargs='+', type=str, + help="path to input data in neo format") +CLI.add_argument("--output", nargs='?', type=str, + help="path of output file") +CLI.add_argument("--output_img", nargs='?', type=str, + help="") +CLI.add_argument("--merge_key", nargs='+', type=str, + help="") if __name__ == '__main__': args, unknown = CLI.parse_known_args() diff --git a/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/spatial_derivative.py b/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/spatial_derivative.py index 2307f598..68252a81 100644 --- a/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/spatial_derivative.py +++ b/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/spatial_derivative.py @@ -17,19 +17,19 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--output_img", nargs='?', type=none_or_str, default=None, - help="path of output image file") + help="path of output image file") CLI.add_argument("--kernel", "--KERNEL", nargs='?', type=none_or_str, default=None, - help="derivative kernel") + help="derivative kernel") CLI.add_argument("--event_name", "--EVENT_NAME", nargs='?', type=str, default='wavefronts', - help="name of neo.Event to analyze (must contain waves)") + help="name of neo.Event to analyze (must contain waves)") CLI.add_argument("--interpolate", "--INTERPOLATE", nargs='?', type=bool, default=False, - help="whether to thin-plate-spline interpolate the wave patterns before derivation") + help="whether to thin-plate-spline interpolate the wave patterns before derivation") CLI.add_argument("--smoothing", "--SMOOTHING", nargs='?', type=float, default=0, - help="smoothing factor for the interpolation") + help="smoothing factor for the interpolation") def interpolate_grid(grid, smoothing): y, x = np.where(np.isfinite(grid)) diff --git a/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/velocity_local.py b/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/velocity_local.py index 93aad312..014ee571 100644 --- a/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/velocity_local.py +++ b/cobrawap/pipeline/stage05_channel_wave_characterization/scripts/velocity_local.py @@ -11,13 +11,13 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to spatial derivative dataframe") + help="path to spatial derivative dataframe") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--output_img", nargs='?', type=none_or_str, default=None, - help="path of output image file") + help="path of output image file") CLI.add_argument("--event_name", "--EVENT_NAME", nargs='?', type=str, default='wavefronts', - help="name of neo.Event to analyze (must contain waves)") + help="name of neo.Event to analyze (must contain waves)") if __name__ == '__main__': args, unknown = CLI.parse_known_args() diff --git a/cobrawap/pipeline/stage05_wave_characterization/Snakefile b/cobrawap/pipeline/stage05_wave_characterization/Snakefile index 594e7ccc..aa283aa9 100644 --- a/cobrawap/pipeline/stage05_wave_characterization/Snakefile +++ b/cobrawap/pipeline/stage05_wave_characterization/Snakefile @@ -40,5 +40,5 @@ use rule template as compute_measure with: params(config.__dict__) output: Path('{dir}') / '{measure}' / f'{config.EVENT_NAME}_{{measure}}.csv', - output_img = Path('{dir}') / '{measure}' + output_img = Path('{dir}') / '{measure}' / f'{config.EVENT_NAME}_{{measure}}.{config.PLOT_FORMAT}' diff --git a/cobrawap/pipeline/stage05_wave_characterization/scripts/annotations.py b/cobrawap/pipeline/stage05_wave_characterization/scripts/annotations.py index 425e06bc..1826308c 100644 --- a/cobrawap/pipeline/stage05_wave_characterization/scripts/annotations.py +++ b/cobrawap/pipeline/stage05_wave_characterization/scripts/annotations.py @@ -14,19 +14,19 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--output_img", nargs='?', type=none_or_str, default=None, - help="path of output image file") + help="path of output image file") CLI.add_argument("--event_name", "--EVENT_NAME", nargs='?', type=str, default='wavefronts', - help="name of neo.Event to analyze (must contain waves)") + help="name of neo.Event to analyze (must contain waves)") CLI.add_argument("--ignore_keys", "--IGNORE_KEYS", nargs='*', type=str, default=[], - help="neo.Event annotations keys to not include in dataframe") + help="neo.Event annotations keys to not include in dataframe") CLI.add_argument("--include_keys", "--INCLUDE_KEYS", nargs='*', type=str, default=[], - help="neo object annotations keys to include in dataframe") + help="neo object annotations keys to include in dataframe") CLI.add_argument("--profile", "--PROFILE", nargs='?', type=none_or_str, default=None, - help="profile name") + help="profile name") def add_annotations_to_df(df, annotations, include_keys=[]): use_all_keys = not bool(len(include_keys)) @@ -75,7 +75,6 @@ def add_array_annotations_to_df(df, array_annotations, labels, index_name, if __name__ == '__main__': args, unknown = CLI.parse_known_args() - args.ignore_keys = [re.sub('[\[\],\s]', '', key) for key in args.ignore_keys] args.include_keys = [re.sub('[\[\],\s]', '', key) for key in args.include_keys] if len(args.include_keys): diff --git a/cobrawap/pipeline/stage05_wave_characterization/scripts/check_input.py b/cobrawap/pipeline/stage05_wave_characterization/scripts/check_input.py index 2d220abe..25bfbfdf 100644 --- a/cobrawap/pipeline/stage05_wave_characterization/scripts/check_input.py +++ b/cobrawap/pipeline/stage05_wave_characterization/scripts/check_input.py @@ -13,11 +13,11 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--event_name", "--EVENT_NAME", nargs='?', type=none_or_str, default=None, - help="name of neo.Event to analyze (must contain waves)") + help="name of neo.Event to analyze (must contain waves)") CLI.add_argument("--measures", "--MEASURES", nargs='+', type=none_or_str, default=None, - help="list of measure names to apply") + help="list of measure names to apply") if __name__ == '__main__': args, unknown = CLI.parse_known_args() diff --git a/cobrawap/pipeline/stage05_wave_characterization/scripts/direction_planar.py b/cobrawap/pipeline/stage05_wave_characterization/scripts/direction_planar.py index 3326aab2..f40cd122 100644 --- a/cobrawap/pipeline/stage05_wave_characterization/scripts/direction_planar.py +++ b/cobrawap/pipeline/stage05_wave_characterization/scripts/direction_planar.py @@ -19,15 +19,15 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--output_img", nargs='?', type=none_or_str, default=None, - help="path of output image file") + help="path of output image file") CLI.add_argument("--method", "--DIRECTION_METHOD", nargs='?', type=str, default='trigger_interpolation', - help="'tigger_interpolation' or 'optical_flow'") + help="'tigger_interpolation' or 'optical_flow'") CLI.add_argument("--event_name", "--EVENT_NAME", nargs='?', type=str, default='wavefronts', - help="name of neo.Event to analyze (must contain waves)") + help="name of neo.Event to analyze (must contain waves)") def calc_displacement(times, locations): slope, offset, _, _, stderr = scipy.stats.linregress(times, locations) diff --git a/cobrawap/pipeline/stage05_wave_characterization/scripts/duration.py b/cobrawap/pipeline/stage05_wave_characterization/scripts/duration.py index 4684fe8b..5161e20e 100644 --- a/cobrawap/pipeline/stage05_wave_characterization/scripts/duration.py +++ b/cobrawap/pipeline/stage05_wave_characterization/scripts/duration.py @@ -10,13 +10,13 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--output_img", nargs='?', type=none_or_str, default=None, - help="path of output image file") + help="path of output image file") CLI.add_argument("--event_name", "--EVENT_NAME", nargs='?', type=str, default='wavefronts', - help="name of neo.Event to analyze (must contain waves)") + help="name of neo.Event to analyze (must contain waves)") if __name__ == '__main__': args, unknown = CLI.parse_known_args() diff --git a/cobrawap/pipeline/stage05_wave_characterization/scripts/inter_wave_interval.py b/cobrawap/pipeline/stage05_wave_characterization/scripts/inter_wave_interval.py index 5432c266..2004fd98 100644 --- a/cobrawap/pipeline/stage05_wave_characterization/scripts/inter_wave_interval.py +++ b/cobrawap/pipeline/stage05_wave_characterization/scripts/inter_wave_interval.py @@ -17,13 +17,13 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=Path, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=Path, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--output_img", nargs='?', type=none_or_str, default=None, - help="path of output image file") + help="path of output image file") CLI.add_argument("--event_name", "--EVENT_NAME", nargs='?', type=str, default='wavefronts', - help="name of neo.Event to analyze (must contain waves)") + help="name of neo.Event to analyze (must contain waves)") if __name__ == '__main__': args, unknown = CLI.parse_known_args() diff --git a/cobrawap/pipeline/stage05_wave_characterization/scripts/label_planar.py b/cobrawap/pipeline/stage05_wave_characterization/scripts/label_planar.py index 624b8831..00b5c919 100644 --- a/cobrawap/pipeline/stage05_wave_characterization/scripts/label_planar.py +++ b/cobrawap/pipeline/stage05_wave_characterization/scripts/label_planar.py @@ -16,15 +16,15 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--output_img", nargs='?', type=none_or_str, default=None, - help="path of output image file") + help="path of output image file") CLI.add_argument("--alignment_threshold", nargs='?', type=float, default=.85, - help="threshold for alignment of velocity vectors at transitions") + help="threshold for alignment of velocity vectors at transitions") CLI.add_argument("--event_name", "--EVENT_NAME", nargs='?', type=str, default='wavefronts', - help="name of neo.Event to analyze (must contain waves)") + help="name of neo.Event to analyze (must contain waves)") def label_planar(waves_event, vector_field, times, threshold): labels = np.unique(waves_event.labels) diff --git a/cobrawap/pipeline/stage05_wave_characterization/scripts/merge_dataframes.py b/cobrawap/pipeline/stage05_wave_characterization/scripts/merge_dataframes.py index 7b14cbba..bc143825 100644 --- a/cobrawap/pipeline/stage05_wave_characterization/scripts/merge_dataframes.py +++ b/cobrawap/pipeline/stage05_wave_characterization/scripts/merge_dataframes.py @@ -7,10 +7,14 @@ from copy import deepcopy CLI = argparse.ArgumentParser() -CLI.add_argument("--output", nargs='?', type=str) -CLI.add_argument("--data", nargs='+', type=str) -CLI.add_argument("--output_img",nargs='?', type=str) -# CLI.add_argument("--merge_key", nargs='?', type=str) +CLI.add_argument("--data", nargs='+', type=str, + help="path to input data in neo format") +CLI.add_argument("--output", nargs='?', type=str, + help="path of output file") +CLI.add_argument("--output_img", nargs='?', type=str, + help="") +# CLI.add_argument("--merge_key", nargs='?', type=str, +# help="") if __name__ == '__main__': args, unknown = CLI.parse_known_args() diff --git a/cobrawap/pipeline/stage05_wave_characterization/scripts/number_of_triggers.py b/cobrawap/pipeline/stage05_wave_characterization/scripts/number_of_triggers.py index 81213e19..2a80edb0 100644 --- a/cobrawap/pipeline/stage05_wave_characterization/scripts/number_of_triggers.py +++ b/cobrawap/pipeline/stage05_wave_characterization/scripts/number_of_triggers.py @@ -10,13 +10,13 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--output_img", nargs='?', type=none_or_str, default=None, - help="path of output image file") + help="path of output image file") CLI.add_argument("--event_name", "--EVENT_NAME", nargs='?', type=str, default='wavefronts', - help="name of neo.Event to analyze (must contain waves)") + help="name of neo.Event to analyze (must contain waves)") if __name__ == '__main__': args, unknown = CLI.parse_known_args() diff --git a/cobrawap/pipeline/stage05_wave_characterization/scripts/time_stamp.py b/cobrawap/pipeline/stage05_wave_characterization/scripts/time_stamp.py index 0078021a..9e7f1249 100644 --- a/cobrawap/pipeline/stage05_wave_characterization/scripts/time_stamp.py +++ b/cobrawap/pipeline/stage05_wave_characterization/scripts/time_stamp.py @@ -11,15 +11,15 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=str, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--output_img", nargs='?', type=none_or_str, default=None, - help="path of output image") + help="path of output image") CLI.add_argument("--time_point", "--TIME_STAMP_POINT", nargs='?', type=str, default='start', - help="when to register the time for a wave [start, middle, end]") + help="when to register the time for a wave [start, middle, end]") CLI.add_argument("--event_name", "--EVENT_NAME", nargs='?', type=str, default='wavefronts', - help="name of neo.Event to analyze (must contain waves)") + help="name of neo.Event to analyze (must contain waves)") if __name__ == '__main__': args, unknown = CLI.parse_known_args() diff --git a/cobrawap/pipeline/stage05_wave_characterization/scripts/velocity_planar.py b/cobrawap/pipeline/stage05_wave_characterization/scripts/velocity_planar.py index 1c091e36..ee435f3d 100644 --- a/cobrawap/pipeline/stage05_wave_characterization/scripts/velocity_planar.py +++ b/cobrawap/pipeline/stage05_wave_characterization/scripts/velocity_planar.py @@ -13,13 +13,13 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=Path, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=Path, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--output_img", nargs='?', type=none_or_str, default=None, - help="path of output image file") + help="path of output image file") CLI.add_argument("--event_name", "--EVENT_NAME", nargs='?', type=str, default='wavefronts', - help="name of neo.Event to analyze (must contain waves)") + help="name of neo.Event to analyze (must contain waves)") def center_points(x, y): return x - np.mean(x), y - np.mean(y) diff --git a/cobrawap/pipeline/stageXY_template/scripts/check_input.py b/cobrawap/pipeline/stageXY_template/scripts/check_input.py index bea44f58..9668b06f 100644 --- a/cobrawap/pipeline/stageXY_template/scripts/check_input.py +++ b/cobrawap/pipeline/stageXY_template/scripts/check_input.py @@ -8,10 +8,9 @@ import argparse from utils.io_utils import load_neo -CLI = argparse.ArgumentParser(description=__doc__, - formatter_class=argparse.RawDescriptionHelpFormatter) +CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=str, required=True, - help="path to input data in neo format") + help="path to input data in neo format") if __name__ == '__main__': args, unknown = CLI.parse_known_args() diff --git a/cobrawap/pipeline/stageXY_template/scripts/minimal_example.py b/cobrawap/pipeline/stageXY_template/scripts/minimal_example.py index 19e5b657..308f41d9 100644 --- a/cobrawap/pipeline/stageXY_template/scripts/minimal_example.py +++ b/cobrawap/pipeline/stageXY_template/scripts/minimal_example.py @@ -9,9 +9,9 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=Path, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=Path, required=True, - help="path of output file") + help="path of output file") if __name__ == '__main__': args, unknown = CLI.parse_known_args() diff --git a/cobrawap/pipeline/stageXY_template/scripts/script_template.py b/cobrawap/pipeline/stageXY_template/scripts/script_template.py index 85a3f953..edd5ca7f 100644 --- a/cobrawap/pipeline/stageXY_template/scripts/script_template.py +++ b/cobrawap/pipeline/stageXY_template/scripts/script_template.py @@ -11,21 +11,21 @@ CLI = argparse.ArgumentParser() CLI.add_argument("--data", nargs='?', type=Path, required=True, - help="path to input data in neo format") + help="path to input data in neo format") CLI.add_argument("--output", nargs='?', type=Path, required=True, - help="path of output file") + help="path of output file") CLI.add_argument("--offset", nargs='?', type=none_or_float, default=None, - help="offset the signal by some value") + help="offset the signal by some value") CLI.add_argument("--img_dir", nargs='?', type=none_or_str, default=None, - help="path of figure directory") + help="path of figure directory") CLI.add_argument("--img_name", nargs='?', type=str, default='offset_channel0.png', - help='example image filename for channel 0') + help='example image filename for channel 0') CLI.add_argument("--plot_channels", nargs='+', type=none_or_int, default=None, - help="list of channels to plot") + help="list of channels to plot") CLI.add_argument("--plot_tstart", nargs='?', type=none_or_float, default=0, - help="plotting start time in seconds") + help="plotting start time in seconds") CLI.add_argument("--plot_tstop", nargs='?', type=none_or_float, default=10, - help="plotting stop time in seconds") + help="plotting stop time in seconds") def offset_signal(asig, offset=None): if offset is None: @@ -66,7 +66,7 @@ def plot_signal(asig, new_asig, channel=0, t_start=None, t_stop=None): block = load_neo(args.data) asig = block.segments[0].analogsignals[0] - # PERFOMING METHOD + # PERFORMING METHOD new_asig = offset_signal(asig, offset=args.offset) block.segments[0].analogsignals[0] = new_asig diff --git a/cobrawap/pipeline/utils/Snakefile b/cobrawap/pipeline/utils/Snakefile index 44f340ee..44580100 100644 --- a/cobrawap/pipeline/utils/Snakefile +++ b/cobrawap/pipeline/utils/Snakefile @@ -150,4 +150,4 @@ rule template_all: shell: """ {params.command} "{input.data}" "{output.data}" - """ \ No newline at end of file + """ diff --git a/cobrawap/pipeline/utils/io_utils.py b/cobrawap/pipeline/utils/io_utils.py index d532f20e..a39920d9 100644 --- a/cobrawap/pipeline/utils/io_utils.py +++ b/cobrawap/pipeline/utils/io_utils.py @@ -22,7 +22,7 @@ def load_neo(filename, object='block', lazy=False, *args, **kwargs): block = nio.read_block() except Exception as e: - # io.close() + # nio.close() raise e finally: if not lazy and hasattr(nio, 'close'): diff --git a/cobrawap/pipeline/utils/neo_utils.py b/cobrawap/pipeline/utils/neo_utils.py index fc03dcf9..caf9fc46 100644 --- a/cobrawap/pipeline/utils/neo_utils.py +++ b/cobrawap/pipeline/utils/neo_utils.py @@ -84,7 +84,7 @@ def flip_image(imgseq, axis=-1): flipped_imgseq.annotations['array_annotations'][key] \ = np.flip(value, axis=axis) flipped_imgseq.annotations['array_annotations']['y_coords'] \ - = imgseq.annotations['array_annotations']['y_coords'] + = imgseq.annotations['array_annotations']['y_coords'] return flipped_imgseq @@ -296,8 +296,8 @@ def add_empty_sites_to_analogsignal(asig): if type(values) == pq.Quantity: new_values = new_values.magnitude * values.units new_asig.array_annotations[key] = new_values - new_asig.array_annotate(x_coords=np.append(x_coords, x_nan_coords), y_coords=np.append(y_coords, y_nan_coords)) + return new_asig diff --git a/cobrawap/pipeline/utils/snakefile.py b/cobrawap/pipeline/utils/snakefile.py index fe087d97..51096a86 100644 --- a/cobrawap/pipeline/utils/snakefile.py +++ b/cobrawap/pipeline/utils/snakefile.py @@ -165,7 +165,7 @@ def get_config(config_dir, config_name, get_path_instead=False): else: return config_dict - + def create_temp_configs(stages, configs_dir, config_name, output_dir, temp_name='temp_config.yaml'): for i, stage in enumerate(stages):