Skip to content

Commit 2ea01fb

Browse files
committed
Update
1 parent 9d5d602 commit 2ea01fb

2 files changed

Lines changed: 107 additions & 159 deletions

File tree

inst/extdata/scripts/example.R

Lines changed: 44 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ lakeRS::display_geometry(geom = geom)
2525
# parallel to the axis it masks the output file by that polygon and further
2626
# compression lead to much lower data size.
2727

28-
2928
tBeg <- "2020-01-01"
3029
tEnd <- "2021-01-01"
3130

@@ -57,23 +56,23 @@ lakeRS::download_openEO_job(
5756
# Scene analysis per time
5857

5958
filePath <- "C:/Users/mzamzo/Documents/tmp/pcl/01_data/input/ndtri_openeo/Koerbaer Teich_lakeRS-example_2020-01-01_2021-01-01"
60-
filePath <- "C:/Users/mzamzo/Documents/tmp/pcl/01_data/input/ndtri_openeo/TrichonisLake_DS1_20190101-20200101"
59+
filePath <- "C:/Users/mzamzo/Documents/tmp/pcl/01_data/input/ndtri_openeo/Brates Lake_DS2_20180101-20251201"
6160

6261
# further input
6362
lakeName <-
64-
"Lake Trichonis"
65-
# "Körbaer Teich"
63+
# "Lake Brates"
64+
"Körbaer Teich"
6665
lakeID <-
67-
"DS1"
68-
# "800015388119"
66+
# "DS2"
67+
"800015388119"
6968
indexName <-
7069
"NDTrI"
7170
#"NDCI"
7271
# "NDTI"
7372
# "NDSSI"
7473

7574
indexBands <-
76-
# c("B05", "B02")
75+
c("B05", "B02")
7776
# c("B05", "B03")
7877
# c("B04", "B03")
7978
# c("B02", "B08")
@@ -82,11 +81,40 @@ indexBands <-
8281
# open netcdf connection
8382
nc <- lakeRS::open_netcdf(filePath = filePath)
8483

84+
# General information on image and scene classification frequency
85+
xScene <- lakeRS::nc_scene_per_image(nc = nc, scene = "clouds")
86+
lakeRS::plot_scene_coverage(
87+
vDate = xScene$date,
88+
vCoverage = xScene$coverage
89+
)
90+
91+
lakeRS::sceneIDs
92+
93+
sceneProportion <- lakeRS::waterscene_proportion(scl_image = lakeRS:::load_BandLayer(nc = nc, band = "SCL")$band)
94+
lakeRS::plot_layer(
95+
ncLayer = sceneProportion$water,
96+
nc = nc,
97+
lowerLimits = c(0,0.1, 0.3, 0.5, 0.7, 0.8, 0.9),
98+
classColors = c("white","gray80", "gray60", "chartreuse1","chartreuse4",
99+
"dodgerblue", "dodgerblue4"),
100+
legendTitle = "Water Classification Quality"
101+
)
102+
103+
lakeRS::plot_layer(
104+
ncLayer = sceneProportion$allScenes[[5]],
105+
nc = nc,
106+
lowerLimits = c(0,0.02,0.05,0.1,0.15,0.2,0.25,0.3,0.4,0.5,0.6,1) ,
107+
classColors = c("white","gray80","gray60", "aquamarine1", "aquamarine3",
108+
"chartreuse1", "chartreuse3", "darkgreen", "goldenrod1",
109+
"chocolate1", "orangered1"),
110+
legendTitle = paste0("Proportion of '", lakeRS::sceneIDs$name[5],"'")
111+
)
112+
85113
# Index per image
86114
range(nc$t_date)
87115
imageIndex <- lakeRS::ndi_per_image(
88116
nc = nc,
89-
year = 2019,
117+
year = 2020,
90118
bandNames = indexBands
91119
)
92120

@@ -141,6 +169,7 @@ imageIndex <- lakeRS::ndi_per_image(
141169
TSnames = paste0("C", 1:k)
142170
)
143171

172+
pClusters$clusterVector
144173

145174
}
146175

