-
Notifications
You must be signed in to change notification settings - Fork 0
/
LPModel2.R
413 lines (372 loc) · 33.4 KB
/
LPModel2.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
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
#Quick script for plotting variance measures of sky brightness for poster.
require(dplyr)
require(plyr)
require(ggplot2)
require(relaimpo)
require(matrixStats)
require(Hmisc)
require(corrplot)
require("PerformanceAnalytics")
require(ggmap)
require(maps)
require(mapview)
require(mapdata)
require(munsell)
require(leaflet)
require(devtools)
require(webshot)
require(stats)
require(segmented)
require(viridis)
require(lubridate)
require(vegan)
wd <- "~/Desktop/Coastlight"
setwd(wd)
#Read in data generated by SQC batch analysis.
SQCData <- read.table("CoastlightSkyVarianceAllSites.csv", header=TRUE, sep=",",as.is=T,skip=0,fill=TRUE,check.names=FALSE, encoding = "UTF-8")
SQCData <- arrange(SQCData,`SQC File Name`)
#Rename verbose variables
colnames(SQCData)[which(names(SQCData) == "Scalar Illuminance")] <- "ScalarIlluminance"
#Calculate whole sky coefficient of variation in scalar illuminance
SQCData[SQCData<0] <- NA
SQCData$SDLuminance <- rowSds(as.matrix(SQCData[grepl("D(.*?)R(.*?)Luminance", names(SQCData))]),na.rm=TRUE)
SQCData$MeanLuminance <- rowMeans(as.matrix(SQCData[grepl("D(.*?)R(.*?)Luminance", names(SQCData))]),na.rm=TRUE)
SQCData$CoVLuminance <- SQCData$SDLuminance/SQCData$MeanLuminance
#Calculate luminance statistics for the bottom band of the sky (0 - 11.54 degrees above the horizon).
SQCData$SDLuminanceD1 <- rowSds(as.matrix(SQCData[grepl("D1R(.*?)Luminance", names(SQCData))]),na.rm=TRUE)
SQCData$MeanLuminanceD1 <- rowMeans(as.matrix(SQCData[grepl("D1R(.*?)Luminance", names(SQCData))]),na.rm=TRUE)
SQCData$CoVLuminanceD1 <- SQCData$SDLuminanceD1/SQCData$MeanLuminanceD1
#Calculate luminance statistics for the top band of the sky (53.13 - 90 degrees above the horizon).
SQCData$SDLuminanceD5 <- rowSds(as.matrix(SQCData[grepl("D5R(.*?)Luminance", names(SQCData))]),na.rm=TRUE)
SQCData$MeanLuminanceD5 <- rowMeans(as.matrix(SQCData[grepl("D5R(.*?)Luminance", names(SQCData))]),na.rm=TRUE)
SQCData$CoVLuminanceD5 <- SQCData$SDLuminanceD5/SQCData$MeanLuminanceD5
#Estimate the mean color correlated temperature for the bottom band of the sky (0 - 11.54 degrees above the horizon).
SQCData$CCTD1 <- rowMeans(as.matrix(SQCData[grepl("D1R(.*?)CCT", names(SQCData))]),na.rm=TRUE)
#Estimate the mean color correlated temperature for the bottom band of the sky (53.13 - 90 degrees above the horizon).
SQCData$CCTD5 <- rowMeans(as.matrix(SQCData[grepl("D5R(.*?)CCT", names(SQCData))]),na.rm=TRUE)
#Convert NaN values to NA.
SQCData[is.nan(as.matrix(SQCData))] <- NA
FieldSQCMerge$MeanLuminanceD5[is.nan(FieldSQCMerge$MeanLuminanceD5)] <- NA
FieldSQCMerge$MeanLuminanceD1[is.nan(FieldSQCMerge$MeanLuminanceD1)] <- NA
#Read in 2012 VIIRS upwards radiance data per site.
VIIRS <- read.table("LPPointsUnder150.csv", header=TRUE, sep=",",as.is=T,skip=0,fill=TRUE,check.names=FALSE)
VIIRS[,'Latitude'] = round(VIIRS[,'Latitude'],5)
VIIRS[,'Longitude'] = round(VIIRS[,'Longitude'],5)
colnames(VIIRS)[which(names(VIIRS) == "Brightness (nW/Sr/cm^2)")] <- "VIIRSBrightness"
#Read in field data.
FieldData <- read.table("CoastlightFieldData.csv", header=TRUE, sep=",",as.is=T,skip=0,fill=TRUE,check.names=FALSE)
FieldData[,'Centroid latitude'] = round(FieldData[,'Centroid latitude'],5)
FieldData[,'Centroid longitude'] = round(FieldData[,'Centroid longitude'],5)
colnames(FieldData)[which(names(FieldData) == "SQM2015Atlas (mcd/m^2)")] <- "SQA"
#Merge in VIIRS data by pixel to field data.
FieldData <- left_join(FieldData,VIIRS[,c("Latitude","Longitude","VIIRSBrightness","OBJECTID")],by=c("Centroid latitude" = "Latitude","Centroid longitude" = "Longitude"))
#Create unique site ID. Each site contains 5 locations.
colnames(FieldData)[which(names(FieldData) == "OBJECTID")] <- "UniqueID"
FieldData$UniqueID <- as.factor(as.character(FieldData$UniqueID))
#Keep batch analysis data for images with zero horizon.
SQCDataZeroHorizon <- SQCData[!grepl("Horizon",SQCData$'SQC File Name'),]
SQCDataZeroHorizon <- arrange(SQCDataZeroHorizon,`SQC File Name`)
#Keep batch analysis data for images with edited horizon.
SQCDataEditedHorizon <- SQCData[grepl("Horizon",SQCData$'SQC File Name'),]
SQCDataEditedHorizon <- arrange(SQCDataEditedHorizon,`SQC File Name`)
#Zero-horizon merged data set
FieldSQCMergeZH <- left_join(FieldData,SQCDataZeroHorizon,by=c("SQCSiteName"="Location"))
#Edited-horizon merged data set
FieldSQCMergeEH <- left_join(FieldData,SQCDataEditedHorizon,by=c("SQCSiteName"="Location"))
#Determine the fraction of horizon radiance to full sky radiance.
FieldSQCMergeZH$HorizonLuminance <- (FieldSQCMergeZH$ScalarIlluminance - FieldSQCMergeEH$ScalarIlluminance)/FieldSQCMergeZH$ScalarIlluminance
FieldSQCMergeEH$HorizonLuminance <- (FieldSQCMergeZH$ScalarIlluminance - FieldSQCMergeEH$ScalarIlluminance)/FieldSQCMergeZH$ScalarIlluminance
#Subset horizon-edited data for analysis of spatial variability of scalar illuminance.
SpatialEH <- FieldSQCMergeEH
SpatialEH <- SpatialEH[,c("UniqueID","ScalarIlluminance")]
SpatialEH <- arrange(SpatialEH,UniqueID)
#Determine the mean of scalar illuminance by UniqueID
tmp <- as.data.frame(aggregate(SpatialEH$ScalarIlluminance,by=list(SpatialEH$UniqueID),FUN=mean))
colnames(tmp) <- c("UniqueID","ScalarIlluminanceSiteMean")
SpatialEH <- merge(SpatialEH,tmp,by=c("UniqueID"))
#Determine the coefficient of variation of scalar illuminance by UniqueID
tmp <- as.data.frame(aggregate(SpatialEH$ScalarIlluminance,by=list(SpatialEH$UniqueID),FUN=function(ScalarIlluminance){sd(ScalarIlluminance)/mean(ScalarIlluminance)}))
colnames(tmp) <- c("UniqueID","ScalarIlluminanceSiteCoV")
SpatialEH <- merge(SpatialEH,tmp,by=c("UniqueID"))
#Merge into larger data set.
FieldSQCMergeEH <- left_join(FieldSQCMergeEH,SpatialEH,by=c("UniqueID"))
#Subset zero horizon data for analysis of spatial variability of scalar illuminance.
SpatialZH <- FieldSQCMergeZH
SpatialZH <- SpatialZH[,c("UniqueID","ScalarIlluminance")]
SpatialZH <- arrange(SpatialZH,UniqueID)
#Determine the mean of scalar illuminance by UniqueID
tmp <- as.data.frame(aggregate(SpatialZH$ScalarIlluminance,by=list(SpatialZH$UniqueID),FUN=mean))
colnames(tmp) <- c("UniqueID","ScalarIlluminanceSiteMean")
SpatialZH <- merge(SpatialZH,tmp,by=c("UniqueID"))
#Determine the coefficient of variation of scalar illuminance by UniqueID
tmp <- as.data.frame(aggregate(SpatialZH$ScalarIlluminance,by=list(SpatialZH$UniqueID),FUN=function(ScalarIlluminance){sd(ScalarIlluminance)/mean(ScalarIlluminance)}))
colnames(tmp) <- c("UniqueID","ScalarIlluminanceSiteCoV")
SpatialZH <- merge(SpatialZH,tmp,by=c("UniqueID"))
#Merge into larger data set.
FieldSQCMergeZH <- left_join(FieldSQCMergeZH,SpatialZH,by=c("UniqueID"))
#Full merged data set
FieldSQCMergeEH$TypeHorizon <- "EditedHorizon"
FieldSQCMergeZH$TypeHorizon <- "ZeroHorizon"
FieldSQCMergeEH$`ScalarIlluminance.y` <- NULL
FieldSQCMergeZH$`ScalarIlluminance.y` <- NULL
colnames(FieldSQCMergeEH)[which(names(FieldSQCMergeEH) == "ScalarIlluminance.x")] <- "ScalarIlluminance"
colnames(FieldSQCMergeZH)[which(names(FieldSQCMergeZH) == "ScalarIlluminance.x")] <- "ScalarIlluminance"
#Use the same %horizon values for both the full hemispheric and edited horizon images.
FieldSQCMergeZH$Horizon <- FieldSQCMergeEH$Horizon
FieldSQCMergeZH <- FieldSQCMergeZH[!duplicated(FieldSQCMergeZH),]
FieldSQCMergeEH <- FieldSQCMergeEH[!duplicated(FieldSQCMergeEH),]
FieldSQCMerge <- rbind(FieldSQCMergeZH,FieldSQCMergeEH)
#Clear out duplicate columns.
FieldSQCMerge$Date.y <- NULL
FieldSQCMerge$Time.y <- NULL
names(FieldSQCMerge)[names(FieldSQCMerge)=="Date.x"] <- "Date"
names(FieldSQCMerge)[names(FieldSQCMerge)=="Time.x"] <- "Time"
#Convert variable types for statistial analysis.
FieldSQCMerge$SQCSiteName <- as.factor(FieldSQCMerge$SQCSiteName)
FieldSQCMerge$UniqueID <- as.factor(FieldSQCMerge$UniqueID)
FieldSQCMerge$TypeHorizon <- as.factor(FieldSQCMerge$TypeHorizon)
#Calculate the number of days from the start of fieldwork.
FieldSQCMerge$Days <- as.numeric(difftime(as.Date(FieldSQCMerge$Date,"%m/%d/%Y"),min(as.Date(FieldSQCMerge$Date,"%m/%d/%Y")),units="days"))
#Check for variables which make a significant contribution to scalar illuminance. Use VIIRS as the illumination variable.
adonis(log10(ScalarIlluminance)~log10(VIIRSBrightness+1)+Days+`Sun Altitude`+`Air temp (C)`+`RH (%)`+Clouds+Horizon, data=FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon",],permutations=1000,method="manhattan")
adonis(log10(ScalarIlluminance)~log10(VIIRSBrightness+1)+Days+`Sun Altitude`+`Air temp (C)`+`RH (%)`+Clouds+Horizon, data=FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon",],permutations=1000,method="manhattan")
#Check for variables which make a significant contribution to scalar illuminance. Use the sky quality atlas as the illumination variable.
adonis(log10(ScalarIlluminance)~log10(SQA)+Days+`Sun Altitude`+`Air temp (C)`+`RH (%)`+Clouds+Horizon, data=FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon",],permutations=1000,method="manhattan")
adonis(log10(ScalarIlluminance)~log10(SQA)+Days+`Sun Altitude`+`Air temp (C)`+`RH (%)`+Clouds+Horizon, data=FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon",],permutations=1000,method="manhattan")
#Check for variables which make a significant contribution to variation on scalar illuminance within sites. Use various measures of the nighttime environment.
adonis(ScalarIlluminanceSiteCoV~log10(SQA)+log10(VIIRSBrightness+1)+log10(MeanLuminanceD1+1)+log10(MeanLuminanceD5+1)+Horizon, data=FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon" & !is.na(FieldSQCMerge$MeanLuminanceD5),],permutations=1000,method="manhattan")
adonis(ScalarIlluminanceSiteCoV~log10(SQA)+log10(VIIRSBrightness+1)+log10(MeanLuminanceD1+1)+log10(MeanLuminanceD5+1)+Horizon, data=FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon" & !is.na(FieldSQCMerge$MeanLuminanceD5),],permutations=1000,method="manhattan")
#Check for variables which make a significant contribution to variation on luminance within 0 to 11.54 degees above the horizon.
adonis(log10(MeanLuminanceD1 + 1)~log10(ScalarIlluminance)+log10(SQA)+log10(VIIRSBrightness+1)+Horizon, data=FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon",],permutations=1000,method="manhattan")
adonis(log10(MeanLuminanceD1 + 1)~log10(ScalarIlluminance)+log10(SQA)+log10(VIIRSBrightness+1)+Horizon, data=FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon",],permutations=1000,method="manhattan")
#Check for variables which make a significant contribution to variation on luminance within 53.13 to 90 degees above the horizon.
adonis(log10(MeanLuminanceD5 + 1)~log10(ScalarIlluminance)+log10(SQA)+log10(VIIRSBrightness+1)+Horizon, data=FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon" & !is.na(FieldSQCMerge$MeanLuminanceD5),],permutations=1000,method="manhattan")
adonis(log10(MeanLuminanceD5 + 1)~log10(ScalarIlluminance)+log10(SQA)+log10(VIIRSBrightness+1)+Horizon, data=FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon" & !is.na(FieldSQCMerge$MeanLuminanceD5),],permutations=1000,method="manhattan")
#Build a linear model of the log of scalar illuminance from the remaining significant factors.
LPLogModelZH <- lm(log10(ScalarIlluminance)~log10(SQA)+`Air temp (C)`+Clouds+Horizon,data=FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon",])
FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","LogFit"] <- LPLogModelZH$coefficients[1]+
LPLogModelZH$coefficients[2]*log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","SQA"])+
LPLogModelZH$coefficients[3]*FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","Air temp (C)"]+
LPLogModelZH$coefficients[4]*FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","Clouds"]+
LPLogModelZH$coefficients[5]*FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","Horizon"]
cor.test(log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","ScalarIlluminance"]),FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","LogFit"])
#Build a linear model of the log of scalar illuminance from the remaining permanent significant factors.
LPLogModelZH <- lm(log10(ScalarIlluminance)~log10(SQA)+Horizon,data=FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon",])
FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","LogFit"] <- LPLogModelZH$coefficients[1]+
LPLogModelZH$coefficients[2]*log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","SQA"])+
LPLogModelZH$coefficients[3]*FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","Horizon"]
cor.test(log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","ScalarIlluminance"]),FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","LogFit"])
# Calculate relative importance of remaining variables.
calc.relimp(LPLogModelZH)
LPLogModelEH <- lm(log10(ScalarIlluminance)~log10(SQA)+`Air temp (C)`+Clouds+Horizon,data=FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon",])
FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","LogFit"] <- LPLogModelEH$coefficients[1]+
LPLogModelEH$coefficients[2]*log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","SQA"])+
LPLogModelEH$coefficients[3]*FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","Air temp (C)"]+
LPLogModelEH$coefficients[4]*FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","Clouds"]+
LPLogModelEH$coefficients[5]*FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","Horizon"]
cor.test(log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","ScalarIlluminance"]),FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","LogFit"])
#Build a linear model of the log of scalar illuminance from the remaining permanent significant factors.
LPLogModelEH <- lm(log10(ScalarIlluminance)~log10(SQA)+Horizon,data=FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon",])
FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","LogFit"] <- LPLogModelEH$coefficients[1]+
LPLogModelEH$coefficients[2]*log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","SQA"])+
LPLogModelEH$coefficients[3]*FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","Horizon"]
cor.test(log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","ScalarIlluminance"]),FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","LogFit"])
# Calculate relative importance of remaining variables.
calc.relimp(LPLogModelEH)
#Plot models of log SI versus measured log SI.
LPPlotZH <- ggplot(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon",], aes(x=log10(ScalarIlluminance),y=LogFit,color=`CCT (Scalar)`))+geom_point()+theme(text = element_text(size=25))+geom_smooth(method=glm, aes(fill=LogFit))
LPPlotZH+xlab(expression(atop("Log(SI (mlx))","(Measured)")))+ylab(expression(atop("Log(SI (mlx))","(Modeled)")))+scale_color_gradientn("CCT (K)",colours = rev(plasma(10)),limits=c(1500,4500))
#
LPPlotEH <- ggplot(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon",], aes(x=log10(ScalarIlluminance),y=LogFit,color=`CCT (Scalar)`))+geom_point()+theme(text = element_text(size=25))+geom_smooth(method=glm, aes(fill=LogFit))
LPPlotEH+xlab(expression(atop("Log(SI (mlx))","(Measured)")))+ylab(expression(atop("Log(SI (mlx))","(Modeled)")))+scale_color_gradientn("CCT (K)",colours = rev(plasma(10)),limits=c(1500,4500))
#Compare models generated from full sky scalar illuminance, or the luminance from particular bands of the sky, using WAANSB and the input variable.
#Try a logrithmic model of scalar illuminance versus WAANSB for the full data set for the full hemispheric images.
LPLogModelZH <- lm(log10(ScalarIlluminance)~log10(SQA),data=FieldSQCMergeZH)
FieldSQCMergeZH$LogFit <- log10(FieldSQCMergeZH$SQA*LPLogModelZH$coefficients[2])+LPLogModelZH$coefficients[1]
FieldSQCMergeZHSubset <- na.omit(FieldSQCMergeZH,cols=c("LogFit"))
cor.test(log10(FieldSQCMergeZHSubset$ScalarIlluminance),log10(FieldSQCMergeZHSubset$SQA))
#Log-log model summary. Get the coefficients via 'summary and then test the correlation.
summary(lm(log10(FieldSQCMergeZHSubset$ScalarIlluminance)~log10(FieldSQCMergeZHSubset$SQA)))
cor.test(1.52065+log10(1.19760*FieldSQCMergeZHSubset$SQA),log10(FieldSQCMergeZHSubset$ScalarIlluminance))
#Plot model
LPPlotZH <- ggplot(FieldSQCMergeZHSubset, aes(x=log10(SQA),y=log10(ScalarIlluminance),color=`CCT (Scalar)`))+geom_point()+theme(text = element_text(size=25))+geom_smooth(method=glm, aes(fill=LogFit))
LPPlotZH+xlab(bquote("Log(WAANSB)"~log(mcd/m^2)))+ylab("Log(SI (mlx))\nFull hemisphere")+scale_color_gradientn("CCT (K)",colours = rev(plasma(10)),limits=c(1500,5000))
#Plot residuals of scalar illuminance to log model versus color temperature
LPPlotZH <- ggplot(FieldSQCMergeZHSubset, aes(x=`CCT (Scalar)`,y=log10(ScalarIlluminance)-LogFit))+geom_point()+theme(text = element_text(size=25))+geom_smooth(method=glm, aes(fill=ScalarIlluminance-LogFit))
LPPlotZH+xlab("CCT (K)")+ylab("(Observed - Modeled) SI\nlog(mlx)")
cor.test(FieldSQCMergeZHSubset$`CCT (Scalar)`,log10(FieldSQCMergeZHSubset$ScalarIlluminance)-FieldSQCMergeZHSubset$LogFit)
#Try a logrithmic model of scalar illuminance versus WAANSB for the data set with no cloud cover for the full hemispheric images.
FieldSQCMergeZHSubset <- subset(FieldSQCMergeZH,Clouds==0)
LPLogModelZH <- lm(log10(ScalarIlluminance)~log10(SQA),data=FieldSQCMergeZHSubset)
FieldSQCMergeZHSubset$LogFit <- log10(FieldSQCMergeZHSubset$SQA*LPLogModelZH$coefficients[2])+LPLogModelZH$coefficients[1]
FieldSQCMergeZHSubset <- na.omit(FieldSQCMergeZHSubset,cols=c("LogFit"))
cor.test(log10(FieldSQCMergeZHSubset$ScalarIlluminance),log10(FieldSQCMergeZHSubset$SQA))
#Plot model
LPPlotZH <- ggplot(FieldSQCMergeZHSubset, aes(x=log10(SQA),y=log10(ScalarIlluminance),color=`CCT (Scalar)`))+geom_point()+theme(text = element_text(size=25))+geom_smooth(method=glm, aes(fill=LogFit))
LPPlotZH+xlab(bquote("Log(WAANSB)"~log(mcd/m^2)))+ylab("Log(SI (mlx))\nFull hemisphere")+scale_color_gradientn("CCT (K)",colours = rev(plasma(10)),limits=c(1500,5000))
#Plot fitted scalar illuminance (Using log model) versus log(WAANSB) for ring 1 (Top 30 degrees of the sky using full hemispheric images)
FieldSQCMergeZHSubset <- na.omit(FieldSQCMergeZH,cols=c("Ring 1Luminance","Ring 1CCT"))
LPLogModelZH <- lm(log10(`Ring 1Luminance`)~log10(SQA),data=FieldSQCMergeZHSubset)
FieldSQCMergeZHSubset$LogFit <- log10(FieldSQCMergeZHSubset$SQA*LPLogModelZH$coefficients[2])+LPLogModelZH$coefficients[1]
FieldSQCMergeZHSubset <- na.omit(FieldSQCMergeZHSubset,cols=c("LogFit"))
cor.test(log10(FieldSQCMergeZHSubset$SQA),log10(FieldSQCMergeZHSubset$`Ring 1Luminance`))
#Plot model
LPPlotZH <- ggplot(FieldSQCMergeZHSubset, aes(x=log10(SQA),y=log10(`Ring 1Luminance`),color=`Ring 1CCT`))+geom_point()+theme(text = element_text(size=25))+geom_smooth(method=glm, aes(fill=LogFit))
LPPlotZH+xlab(bquote("Log(WAANSB)"~log(mcd/m^2)))+ylab(expression(atop("Log(L) Top 30°",paste("Log(mcd/",m^{2},")"))))+scale_color_gradientn("CCT (K)",colours = rev(plasma(10)),limits=c(1500,5000))
#Plot fitted scalar illuminance (Using log model) versus log(WAANSB) for ring 1 (Top 30 degrees of the sky using images without cloud cover)
FieldSQCMergeZHSubset <- na.omit(subset(FieldSQCMergeZH,Clouds==0),cols=c("Ring 1Luminance","Ring 1CCT"))
LPLogModelZH <- lm(log10(`Ring 1Luminance`)~log10(SQA),data=FieldSQCMergeZHSubset)
FieldSQCMergeZHSubset$LogFit <- log10(FieldSQCMergeZHSubset$SQA*LPLogModelZH$coefficients[2])+LPLogModelZH$coefficients[1]
FieldSQCMergeZHSubset <- na.omit(FieldSQCMergeZHSubset,cols=c("LogFit"))
cor.test(log10(FieldSQCMergeZHSubset$SQA),log10(FieldSQCMergeZHSubset$`Ring 1Luminance`))
#Plot model
LPPlotZH <- ggplot(FieldSQCMergeZHSubset, aes(x=log10(SQA),y=log10(`Ring 1Luminance`),color=`Ring 1CCT`))+geom_point()+theme(text = element_text(size=25))+geom_smooth(method=glm, aes(fill=LogFit))
LPPlotZH+xlab(bquote("Log(WAANSB)"~log(mcd/m^2)))+ylab(expression(atop("Log(L) Top 30°",paste("Log(mcd/",m^{2},")"))))+scale_color_gradientn("CCT (K)",colours = rev(plasma(10)),limits=c(1500,5000))
#Plot fitted scalar illuminance (Using log model) versus log(WAANSB) for ring 7 (Bottom 10 degrees of the sky using full hemispheric images)
FieldSQCMergeZHSubset <- na.omit(FieldSQCMergeZH,cols=c("Ring 7Luminance","Ring 7CCT"))
LPLogModelZH <- lm(log10(`Ring 7Luminance`)~log10(SQA),data=FieldSQCMergeZHSubset)
FieldSQCMergeZHSubset$LogFit <- log10(FieldSQCMergeZHSubset$SQA*LPLogModelZH$coefficients[2])+LPLogModelZH$coefficients[1]
FieldSQCMergeZHSubset <- na.omit(FieldSQCMergeZHSubset,cols=c("LogFit"))
cor.test(log10(FieldSQCMergeZHSubset$SQA),log10(FieldSQCMergeZHSubset$`Ring 7Luminance`))
#Plot model
LPPlotZH <- ggplot(FieldSQCMergeZHSubset, aes(x=log10(SQA),y=log10(`Ring 7Luminance`),color=`Ring 7CCT`))+geom_point()+theme(text = element_text(size=25))+geom_smooth(method=glm, aes(fill=LogFit))
LPPlotZH+xlab(bquote("Log(WAANSB)"~log(mcd/m^2)))+ylab(expression(atop("Log(L) Bottom 10°",paste("Log(mcd/",m^{2},")"))))+scale_color_gradientn("CCT (K)",colours = rev(plasma(10)),limits=c(1500,5000))
#Plot fitted scalar illuminance (Using log model) versus log(WAANSB) for ring 7 (Bottom 10 degrees of the sky using images without cloud cover)
FieldSQCMergeZHSubset <- na.omit(subset(FieldSQCMergeZH,Clouds==0),cols=c("Ring 7Luminance","Ring 7CCT"))
LPLogModelZH <- lm(log10(`Ring 7Luminance`)~log10(SQA),data=FieldSQCMergeZHSubset)
FieldSQCMergeZHSubset$LogFit <- log10(FieldSQCMergeZHSubset$SQA*LPLogModelZH$coefficients[2])+LPLogModelZH$coefficients[1]
FieldSQCMergeZHSubset <- na.omit(FieldSQCMergeZHSubset,cols=c("LogFit"))
cor.test(log10(FieldSQCMergeZHSubset$SQA),log10(FieldSQCMergeZHSubset$`Ring 7Luminance`))
#Plot model
LPPlotZH <- ggplot(FieldSQCMergeZHSubset, aes(x=log10(SQA),y=log10(`Ring 7Luminance`),color=`Ring 7CCT`))+geom_point()+theme(text = element_text(size=25))+geom_smooth(method=glm, aes(fill=LogFit))
LPPlotZH+xlab(bquote("Log(WAANSB)"~log(mcd/m^2)))+ylab(expression(atop("Log(L) Bottom 10°",paste("Log(mcd/",m^{2},")"))))+scale_color_gradientn("CCT (K)",colours = rev(plasma(10)),limits=c(1500,5000))
#Try a logrithmic model of scalar illuminance versus WAANSB for the full set of edited horizon images.
FieldSQCMergeEHSubset <- FieldSQCMergeEH
LPLogModelEH <- lm(log10(ScalarIlluminance)~log10(SQA),data=FieldSQCMergeEHSubset)
FieldSQCMergeEHSubset$LogFit <- log10(FieldSQCMergeEHSubset$SQA*LPLogModelZH$coefficients[2])+LPLogModelEH$coefficients[1]
FieldSQCMergeEHSubset <- na.omit(FieldSQCMergeEHSubset,cols=c("LogFit"))
cor.test(log10(FieldSQCMergeEHSubset$ScalarIlluminance),log10(FieldSQCMergeEHSubset$SQA))
#Plot model
LPPlotEH <- ggplot(FieldSQCMergeEHSubset, aes(x=log10(SQA),y=log10(ScalarIlluminance),color=`CCT (Scalar)`))+geom_point()+theme(text = element_text(size=25))+geom_smooth(method=glm, aes(fill=LogFit))
LPPlotEH+xlab(bquote("Log(WAANSB)"~log(mcd/m^2)))+ylab("Log(SI (mlx))\nEdited horizon")+scale_color_gradientn("CCT (K)",colours = rev(plasma(10)),limits=c(1500,5000))
#Try a logrithmic model of scalar illuminance versus WAANSB for the data set with no cloud cover for the edited horizon images.
FieldSQCMergeEHSubset <- subset(FieldSQCMergeEH,Clouds==0)
LPLogModelEH <- lm(log10(ScalarIlluminance)~log10(SQA),data=FieldSQCMergeEHSubset)
FieldSQCMergeEHSubset$LogFit <- log10(FieldSQCMergeEHSubset$SQA*LPLogModelZH$coefficients[2])+LPLogModelEH$coefficients[1]
FieldSQCMergeEHSubset <- na.omit(FieldSQCMergeEHSubset,cols=c("LogFit"))
cor.test(FieldSQCMergeEHSubset$LogFit,FieldSQCMergeEHSubset$SQA)
#Plot model
LPPlotEH <- ggplot(FieldSQCMergeEHSubset, aes(x=log10(SQA),y=log10(ScalarIlluminance),color=`CCT (Scalar)`))+geom_point()+theme(text = element_text(size=25))+geom_smooth(method=glm, aes(fill=LogFit))
LPPlotEH+xlab(bquote("Log(WAANSB)"~log(mcd/m^2)))+ylab("Log(SI (mlx))\nEdited horizon")+scale_color_gradientn("CCT (K)",colours = rev(plasma(10)),limits=c(1500,5000))
##Compare luminance within the top and bottom bands of the sky with measurements of the nighttime sky.
cor.test(log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","MeanLuminanceD1"]+1),log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","ScalarIlluminance"]+1))
cor.test(log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","MeanLuminanceD1"]+1),log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","SQA"]+1))
cor.test(log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","MeanLuminanceD1"]+1),log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","VIIRSBrightness"]+1))
cor.test(log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","MeanLuminanceD1"]+1),log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","ScalarIlluminance"]+1))
cor.test(log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","MeanLuminanceD1"]+1),log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","SQA"]+1))
cor.test(log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","MeanLuminanceD1"]+1),log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","VIIRSBrightness"]+1))
cor.test(log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","MeanLuminanceD5"]+1),log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","ScalarIlluminance"]+1))
cor.test(log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","MeanLuminanceD5"]+1),log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","SQA"]+1))
cor.test(log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","MeanLuminanceD5"]+1),log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","VIIRSBrightness"]+1))
cor.test(log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","MeanLuminanceD5"]+1),log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","ScalarIlluminance"]+1))
cor.test(log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","MeanLuminanceD5"]+1),log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","SQA"]+1))
cor.test(log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","MeanLuminanceD5"]+1),log10(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","VIIRSBrightness"]+1))
##Color temperature versus luminance for the top and bottom bands of the sky.
#Plot color temperature versus luminance for ring 1, the top 30 degrees of the sky. Use full hemispheric images.
FieldSQCMergeZHSubset <- na.omit(FieldSQCMergeZH,cols=c("Ring 1Luminance","Ring 1CCT"))
LPPlotZH <- ggplot(FieldSQCMergeZHSubset, aes(x=log10(`Ring 1Luminance`),y=`Ring 1CCT`))+geom_point()+theme(text = element_text(size=25))+geom_smooth(method=glm, aes(fill=`Ring 1CCT`))
LPPlotZH+xlab( bquote("Log(Ring 1 Luminance)"~log(mcd/m^2)))+ylab("Ring 1 CCT (K)")
cor.test(FieldSQCMergeZHSubset$`Ring 1CCT`,log10(FieldSQCMergeZHSubset$`Ring 1Luminance`))
mean(FieldSQCMergeZHSubset$`Ring 1CCT`)
sd(FieldSQCMergeZHSubset$`Ring 1CCT`)
mean(FieldSQCMergeZHSubset[which(FieldSQCMergeZHSubset$`Ring 1Luminance`>=0),c("Ring 1Luminance")])
mean((FieldSQCMergeZHSubset[which(FieldSQCMergeZHSubset$`Ring 1Luminance`>=0),c("Ring 1Luminance")])/(FieldSQCMergeZHSubset[which(FieldSQCMergeZHSubset$`Ring 1Luminance`>=0),c("Ring 3Luminance")]))
sd(FieldSQCMergeZH[which(FieldSQCMergeZH$`Ring 1Luminance`>=0),c("Ring 1Luminance")])
#Plot color temperature versus luminance for ring 7, the bottom 10 degrees of the sky. Use full hemispheric images.
FieldSQCMergeZHSubset <- na.omit(FieldSQCMergeZH,cols=c("Ring 7Luminance","Ring 7CCT"))
LPPlotZH <- ggplot(FieldSQCMergeZHSubset, aes(x=log10(`Ring 7Luminance`),y=`Ring 7CCT`))+geom_point()+theme(text = element_text(size=25))+geom_smooth(method=glm, aes(fill=`Ring 7CCT`))
LPPlotZH+xlab( bquote("Log(Ring 7 Luminance)"~(mcd/m^2)))+ylab("Ring 7 CCT (K)")
cor.test(FieldSQCMergeZHSubset$`Ring 7CCT`,log10(FieldSQCMergeZHSubset$`Ring 7Luminance`))
mean(FieldSQCMergeZHSubset$`Ring 7CCT`)
sd(FieldSQCMergeZHSubset$`Ring 7CCT`)
mean(FieldSQCMergeZHSubset[which(FieldSQCMergeZHSubset$`Ring 7Luminance`>=0),c("Ring 7Luminance")])
mean((FieldSQCMergeZHSubset[which(FieldSQCMergeZHSubset$`Ring 7Luminance`>=0),c("Ring 7Luminance")])/(FieldSQCMergeZHSubset[which(FieldSQCMergeZHSubset$`Ring 7Luminance`>=0),c("Ring 3Luminance")]))
sd(FieldSQCMergeZH[which(FieldSQCMergeZH$`Ring 7Luminance`>=0),c("Ring 7Luminance")])
#Boxplot of luminance values for the top and bottom rings of the sky.
tmp <- as.data.frame(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","MeanLuminanceD5"])
colnames(tmp) <- c("Luminance")
tmp$Ring <- "51.13° to 90°"
tmp2 <- as.data.frame(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","MeanLuminanceD1"])
colnames(tmp2) <- c("Luminance")
tmp2$Ring <- "0° to 11.54°"
tmp <- rbind(tmp,tmp2)
tmp <- na.omit(tmp)
tmp <- tmp[!duplicated(tmp),]
tmp <- subset(tmp,Luminance>=0)
tmp$Ring <- as.factor(tmp$Ring)
LPBoxPlot <- ggplot(tmp,aes(x=Ring,y=Luminance))+geom_boxplot()
LPBoxPlot <- LPBoxPlot + scale_x_discrete(name = "Declination band of sky") + scale_y_continuous(name = bquote("Luminance"~(mcd/m^2)))
LPBoxPlot <- LPBoxPlot + theme(axis.text.x=element_text(colour="black", size = 25), axis.text.y=element_text(colour="black", size = 25),text=element_text(size = 25))
LPBoxPlot
mean(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","MeanLuminanceD1"])
mean(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="ZeroHorizon","MeanLuminanceD5"])
wilcox.test(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","MeanLuminanceD1"],FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","MeanLuminanceD5"],alternative="greater")
#Boxplot of color temperature values for the top and bottom rings of the sky.
tmp <- as.data.frame(as.data.frame(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","CCTD1"]))
colnames(tmp) <- c("CCT")
tmp$Ring <- "0° to 11.54°"
tmp2 <- as.data.frame(as.data.frame(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","CCTD5"]))
colnames(tmp2) <- c("CCT")
tmp2$Ring <- "51.13° to 90°"
tmp <- rbind(tmp,tmp2)
tmp <- na.omit(tmp)
tmp <- tmp[!duplicated(tmp),]
tmp$Ring <- as.factor(tmp$Ring)
LPBoxPlot <- ggplot(tmp,aes(x=Ring,y=CCT))+geom_boxplot()
LPBoxPlot <- LPBoxPlot + scale_x_discrete(name = "Declination band of sky") + scale_y_continuous(name = "CCT (K)")
LPBoxPlot <- LPBoxPlot + theme(axis.text.x=element_text(colour="black", size = 25), axis.text.y=element_text(colour="black", size = 25),text=element_text(size = 25))
LPBoxPlot
mean(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","CCTD1"])
mean(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","CCTD5"])
wilcox.test(FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","CCTD1"],FieldSQCMerge[FieldSQCMerge$TypeHorizon=="EditedHorizon","CCTD5"],alternative="less")
#Plot coefficient of variation on scalar illuminance within VIIRS pixels.
LPPlotZH <- ggplot(FieldSQCMergeZH, aes(x=log10(VIIRSBrightness+1),y=ScalarIlluminanceSiteCoV))+geom_point()+theme(text = element_text(size=25))+geom_smooth(method=glm, aes(fill=CoVLuminance))
LPPlotZH+xlab(bquote("Log(VIIRS+1)"~log(nW/Sr/cm^2)))+ylab("CoV on SI within sites")
cor.test(log10(FieldSQCMergeZH$VIIRSBrightness+1),FieldSQCMergeZH$ScalarIlluminanceSiteCoV)
#
LPPlotZH <- ggplot(FieldSQCMergeZH, aes(x=log10(SQA),y=ScalarIlluminanceSiteCoV))+geom_point()+theme(text = element_text(size=25))+geom_smooth(method=glm, aes(fill=CoVLuminance))
LPPlotZH+xlab(bquote("Log(WAANSB)"~log(mcd/m^2)))+ylab("CoV on SI within sites")
cor.test(log10(FieldSQCMergeZH$SQA),FieldSQCMergeZH$ScalarIlluminanceSiteCoV)
#Plot coefficient of variation on luminance within images.
LPPlotZH <- ggplot(FieldSQCMergeZH, aes(x=Clouds,y=CoVLuminance))+geom_point()+theme(text = element_text(size=25))+geom_smooth(method=glm, aes(fill=CoVLuminance))
LPPlotZH+xlab("% Clouds")+ylab("CoV on Luminance")
cor.test(FieldSQCMergeZH$Clouds,FieldSQCMergeZH$CoVLuminance)
#
LPPlotZH <- ggplot(FieldSQCMergeZH, aes(x=Horizon,y=CoVLuminance))+geom_point()+theme(text = element_text(size=25))+geom_smooth(method=glm, aes(fill=CoVLuminance))
LPPlotZH+xlab("% Horizon")+ylab("CoV on Luminance")
cor.test(FieldSQCMergeZH$Horizon,FieldSQCMergeZH$CoVLuminance)
#Plot mean SQM readings against luminance in different regions of the sky.
FieldSQCMergeZHSubset <- na.omit(FieldSQCMergeZH,cols=c("Ring 1Luminance"))
LPPlotZH <- ggplot(FieldSQCMergeZHSubset, aes(x=SQMMean,y=log10(`Ring 1Luminance`),color=`CCT (Scalar)`))+geom_point()+theme(text = element_text(size=25))+geom_smooth(method=glm, aes(fill=log10(`Ring 1Luminance`)))
LPPlotZH+xlab("SQM Mean (mag)")+ylab(expression(atop("Log(L) Top 30°",paste("Log(mcd/",m^{2},")"))))+scale_color_gradientn("CCT (K)",colours = rev(plasma(10)),limits=c(1500,5000))
LPLogModelZH <- lm(log10(`Ring 1Luminance`)~SQMMean,data=FieldSQCMergeZHSubset)
cor.test(FieldSQCMergeZHSubset$SQMMean,log10(FieldSQCMergeZHSubset$`Ring 1Luminance`))
#
FieldSQCMergeZHSubset <- na.omit(FieldSQCMergeZH,cols=c("Ring 7Luminance"))
LPPlotZH <- ggplot(FieldSQCMergeZHSubset, aes(x=SQMMean,y=log10(`Ring 7Luminance`),color=`CCT (Scalar)`))+geom_point()+theme(text = element_text(size=25))+geom_smooth(method=glm, aes(fill=log10(`Ring 7Luminance`)))
LPPlotZH+xlab("SQM Mean (mag)")+ylab(expression(atop("Log(L) Bottom 10°",paste("Log(mcd/",m^{2},")"))))+scale_color_gradientn("CCT (K)",colours = rev(plasma(10)),limits=c(1500,5000))
LPLogModelZH <- lm(log10(`Ring 7Luminance`)~SQMMean,data=FieldSQCMergeZHSubset)
cor.test(FieldSQCMergeZHSubset$SQMMean,log10(FieldSQCMergeZHSubset$`Ring 7Luminance`))
#To map various measures of coastal light pollution.
MapCoordinates <- FieldSQCMergeZH
colnames(MapCoordinates)[which(names(MapCoordinates) == "Latitude")] <- "SQCLatitude"
colnames(MapCoordinates)[which(names(MapCoordinates) == "Longitude")] <- "SQCLongitude"
colnames(MapCoordinates)[which(names(MapCoordinates) == "Adjusted latitude")] <- "latitude"
colnames(MapCoordinates)[which(names(MapCoordinates) == "Adjusted longitude")] <- "longitude"
MapCoordinates <- MapCoordinates[!is.na(MapCoordinates$latitude) & !is.na(MapCoordinates$longitude),]
CalMap = leaflet(MapCoordinates) %>%
addTiles()
ColorScale <- colorNumeric(palette=plasma(10),domain=log10(FieldSQCMergeZH$VIIRSBrightness+1))
CalMap %>% addCircleMarkers(color = ~ColorScale(log10(VIIRSBrightness+1)), fill = TRUE,radius=2,fillOpacity = 0.1) %>%
addProviderTiles(providers$Esri.WorldTopoMap) %>%
leaflet::addLegend(position="topright", pal=ColorScale,values=~log10(VIIRSBrightness+1),opacity=1,title="log(VIIRS+1)<br>log(nW/cm<sup>2</sup>/sr)")