-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWet_03_analysis_12_2020SiteAdjust.R
143 lines (112 loc) · 5.79 KB
/
Wet_03_analysis_12_2020SiteAdjust.R
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
# Copyright 2020 Province of British Columbia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.
# For dropping sample records and re-picking so requirements still met
#Read ins 2020 samples
SampleStrataS<-readRDS(file='tmp/AOI/SampleStrataS')
SampleStrata2019Full<-readRDS(file = 'tmp/AOI/SampleStrata2019Full')
nrow(subset(SampleStrataS, Sampled==1))
table(SampleStrataS$SampleType)
#Read in sites completed and dropped
WetPlotFnSheets<- excel_sheets(file.path(Tier2Dir,'2020FieldData/Sampling2020_3Sept.xlsx'))
Wet2020Complete<-read_excel(file.path(Tier2Dir,'2020FieldData/Sampling2020_3Sept.xlsx'),
sheet = WetPlotFnSheets[2]) %>%
mutate(Sampled=1) %>%
mutate(SampleType=8)
Wet2020Drop<-read_excel(file.path(Tier2Dir,'2020FieldData/Sampling2020_3Sept.xlsx'),
sheet = WetPlotFnSheets[3]) %>%
mutate(Sampled=0) %>%
mutate(SampleType=99)
# note ‘Lower Skeena’ = ‘Kitwanga’ = ‘Gitwangak’
AdminsToDrop<-c("Gitxsan_ Suskwa", "Gitxsan_ Kitwanga")
#Drop wetlands from sample pool for those in pool that were dropped
SampleStrataS <- SampleStrataS %>%
dplyr::filter(!Wetland_Co %in% Wet2020Drop$Wetland_Co) %>%
dplyr::filter(!House_Name %in% AdminsToDrop)
#Update wetlands sampled that are in the sample pool
SampleStrataS2 <- SampleStrataS %>%
mutate(SampleType=ifelse(Wetland_Co %in% Wet2020Complete$Wetland_Co, 8, SampleType)) %>%
mutate(Sampled=ifelse(Wetland_Co %in% Wet2020Complete$Wetland_Co, 1, Sampled))
#Add wetlands that were sampled but not in sample pool
nrow(subset(Wet2020Complete, !Wetland_Co %in% SampleStrataS2$Wetland_Co))
AddComp<-Wet2020Complete %>%
dplyr::filter(!Wetland_Co %in% SampleStrataS2$Wetland_Co) %>%
dplyr::select(Wetland_Co)
WetlandsToAdd<-SampleStrata2019Full %>%
right_join(AddComp, by='Wetland_Co') %>%
mutate(Sampled=1) %>%
mutate(SampleType=8) %>%
dplyr::select(Wetland_Co, Sampled, SampleType, kmRd, StrataGroup, House_Name, Dist_to_Road, BEC,
FlowCode, Verticalflow, Bidirectional,Throughflow, Outflow, Inflow,
LanCoverLabel, DisturbType,Wshd_Sample_Type,WatershedID,
FREP_OPENING_ID,FREP_DISTRICT_NAME,FREP_OPENING_GROSS_AREA,FREP_DISTURBANCE_END_DATE)
SampleStrataM <- rbind(SampleStrataS2,WetlandsToAdd)
#WFN priority wetlands
WFNSheets<- excel_sheets(file.path(DataDir,'Wetlands2020_Wetlands3_WFNSamplePlan_06Sep2020.xlsx'))
WFNpriority<-read_excel(file.path(DataDir,'Wetlands2020_Wetlands3_WFNSamplePlan_06Sep2020.xlsx'),
sheet = WFNSheets[1])
nrow(WFNpriority) #25
#Check if any WFN wetlands are in sample frame
#tt<-subset(SampleStrataM, Wetland_Co %in% WFNpriority$Wetland_Co)
nrow(subset(SampleStrataM, House_Name == 'Wetsuweten')) #791
nrow(subset(SampleStrataM, Sampled==1 & House_Name == 'Wetsuweten'))#56
WetSites<-SampleStrataM %>%
dplyr::filter(SampleType>0 & House_Name == 'Wetsuweten')
table(WetSites$SampleType)
#1 2 3 4 5 8
#9 5 3 5 28 6
WetSitesDrop<-WetSites %>%
dplyr::filter(!SampleType %in% c(1,8)) #41
table(WetSitesDrop$SampleType)
#Drop 28 administrative sites from Wetsuweten and replace with WFN sites.
AddWFN<-WFNpriority %>%
dplyr::filter(!Wetland_Co %in% SampleStrataM$Wetland_Co) %>%
dplyr::select(Wetland_Co)
WFNToAdd<-SampleStrata2019Full %>%
right_join(AddWFN, by='Wetland_Co') %>%
mutate(Sampled=1) %>%
mutate(SampleType=6) %>%
mutate(SampleTDescrip='WFN priority') %>%
dplyr::select(Wetland_Co, Sampled, SampleType, kmRd, StrataGroup, House_Name, Dist_to_Road, BEC,
FlowCode, Verticalflow, Bidirectional,Throughflow, Outflow, Inflow,
LanCoverLabel, DisturbType,Wshd_Sample_Type,WatershedID,
FREP_OPENING_ID,FREP_DISTRICT_NAME,FREP_OPENING_GROSS_AREA,FREP_DISTURBANCE_END_DATE)
SampleStrataM <- SampleStrataM %>%
rbind(WFNToAdd) %>%
dplyr::filter(!(SampleType==5 & House_Name == 'Wetsuweten'))
#Gitxsan priority wetlands
#Read in boundaries to identify wetlands
FN_house_layers <- st_layers(file.path(SyncDir, "BC Gov Internal/FN_Territory.gpkg"))
Gitxsan_housesIn <- st_read(file.path(SyncDir, "BC Gov Internal/FN_Territory.gpkg"), layer='gitxsan_houses_v6_191007') %>%
st_transform(st_crs(ESI))
Gitxsan_house_pts <-st_intersection(wetptW, Gitxsan_housesIn) %>%
st_drop_geometry()
Gitxsan_houses <- Gitxsan_house_pts %>%
dplyr::select(Wetland_Co,LAXWIIYIP,PDEEK,SIMGIIGYET,WATERSHED_) %>%
dplyr::filter((LAXWIIYIP=='Xsi Git Gat Gaitin' & PDEEK=='Giskaast' &
SIMGIIGYET=='Gwii Yeehl' & WATERSHED_=='Kispiox') |
(LAXWIIYIP=='Sgan Snaat' & PDEEK=='Lax Gibuu' &
SIMGIIGYET=='Wii Mugulsxw' & WATERSHED_=='Kispiox'))
nrow(Gitxsan_houses) #142
nrow(subset(SampleStrataM, Wetland_Co %in% Gitxsan_houses$Wetland_Co)) #22
tt<- SampleStrataM %>%
dplyr::filter(Wetland_Co %in% Gitxsan_houses$Wetland_Co)
#41216 and 41235
tttt<- Gitxsan_house_pts %>%
dplyr::filter(Wetland_Co %in% c(41216, 41235)) %>%
dplyr::select(Wetland_Co,LAXWIIYIP,PDEEK,SIMGIIGYET,WATERSHED_)
#Join point coverage back to main wetland file
Wetlands3<-Wetlands %>%
#st_drop_geometry %>%
left_join(FREP_pts, by='Wetland_Co')
#Save revised output
saveRDS(SampleStrataM , file = 'tmp/AOI/SampleStrataM')
tt<-subset(SampleStrataM, Sampled==1)