Пример #1
0
    class ScaleLinear(PyBioSchema):
        axes = fields.Axes(required=True, valid_axes="czyx")
        gain = fields.Array(fields.Float(), missing=fields.Float(
            missing=1.0))  # todo: check if gain match input axes
        offset = fields.Array(
            fields.Float(), missing=fields.Float(
                missing=0.0))  # todo: check if offset match input axes

        @validates_schema
        def either_gain_or_offset(self, data, **kwargs):
            if data["gain"] == 1.0 and data["offset"] == 0:
                raise PyBioValidationException(
                    "Specify gain!=1.0 or offset!=0.0")
Пример #2
0
    class ZeroMeanUnitVariance(PyBioSchema):
        mode = fields.ProcMode(required=True)
        axes = fields.Axes(required=True, valid_axes="czyx")
        mean = fields.Array(
            fields.Float(), missing=None
        )  # todo: check if means match input axes (for mode 'fixed')
        std = fields.Array(fields.Float(), missing=None)
        eps = fields.Float(missing=1e-6)

        @validates_schema
        def mean_and_std_match_mode(self, data, **kwargs):
            if data["mode"] == "fixed" and (data["mean"] is None
                                            or data["std"] is None):
                raise PyBioValidationException(
                    "`kwargs` for 'zero_mean_unit_variance' preprocessing with `mode` 'fixed' require additional `kwargs`: `mean` and `std`."
                )
            elif data["mode"] != "fixed" and (data.get("mean") is not None
                                              or data.get("std") is not None):
                raise PyBioValidationException(
                    "`kwargs`: `mean` and `std` for 'zero_mean_unit_variance' preprocessing are only valid for `mode` 'fixed'."
                )
Пример #3
0
 def test_wrong_dtype(self):
     data = [[1, 2], [3, 4.5]]
     with raises(ValidationError):
         fields.Array(fields.Integer(strict=True)).deserialize(data)
Пример #4
0
 def test_2d(self):
     data = [[1, 2], [3, 4]]
     expected = numpy.array(data, dtype=int)
     actual = fields.Array(fields.Integer(strict=True)).deserialize(data)
     assert_equal(actual, expected)
Пример #5
0
 def test_invalid_scalar(self):
     data = "invalid"
     with raises(ValidationError):
         fields.Array(fields.Integer(strict=True)).deserialize(data)
Пример #6
0
 def test_scalar(self):
     data = 1
     expected = data
     actual = fields.Array(fields.Integer(strict=True)).deserialize(data)
     assert_equal(actual, expected)
Пример #7
0
 def test_uneuqal_sublen(self):
     with raises(ValidationError):
         fields.Array(fields.Integer(strict=True)).deserialize([[1, 2],
                                                                [3]])
Пример #8
0
 def test_unequal_nesting_depth(self):
     with raises(ValidationError):
         fields.Array(fields.Integer(strict=True)).deserialize([[1, 2], 3])