Skip to content

Commit

Permalink
MNT: Change to staticmethod for datahandler methods
Browse files Browse the repository at this point in the history
  • Loading branch information
scottclowe committed Jun 8, 2021
1 parent 3059d9b commit e878d23
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
3 changes: 2 additions & 1 deletion examples/Basic usage.html
Original file line number Diff line number Diff line change
Expand Up @@ -16745,7 +16745,8 @@ <h3 id="Handling-custom-formats">Handling custom formats<a class="anchor-link" h
<span class="c1"># `image2array` method to work with our custom data format.</span>

<span class="k">class</span> <span class="nc">DataHandlerCustom</span><span class="p">(</span><span class="n">DataHandlerTifffile</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">image2array</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">image</span><span class="p">):</span>
<span class="nd">@staticmethod</span>
<span class="k">def</span> <span class="nf">image2array</span><span class="p">(</span><span class="n">image</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Open a given image file as a custom instance.</span>

<span class="sd"> Parameters</span>
Expand Down
3 changes: 2 additions & 1 deletion examples/Basic usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2326,7 +2326,8 @@
"# `image2array` method to work with our custom data format.\n",
"\n",
"class DataHandlerCustom(DataHandlerTifffile):\n",
" def image2array(self, image):\n",
" @staticmethod\n",
" def image2array(image):\n",
" \"\"\"Open a given image file as a custom instance.\n",
"\n",
" Parameters\n",
Expand Down
41 changes: 24 additions & 17 deletions fissa/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ class DataHandlerAbstract():
See :class:`DataHandlerTifffile` and :class:`DataHandlerPillow` for example
subclasses.
"""
def __init__(self):
pass

def image2array(self, image):
@staticmethod
def image2array(image):
"""
Load data (from a path) as an array, or similar internal structure.
Expand All @@ -55,7 +53,8 @@ def image2array(self, image):
"""
raise NotImplementedError()

def getmean(self, data):
@staticmethod
def getmean(data):
"""
Determine the mean image across all frames.
Expand All @@ -73,7 +72,8 @@ def getmean(self, data):
"""
raise NotImplementedError()

def rois2masks(self, rois, data):
@staticmethod
def rois2masks(rois, data):
"""
Convert `rois` into a collection of binary masks.
Expand All @@ -91,7 +91,8 @@ def rois2masks(self, rois, data):
"""
raise NotImplementedError()

def extracttraces(self, data, masks):
@staticmethod
def extracttraces(data, masks):
"""
Extract from data the average signal within each mask, across time.
Expand All @@ -116,8 +117,8 @@ class DataHandlerTifffile(DataHandlerAbstract):
"""
Extract data from TIFF images using tifffile.
"""

def image2array(self, image):
@staticmethod
def image2array(image):
"""
Load a TIFF image from disk.
Expand All @@ -136,7 +137,8 @@ def image2array(self, image):
return tifffile.imread(image)
return np.array(image)

def getmean(self, data):
@staticmethod
def getmean(data):
"""
Determine the mean image across all frames.
Expand All @@ -152,7 +154,8 @@ def getmean(self, data):
"""
return data.mean(axis=0)

def rois2masks(self, rois, data):
@staticmethod
def rois2masks(rois, data):
"""Take the object `rois` and returns it as a list of binary masks.
Parameters
Expand Down Expand Up @@ -192,7 +195,8 @@ def rois2masks(self, rois, data):

raise ValueError('Wrong ROIs input format: unfamiliar shape.')

def extracttraces(self, data, masks):
@staticmethod
def extracttraces(data, masks):
"""
Extract a temporal trace for each spatial mask.
Expand Down Expand Up @@ -229,8 +233,8 @@ class DataHandlerPillow(DataHandlerAbstract):
Slower, but less memory-intensive than :class:`DataHandlerTifffile`.
"""

def image2array(self, image):
@staticmethod
def image2array(image):
"""
Open an image file as a :class:`PIL.Image` instance.
Expand All @@ -247,7 +251,8 @@ def image2array(self, image):
"""
return Image.open(image)

def getmean(self, data):
@staticmethod
def getmean(data):
"""
Determine the mean image across all frames.
Expand Down Expand Up @@ -279,7 +284,8 @@ def getmean(self, data):
avg /= data.n_frames
return avg

def rois2masks(self, rois, data):
@staticmethod
def rois2masks(rois, data):
"""
Take the object `rois` and returns it as a list of binary masks.
Expand Down Expand Up @@ -319,7 +325,8 @@ def rois2masks(self, rois, data):

raise ValueError('Wrong ROIs input format: unfamiliar shape.')

def extracttraces(self, data, masks):
@staticmethod
def extracttraces(data, masks):
"""
Extract the average signal within each mask across the data.
Expand Down

0 comments on commit e878d23

Please sign in to comment.