@@ -160,7 +189,6 @@ if(FALSE){
160189
lowerLimits = lakeRS::NDTrIColors$ndtri,
161190
classColors = lakeRS::NDTrIColors$color,
162191
plotLegend = FALSE)
163-
164192
}
165193

166194
# spatial aggregation
@@ -171,10 +199,14 @@ lakeIndex <- lakeRS::seasonal_index_per_lake(
171199
)
172200

173201
# yearly data set of lakewise data
174-
yearlyLakes <- lakeRS::combine_years_lakeData(lakeIndexList = list(lakeIndex))
202+
yearlyLakes <- lakeRS::combine_years_lakeData(
203+
lakeIndexList = list(lakeIndex),
204+
aggregationType = "modus"
205+
)
175206

176207
# Plots ------------------------------------------------------------------------
177208
if(FALSE){
209+
178210
lakeRS::plot_lake_index_histogram(
179211
lakeIndex = lakeIndex,
180212
lakeName = lakeName,
@@ -197,6 +229,8 @@ if(FALSE){
197229
plotLegend = FALSE)
198230
}
199231

232+
233+
200234
# yearly data set of pixelwise data
201235
yearlyPixels <- lakeRS::combine_years_pixelData(lakeIndexList = list(lakeIndex))
202236
classData <- lakeRS::discreteClassAssessment(
@@ -224,60 +258,3 @@ numData <- lakeRS::numericAssessment(
224258

225259

226260

227-
228-
229-
230-
231-
# -------------------------------------------------------
232-
# old
233-
234-
xScene <- lakeRS::nc_scene_per_image(
235-
nc = nc,
236-
scene = "water"
237-
)
238-
239-
cMax <- max(xScene$coverage)
240-
dev.new(noRStudioGD = TRUE, width = 13.4, height = 5.1)
241-
lakeRS::plot_scene_coverage(
242-
vDate = xScene$date,
243-
vCoverage = xScene$coverage,
244-
upperLimits = round(
245-
c(0.05 * cMax, 0.2 * cMax, 0.5 * cMax, 0.8 * cMax, 0.9 * cMax, cMax), 3)
246-
)
247-
248-
# Scene analysis per pixel
249-
nc <- lakeRS::nc
250-
251-
ncf <- lakeRS::nc_time_filter(
252-
nc = nc,
253-
tBeg = "2020-04-01",
254-
tEnd = "2020-12-31"
255-
)
256-
257-
scl_image <- lapply(
258-
seq_along(ncf$t_date),
259-
lakeRS::load_bandLayer,
260-
nc = ncf,
261-
bandName = "SCL"
262-
)
263-
scl_image <- lapply(scl_image, function(x){
264-
x[is.na(x)] <- 0
265-
x
266-
})
267-
sceneProportion <- lakeRS::waterscene_proportion(
268-
scl_image = scl_image
269-
)
270-
271-
# --> Map Layer muss gemacht werden
272-
lakeRS::map_layer(
273-
ncLayer = sceneProportion$water,
274-
nc = ncf,
275-
lowerLimits = c(0,0.1, 0.3, 0.5, 0.7, 0.8, 0.9),
276-
classColors = c("white","gray80", "gray60", "chartreuse1","chartreuse4",
277-
"dodgerblue", "dodgerblue4"),
278-
legendTitle = "Water Classification Quality"
279-
)
280-
281-
years <- as.numeric(unique(format(x = nc$t_date, "%Y")))
282-
matrixDim <- c(length(nc$y), length(nc$x))
283-
Lines changed: 63 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
filePath <- "C:/Users/mzamzo/Documents/tmp/pcl/01_data/input/ndtri_openeo/Brates Lake_DS2_20180101-20251201"
1+
filePath <- "C:/Users/mzamzo/Documents/tmp/pcl/01_data/input/ndtri_openeo/Koerbaer Teich_Example_20180101-20241231"
22

33
# open netcdf connection
44
system.time(
@@ -7,7 +7,7 @@ system.time(
77

88
# Dynmaic
99
DynamicList <- list()
10-
years <- 2018:2025
10+
years <- 2018:2024
1111
for(year in years){
1212
cat(paste0("Processing year ", year, " ...\n"))
1313
imageIndex <- lakeRS::ndi_per_image(
@@ -22,39 +22,50 @@ for(year in years){
2222
returnSinglePixels = FALSE,
2323
days_around_ma = 30)
2424

25-
# plot alle years
26-
x <- lapply(DynamicList, function(x){x$lakeDynamic$q_0.5})
27-
lakeRS::plot_dynamic(
28-
v_averageList = x,
29-
TSnames = names(x)
30-
)
31-
32-
d <- lakeRS::combine_years_dynamic(
33-
indexDynamicList = DynamicList,
34-
years = 2018:2024
35-
)
36-
37-
lakeRS::plot_dynamic(
38-
v_averageList = list(d$mean_of_median),
39-
v_sdList = list(d$sd_over_median),
40-
TSnames = "Years 2018 - 2024",
41-
df_reference = data.frame(
42-
"doy" = 1:365,
43-
"value" = DynamicList$y_2025$lakeDynamic$q_0.5),
44-
RefName = "2025",
45-
lakeName = "Lake Brates"
46-
)
47-
48-
49-
50-
5125
}
5226

27+
# plot alle years
28+
x <- lapply(DynamicList, function(x){x$lakeDynamic$q_0.5})
29+
30+
lakeRS::plot_dynamic(
31+
v_averageList = x,
32+
TSnames = years
33+
)
34+
# without reference year
35+
d <- lakeRS::combine_years_dynamic(
36+
indexDynamicList = DynamicList,
37+
years = 2018:2024
38+
)
39+
lakeRS::plot_dynamic(
40+
v_averageList = list(d$mean_of_median),
41+
v_sdList = list(d$sd_over_median),
42+
TSnames = "Years 2018 - 2024",
43+
lakeName = "Körbaer Teich"
44+
)
45+
46+
47+
# with references year
48+
# Exclude reference year from averaging
49+
d <- lakeRS::combine_years_dynamic(
50+
indexDynamicList = DynamicList,
51+
years = 2018:2023
52+
)
53+
lakeRS::plot_dynamic(
54+
v_averageList = list(d$mean_of_median),
55+
v_sdList = list(d$sd_over_median),
56+
TSnames = "Years 2018 - 2023",
57+
df_reference = data.frame(
58+
"doy" = 1:365,
59+
"value" = DynamicList$y_2024$lakeDynamic$q_0.5),
60+
RefName = "2024",
61+
lakeName = "Körbaer Teich"
62+
)
63+
5364
# Index per image
5465
range(nc$t_date)
5566

5667
lakeIndexList <- list()
57-
years <- 2018:2025
68+
years <- 2018:2024
5869
for(year in years){
5970
cat(paste0("Processing year ", year, " ...\n"))
6071
imageIndex <- lakeRS::ndi_per_image(
@@ -82,22 +93,29 @@ yearlyLakes <- lakeRS::combine_years_lakeData(lakeIndexList = lakeIndexList)
8293

8394
# yearly data set of pixelwise data
8495
yearlyPixels <- lakeRS::combine_years_pixelData(lakeIndexList = lakeIndexList)
96+
8597
classData <- lakeRS::discreteClassAssessment(
8698
yearly_spread = yearlyPixels$indexTable
8799
)
88100

89101

90-
{
91-
# some plot as above
92-
lakeRS::map_layer(
93-
ncLayer = matrix(
94-
data = classData$assessment$year_2020_class,
95-
nrow = length(nc$y), ncol = length(nc$x)),
96-
nc = nc,
97-
lowerLimits = lakeRS::tenClassColors$class,
98-
classColors = lakeRS::tenClassColors$color,
99-
plotLegend = FALSE)
100-
}
102+
lakeRS::map_layer(
103+
ncLayer = matrix(
104+
data = classData$assessment$year_2020_class,
105+
nrow = length(nc$y), ncol = length(nc$x)),
106+
nc = nc,
107+
lowerLimits = lakeRS::tenClassColors$class,
108+
classColors = lakeRS::tenClassColors$color,
109+
plotLegend = TRUE)
110+
111+
lakeRS::plot_layer(
112+
ncLayer = matrix(
113+
data = classData$assessment$year_2020_class,
114+
nrow = length(nc$y), ncol = length(nc$x)),
115+
nc = nc,
116+
lowerLimits = lakeRS::tenClassColors$class,
117+
classColors = lakeRS::tenClassColors$color)
118+
101119

102120
numericData <- lakeRS::numericAssessment(
103121
yearly_spread = yearlyPixels$indexTable,
@@ -111,62 +129,15 @@ lakeRS::plot_numeric_assessment(
111129
numericData = numericData,
112130
rowNumber = fromBadToGood[1]
113131
)
132+
114133
lakeRS::show_pixels(
115-
x = numericData$assessment$x[fromBadToGood[1]],
116-
y = numericData$assessment$y[fromBadToGood[1]],
117-
crs = nc$crs)
134+
x = numericData$assessment$x[fromBadToGood[1:10]],
135+
y = numericData$assessment$y[fromBadToGood[1:10]],
136+
crs = nc$crs, labels = 1:10)
118137

119138
numericData[rowNumber,]
120-
hist(numericData$trend_short)
139+
hist(numericData$assessment$trend_short)
121140
median(numericData$trend_short, na.rm = TRUE)
122141

123-
xScene <- lakeRS::nc_scene_per_image(
124-
nc = nc,
125-
scene = "water"
126-
)
127-
128-
cMax <- max(xScene$coverage)
129-
dev.new(noRStudioGD = TRUE, width = 13.4, height = 5.1)
130-
lakeRS::plot_scene_coverage(
131-
vDate = xScene$date,
132-
vCoverage = xScene$coverage,
133-
upperLimits = round(
134-
c(0.05 * cMax, 0.2 * cMax, 0.5 * cMax, 0.8 * cMax, 0.9 * cMax, cMax), 3)
135-
)
136-
137-
# Scene analysis per pixel
138-
nc <- lakeRS::nc
139-
140-
ncf <- lakeRS::nc_time_filter(
141-
nc = nc,
142-
tBeg = "2020-04-01",
143-
tEnd = "2020-12-31"
144-
)
145-
146-
scl_image <- lapply(
147-
seq_along(ncf$t_date),
148-
lakeRS::load_bandLayer,
149-
nc = ncf,
150-
bandName = "SCL"
151-
)
152-
scl_image <- lapply(scl_image, function(x){
153-
x[is.na(x)] <- 0
154-
x
155-
})
156-
sceneProportion <- lakeRS::waterscene_proportion(
157-
scl_image = scl_image
158-
)
159-
160-
# --> Map Layer muss gemacht werden
161-
lakeRS::map_layer(
162-
ncLayer = sceneProportion$water,
163-
nc = ncf,
164-
lowerLimits = c(0,0.1, 0.3, 0.5, 0.7, 0.8, 0.9),
165-
classColors = c("white","gray80", "gray60", "chartreuse1","chartreuse4",
166-
"dodgerblue", "dodgerblue4"),
167-
legendTitle = "Water Classification Quality"
168-
)
169142

170-
years <- as.numeric(unique(format(x = nc$t_date, "%Y")))
171-
matrixDim <- c(length(nc$y), length(nc$x))
172143

0 commit comments

Comments
 (0)