Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing typos and alignments/spacings #61

Merged
merged 6 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 Down Expand Up @@ -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)
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,13 +11,13 @@
from utils.parse import none_or_str

CLI = argparse.ArgumentParser()
CLI.add_argument("--data", nargs='?', type=Path, required=True,
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,
CLI.add_argument("--output", nargs='?', type=Path, required=True,
help="path of output file")
CLI.add_argument("--output_img", nargs='?', type=none_or_str,
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,
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):
Expand Down
2 changes: 1 addition & 1 deletion cobrawap/pipeline/stage02_processing/scripts/detrending.py
Original file line number Diff line number Diff line change
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
rgutzen marked this conversation as resolved.
Show resolved Hide resolved
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")
rgutzen marked this conversation as resolved.
Show resolved Hide resolved
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="filterfunction used in the scipy backend")

if __name__ == '__main__':
args, unknown = CLI.parse_known_args()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,13 @@ 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)
output_path = args.img_dir \
/ args.img_name.replace('_channel0', f'_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}')
rgutzen marked this conversation as resolved.
Show resolved Hide resolved
save_plot(output_path)

asig.name += ""
Expand Down
4 changes: 2 additions & 2 deletions cobrawap/pipeline/stage02_processing/scripts/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
from utils.io_utils import write_neo, load_neo

CLI = argparse.ArgumentParser()
CLI.add_argument("--data", nargs='?', type=str, required=True,
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,
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'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from utils.parse import none_or_float

CLI = argparse.ArgumentParser()
CLI.add_argument("--data", nargs='?', type=str, required=True,
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,
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")
Expand Down
8 changes: 4 additions & 4 deletions cobrawap/pipeline/stage02_processing/scripts/roi_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
from utils.neo_utils import analogsignal_to_imagesequence, imagesequence_to_analogsignal

CLI = argparse.ArgumentParser()
CLI.add_argument("--data", nargs='?', type=str, required=True,
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,
CLI.add_argument("--output", nargs='?', type=str, required=True,
help="path of output file")
CLI.add_argument("--output_img", nargs='?', type=none_or_str,
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)
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
from utils.neo_utils import analogsignal_to_imagesequence, imagesequence_to_analogsignal

CLI = argparse.ArgumentParser()
CLI.add_argument("--data", nargs='?', type=str, required=True,
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,
CLI.add_argument("--output", nargs='?', type=str, required=True,
help="path of output file")
CLI.add_argument("--output_img", nargs='?', type=none_or_str,
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,
CLI.add_argument("--macro_pixel_dim", nargs='?', type=int,
help="smoothing factor", default=2)

def spatial_smoothing(imgseq, macro_pixel_dim):
Expand Down
4 changes: 2 additions & 2 deletions cobrawap/pipeline/stage02_processing/scripts/subsampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
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,
CLI.add_argument("--output", nargs='?', type=str, required=True,
help="path of output file")
CLI.add_argument("--target_rate", nargs='?', type=float, required=True,
CLI.add_argument("--target_rate", nargs='?', type=float, required=True,
help="rate to subsample to in Hz")

if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion cobrawap/pipeline/stage02_processing/scripts/z_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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,
CLI.add_argument("--output", nargs='?', type=Path, required=True,
help="path of output file")

if __name__ == '__main__':
Expand Down
7 changes: 4 additions & 3 deletions cobrawap/pipeline/stage03_trigger_detection/Snakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
"""
# Stage 03 Trigger Detection
"""

Expand All @@ -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:
Expand Down Expand Up @@ -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)


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment headings are not preceded by two blank lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should instead use two blank lines before comment headings, so to better distinguish rules belonging to different "groups", given that rules from the same group are separated by double blank lines anyway. Let's decide a norm, and then let's stick to it.

#### FILTER BLOCKS (choose any) ####

use rule template as remove_short_states with:
Expand All @@ -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)
config=config)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""w
"""
Determine the threshold between Up and Down states for each channel
by fitting the respective amplitude distributions.
"""
Expand Down Expand Up @@ -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)
np.save(args.output, thresholds)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from utils.io_utils import load_neo

CLI = argparse.ArgumentParser()
CLI.add_argument("--data", nargs='?', type=str, required=True,
CLI.add_argument("--data", nargs='?', type=str, required=True,
help="path to input data in neo format")

if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
"""
Expand Down
10 changes: 5 additions & 5 deletions cobrawap/pipeline/stage04_wave_detection/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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}'
Expand Down Expand Up @@ -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')

Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from snakemake.logging import logger

CLI = argparse.ArgumentParser()
CLI.add_argument("--data", nargs='?', type=str, required=True,
CLI.add_argument("--data", nargs='?', type=str, required=True,
help="path to input data in neo format")

if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

def plot_clustering(events, ax=None):
if ax is None:
fig = plt.figure()
Expand Down
Loading