Пример #1
0
 def test_03(self):
     """ cellvalue_by_index Ordinal """
     raster = pcraster.ordinal(self._read_set_clone("areaarea_Class.map"))
     value, isValid = pcraster.cellvalue_by_index(raster, 0)
     self.assertEqual(isValid, True)
     self.assertTrue(isinstance(value, int))
     self.assertEqual(value, 2)
     value, isValid = pcraster.cellvalue_by_index(raster, 1)
     self.assertEqual(isValid, True)
     self.assertTrue(isinstance(value, int))
     self.assertEqual(value, 6)
     value, isValid = pcraster.cellvalue_by_index(raster, 4)
     self.assertEqual(isValid, False)
Пример #2
0
 def test_07(self):
     """ cellvalue_by_index NonSpatial """
     raster = self._read_set_clone("abs_Expr.map")
     value, isValid = pcraster.cellvalue_by_indices(pcraster.mapmaximum(raster), 0, 0)
     self.assertEqual(isValid, True)
     self.assertTrue(isinstance(value, float))
     self.assertEqual(value, 14.0)
     value, isValid = pcraster.cellvalue_by_index(pcraster.mapmaximum(raster), 0)
     self.assertEqual(isValid, True)
     self.assertTrue(isinstance(value, float))
     self.assertEqual(value, 14.0)
Пример #3
0
 def test_05(self):
     """ cellvalue_by_index Directional """
     raster = self._read_set_clone("nodirection_Expr.map")
     value, isValid = pcraster.cellvalue_by_index(raster, 0)
     self.assertEqual(isValid, True)
     self.assertTrue(isinstance(value, float))
     self.assertAlmostEqual(value, math.radians(280))
     value, isValid = pcraster.cellvalue_by_index(raster, 1)
     self.assertEqual(isValid, True)
     self.assertTrue(isinstance(value, float))
     self.assertAlmostEqual(value, math.radians(25))
     value, isValid = pcraster.cellvalue_by_index(raster, 4)
     self.assertEqual(isValid, True)
     self.assertTrue(isinstance(value, float))
     self.assertAlmostEqual(value, -1.0)
     value, isValid = pcraster.cellvalue_by_index(raster, 6)
     self.assertEqual(isValid, False)
     value, isValid = pcraster.cellvalue_by_index(raster, 8)
     self.assertEqual(isValid, True)
     self.assertTrue(isinstance(value, float))
     self.assertAlmostEqual(value, math.radians(7))
Пример #4
0
 def test_04(self):
     """ cellvalue_by_index Scalar """
     raster = self._read_set_clone("abs_Expr.map")
     value, isValid = pcraster.cellvalue_by_index(raster, 0)
     self.assertEqual(isValid, True)
     self.assertTrue(isinstance(value, float))
     self.assertEqual(value, 2.0)
     value, isValid = pcraster.cellvalue_by_index(raster, 1)
     self.assertEqual(isValid, True)
     self.assertTrue(isinstance(value, float))
     self.assertEqual(value, -7.0)
     value, isValid = pcraster.cellvalue_by_index(raster, 2)
     self.assertEqual(isValid, True)
     self.assertTrue(isinstance(value, float))
     self.assertEqual(value, 3.5)
     value, isValid = pcraster.cellvalue_by_index(raster, 5)
     self.assertEqual(isValid, False)
     value, isValid = pcraster.cellvalue_by_index(raster, 6)
     self.assertEqual(isValid, True)
     self.assertTrue(isinstance(value, float))
     self.assertEqual(value, 0.0)
     value, isValid = pcraster.cellvalue_by_index(raster, 7)
     self.assertEqual(isValid, True)
     self.assertTrue(isinstance(value, float))
     self.assertEqual(value, 14.0)
Пример #5
0
 def test_06(self):
     """ cellvalue_by_index Ldd"""
     raster = self._read_set_clone("accu_Ldd.map")
     value, isValid = pcraster.cellvalue_by_index(raster, 0)
     self.assertEqual(isValid, True)
     self.assertTrue(isinstance(value, int))
     self.assertEqual(value, 2)
     value, isValid = pcraster.cellvalue_by_index(raster, 1)
     self.assertEqual(isValid, True)
     self.assertTrue(isinstance(value, int))
     self.assertEqual(value, 2)
     value, isValid = pcraster.cellvalue_by_index(raster, 8)
     self.assertEqual(isValid, True)
     self.assertTrue(isinstance(value, int))
     self.assertEqual(value, 1)
     value, isValid = pcraster.cellvalue_by_index(raster, 21)
     self.assertEqual(isValid, True)
     self.assertTrue(isinstance(value, int))
     self.assertEqual(value, 5)
     value, isValid = pcraster.cellvalue_by_index(raster, 24)
     self.assertEqual(isValid, True)
     self.assertTrue(isinstance(value, int))
     self.assertEqual(value, 4)
Пример #6
0
 def test_01(self):
     """ cellvalue_by_index Boolean """
     raster = pcraster.readmap("and_Expr1.map")
     value, isValid = pcraster.cellvalue_by_index(raster, 0)
     self.valueTest(value, isValid, True, int, True)
     value, isValid = pcraster.cellvalue_by_index(raster, 1)
     self.valueTest(value, isValid, True, int, True)
     value, isValid = pcraster.cellvalue_by_index(raster, 2)
     self.valueTest(value, isValid, True, int, False)
     value, isValid = pcraster.cellvalue_by_index(raster, 3)
     self.valueTest(value, isValid, True, int, False)
     value, isValid = pcraster.cellvalue_by_index(raster, 4)
     self.valueTest(value, isValid, False, None, None)
     value, isValid = pcraster.cellvalue_by_index(raster, 5)
     self.valueTest(value, isValid, True, int, False)
     value, isValid = pcraster.cellvalue_by_index(raster, 6)
     self.valueTest(value, isValid, True, int, True)
     value, isValid = pcraster.cellvalue_by_index(raster, 7)
     self.valueTest(value, isValid, True, int, True)
     value, isValid = pcraster.cellvalue_by_index(raster, 8)
     self.valueTest(value, isValid, True, int, False)
Пример #7
0
    def test_08(self):
        """ cellvalue_by exceptions """

        raster = self._read_set_clone("abs_Expr.map")

        with self.assertRaises(Exception) as context_manager:
            value, isValid = pcraster.cellvalue_by_index(raster, 9)
        self.assertEqual(str(context_manager.exception), "cellvalue index '9' out of range [0, 8]")

        with self.assertRaises(Exception) as context_manager:
            value, isValid = pcraster.cellvalue_by_indices(raster, 9, 0)
        self.assertEqual(str(context_manager.exception), "cellvalue row index '9' out of range [0, 2]")

        with self.assertRaises(Exception) as context_manager:
            value, isValid = pcraster.cellvalue_by_indices(raster, 0, 9)
        self.assertEqual(str(context_manager.exception), "cellvalue column index '9' out of range [0, 2]")