Example #1
0
 def test_array_slice(self):
     """Test slices applied to a grid."""
     dataset = apply_projection(parse_projection("SimpleGrid[1]"),
                                self.dataset)
     np.testing.assert_array_equal(dataset.SimpleGrid.x.data,
                                   self.dataset.SimpleGrid[1].x.data)
     np.testing.assert_array_equal(dataset.SimpleGrid.y.data,
                                   self.dataset.SimpleGrid[1].y.data)
     np.testing.assert_array_equal(
         dataset.SimpleGrid.SimpleGrid.data,
         self.dataset.SimpleGrid[1:2].SimpleGrid.data)
Example #2
0
 def test_array_slice(self):
     """Test slices applied to a grid."""
     dataset = apply_projection(
         parse_projection("SimpleGrid[1]"), self.dataset)
     np.testing.assert_array_equal(
         dataset.SimpleGrid.x.data, self.dataset.SimpleGrid[1].x.data)
     np.testing.assert_array_equal(
         dataset.SimpleGrid.y.data, self.dataset.SimpleGrid[1].y.data)
     np.testing.assert_array_equal(
         dataset.SimpleGrid.SimpleGrid.data,
         self.dataset.SimpleGrid[1:2].SimpleGrid.data)
Example #3
0
 def test_structure_projection(self):
     """Test projection slicing on a structure."""
     with self.assertRaises(ConstraintExpressionError):
         apply_projection(parse_projection("types[0]"), SimpleStructure)
Example #4
0
 def test_sequence_projection(self):
     """Test projection slicing on sequences."""
     dataset = apply_projection(parse_projection("sequence[2]"),
                                self.dataset)
     np.testing.assert_array_equal(dataset.sequence.data,
                                   VerySimpleSequence.sequence.data[2])
Example #5
0
 def test_array(self):
     """Test that the grid degenerates into a structure."""
     dataset = apply_projection(parse_projection("SimpleGrid.SimpleGrid"),
                                self.dataset)
     self.assertIsInstance(dataset.SimpleGrid, StructureType)
Example #6
0
 def test_simple_projection_with_index(self):
     """Test simple projections."""
     dataset = apply_projection(parse_projection("x[1]"), self.dataset)
     np.testing.assert_array_equal(dataset.x.data, [1])
Example #7
0
 def test_simple_projection_with_index(self):
     """Test simple projections."""
     dataset = apply_projection(parse_projection("x[1]"), self.dataset)
     np.testing.assert_array_equal(
         dataset.x.data, [1])
Example #8
0
 def test_hyperslab(self):
     """Test a projection with a hyperslab."""
     parsed = parse_projection("a,b.c[0:2:9]")
     self.assertEqual(
         parsed, [[("a", ())], [("b", ()), ("c", (slice(0, 10, 2),))]])
Example #9
0
 def test_hyperslab(self):
     """Test a projection with a hyperslab."""
     parsed = parse_projection("a,b.c[0:2:9]")
     self.assertEqual(parsed, [[("a", ())], [("b", ()), ("c", (slice(0, 10, 2),))]])
Example #10
0
 def test_deep(self):
     """Test a projection with a deep id."""
     parsed = parse_projection("a.b.c,d")
     self.assertEqual(parsed, [[("a", ()), ("b", ()), ("c", ())], [("d", ())]])
Example #11
0
 def test_basic(self):
     """Test a basic projection."""
     parsed = parse_projection("a,b,c")
     self.assertEqual(parsed, [[("a", ())], [("b", ())], [("c", ())]])
Example #12
0
 def test_structure_projection(self):
     """Test projection slicing on a structure."""
     with self.assertRaises(ConstraintExpressionError):
         apply_projection(parse_projection("types[0]"), SimpleStructure)
Example #13
0
 def test_sequence_projection(self):
     """Test projection slicing on sequences."""
     dataset = apply_projection(
         parse_projection("sequence[2]"), self.dataset)
     np.testing.assert_array_equal(
         dataset.sequence.data, VerySimpleSequence.sequence.data[2])
Example #14
0
 def test_array(self):
     """Test that the grid degenerates into a structure."""
     dataset = apply_projection(
         parse_projection("SimpleGrid.SimpleGrid"), self.dataset)
     self.assertIsInstance(dataset.SimpleGrid, StructureType)
Example #15
0
 def test_basic(self):
     """Test a basic projection."""
     parsed = parse_projection("a,b,c")
     self.assertEqual(parsed, [[("a", ())], [("b", ())], [("c", ())]])
Example #16
0
 def test_nested_function_call(self):
     """Test a projection with a function call."""
     parsed = parse_projection("mean(mean(a[0],1))")
     self.assertEqual(parsed, ["mean(mean(a[0],1))"])
Example #17
0
 def test_deep(self):
     """Test a projection with a deep id."""
     parsed = parse_projection("a.b.c,d")
     self.assertEqual(
         parsed, [[("a", ()), ("b", ()), ("c", ())], [("d", ())]])
Example #18
0
 def test_simple_projection(self):
     """Test simple projections."""
     dataset = apply_projection(parse_projection("x"), self.dataset)
     self.assertEqual(list(dataset.keys()), ["x"])
Example #19
0
 def test_nested_function_call(self):
     """Test a projection with a function call."""
     parsed = parse_projection("mean(mean(a[0],1))")
     self.assertEqual(
         parsed, ['mean(mean(a[0],1))'])
Example #20
0
 def test_simple_projection(self):
     """Test simple projections."""
     dataset = apply_projection(parse_projection("x"), self.dataset)
     self.assertEqual(list(dataset.keys()), ["x"])