本文整理汇总了Python中molusce.algorithms.dataprovider.Raster.resetMask方法的典型用法代码示例。如果您正苦于以下问题:Python Raster.resetMask方法的具体用法?Python Raster.resetMask怎么用?Python Raster.resetMask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类molusce.algorithms.dataprovider.Raster
的用法示例。
在下文中一共展示了Raster.resetMask方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_Mask
# 需要导入模块: from molusce.algorithms.dataprovider import Raster [as 别名]
# 或者: from molusce.algorithms.dataprovider.Raster import resetMask [as 别名]
def test_Mask(self):
reference = Raster('../../examples/data.tif')
simulated = Raster('../../examples/data1.tif')
reference.resetMask([2])
simulated.resetMask([2])
eb = EBudget(reference, simulated)
W = eb.W
S1 = weightedSum(eb.Sj[1], W)
S3 = weightedSum(eb.Sj[3], W)
np.testing.assert_almost_equal(S1, 5.0/8)
np.testing.assert_almost_equal(S3, 3.0/8)
noNo = eb.NoNo()
np.testing.assert_almost_equal(noNo, 0.5)
noM = eb.NoMed()
np.testing.assert_almost_equal(noM, (5.0*5/8 + 3.0*3/8)/8)
medM= eb.MedMed()
np.testing.assert_almost_equal(medM, 4.0/8)
medP= eb.MedPer()
np.testing.assert_almost_equal(medP, 1.0)
示例2: TestMCE
# 需要导入模块: from molusce.algorithms.dataprovider import Raster [as 别名]
# 或者: from molusce.algorithms.dataprovider.Raster import resetMask [as 别名]
class TestMCE(unittest.TestCase):
def setUp(self):
self.factor = Raster('../../examples/multifact.tif')
#~ [1,1,3]
#~ [3,2,1]
#~ [0,3,1]
self.state = Raster('../../examples/sites.tif')
self.state.resetMask(maskVals= [0])
#~ [1,2,1],
#~ [1,2,1],
#~ [0,1,2]
self.areaAnalyst = AreaAnalyst(self.state, second=None)
def test_MCE(self):
data = [
[1.0, 4.0, 6.0, 7.0],
[1.0/4, 1.0, 3.0, 4.0],
[1.0/6, 1.0/3, 1.0, 2.0],
[1.0/7, 1.0/4, 1.0/2, 1]
]
# Multiband
factor = Raster('../../examples/two_band.tif')
mce = MCE([self.factor, factor, self.factor], data, 1, 2, self.areaAnalyst)
w = mce.getWeights()
answer = [0.61682294, 0.22382863, 0.09723423, 0.06211421]
assert_almost_equal(w, answer)
# One-band
mce = MCE([self.factor, self.factor, self.factor, self.factor], data, 1, 2, self.areaAnalyst)
w = mce.getWeights()
answer = [0.61682294, 0.22382863, 0.09723423, 0.06211421]
assert_almost_equal(w, answer)
mask = [
[False, False, False],
[False, False, False],
[False, False, True]
]
p = mce.getPrediction(self.state).getBand(1)
self.assertEquals(p.dtype, np.uint8)
answer = [ # The locations where the big numbers are stored must be masked (see mask and self.state)
[1, 3, 1],
[1, 3, 1],
[100, 1, 100]
]
answer = np.ma.array(data = answer, mask = mask)
assert_almost_equal(p, answer)
c = mce.getConfidence().getBand(1)
self.assertEquals(c.dtype, np.uint8)
answer = [ # The locations where the big numbers are stored must be masked (see mask and self.state)
[sum((w*100).astype(int))/3, 0, sum((w*100).astype(int))],
[sum((w*100).astype(int)), 0, sum((w*100).astype(int))/3],
[10000, sum((w*100).astype(int)), 10000]
]
answer = np.ma.array(data = answer, mask = mask)
assert_almost_equal(c, answer)
示例3: TestSimulator
# 需要导入模块: from molusce.algorithms.dataprovider import Raster [as 别名]
# 或者: from molusce.algorithms.dataprovider.Raster import resetMask [as 别名]
class TestSimulator(unittest.TestCase):
def setUp(self):
# Raster1:
# ~ [1, 1, 3,],
# ~ [3, 2, 1,],
# ~ [0, 3, 1,]
self.raster1 = Raster("../../examples/multifact.tif")
self.raster1.resetMask([0])
self.X = np.array([[1, 2, 3], [3, 2, 1], [0, 1, 1]])
self.X = np.ma.array(self.X, mask=(self.X == 0))
self.raster2 = Raster()
self.raster2.create([self.X], self.raster1.getGeodata())
self.aa = AreaAnalyst(self.raster1, self.raster2)
self.crosstab = CrossTableManager(self.raster1, self.raster2)
# Simple model
self.model = Model(state=self.raster1)
def test_compute_table(self):
# print self.crosstab.getCrosstable().getCrosstable()
# CrossTab:
# [[ 3. 1. 0.]
# [ 0. 1. 0.]
# [ 1. 0. 2.]]
prediction = self.model.getPrediction(self.raster1)
# print prediction.getBand(1)
# prediction = [[1.0 1.0 6.0]
# [6.0 5.0 1.0]
# [-- 6.0 1.0]]
# confidence = self.model.getConfidence()
# print confidence.getBand(1)
# confidence = [[1.0 0.5 0.33]
# [0.5 0.33 0.25]
# [-- 0.25 0.2]]
result = np.array([[2.0, 1.0, 3.0], [1.0, 2.0, 1.0], [0, 3.0, 1.0]])
result = np.ma.array(result, mask=(result == 0))
simulator = Simulator(
state=self.raster1, factors=None, model=self.model, crosstable=self.crosstab
) # The model does't use factors
simulator.setIterationCount(1)
simulator.simN()
state = simulator.getState().getBand(1)
assert_array_equal(result, state)
result = np.array([[2.0, 1.0, 1.0], [2.0, 2.0, 1.0], [0, 3.0, 1.0]])
result = np.ma.array(result, mask=(result == 0))
simulator = Simulator(self.raster1, None, self.model, self.crosstab)
simulator.setIterationCount(2)
simulator.simN()
state = simulator.getState().getBand(1)
assert_array_equal(result, state)
示例4: test_cat2vect
# 需要导入模块: from molusce.algorithms.dataprovider import Raster [as 别名]
# 或者: from molusce.algorithms.dataprovider.Raster import resetMask [as 别名]
def test_cat2vect(self):
smp = Sampler(self.state, self.factors, self.output, ns=0)
assert_array_equal(smp.cat2vect(0), [1, 0])
assert_array_equal(smp.cat2vect(1), [0, 1])
assert_array_equal(smp.cat2vect(2), [0, 0])
inputRast = Raster('../../examples/sites.tif')
inputRast.resetMask([0])
smp = Sampler(inputRast, self.factors, self.output, ns=0)
assert_array_equal(smp.cat2vect(1), [1])
assert_array_equal(smp.cat2vect(2), [0])
示例5: test_getStat
# 需要导入模块: from molusce.algorithms.dataprovider import Raster [as 别名]
# 或者: from molusce.algorithms.dataprovider.Raster import resetMask [as 别名]
def test_getStat(self):
reference = Raster('../../examples/data.tif')
simulated = Raster('../../examples/data1.tif')
reference.resetMask([2])
simulated.resetMask([2])
eb = EBudget(reference, simulated)
stat = eb.getStat(nIter=3)
ans0 = {'NoNo': 0.5, 'NoMed': (5.0*5/8 + 3.0*3/8)/8, 'MedMed': 4.0/8, 'MedPer': 1.0, 'PerPer': 1.0}
for k in stat[0].keys():
np.testing.assert_almost_equal(stat[0][k],ans0[k])
ans1 = {'NoNo': 0.5, 'NoMed': (5.0/8+5.0/32 + 3.0/16 + 3.0/32)/2, 'MedMed': 4.0/8, 'MedPer': 1.0, 'PerPer': 1.0}
for k in stat[1].keys():
np.testing.assert_almost_equal(stat[0][k],ans1[k])
示例6: test_get_state
# 需要导入模块: from molusce.algorithms.dataprovider import Raster [as 别名]
# 或者: from molusce.algorithms.dataprovider.Raster import resetMask [as 别名]
def test_get_state(self):
smp = Sampler(self.state, self.factors, self.output, ns=0)
assert_array_equal(smp.get_state(self.state, 1,1), [0, 0])
assert_array_equal(smp.get_state(self.state, 0,0), [0, 1])
smp = Sampler(self.state, self.factors, self.output, ns=1)
res = [ 0, 1, 0, 0, 0, 1,
0, 1, 0, 0, 0, 1,
1, 0, 0, 1, 0, 0,
]
assert_array_equal(smp.get_state(self.state, 1,1), res)
inputRast = Raster('../../examples/sites.tif')
inputRast.resetMask([0])
smp = Sampler(inputRast, self.factors, self.output, ns=0)
assert_array_equal(smp.get_state(self.state, 1,1), [0])
assert_array_equal(smp.get_state(self.state, 0,0), [1])
示例7: TestLRManager
# 需要导入模块: from molusce.algorithms.dataprovider import Raster [as 别名]
# 或者: from molusce.algorithms.dataprovider.Raster import resetMask [as 别名]
class TestLRManager (unittest.TestCase):
def setUp(self):
self.output = Raster('../../examples/multifact.tif')
#~ [1,1,3]
#~ [3,2,1]
#~ [0,3,1]
self.output.resetMask([0])
self.state = self.output
self.factors = [Raster('../../examples/sites.tif'), Raster('../../examples/sites.tif')]
#~ [1,2,1],
#~ [1,2,1],
#~ [0,1,2]
self.output1 = Raster('../../examples/data.tif')
self.state1 = self.output1
self.factors1 = [Raster('../../examples/fact16.tif')]
def test_LR(self):
data = [
[3.0, 1.0, 3.0],
[3.0, 1.0, 3.0],
[0, 3.0, 1.0]
]
result = np.ma.array(data = data, mask = (data==0))
lr = LR(ns=0) # 3-class problem
lr.setTrainingData(self.state, self.factors, self.output)
lr.train()
predict = lr.getPrediction(self.state, self.factors)
predict = predict.getBand(1)
assert_array_equal(predict, result)
lr = LR(ns=1) # Two-class problem (it's because of boundary effect)
lr.setTrainingData(self.state1, self.factors1, self.output1)
lr.train()
predict = lr.getPrediction(self.state1, self.factors1)
predict = predict.getBand(1)
data = [
[0.0, 0.0, 0.0, 0.0],
[0.0, 1.0, 2.0, 0.0],
[0.0, 2.0, 2.0, 0.0],
[0.0, 0.0, 0.0, 0.0],
]
result = np.ma.array(data = data, mask = (data==0))
assert_array_equal(predict, result)
示例8: TestAreaAnalysisManager
# 需要导入模块: from molusce.algorithms.dataprovider import Raster [as 别名]
# 或者: from molusce.algorithms.dataprovider.Raster import resetMask [as 别名]
class TestAreaAnalysisManager (unittest.TestCase):
def setUp(self):
self.r1 = Raster('../../examples/multifact.tif')
# r1 -> r1 transition
self.r1r1 = [
[5, 5, 15,],
[15, 10, 5, ],
[0, 15, 5, ]
]
self.r2 = Raster('../../examples/multifact.tif')
self.r2.resetMask([0])
self.r2r2 = [
[0, 0, 8,],
[8, 4, 0,],
[100, 8, 0,]
]
self.r3 = Raster('../../examples/multifact.tif')
self.r3.resetMask([2])
def test_AreaAnalyst(self):
aa = AreaAnalyst(self.r1, self.r1)
raster = aa.getChangeMap()
band = raster.getBand(1)
assert_array_equal(band, self.r1r1)
# Masked raster
aa = AreaAnalyst(self.r2, self.r2)
raster = aa.getChangeMap()
band = raster.getBand(1)
assert_array_equal(band, self.r2r2)
def test_encode(self):
aa = AreaAnalyst(self.r1, self.r1)
self.assertEqual(aa.classes, [0,1,2,3])
self.assertEqual(aa.encode(1,2), 6)
for initClass in range(4):
for finalClass in range(4):
k = aa.encode(initClass, finalClass)
self.assertEqual(aa.decode(k), (initClass, finalClass))
self.assertEqual(aa.finalCodes(0), [0,1,2,3])
self.assertEqual(aa.finalCodes(1), [4,5,6,7])
示例9: test_coarse
# 需要导入模块: from molusce.algorithms.dataprovider import Raster [as 别名]
# 或者: from molusce.algorithms.dataprovider.Raster import resetMask [as 别名]
def test_coarse(self):
reference = Raster('../../examples/data.tif')
simulated = Raster('../../examples/data1.tif')
reference.resetMask([2])
simulated.resetMask([2])
eb = EBudget(reference, simulated)
eb.coarse(2)
# W
answer = np.array([[1.0, 0.25], [0.5, 0.25]])
np.testing.assert_array_equal(eb.W, answer)
# Rj
answer1 = np.array([[1.0, 1.0], [0, 0]])
answer3 = np.array([[0, 0], [1.0, 1.0]])
ans = {1: answer1, 3: answer3}
np.testing.assert_equal(eb.Rj, ans)
# Sj
answer1 = np.array([[3.0/4, 0.0], [1.0, 0]])
answer3 = np.array([[1.0/4, 1.0], [0, 1.0]])
ans = {1: answer1, 3: answer3}
np.testing.assert_equal(eb.Sj, ans)
eb.coarse(2)
# W
answer = np.array([[0.5]])
np.testing.assert_array_equal(eb.W, answer)
# Rj
answer1 = np.array([[(1+1.0/4)/2]])
answer3 = np.array([[(1.0/2 + 1.0/4)/2]])
ans = {1: answer1, 3: answer3}
np.testing.assert_equal(eb.Rj, ans)
# Sj
answer1 = np.array([[(3.0/4 + 0.5)/2]])
answer3 = np.array([[(1.0/4 + 1.0/4 + 1.0/4 )/2]])
ans = {1: answer1, 3: answer3}
np.testing.assert_equal(eb.Sj, ans)
示例10: TestWoEManager
# 需要导入模块: from molusce.algorithms.dataprovider import Raster [as 别名]
# 或者: from molusce.algorithms.dataprovider.Raster import resetMask [as 别名]
class TestWoEManager (unittest.TestCase):
def setUp(self):
self.factor = Raster('../../examples/multifact.tif')
#~ [1,1,3]
#~ [3,2,1]
#~ [0,3,1]
self.sites = Raster('../../examples/sites.tif')
#~ [1,2,1],
#~ [1,2,1],
#~ [0,1,2]
self.sites.resetMask(maskVals= [0])
self.mask = [
[False, False, False,],
[False, False, False,],
[True, False, False,]
]
fact = [
[1, 1, 3,],
[3, 2, 1,],
[0, 3, 1,]
]
site = [
[False, True, False,],
[False, True, False,],
[False, False, True,]
]
self.factraster = ma.array(data = fact, mask=self.mask, dtype=np.int)
self.sitesraster = ma.array(data = site, mask=self.mask, dtype=np.bool)
def test_CheckBins(self):
aa = AreaAnalyst(self.sites, self.sites)
w1 = WoeManager([self.factor], aa, bins = None)
self.assertTrue(w1.checkBins())
w1 = WoeManager([self.factor], aa, bins = {0: [None]})
self.assertTrue(w1.checkBins())
w1 = WoeManager([self.factor], aa, bins = {0: [[1, 2, 3]]})
self.assertTrue(w1.checkBins())
w1 = WoeManager([self.factor], aa, bins = {0: [[1, 4]]})
self.assertFalse(w1.checkBins())
w1 = WoeManager([self.factor], aa, bins = {0: [[-1, 1]]})
self.assertFalse(w1.checkBins())
w1 = WoeManager([self.factor], aa, bins = {0: [[2, 3, 1]]})
self.assertFalse(w1.checkBins())
def test_WoeManager(self):
aa = AreaAnalyst(self.sites, self.sites)
w1 = WoeManager([self.factor], aa)
w1.train()
p = w1.getPrediction(self.sites).getBand(1)
answer = [[0,3,0], [0,3,0], [9,0,3]]
answer = ma.array(data = answer, mask = self.mask)
assert_array_equal(p, answer)
initState = Raster('../../examples/data.tif')
#~ [1,1,1,1],
#~ [1,1,2,2],
#~ [2,2,2,2],
#~ [3,3,3,3]
finalState = Raster('../../examples/data1.tif')
#~ [1,1,2,3],
#~ [3,1,2,3],
#~ [3,3,3,3],
#~ [1,1,3,2]
aa = AreaAnalyst(initState, finalState)
w = WoeManager([initState], aa)
w.train()
#print w.woe
p = w.getPrediction(initState).getBand(1)
self.assertEquals(p.dtype, np.uint8)
# Calculate by hands:
#1->1 transition raster:
r11 = [
[1, 1, 0, 0],
[0, 1, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
]
#1->2 raster:
r12 = [
[0, 0, 1, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
]
#1->3 raster:
r13 = [
[0, 0, 0, 1],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
]
# 2->1
r21 = [
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
#.........这里部分代码省略.........
示例11: TestLRManager
# 需要导入模块: from molusce.algorithms.dataprovider import Raster [as 别名]
# 或者: from molusce.algorithms.dataprovider.Raster import resetMask [as 别名]
class TestLRManager (unittest.TestCase):
def setUp(self):
self.output = Raster('../../examples/multifact.tif')
#~ [1,1,3]
#~ [3,2,1]
#~ [0,3,1]
self.output.resetMask([0])
self.state = self.output
self.factors = [Raster('../../examples/sites.tif'), Raster('../../examples/sites.tif')]
#~ [1,2,1],
#~ [1,2,1],
#~ [0,1,2]
self.output1 = Raster('../../examples/data.tif')
self.state1 = self.output1
self.factors1 = [Raster('../../examples/fact16.tif')]
def test_LR(self):
#~ data = [
#~ [3.0, 1.0, 3.0],
#~ [3.0, 1.0, 3.0],
#~ [0, 3.0, 1.0]
#~ ]
#~ result = np.ma.array(data = data, mask = (data==0))
lr = LR(ns=0) # 3-class problem
lr.setState(self.state)
lr.setFactors(self.factors)
lr.setOutput(self.output)
lr.setTrainingData()
lr.train()
predict = lr.getPrediction(self.state, self.factors)
predict = predict.getBand(1)
assert_array_equal(predict, self.output.getBand(1))
lr = LR(ns=1) # Two-class problem (it's because of boundary effect)
lr.setState(self.state1)
lr.setFactors(self.factors1)
lr.setOutput(self.output1)
lr.setTrainingData()
lr.train()
predict = lr.getPrediction(self.state1, self.factors1, calcTransitions=True)
predict = predict.getBand(1)
self.assertEquals(predict.dtype, np.uint8)
data = [
[0.0, 0.0, 0.0, 0.0],
[0.0, 1.0, 2.0, 0.0],
[0.0, 2.0, 2.0, 0.0],
[0.0, 0.0, 0.0, 0.0],
]
result = np.ma.array(data = data, mask = (data==0))
assert_array_equal(predict, result)
# Confidence is zero
confid = lr.getConfidence()
self.assertEquals(confid.getBand(1).dtype, np.uint8)
# Transition Potentials
potentials = lr.getTransitionPotentials()
cats = self.output.getBandGradation(1)
for cat in [1.0, 2.0]:
map = potentials[cat]
self.assertEquals(map.getBand(1).dtype, np.uint8)
示例12: TestWoEManager
# 需要导入模块: from molusce.algorithms.dataprovider import Raster [as 别名]
# 或者: from molusce.algorithms.dataprovider.Raster import resetMask [as 别名]
class TestWoEManager(unittest.TestCase):
def setUp(self):
self.factor = Raster("../../examples/multifact.tif")
self.sites = Raster("../../examples/sites.tif")
self.sites.resetMask(maskVals=[0])
mask = [[False, False, False], [False, False, False], [True, False, False]]
fact = [[1, 1, 3], [3, 2, 1], [0, 3, 1]]
site = [[False, True, False], [False, True, False], [False, False, True]]
self.factraster = ma.array(data=fact, mask=mask, dtype=np.int)
self.sitesraster = ma.array(data=site, mask=mask, dtype=np.bool)
def test_WoeManager(self):
aa = AreaAnalyst(self.sites, self.sites)
w1 = WoeManager([self.factor], aa)
p = w1.getPrediction(self.sites).getBand(1)
assert_array_equal(p, self.sites.getBand(1))
initState = Raster("../../examples/data.tif")
finalState = Raster("../../examples/data1.tif")
aa = AreaAnalyst(initState, finalState)
w = WoeManager([initState], aa)
p = w.getPrediction(initState).getBand(1)
# Calculate by hands:
# 1->1 transition raster:
r11 = [[1, 1, 0, 0], [0, 1, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
# 1->2 raster:
r12 = [[0, 0, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
# 1->3 raster:
r13 = [[0, 0, 0, 1], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
# 2->1
r21 = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
# 2->2
r22 = [[0, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
# 2->3
r23 = [[0, 0, 0, 0], [0, 0, 0, 1], [1, 1, 1, 1], [0, 0, 0, 0]]
# 3->1
r31 = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [1, 1, 0, 0]]
# 3->2
r32 = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1]]
# 3->3
r33 = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 1, 0]]
geodata = initState.getGeodata()
sites = {"11": r11, "12": r12, "13": r13, "21": r21, "22": r22, "23": r23, "31": r31, "32": r32, "33": r33}
woeDict = {} # WoE of transitions
for k in sites.keys(): #
if k != "21": # !!! r21 is zero
x = Raster()
x.create([np.ma.array(data=sites[k])], geodata)
sites[k] = x
woeDict[k] = woe(initState.getBand(1), x.getBand(1))
# w1max = np.maximum(woeDict['11'], woeDict['12'], woeDict['13'])
# w2max = np.maximum(woeDict['22'], woeDict['23'])
# w3max = np.maximum(woeDict['31'], woeDict['32'], woeDict['33'])
# Answer is index of finalClass that maximizes weights of transiotion initClass -> finalClass
answer = [[1, 1, 1, 1], [1, 1, 3, 3], [3, 3, 3, 3], [1, 1, 1, 1]]
assert_array_equal(p, answer)
w = WoeManager([initState], aa, bins={0: [[2]]})
p = w.getPrediction(initState).getBand(1)