-
Notifications
You must be signed in to change notification settings - Fork 5
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
Ticket/425/motion/correction/tiffs #433
Changes from 38 commits
8f978c6
ce64e54
b65b335
246e454
063511f
9ff2e8d
74942dc
3ecc224
3592c14
72c0ef4
793b13d
e7f0412
4124482
4063d94
3dd4f34
fd0c102
dc4fb7c
6811e7d
6befbb9
2f58098
1fd0600
dcd7321
ad3541a
6664846
b955518
5ce63c4
b5ccebb
568608b
bafd616
312141b
293e5c4
f144278
ae549dc
40b1555
256287b
ca9010e
8ba18d0
8ae5f3c
8fa8a40
8ea25d6
e56b121
26e709a
f0ef500
67df7ee
bf6523c
534a109
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import argschema | ||
import pathlib | ||
from marshmallow import post_load | ||
from marshmallow.validate import OneOf | ||
|
||
|
||
class VideoBaseSchema(argschema.ArgSchema): | ||
|
@@ -16,8 +17,23 @@ class VideoBaseSchema(argschema.ArgSchema): | |
required=False, | ||
allow_none=True, | ||
default=3, | ||
description=("Radius of median filter kernel; " | ||
"if None, no median filter applied")) | ||
description=("Size of spatial filter kernel; " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry can you please make it clear that these kernels apply specifically downsampling . It is possible to apply a sliding kernel with no downsampling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our default median filter actually doesn't apply downsampling. The size of the frame coming in is the size of the frame coming out
(because this isn't complicated enough...) |
||
"if None or zero, no spatial filter applied")) | ||
|
||
kernel_type = argschema.fields.String( | ||
required=False, | ||
allow_none=False, | ||
default='median', | ||
validation=OneOf(('median', 'mean')), | ||
description=("Type of spatial smoothing kernel to be " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thoughts above about mentioning "downsampling". Also I'm assuming the "downsampling" mentioned already here is the temporal downsampling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I modified the docstring to explicitly call out that the "mean" filter downsamples the video frames while the "median" filter does not. |
||
"applied to the video after downsampling")) | ||
|
||
video_dtype = argschema.fields.String( | ||
required=False, | ||
allow_none=False, | ||
default='uint8', | ||
validation=OneOf(('uint8', 'uint16')), | ||
description=("Type to which the output video is cast")) | ||
|
||
input_frame_rate_hz = argschema.fields.Float( | ||
required=True, | ||
|
@@ -113,8 +129,10 @@ def check_quality(self, data, **kwargs): | |
def check_output_path(self, data, **kwargs): | ||
output_path = pathlib.Path(data['output_path']) | ||
output_suffix = output_path.suffix | ||
if output_suffix not in ('.mp4', '.avi'): | ||
msg = "output_path must be an .mp4 or .avi file\n" | ||
allowed = ('.mp4', '.avi', '.tiff', '.tif') | ||
if output_suffix not in allowed: | ||
msg = "output_path must have one of these extensions:\n" | ||
msg += f"{allowed}\n" | ||
msg += f"you gave {data['output_path']}" | ||
raise ValueError(msg) | ||
return data |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from ophys_etl.modules.video.utils import ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please make it clear that this is specific to the CLI? Ie by calling this module There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
apply_downsampled_mean_filter_to_video) | ||
from ophys_etl.modules.median_filtered_max_projection.utils import ( | ||
apply_median_filter_to_video) | ||
from functools import partial | ||
import numpy as np | ||
|
||
|
||
class VideoModuleMixin(object): | ||
|
||
def _get_supplemental_args(self) -> dict: | ||
""" | ||
Parse self.args and return a dict like | ||
{'quantiles': optional tuple of quantiles to use in clipping video | ||
'spatial_filter': optional callable spatial filter to apply to video | ||
'video_dtype': dtype of video | ||
""" | ||
if self.args['upper_quantile'] is not None: | ||
quantiles = (self.args['lower_quantile'], | ||
self.args['upper_quantile']) | ||
else: | ||
quantiles = (0.0, 1.0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you instead change the default to 0 and 1 instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
use_kernel = False | ||
if self.args['kernel_size'] is not None: | ||
if self.args['kernel_size'] > 0: | ||
use_kernel = True | ||
|
||
if use_kernel: | ||
if self.args['kernel_type'] == 'median': | ||
spatial_filter = partial(apply_median_filter_to_video, | ||
kernel_size=self.args['kernel_size']) | ||
else: | ||
spatial_filter = partial( | ||
apply_downsampled_mean_filter_to_video, | ||
kernel_size=self.args['kernel_size']) | ||
else: | ||
spatial_filter = None | ||
|
||
video_dtype = np.dtype(self.args['video_dtype']) | ||
|
||
return {'quantiles': quantiles, | ||
'spatial_filter': spatial_filter, | ||
'video_dtype': video_dtype} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you instead add a new argument
use_spatial_filter
to control whether to apply spatial filtering? Passing None or 0 here is a little awkward, imo.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am of the opposite opinion. I don't like the idea of adding more parameters to the schema. It clutters up
--help
and leaves more places for users to screw up (settinguse_spatial_filter=False, kernel_size=2
when they intended to use a kernel of size 2). I like the idea that you can just turn filtering off by setting the kernel size to nothing. We can talk about this, if you want.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case you could just issue a warning that
use_spatial_filter
is False butkernel_size
is not NoneThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me, that seems just as complicated as the present
I'm going to leave this.