Esempio n. 1
0
class Histogram(Processor):
    bins = Param(int, 256)

    def function(self, data):
        hists = np.stack([
            np.stack([
                np.histogram(arr.reshape(arr.shape[0],
                                         np.prod(arr.shape[1:3])),
                             bins=self.bins,
                             density=True) for arr in channel
            ]) for channel in data.transpose(3, 0, 1, 2)
        ])
        return hists
Esempio n. 2
0
class Normalize(Processor):
    axes = Param(tuple, (1, 2))

    def function(self, data):
        data = data / data.sum(self.axes, keepdims=True)
        return data
Esempio n. 3
0
 def test_instatiation():
     """Param should instatiate correctly when passing any dtype."""
     Param(object)
Esempio n. 4
0
 def test_dtype_single_to_tuple():
     """A single dtype should result in a class parameter of a tuple with a single type."""
     param = Param(object)
     assert param.dtype == (object, )
Esempio n. 5
0
 def test_dtype_multiple():
     """Param should support multiple dtypes in a tuple."""
     param = Param((object, type))
     assert param.dtype == (object, type)
Esempio n. 6
0
 def test_dtype_no_type():
     """A TypeError should be raised when dtype is not a type."""
     with pytest.raises(TypeError):
         Param('monkey')
Esempio n. 7
0
 def test_dtype_not_assigned():
     """A TypeError should be raised when not providing any dtype."""
     with pytest.raises(TypeError):
         # pylint: disable=no-value-for-parameter
         Param()