예제 #1
0
 def test_different_dimensions(self):
     dataset = xr.Dataset({
         'var': ('x', [1, 2]),
         'var2': ('y', [3, 4]),
         'var3': (('x', 'y'), [[5, 6], [7, 8]]),
         'var4': (('y', 'x'), [[9, 10], [11, 12]]),
     })
     array = CalculatedArray(dataset, "var + var2", ['x'])
     self.assertIsNan(array[0])
     array = CalculatedArray(dataset, "var3 + var4", ['x'])
     self.assertIsNan(array[0, 0])
     array = CalculatedArray(dataset, "var + var3", ['x', 'y'])
     self.assertEqual(array[0, 0], 6)
     self.assertEqual(array[0, 1], 7)
     self.assertEqual(array[1, 0], 9)
     self.assertEqual(array[1, 1], 10)
예제 #2
0
    def test_attrs(self):
        attrs = {"my_attr": 420}

        dataset = xr.Dataset()
        array = CalculatedArray(dataset, "3 * 5", [], attrs)
        self.assertEqual(array[:].attrs, attrs)
        self.assertEqual(array.attrs, attrs)
예제 #3
0
 def test_multiple_expression(self):
     dataset = xr.Dataset({
         'var': ('x', [1, 2, 3, 4, 5]),
         'var2': ('x', [5, 4, 3, 2, 1]),
     })
     array = CalculatedArray(dataset, "var + var2", ['x'])
     self.assertEqual(array[0], 6)
     self.assertEqual(array[2], 6)
     self.assertEqual(array[4], 6)
예제 #4
0
 def test_different_dimensions(self):
     dataset = xr.Dataset(
         {
             "var": ("x", [1, 2]),
             "var2": ("y", [3, 4]),
             "var3": (("x", "y"), [[5, 6], [7, 8]]),
             "var4": (("y", "x"), [[9, 10], [11, 12]]),
         }
     )
     array = CalculatedArray(dataset, "var + var2", ["x"])
     self.assertIsNan(array[0])
     array = CalculatedArray(dataset, "var3 + var4", ["x"])
     self.assertIsNan(array[0, 0])
     array = CalculatedArray(dataset, "var + var3", ["x", "y"])
     self.assertEqual(array[0, 0], 6)
     self.assertEqual(array[0, 1], 7)
     self.assertEqual(array[1, 0], 9)
     self.assertEqual(array[1, 1], 10)
예제 #5
0
 def test_multiple_expression(self):
     dataset = xr.Dataset(
         {
             "var": ("x", [1, 2, 3, 4, 5]),
             "var2": ("x", [5, 4, 3, 2, 1]),
         }
     )
     array = CalculatedArray(dataset, "var + var2", ["x"])
     self.assertEqual(array[0], 6)
     self.assertEqual(array[2], 6)
     self.assertEqual(array[4], 6)
예제 #6
0
 def test_single_expression(self):
     dataset = xr.Dataset({'var': ('x', [1, 2, 3, 4, 5])})
     array = CalculatedArray(dataset, "var * 5", ['x'])
     self.assertEqual(array[0], 5)
     self.assertEqual(array[2], 15)
     self.assertEqual(array[4], 25)
예제 #7
0
 def test_passthrough(self):
     dataset = xr.Dataset({'var': ('x', [1, 2, 3, 4, 5])})
     array = CalculatedArray(dataset, "var", ['x'])
     self.assertEqual(array[0], 1)
     self.assertEqual(array[2], 3)
     self.assertEqual(array[4], 5)
예제 #8
0
 def test_static(self):
     dataset = xr.Dataset()
     array = CalculatedArray(dataset, "3 * 5", [])
     self.assertEqual(array[0], 15)