-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharcpyBuildInputMaskForLFT_v2.py
More file actions
796 lines (672 loc) · 24.1 KB
/
arcpyBuildInputMaskForLFT_v2.py
File metadata and controls
796 lines (672 loc) · 24.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
####################################################################
# This script builds the input mask for the LFT based on FACET
#
#
# - Previously the mask was built manually and then refined with script arcpyBuildSelectionMaskForNFandWD.py
# To filter out fragmented forest caused by small rivers and NF patches.
# - This mask is built on facet
# - Have to run this to get the baseline 2000 mask that's built on FACET, subsequent script replaces other years though.
#
# Version History
# GM 06/25/2014
# revision for v14
# 10/30/2014
# 11/09/2014
# 04/2018 revision for v18 - in this version run for just 2018?
####################################################################
####################################################################
#Import arcpy modules
import arcpy
from arcpy import env
from arcpy.sa import *
import os
# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")
# If you want to overwrite output files
# arcpy.env.overwriteOutput=True
####################################################################
# Global variables
# LFT directory
root=r"C:\Data_Molinario\temp\LFT_local\19th_run"
# FACET class masks folder
facetMasks=r"C:\Data_Molinario\temp\LFT_local\19th_run\FACET_class_masks"
# Secondary forest folder
sfMaskFolder=r"C:\Data_Molinario\temp\LFT_local\19th_run\FACET_class_masks\Secondary_forest\SF_2000"
#FACET folder
facetFolder=r"C:\Data_Molinario\temp\LFT_local\19th_run\FACET_ROC"
# SF and loss masks expansions for LFT input mask building
facetMaskWorkFolder=r"SF_and_Loss_Masks_for_NF_WD_selection\\v19"
facetMaskWorkFolderPath=facetMasks+"/"+facetMaskWorkFolder
if not os.path.exists(facetMaskWorkFolderPath):
os.makedirs(facetMaskWorkFolderPath)
print "Made "+facetMaskWorkFolder+" folder."
# if needed, if I don't rebuild from scratch.
# Raw LFT input mask
# Contains all SF, all NF and all WD as class (1) Perforating element
# rawInputMask=root+"Raw_LFT_Input_Mask"
# Threshold value for region group to separate buffers of NF and WD
# threshold=200
# Periods of LFT
LFTs= ["2000","2005", "2010", "2015"]
# Build root folder structure to put final Master LFT input masks in
# Master folder
lftMaster = "Master"
for lft in LFTs:
# Period folder
outputFolder=str(lft)
# Period folder path
outputFolderPath = root+"/"+outputFolder
# Create the folder if it doesn't exist
if not os.path.exists(outputFolderPath):
os.makedirs(outputFolderPath)
print "Made "+str(lft)+" folder."
# Create the master folder in it
masterFolderPath=outputFolderPath+"/"+lftMaster
if not os.path.exists(masterFolderPath):
os.makedirs(masterFolderPath)
print "Made Master folder for "+str(lft)+"."
# Insert path to raster to snap to
tempEnvironment0 = arcpy.env.snapRaster
arcpy.env.snapRaster = r"C:\Data_Molinario\temp\LFT_local\19th_run\FACET_ROC\myfacet.tif"
# Set extent to FACET extent
arcpy.env.extent = r"C:\Data_Molinario\temp\LFT_local\19th_run\FACET_ROC\myfacet.tif"
arcpy.env.overwriteOutput=True
###############################################################################
################################################
# Manually build folders that are not automated:
################################################
# - Raw_input_mask (unless I build it with script)
# - Core_stratification and Rural_complex folder (unless they are completely automated - check following.
# - is the water distinction for core classification automated?
# - is the focal distance creation for NF and WD automated?
# - WaterAndNoData folder
# - AOI folder
################################################
# Readme - process to build LFT input mask
################################################
# For 2000 include:
# Class 0: All water and NoData, all large NF and WD not close to loss.
# Class 1:
# - SF only if large groups or small groups if in proximity of PFL or SFL 2005/2010
# - Filtered for MMU, no single pixels
# - NF and WD only small groups if in proximity of PFL or SFL 2005/2010
# - Filtered for MMU, no single pixels go to NoData
# Class 2: All PF
# For 2005 include:
# Class 0: All water and NoData, all large NF and WD not close to loss.
# Class 1:
# As above, but also:
# - PFL, SFL and WDL 2005
# Class 2: All PF
# For 2010 include:
# Class 0: All water and NoData, all large NF and WD not close to loss.
# Class 1:
# As above, but also:
# - PFL, SFL and WDL 2010
# Class 2: All PF
##########################################################
# Expand Primary, secondary loss (and experimentally GFC)
##########################################################
# Develop code to do also "GFC" if wanted
rasters=["PFL","SFL"]
# gfcYearlyLossFolder=r"Z:\Giuseppe\PhD\GFC\LossYear\Mosaic\ROC"
primaryLossFolder=facetMasks+"/" + "Primary_loss\Primary_loss_2000_2010"
secondaryLossFolder=facetMasks+"/"+"Secondary_loss\Secondary_loss_00_10"
outputFolder="Loss_expanded"
expandedMaskFolderPath=facetMaskWorkFolderPath+"/"+outputFolder
if not os.path.exists(expandedMaskFolderPath):
os.makedirs(expandedMaskFolderPath)
print "Made "+ outputFolder+" folder."
# Expand by how many pixels?
numberCells=5
# area threshold in pixels for the minimum area buffer to keep (this corresponds to filtering out areas around about 1 loss px)
threshold=2000
# Make output folder
outputFolder="Within_loss_buffer"
# Period folder path
outputFolderPath = facetMaskWorkFolderPath+"/"+outputFolder
# Create the folder if it doesn't exist
if not os.path.exists(outputFolderPath):
os.makedirs(outputFolderPath)
# loop through and make expanded masks
for raster in rasters:
if "PFL" in raster:
env.workspace=primaryLossFolder
raster=arcpy.ListRasters()[0]
print primaryLossFolder
elif "SFL" in raster:
env.workspace=secondaryLossFolder
raster=arcpy.ListRasters()[0]
# add and fix below if ou want to use GFC as well
# elif "GFC" in raster:
# env.workspace=gfcYearlyLossFolder
# raster=arcpy.ListRasters("*total*")[0]
else:
pass
print raster
zoneValues=[1]
outExpand = Expand(raster, numberCells, zoneValues)
name="_exp_"+str(numberCells)+"px"
rasterName=raster[:-4]+name+".tif"
outExpand.save(expandedMaskFolderPath+"/"+rasterName)
print "Saved output."
#################################################
# Merge together expanded pfl and sfl
#################################################
# versionsToMerge=["15","10"]
versionsToMerge=["5"]
print versionsToMerge
env.workspace=expandedMaskFolderPath
for version in versionsToMerge:
pflMask=arcpy.ListRasters("*prim*"+version+"*")[0]
sflMask=arcpy.ListRasters("secondary*"+version+"*")[0]
mergedMask=Raster(pflMask)+Raster(sflMask)
name="Merged_PFL_and_SFL_tot_exp_"+version+"px.tif"
print name
mergedMask.save(name)
###############################################
# Reclass merged output for focal stats
###############################################
rasters=arcpy.ListRasters("*Merged*")
print rasters
for raster in rasters:
print raster
reclassField = "Value"
remap=RemapRange([
[0,0,0],
[1,2,1]])
outReclassify=Reclassify(raster,reclassField,remap)
# overwrite the previous merged rasters
arcpy.env.overwriteOutput = True
outReclassify.save(raster)
###############################################
# Focal stats to smooth the merged output
###############################################
rasters=arcpy.ListRasters("*Merged*px.tif*")
print rasters
for raster in rasters:
print raster
neighbor=NbrCircle(12,"CELL")
outFS=FocalStatistics(raster,neighbor, "Mean", "")
description="_crcl_12r"
outputRaster=raster[:-4]+description+".tif"
print outputRaster
outFS.save(outputRaster)
##############################################
# Reclass the focal stats output
##############################################
rasters=arcpy.ListRasters("*_crcl_12r*")
print rasters
for raster in rasters:
print raster
reclassField = "Value"
remap=RemapRange([
[0,0.1,0],
[0.1,1,1]])
outReclassify=Reclassify(raster,reclassField,remap)
description="_rcl"
outputRaster=raster[:-4]+description+".tif"
outReclassify.save(outputRaster)
##############################################
# Region group and MMU
##############################################
env.workspace=expandedMaskFolderPath
# area threshold in pixels for the MMU is defined at top
# Loop through, region group and divide
rasters=arcpy.ListRasters("*_crcl_12r_rcl*")
for raster in rasters:
print raster
threshold=threshold # just a reminder, variable up at top
# (set null to the looked up count values of the region group where a group is smaller then pixels of threshold)
# Ignore value 1 (everything but the buffers) and region group value 0,
# then set to null if bigger then threshold, otherwise set to 1
inTrueValue=0
inFalseValue=1
whereClause="VALUE >= "+str(threshold)
lookupRaster=Lookup(RegionGroup(raster, "EIGHT", "WITHIN", "NO_LINK", "0"),"COUNT")
rasterName=raster[:-8]+"_lkp.tif"
arcpy.env.overwriteOutput = True
lookupRaster.save(rasterName)
RegionGrpRaster = Con(Raster(rasterName), inTrueValue, inFalseValue, whereClause)
# Get the name of the raster
rasterName = raster[:-8]
print rasterName
# Save the raster output
# outputRaster= rasterName+"_RgnGrp_"+str(threshold)+"_NoD.tif"
outputRaster= rasterName+"_RgnGrp_"+str(threshold)+".tif"
arcpy.env.overwriteOutput = True
RegionGrpRaster.save(outputRaster)
##############################################
# Subtract the small groups from mask
##############################################
rasters=arcpy.ListRasters("*_RgnGrp_*"+str(threshold)+"*.tif*")
for raster in rasters:
if "10" in raster:
print "input is " + raster
rasterName=raster[:-4]+"lrg.tif"
print "output is "+ rasterName
onlyLargeBuffers=Raster(arcpy.ListRasters("*10*_crcl_12r_rcl*")[0])-Raster(raster)
onlyLargeBuffers.save(rasterName)
elif "15" in raster:
print "input is " + raster
rasterName=raster[:-4]+"lrg.tif"
print "output is "+ rasterName
onlyLargeBuffers=Raster(arcpy.ListRasters("*15*_crcl_12r_rcl*")[0])-Raster(raster)
onlyLargeBuffers.save(rasterName)
#Code below added later to build output name using the correct numberc ells being used
else:
print "input is " + raster
rasterName=raster[:-4]+"lrg.tif"
print "output is "+ rasterName
onlyLargeBuffers=Raster(arcpy.ListRasters("*"+str(numberCells)+"*_crcl_12r_rcl*")[0])-Raster(raster)
onlyLargeBuffers.save(rasterName)
##################################################
# Now use this mask to select secondary forest
##################################################
env.workspace=expandedMaskFolderPath
# the version you want to use (just var numberCells if only one version was created)
selectedPxExpansion=numberCells
# the final loss mask to load up in memory
lossMask=arcpy.ListRasters("*"+str(selectedPxExpansion)+"*_RgnGrp_*"+str(threshold)+"*lrg.tif*")[0]
# get full path
lossMaskPath=env.workspace+"/"+lossMask
env.workspace=sfMaskFolder
sfInput=arcpy.ListRasters("*SF_only_not_inc_loss_2000.tif*")[0]
# add sf mask and loss mask
selectSF=Raster(lossMaskPath)+Raster(sfInput)
outputName="SF_2000_In_Loss_Buff.tif"
# save it to new folder
env.workspace=outputFolderPath
selectSF.save(outputName)
##############################################
# Reclass selected SF within this buffer area
##############################################
selectSF=arcpy.ListRasters("*SF_2000_In_Loss_Buff.tif*")[0]
reclassField = "Value"
rename=selectSF[:-4]+"_rcl.tif"
remap=RemapValue([
[0,0],
[1,0],
[2,1]])
outReclassify=Reclassify(selectSF,reclassField,remap)
# overwrite the previous merged rasters
# arcpy.env.overwriteOutput = True
outReclassify.save(rename)
##############################################
# Expand selected secondary forest
##############################################
selectSF=arcpy.ListRasters("*SF_2000_In_Loss_Buff_rcl.tif*")[0]
numberCells=selectedPxExpansion # from above - the px expansion selected to be used (10 or 15 or)
zoneValues=[1]
outExpand = Expand(selectSF, numberCells, zoneValues)
name="_exp_"+str(numberCells)+"px"
rasterName=selectSF[:-8]+name+".tif"
outExpand.save(outputFolderPath+"/"+rasterName)
print "Saved expdanded SF"
###############################################
# Focal stats to smooth the expanded SF
###############################################
env.workspace=outputFolderPath
raster=arcpy.ListRasters("*px.tif*")[0]
print rasters
print raster
neighbor=NbrCircle(12,"CELL")
outFS=FocalStatistics(raster,neighbor, "Mean", "")
description="_crcl_12r"
outputRaster=raster[:-4]+description+".tif"
print outputRaster
outFS.save(outputRaster)
##############################################
# Reclass focal stats output
##############################################
raster=arcpy.ListRasters("*_crcl_12r*")[0]
print raster
reclassField = "Value"
remap=RemapRange([
# previous
# [0,0.1,0],
# [0.1,1,1]])
[0,0.624,0],
[0.624,1,1]])
outReclassify=Reclassify(raster,reclassField,remap)
description="_rcl"
outputRaster=raster[:-4]+description+".tif"
outReclassify.save(outputRaster)
##############################################
# Region group and MMU
##############################################
# area threshold in pixels for the minimum area buffer to keep
threshold=2000
raster=arcpy.ListRasters("*_crcl_12r_rcl*")[0]
print raster
threshold=threshold # just a reminder, variable up at top
# (set null to the looked up count values of the region group where a group is smaller then pixels of threshold)
# Ignore value 1 (everything but the buffers) and region group value 0,
# then set to null if bigger then threshold, otherwise set to 1
inTrueValue=0
inFalseValue=1
whereClause="VALUE >= "+str(threshold)
lookupRaster=Lookup(RegionGroup(raster, "EIGHT", "WITHIN", "NO_LINK", "0"),"COUNT")
rasterName=raster[:-8]+"_lkp.tif"
#arcpy.env.overwriteOutput = True
lookupRaster.save(rasterName)
RegionGrpRaster = Con(Raster(rasterName), inTrueValue, inFalseValue, whereClause)
# Get the name of the raster
rasterName = raster[:-8]
print rasterName
# Save the raster output
# outputRaster= rasterName+"_RgnGrp_"+str(threshold)+"_NoD.tif"
outputRaster= rasterName+"_RgnGrp_"+str(threshold)+".tif"
# arcpy.env.overwriteOutput = True
RegionGrpRaster.save(outputRaster)
##############################################
# Subtract small groups from mask
##############################################
raster=arcpy.ListRasters("*_RgnGrp_*"+str(threshold)+"*.tif*")[0]
print "input is " + raster
rasterName=raster[:-4]+"lrg.tif"
print "output is "+ rasterName
onlyLargeBuffers=Raster(arcpy.ListRasters("*"+str(numberCells)+"*_crcl_12r_rcl*")[0])-Raster(raster)
onlyLargeBuffers.save(rasterName)
##############################################
# Add buffered SF to Loss buffer
##############################################
env.workspace=expandedMaskFolderPath
lossBuffer=arcpy.ListRasters("*"+str(numberCells)+"*lrg.tif")[0]
lossBufferPath=env.workspace+"/"+lossBuffer
env.workspace=outputFolderPath
sfBuffer=arcpy.ListRasters("*lrg.tif*")[0]
mergedMask=Raster(lossBufferPath)+Raster(sfBuffer)
name=sfBuffer[:-4]+"_mrg.tif"
mergedMask.save(name)
##############################################
# reclass to 100 to keep things sorted when added to FACET
##############################################
env.workspace=outputFolderPath
raster=arcpy.ListRasters("*lrg_mrg.tif*")[0]
print raster
reclassField = "Value"
remap=RemapValue([
[0,0],
[1,100],
[2,100]])
outReclassify=Reclassify(raster,reclassField,remap)
description="_rcl"
outputRaster=raster[:-4]+description+".tif"
outReclassify.save(outputRaster)
##############################################
# # Now add this area to facet
##############################################
env.workspace=facetFolder
facet=arcpy.ListRasters()[0]
print facet
facetPath=facetFolder+"/"+facet
env.workspace=outputFolderPath
raster=arcpy.ListRasters("*lrg_mrg_rcl.tif*")[0]
addFacet=Raster(facetPath)+Raster(raster)
name="Facet_merged_w_SF_and_Loss_buffer.tif"
print name
addFacet.save(name)
####################################################################
# Reclass product into mask for LFT
#
# Version A.
#
# In this version:
# Outside the buffer of loss:
# WD is classified as 0
# WDL is classified as 1 (Fragmenting land cover) as RURAL COMPLEX.
# Inside the buffer:
# WD is classified as 1
# WDL is classified as 1 in 2000, 2005, 2010 (like secondary forest)
#
# This is the version used.
#
####################################################################
#maskVersion="v14_r4_1"
maskVersion="19"
wdLossVariant=outputFolderPath+"\Version_w_WDL_outs_buff_as_fragmenting_class"
# Create the folder if it doesn't exist
if not os.path.exists(wdLossVariant):
os.makedirs(wdLossVariant)
env.workspace=outputFolderPath
# create this raster
raster=arcpy.ListRasters("*Facet_merged_w_SF_and_Loss_buffer.tif*")[0]
print raster
#periods=["2000","2005","2010","2015"]
periods=["2000"]
reclassField = "Value"
# LFT input classes
# Class 0 = not included in analysis\
# Class 1 = fragmenting land cover (clearing)
# Class 2 = fragmented land cover (forest)
for period in periods:
env.workspace=outputFolderPath
if "2000" in period:
remap=RemapRange([
# Outside of buffer
[0,4,0], # No data, water, NF and WD
[5,5,2], # primary forest
[6,6,0], # SF
[7,7,0], # WDL 2005
[8,8,2], # PFL 2005
[9,9,0], # SFL 2005
[10,10,0], # WDL 2010
[11,11,2], # PFL 2010
[12,12,0], # SFL 2010
# Inside of buffer
[100,100,0], # No data
[101,101,1], # NF in buffer
[102,102,0], # Water
[103,103,0], # No data
[104,104,1], # WD in buffer
[105,105,2], # PF
[106,106,1], # SF
[107,107,0], # WDL 2005 in buffer (has to start as either 0/2 to become 1)
[108,108,2], # PFL 2005
[109,109,1], # SFL 2005
[110,110,0], # WDL 2010 in buffer (has to start as either 0/2 to become 1)
[111,111,2], # PFL 2010
[112,112,1]]) # SFL 2010 in buffer
name="ROC_"+period+"_Mask_for_LFT_v"+maskVersion+".tif"
elif "2005" in period:
remap=RemapRange([
# Outside of buffer
[0,4,0], # No data, water, NF and WD
[5,5,2], # primary forest
[6,6,0], # Secondary forest
# Difference below with v B.
[7,7,1], # WDL 2005 (0 in v B.)
[8,8,1], # PFL 2005
[9,9,1], # SFL 2005
[10,10,0], # WDL 2010
[11,11,2], # PFL 2010
[12,12,0], # SFL 2010
# Inside buffer
[100,100,0], # No data
[101,101,1], # NF in buffer
[102,102,0], # Water
[103,103,0], # No data
[104,104,1], # WD in buffer
[105,105,2], # PF
[106,106,1], # SF
[107,107,1], # WDL 2005 in buffer (was 0)
[108,108,1], # PFL 2005 (was 2)
[109,109,1], # SFL 2005 (always 1)
[110,110,0], # WDL 2010 in buffer
[111,111,2], # PFL 2010
[112,112,1]]) # SFL 2010 in buffer
name="ROC_"+period+"_Mask_for_LFT_v"+maskVersion+".tif"
elif "2010" in period:
remap=RemapRange([
# Outside Buffer
[0,4,0], # No data, water, NF and WD
[5,5,2], # Primary forest
[6,6,0], # SF
[7,7,1], # WDL 2005 (0 in v B.)
[8,8,1], # PFL 2005
[9,9,1], # SFL 2005
[10,10,1], # WDL 2010
[11,11,1], # PFL 2010
[12,12,1], # SFL 2010
# Inside buffer
[100,100,0], # No data
[101,101,1], # NF in buffer
[102,102,0], # Water
[103,103,0], # No data
[104,104,1], # WD in buffer
[105,105,2], # PF
[106,106,1], # SF
[107,107,1], # WDL 2005 in buffer
[108,108,1], # PFL 2005
[109,109,1], # SFL 2005
[110,110,1], # WDL 2010 in buffer (was 0)
[111,111,1], # PFL 2010 (was 2)
[112,112,1]]) # sfl 2010 in buffer (always 1)
name="ROC_"+period+"_Mask_for_LFT_v"+maskVersion+".tif"
else:
pass
outReclassify=Reclassify(raster,reclassField,remap)
env.workspace=wdLossVariant
print env.workspace
print name
outReclassify.save(name)
print "Mask for "+ period + " exported. Version "+maskVersion
##################################################################
# Reclass product into mask selecting only SF, NF and WD within it
#
# Version B.
#
# In this version:
# Outside the buffer:
# WD is classified as 0
# WDL is classified as 0
# Inside the buffer:
# WD is classified as 1
# WDL is classified 1 in 2000,2005,2010 like SF loss
#
#
###################################################################
# Comment out
'''
maskVersion="v15"
env.workspace=outputFolderPath
raster=arcpy.ListRasters("*Facet_merged_w_SF_and_Loss_buffer.tif*")[0]
print raster
periods=["2000", "2005", "2010","2014"]
# mask version to be created and copied to lft folder
reclassField = "Value"
# below for 2000
#
for period in periods:
if "2000" in period:
remap=RemapRange([
# Outside of buffer
[0,4,0], # No data, water, NF and WD
[5,5,2], # primary forest
[6,6,0], # SF
[7,7,0], # WDL 2005
[8,8,2], # PFL 2005
[9,9,0], # SFL 2005
[10,10,0], # WDL 2010
[11,11,2], # PFL 2010
[12,12,0], # SFL 2010
# Inside buffer
[100,100,0], # no data
[101,101,1], # NF in buffer
[102,102,0], # Water
[103,103,0], # No data
[104,104,1], # WD in buffer
[105,105,2], # PF
[106,106,1], # SF
[107,107,1], # WDL 2005 in buffer
[108,108,2], # PFL 2005
[109,109,1], # SFL 2005
[110,110,1], # WDL 2010 in buffer
[111,111,2], # PFL 2010
[112,112,1]]) # SFL 2010 in buffer
name="ROC_"+period+"_Mask_for_LFT_v"+maskVersion+".tif"
elif "2005" in period:
remap=RemapRange([
# Outside buffer
[0,4,0], # No data, water, NF and WD
[5,5,2], # Primary forest
[6,6,0], # SF
# Difference below
[7,7,0], # WDL 2005
[8,8,1], # PFL 2005
[9,9,1], # SFL 2005
[10,10,0], # WDL 2010
[11,11,2], # PFL 2010
[12,12,0], # SFL 2010
# Inside buffer
[100,100,0], # No data
[101,101,1], # Non forest in buffer
[102,102,0], # water
[103,103,0], # No data
[104,104,1], # WD in buffer
[105,105,2], # PF
[106,106,1], # SF
[107,107,1], # WDL 2005 in buffer
[108,108,1], # PFL 2005
[109,109,1], # SFL 2005
[110,110,1], # WDL 2010 in buffer
[111,111,2], # PFL 2010
[112,112,1]]) # SFL 2010 in buffer
name="ROC_"+period+"_Mask_for_LFT_v"+maskVersion+".tif"
elif "2010" in period:
remap=RemapRange([
# Outside buffer
[0,4,0], # No data, water, NF and WD
[5,5,2], # primary forest
[6,6,0], # Secondary forest
# difference below
[7,7,0], # WDL 2005
[8,8,1], # PFL 2005
[9,9,1], # SFL 2005
[10,10,0], # WDL 2010
[11,11,1], # PFL 2010
[12,12,1], # SFL 2010
# Inside buffer
[100,100,0], # no data
[101,101,1], # Non forest in buffer
[102,102,0], # water
[103,103,0], # No data
[104,104,1], # WD in buffer
[105,105,2], # PF
[106,106,1], # SF
[107,107,1], # WDL 2005 in buffer
[108,108,1], # PFL 2005
[109,109,1], # SFL 2005
[110,110,1], # WDL 2010 in buffer
[111,111,1], # PFL 2010
[112,112,1]]) # SFL 2010 in buffer
name="ROC_"+period+"_Mask_for_LFT_v"+maskVersion+".tif"
else:
pass
outReclassify=Reclassify(raster,reclassField,remap)
arcpy.env.overwriteOutput = True
outReclassify.save(name)
'''
##########################################################
# Copy the final LFT masks into the master folders
##########################################################
lftVersion="19"
maskVersion="v19"
env.workspace=wdLossVariant
rasters=arcpy.ListRasters("*LFT_*"+maskVersion+"*.tif*")
print rasters
for raster in rasters:
if "2000" in raster:
dst=root+"/2000/Master/"+raster
arcpy.CopyRaster_management(raster,dst,"DEFAULTS","","","","","")
elif "2005" in raster:
dst=root+"/2005/Master/"+raster
arcpy.CopyRaster_management(raster,dst,"DEFAULTS","","","","","")
else:
dst=root+"/2010/Master/"+raster
arcpy.CopyRaster_management(raster,dst,"DEFAULTS","","","","","")
# put those masks in the LFT folder.
# 4/2018 - for ROC version there are a couple error values (-1 &-2 for about 600 pixels in total)
# run the clean master for LFT script
# Then run the build hybrid mask script