From b9b354992159361c807e168c292f374606a5dc3d Mon Sep 17 00:00:00 2001 From: Ryan Ly Date: Fri, 16 Oct 2020 21:05:15 -0700 Subject: [PATCH 1/5] Improve PlaneSegmentation.add_roi doc --- src/pynwb/ophys.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pynwb/ophys.py b/src/pynwb/ophys.py index 2dd329749..b7b0e6945 100644 --- a/src/pynwb/ophys.py +++ b/src/pynwb/ophys.py @@ -238,13 +238,17 @@ def __init__(self, **kwargs): self.reference_images = reference_images @docval({'name': 'pixel_mask', 'type': 'array_data', 'default': None, - 'doc': 'pixel mask for 2D ROIs: [(x1, y1, weight1), (x2, y2, weight2), ...]', + 'doc': ('Pixel mask for 2D ROIs: [(x1, y1, weight1), (x2, y2, weight2), ...]. This should be used ' + 'for sparse masks, i.e., masks that have few pixels relative to the size of the image.'), 'shape': (None, 3)}, {'name': 'voxel_mask', 'type': 'array_data', 'default': None, - 'doc': 'voxel mask for 3D ROIs: [(x1, y1, z1, weight1), (x2, y2, z2, weight2), ...]', + 'doc': ('Voxel mask for 3D ROIs: [(x1, y1, z1, weight1), (x2, y2, z2, weight2), ...]. This should be used ' + 'for sparse masks, i.e., masks that have few voxels relative to the size of the volume.'), 'shape': (None, 4)}, {'name': 'image_mask', 'type': 'array_data', 'default': None, - 'doc': 'image with the same size of image where positive values mark this ROI', + 'doc': ('Image with the same size of image where positive values mark the ROI weights for each pixel of ' + 'the image. This should be used for dense masks, i.e., masks where most of the pixels have a ' + 'positive weight.'), 'shape': [[None]*2, [None]*3]}, {'name': 'id', 'type': int, 'doc': 'the ID for the ROI', 'default': None}, allow_extra=True) From d623905d566ccc6125b81eb9995c71d85689fa15 Mon Sep 17 00:00:00 2001 From: Ryan Ly Date: Fri, 16 Oct 2020 21:28:43 -0700 Subject: [PATCH 2/5] Fix package dependency issues with importlib --- requirements-dev.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements-dev.txt b/requirements-dev.txt index 99117eca7..f5a4edb2d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,4 +3,5 @@ coverage==5.2 flake8==3.8.3 flake8-debugger==3.1.0 flake8-print==3.1.4 +importlib-metadata<2 tox==3.17.1 From 470e917866dbe5ec9215c2ff736c58c19f5b6a0e Mon Sep 17 00:00:00 2001 From: Ryan Ly Date: Sat, 17 Oct 2020 21:52:25 -0700 Subject: [PATCH 3/5] Update ophys.py --- src/pynwb/ophys.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pynwb/ophys.py b/src/pynwb/ophys.py index b7b0e6945..8d32f3f06 100644 --- a/src/pynwb/ophys.py +++ b/src/pynwb/ophys.py @@ -247,8 +247,11 @@ def __init__(self, **kwargs): 'shape': (None, 4)}, {'name': 'image_mask', 'type': 'array_data', 'default': None, 'doc': ('Image with the same size of image where positive values mark the ROI weights for each pixel of ' - 'the image. This should be used for dense masks, i.e., masks where most of the pixels have a ' - 'positive weight.'), + 'the image. This should be used when the NWB file will be compressed or when using ' + 'dense masks, i.e., masks where most of the pixels have a ' + 'positive weight. In a compressed file, an image mask will often take up less space ' + 'than a pixel mask, whereas in an uncomprsesed file, a pixel mask will often take up ' + 'less space than an image mask.'), 'shape': [[None]*2, [None]*3]}, {'name': 'id', 'type': int, 'doc': 'the ID for the ROI', 'default': None}, allow_extra=True) From 04161b95883ffbaa563c66f48e44a1a1fc9d9799 Mon Sep 17 00:00:00 2001 From: Ryan Ly Date: Sat, 17 Oct 2020 23:52:51 -0700 Subject: [PATCH 4/5] Update ophys.py --- src/pynwb/ophys.py | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/pynwb/ophys.py b/src/pynwb/ophys.py index 8d32f3f06..b704504d9 100644 --- a/src/pynwb/ophys.py +++ b/src/pynwb/ophys.py @@ -238,28 +238,40 @@ def __init__(self, **kwargs): self.reference_images = reference_images @docval({'name': 'pixel_mask', 'type': 'array_data', 'default': None, - 'doc': ('Pixel mask for 2D ROIs: [(x1, y1, weight1), (x2, y2, weight2), ...]. This should be used ' - 'for sparse masks, i.e., masks that have few pixels relative to the size of the image.'), + 'doc': ('Pixel mask for 2D ROIs: [(x1, y1, weight1), (x2, y2, weight2), ...]. '), 'shape': (None, 3)}, {'name': 'voxel_mask', 'type': 'array_data', 'default': None, - 'doc': ('Voxel mask for 3D ROIs: [(x1, y1, z1, weight1), (x2, y2, z2, weight2), ...]. This should be used ' - 'for sparse masks, i.e., masks that have few voxels relative to the size of the volume.'), + 'doc': ('Voxel mask for 3D ROIs: [(x1, y1, z1, weight1), (x2, y2, z2, weight2), ...].'), 'shape': (None, 4)}, {'name': 'image_mask', 'type': 'array_data', 'default': None, - 'doc': ('Image with the same size of image where positive values mark the ROI weights for each pixel of ' - 'the image. This should be used when the NWB file will be compressed or when using ' - 'dense masks, i.e., masks where most of the pixels have a ' - 'positive weight. In a compressed file, an image mask will often take up less space ' - 'than a pixel mask, whereas in an uncomprsesed file, a pixel mask will often take up ' - 'less space than an image mask.'), + 'doc': ('Image with the same size of image where positive values mark the ROI weights for ' + 'each pixel of the image.'), 'shape': [[None]*2, [None]*3]}, {'name': 'id', 'type': int, 'doc': 'the ID for the ROI', 'default': None}, allow_extra=True) def add_roi(self, **kwargs): - """Add a Region Of Interest (ROI) data to this""" + """Add a Region Of Interest (ROI) data to this PlaneSegmentation table + + Add an ROI using an image mask, a pixel mask, or a voxel mask. An image mask is an image with + the same size of the data image where positive values mark the ROI weights for each pixel of + the image. A pixel mask is a list of triplets [(x1, y1, weight1), (x2, y2, weight2), ...] or + Nx3 array that indicates the ROI weights for each pixel. Pixels without a weight have a + weight of 0. A voxel mask is a list of quadruplets or Nx4 array, that is similar to the pixel + mask, except the format is (x1, y1, z1, weight1). + + If the NWB file will be compressed, then using an image mask will usually result in a smaller + file than using a pixel mask. However, note that the image mask will be represented as an + array of the same size as the image when read into memory. + + If the NWB file will not be compressed and there are relatively many pixels that comprise the + mask (i.e., a dense mask), then using an image mask will usually result in a smaller file and + memory usage than using a pixel mask. Conversely, if the NWB file will not be compressed and + there are relatively few pixels that comprise the mask (i.e., a sparse mask), then using a + pixel mask will usually result in a smaller file and memory usage than using an image mask. + """ pixel_mask, voxel_mask, image_mask = popargs('pixel_mask', 'voxel_mask', 'image_mask', kwargs) if image_mask is None and pixel_mask is None and voxel_mask is None: - raise ValueError("Must provide 'image_mask' and/or 'pixel_mask'") + raise ValueError("Must provide 'image_mask', 'pixel_mask', or 'voxel_mask'.") rkwargs = dict(kwargs) if image_mask is not None: rkwargs['image_mask'] = image_mask From bfa712e1fc7450ec03a0bbae9a88d71f049f663a Mon Sep 17 00:00:00 2001 From: Ryan Ly Date: Sun, 18 Oct 2020 00:27:20 -0700 Subject: [PATCH 5/5] Fix flake8 --- src/pynwb/ophys.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/pynwb/ophys.py b/src/pynwb/ophys.py index b704504d9..c8fcab0b7 100644 --- a/src/pynwb/ophys.py +++ b/src/pynwb/ophys.py @@ -250,24 +250,24 @@ def __init__(self, **kwargs): {'name': 'id', 'type': int, 'doc': 'the ID for the ROI', 'default': None}, allow_extra=True) def add_roi(self, **kwargs): - """Add a Region Of Interest (ROI) data to this PlaneSegmentation table - + """Add a Region Of Interest (ROI) data to this PlaneSegmentation table + Add an ROI using an image mask, a pixel mask, or a voxel mask. An image mask is an image with the same size of the data image where positive values mark the ROI weights for each pixel of the image. A pixel mask is a list of triplets [(x1, y1, weight1), (x2, y2, weight2), ...] or - Nx3 array that indicates the ROI weights for each pixel. Pixels without a weight have a - weight of 0. A voxel mask is a list of quadruplets or Nx4 array, that is similar to the pixel + Nx3 array that indicates the ROI weights for each pixel. Pixels without a weight have a + weight of 0. A voxel mask is a list of quadruplets or Nx4 array, that is similar to the pixel mask, except the format is (x1, y1, z1, weight1). - + If the NWB file will be compressed, then using an image mask will usually result in a smaller - file than using a pixel mask. However, note that the image mask will be represented as an + file than using a pixel mask. However, note that the image mask will be represented as an array of the same size as the image when read into memory. If the NWB file will not be compressed and there are relatively many pixels that comprise the mask (i.e., a dense mask), then using an image mask will usually result in a smaller file and - memory usage than using a pixel mask. Conversely, if the NWB file will not be compressed and - there are relatively few pixels that comprise the mask (i.e., a sparse mask), then using a - pixel mask will usually result in a smaller file and memory usage than using an image mask. + memory usage than using a pixel mask. Conversely, if the NWB file will not be compressed and + there are relatively few pixels that comprise the mask (i.e., a sparse mask), then using a + pixel mask will usually result in a smaller file and memory usage than using an image mask. """ pixel_mask, voxel_mask, image_mask = popargs('pixel_mask', 'voxel_mask', 'image_mask', kwargs) if image_mask is None and pixel_mask is None and voxel_mask is None: