def test_insufficient_coordinates(self):
     with self.assertRaises(ValueError):
         OceanSigmaFactory()
     with self.assertRaises(ValueError):
         OceanSigmaFactory(sigma=None, eta=self.eta, depth=self.depth)
     with self.assertRaises(ValueError):
         OceanSigmaFactory(sigma=self.sigma, eta=None, depth=self.depth)
     with self.assertRaises(ValueError):
         OceanSigmaFactory(sigma=self.sigma, eta=self.eta, depth=None)
 def test_derived_points(self):
     # Broadcast expected points given the known dimensional mapping.
     sigma = self.sigma.points[..., np.newaxis, np.newaxis]
     eta = self.eta.points[np.newaxis, ...]
     depth = self.depth.points[np.newaxis, ...]
     # Calculate the expected result.
     expected_coord = self.derive(sigma, eta, depth)
     # Calculate the actual result.
     factory = OceanSigmaFactory(**self.kwargs)
     coord = factory.make_coord(self.coord_dims)
     self.assertEqual(expected_coord, coord)
示例#3
0
 def test_derived_points(self):
     # Broadcast expected points given the known dimensional mapping.
     sigma = self.sigma.points[..., np.newaxis, np.newaxis]
     eta = self.eta.points[np.newaxis, ...]
     depth = self.depth.points[np.newaxis, ...]
     # Calculate the expected result.
     expected_coord = self.derive(sigma, eta, depth)
     # Calculate the actual result.
     factory = OceanSigmaFactory(**self.kwargs)
     coord = factory.make_coord(self.coord_dims)
     self.assertEqual(expected_coord, coord)
 def test_values(self):
     factory = OceanSigmaFactory(**self.kwargs)
     self.assertEqual(factory.dependencies, self.kwargs)
 def test_depth_incompatible_units(self):
     self.depth.units = Unit('km')
     with self.assertRaises(ValueError):
         OceanSigmaFactory(**self.kwargs)
 def test_sigma_too_many_bounds(self):
     self.sigma.nbounds = 4
     with self.assertRaises(ValueError):
         OceanSigmaFactory(**self.kwargs)
 def setUp(self):
     self.sigma = mock.Mock(units=Unit('1'), nbounds=0)
     self.eta = mock.Mock(units=Unit('m'), nbounds=0)
     self.depth = mock.Mock(units=Unit('m'), nbounds=0)
     self.kwargs = dict(sigma=self.sigma, eta=self.eta, depth=self.depth)
     self.factory = OceanSigmaFactory(**self.kwargs)
class Test_update(tests.IrisTest):
    def setUp(self):
        self.sigma = mock.Mock(units=Unit('1'), nbounds=0)
        self.eta = mock.Mock(units=Unit('m'), nbounds=0)
        self.depth = mock.Mock(units=Unit('m'), nbounds=0)
        self.kwargs = dict(sigma=self.sigma, eta=self.eta, depth=self.depth)
        self.factory = OceanSigmaFactory(**self.kwargs)

    def test_sigma(self):
        new_sigma = mock.Mock(units=Unit('1'), nbounds=0)
        self.factory.update(self.sigma, new_sigma)
        self.assertIs(self.factory.sigma, new_sigma)

    def test_sigma_too_many_bounds(self):
        new_sigma = mock.Mock(units=Unit('1'), nbounds=4)
        with self.assertRaises(ValueError):
            self.factory.update(self.sigma, new_sigma)

    def test_sigma_incompatible_units(self):
        new_sigma = mock.Mock(units=Unit('Pa'), nbounds=0)
        with self.assertRaises(ValueError):
            self.factory.update(self.sigma, new_sigma)

    def test_eta(self):
        new_eta = mock.Mock(units=Unit('m'), nbounds=0)
        self.factory.update(self.eta, new_eta)
        self.assertIs(self.factory.eta, new_eta)

    def test_eta_incompatible_units(self):
        new_eta = mock.Mock(units=Unit('Pa'), nbounds=0)
        with self.assertRaises(ValueError):
            self.factory.update(self.eta, new_eta)

    def test_depth(self):
        new_depth = mock.Mock(units=Unit('m'), nbounds=0)
        self.factory.update(self.depth, new_depth)
        self.assertIs(self.factory.depth, new_depth)

    def test_depth_incompatible_units(self):
        new_depth = mock.Mock(units=Unit('Pa'), nbounds=0)
        with self.assertRaises(ValueError):
            self.factory.update(self.depth, new_depth)
示例#9
0
 def setUp(self):
     self.sigma = mock.Mock(units=Unit('1'), nbounds=0)
     self.eta = mock.Mock(units=Unit('m'), nbounds=0)
     self.depth = mock.Mock(units=Unit('m'), nbounds=0)
     self.kwargs = dict(sigma=self.sigma, eta=self.eta, depth=self.depth)
     self.factory = OceanSigmaFactory(**self.kwargs)
示例#10
0
class Test_update(tests.IrisTest):
    def setUp(self):
        self.sigma = mock.Mock(units=Unit('1'), nbounds=0)
        self.eta = mock.Mock(units=Unit('m'), nbounds=0)
        self.depth = mock.Mock(units=Unit('m'), nbounds=0)
        self.kwargs = dict(sigma=self.sigma, eta=self.eta, depth=self.depth)
        self.factory = OceanSigmaFactory(**self.kwargs)

    def test_sigma(self):
        new_sigma = mock.Mock(units=Unit('1'), nbounds=0)
        self.factory.update(self.sigma, new_sigma)
        self.assertIs(self.factory.sigma, new_sigma)

    def test_sigma_too_many_bounds(self):
        new_sigma = mock.Mock(units=Unit('1'), nbounds=4)
        with self.assertRaises(ValueError):
            self.factory.update(self.sigma, new_sigma)

    def test_sigma_incompatible_units(self):
        new_sigma = mock.Mock(units=Unit('Pa'), nbounds=0)
        with self.assertRaises(ValueError):
            self.factory.update(self.sigma, new_sigma)

    def test_eta(self):
        new_eta = mock.Mock(units=Unit('m'), nbounds=0)
        self.factory.update(self.eta, new_eta)
        self.assertIs(self.factory.eta, new_eta)

    def test_eta_incompatible_units(self):
        new_eta = mock.Mock(units=Unit('Pa'), nbounds=0)
        with self.assertRaises(ValueError):
            self.factory.update(self.eta, new_eta)

    def test_depth(self):
        new_depth = mock.Mock(units=Unit('m'), nbounds=0)
        self.factory.update(self.depth, new_depth)
        self.assertIs(self.factory.depth, new_depth)

    def test_depth_incompatible_units(self):
        new_depth = mock.Mock(units=Unit('Pa'), nbounds=0)
        with self.assertRaises(ValueError):
            self.factory.update(self.depth, new_depth)
示例#11
0
 def test_eta_incompatible_units(self):
     self.eta.units = Unit("km")
     with self.assertRaises(ValueError):
         OceanSigmaFactory(**self.kwargs)
示例#12
0
 def test_promote_sigma_units_unknown_to_dimensionless(self):
     sigma = mock.Mock(units=Unit("unknown"), nbounds=0)
     self.kwargs["sigma"] = sigma
     factory = OceanSigmaFactory(**self.kwargs)
     self.assertEqual("1", factory.dependencies["sigma"].units)