Skip to content

Commit

Permalink
Fixing typos and alignments/spacings (#61)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
cosimolupo committed Mar 22, 2024
1 parent 6c1b2f4 commit a1c0579
Show file tree
Hide file tree
Showing 67 changed files with 384 additions and 361 deletions.
2 changes: 1 addition & 1 deletion cobrawap/pipeline/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 18 additions & 18 deletions cobrawap/pipeline/stage01_data_entry/scripts/enter_data_template.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,55 +14,55 @@

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()

# 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)
Expand Down
10 changes: 5 additions & 5 deletions cobrawap/pipeline/stage01_data_entry/scripts/plot_traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion cobrawap/pipeline/stage02_processing/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ RERUN_MODE: True
#################################
# No parameters needed

# BLOCK - spatial_smoothig
# BLOCK - spatial_smoothing
#################################
MACRO_PIXEL_DIM: 2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 8 additions & 8 deletions cobrawap/pipeline/stage02_processing/scripts/detrending.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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 += ""
Expand Down
16 changes: 8 additions & 8 deletions cobrawap/pipeline/stage02_processing/scripts/frequency_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
38 changes: 19 additions & 19 deletions cobrawap/pipeline/stage02_processing/scripts/logMUA_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions cobrawap/pipeline/stage02_processing/scripts/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading

0 comments on commit a1c0579

Please sign in to comment.