forked from overeem11/RAINLINK
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRun.R
More file actions
426 lines (305 loc) · 20.3 KB
/
Run.R
File metadata and controls
426 lines (305 loc) · 20.3 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
## The RAINLINK package. Retrieval algorithm for rainfall mapping from microwave links
## in a cellular communication network.
##
## Version 1.11
## Copyright (C) 2017 Aart Overeem
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
## R program 'Run.R'.
## SCRIPT FOR RAINFALL ESTIMATION USING MICROWAVE LINKS.
## source("Run.R")
## Run this script by pasting the line above (source(...)) or by pasting parts of the script into the R shell.
# Note that it is not necessarily a problem if a function argument is not supplied to the function. If the
# function argument is not used, then there is no problem. Only be aware that you should use e.g.
# MaxFrequency=MaxFrequency. I.e. if you only supply MaxFrequency and the function argument before
# MaxFrequency is missing, than the function will not execute properly.
#############################################################
# 0. Load R libraries, parameter values, and other settings.#
# This also loads the RAINLINK package. #
#############################################################
source("Config.R")
############################
# 1. PreprocessingMinMaxRSL#
############################
# Load example data:
data(Linkdata)
# Run R function:
StartTime <- proc.time()
DataPreprocessed <- PreprocessingMinMaxRSL(Data=Linkdata,MaxFrequency=MaxFrequency,MinFrequency=MinFrequency,verbose=TRUE)
cat(sprintf("Finished. (%.1f seconds)\n",round((proc.time()-StartTime)[3],digits=1)))
############################################
# 2. WetDryNearbyLinkApMinMaxRSL (OPTIONAL)#
############################################
# Run R function:
StartTime <- proc.time()
WetDry <- WetDryNearbyLinkApMinMaxRSL(Data=DataPreprocessed,CoorSystemInputData=NULL,
MinHoursPmin=MinHoursPmin,PeriodHoursPmin=PeriodHoursPmin,Radius=Radius,Step8=Step8,
ThresholdMedian=ThresholdMedian,ThresholdMedianL=ThresholdMedianL,ThresholdNumberLinks=ThresholdNumberLinks,
ThresholdWetDry=ThresholdWetDry)
cat(sprintf("Finished. (%.1f seconds)\n",round((proc.time()-StartTime)[3],digits=1)))
#######################
# 3. RefLevelMinMaxRSL#
#######################
# Run R function:
StartTime <- proc.time()
Pref <- RefLevelMinMaxRSL(Data=DataPreprocessed,Dry=WetDry$Dry,HoursRefLevel=HoursRefLevel,PeriodHoursRefLevel=PeriodHoursRefLevel)
cat(sprintf("Finished. (%.1f seconds)\n",round((proc.time()-StartTime)[3],digits=1)))
# If wet-dry classification (function WetDryNearbyLinkApMinMaxRSL) has not been applied, run the R function as follows:
StartTime <- proc.time()
Pref <- RefLevelMinMaxRSL(Data=DataPreprocessed,HoursRefLevel=HoursRefLevel,PeriodHoursRefLevel=PeriodHoursRefLevel)
cat(sprintf("Finished. (%.1f seconds)\n",round((proc.time()-StartTime)[3],digits=1)))
#############################################################################################################
# 4. OutlierFilterMinMax (OPTIONAL) - Can only be applied when WetDryNearbyLinkApMinMaxRSL has been applied.#
#############################################################################################################
# Run R function:
DataOutlierFiltered <- OutlierFilterMinMaxRSL(Data=DataPreprocessed,F=WetDry$F,FilterThreshold=FilterThreshold)
######################
# 5. CorrectMinMaxRSL#
######################
# Run R function:
Pcor <- CorrectMinMaxRSL(Data=DataOutlierFiltered,Dry=WetDry$Dry,Pref=Pref)
# If wet-dry classification (function WetDryNearbyLinkApMinMaxRSL) has not been applied, run the R function as follows:
Pcor <- CorrectMinMaxRSL(Data=DataPreprocessed,Pref=Pref)
############################
# 6. RainRetrievalMinMaxRSL#
############################
kRPowerLawData <- read.table(FileRainRetr)
colnames(kRPowerLawData) <- c("f", "a", "b")
# Run R function:
StartTime <- proc.time()
Rmean <- RainRetrievalMinMaxRSL(Aa=Aa,alpha=alpha,Data=DataOutlierFiltered,kRPowerLawData=kRPowerLawData,PmaxCor=Pcor$PmaxCor,PminCor=Pcor$PminCor,Pref=Pref)
cat(sprintf("Finished. (%.1f seconds)\n",round((proc.time()-StartTime)[3],digits=1)))
# If wet-dry classification (function WetDryNearbyLinkApMinMaxRSL) has not been applied, run the R function as follows:
StartTime <- proc.time()
Rmean <- RainRetrievalMinMaxRSL(Aa=Aa,alpha=alpha,Data=DataPreprocessed,kRPowerLawData=kRPowerLawData,PmaxCor=Pcor$PmaxCor,PminCor=Pcor$PminCor,Pref=Pref)
cat(sprintf("Finished. (%.1f seconds)\n",round((proc.time()-StartTime)[3],digits=1)))
# Duration of time interval of sampling strategy (min):
TIMESTEP <- 15
# Location of output link data:
FolderRainEstimates <- paste("LinkPathRainDepths",TIMESTEP,"min",sep="")
ToFile = TRUE
if (ToFile)
{
# Create directory for output files:
if(!dir.exists(FolderRainEstimates)){ dir.create(FolderRainEstimates) }
# Write output to file
ID <- unique(DataPreprocessed$ID)
t <- sort(unique(DataPreprocessed$DateTime))
t_sec <- as.numeric(as.POSIXct(as.character(t), format = "%Y%m%d%H%M"))
dt <- min(diff(t_sec))
for (i in 1 : length(t))
{
ind <- which(DataPreprocessed$DateTime == t[i])
int_data <- data.frame(ID = DataPreprocessed$ID[ind], RainfallDepthPath = Rmean[ind] * dt / 3600,
PathLength = DataPreprocessed$PathLength[ind], XStart = DataPreprocessed$XStart[ind],
YStart = DataPreprocessed$YStart[ind], XEnd = DataPreprocessed$XEnd[ind],
YEnd = DataPreprocessed$YEnd[ind], IntervalNumber = rep(i, length(ind)),
Frequency = DataPreprocessed$Frequency[ind])
Filename <- paste(FolderRainEstimates, "/linkdata_", t[i], ".dat", sep="")
write.table(int_data, Filename, row.names = FALSE, col.names = TRUE, append = FALSE, quote = FALSE)
}
}
# Note that the output files contain rainfall depths (mm). If these data are to be used for the interpolation, they must first be read ("Interpolation.R" does not read these files).
# Using the data for "Interpolation.R" requires a conversion from rainfall depth (mm) to rainfall intensity (mm/h).
###################
# 7. Interpolation#
###################
# Read grid onto which data are interpolated
RainGrid <- read.table(FileGrid, header = TRUE, sep=",")
# Duration of time interval of sampling strategy (min):
TIMESTEP <- 15
# Location of output link data:
FolderRainMaps <- paste("RainMapsLinks",TIMESTEP,"min",sep="")
# Run R function:
StartTime <- proc.time()
Interpolation(Data=DataPreprocessed,CoorSystemInputData=NULL,idp=idp,IntpMethod=IntpMethod,nmax=nmax,
NUGGET=NUGGET,RANGE=RANGE,RainGrid=RainGrid,Rmean=Rmean,SILL=SILL,Variogram=Variogram,OutputDir=FolderRainMaps)
cat(sprintf("Finished. (%.1f seconds)\n",round((proc.time()-StartTime)[3],digits=1)))
###################
# 8. Visualisation#
###################
# Executing the "RainMaps...R" functions can often give the error below for Google Maps, which is
# caused by the Google server. Apparently, maps have been downloaded too often. Just try again (and again).
# Error in data.frame(ll.lat = ll[1], ll.lon = ll[2], ur.lat = ur[1], ur.lon = ur[2]) :
# arguments imply differing number of rows: 0, 1
# In addition: Warning message:
# geocode failed with status OVER_QUERY_LIMIT, location = "De Eemhof, Zeewolde"
# Executing revgeocode(c(Lon,Lat)) can also give an error, which is probably also related to obtaining the map from the Google Maps server. Just try again (and again):
# Warning message:
# In revgeocode(c(LonLocation, LatLocation)) :
# reverse geocode failed - bad location? location = "4.85"reverse geocode failed - bad location? location = "52.39"
############################
# 8.1 RainMapsLinksTimeStep#
############################
# Date and time at which rainfall mapping starts:
DateTimeStartRainMaps <- "201109102045"
# Date and time at which rainfall mapping ends:
DateTimeEndRainMaps <- "201109102045"
# Both should be "201109102045" to reproduce Figure 5 from AMT manuscript.
# Both should be "201109102015" to reproduce Figure 7 from AMT manuscript.
# Run function RainMapsLinksTimeStep:
RainMapsLinksTimeStep(AlphaLinksTimeStep=AlphaLinksTimeStep,AlphaPlotLocation=AlphaPlotLocation,AlphaPolygon=AlphaPolygon,
AutDefineLegendTop=AutDefineLegendTop,BBoxOSMauto=BBoxOSMauto,ColourLinks=ColourLinks,ColoursNumber=ColoursNumber,ColourPlotLocation=ColourPlotLocation,
ColourPlotLocationText=ColourPlotLocationText,ColourScheme=ColourScheme,ColourType=ColourType,ConversionDepthToIntensity=ConversionDepthToIntensity,
CoorSystemInputData=CoorSystemInputData,DateTimeEndRainMaps=DateTimeEndRainMaps,DateTimeStartRainMaps=DateTimeStartRainMaps,ExtraDeg=ExtraDeg,ExtraText=ExtraText,
FigFileLinksTimeStep=FigFileLinksTimeStep,FigHeight=FigHeight,FigWidth=FigWidth,FileGrid=FileGrid,FilePolygonsGrid=FilePolygonsGrid,FolderFigures=FolderFigures,
FolderRainMaps=FolderRainMaps,FolderRainEstimates=FolderRainEstimates,FontFamily=FontFamily,GoogleLocDegSpecified=GoogleLocDegSpecified,GoogleLocLat=GoogleLocLat,
GoogleLocLon=GoogleLocLon,GoogleLocName=GoogleLocName,GoogleLocNameSpecified=GoogleLocNameSpecified,GoogleMapType=GoogleMapType,GoogleZoomlevel=GoogleZoomlevel,
LabelAxisLat=LabelAxisLat,LabelAxisLonGoogle=LabelAxisLonGoogle,LabelAxisLonOSM=LabelAxisLonOSM,LatLocation=LatLocation,LatText=LatText,
LegendTitleLinksTimeStep=LegendTitleLinksTimeStep,LonLocation=LonLocation,LonText=LonText,ManualScale=ManualScale,MapBackground=MapBackground,OSMBottom=OSMBottom,
OSMLeft=OSMLeft,OSMRight=OSMRight,OSMScale=OSMScale,OSMTop=OSMTop,PlotLocation=PlotLocation,PixelBorderCol=PixelBorderCol,
PlotBelowScaleBottom=PlotBelowScaleBottom,PlotLocLinks=PlotLocLinks,ScaleBottomTimeStep=ScaleBottomTimeStep,ScaleHigh=ScaleHigh,ScaleLow=ScaleLow,
ScaleTopTimeStep=ScaleTopTimeStep,SizeLinks=SizeLinks,SizePixelBorder=SizePixelBorder,SizePlotLocation=SizePlotLocation,SizePlotTitle=SizePlotTitle,
SymbolPlotLocation=SymbolPlotLocation,TitleLinks=TitleLinks,XMiddle=XMiddle,YMiddle=YMiddle)
#########################
# 8.2 RainMapsLinksDaily#
#########################
# Date and time at which rainfall mapping starts:
DateTimeStartRainMaps <- "201109100800"
# Date and time at which rainfall mapping ends:
DateTimeEndRainMaps <- "201109110800"
# Run function RainMapsLinksDaily:
RainMapsLinksDaily(AlphaLinksDaily=AlphaLinksDaily,AlphaPlotLocation=AlphaPlotLocation,AlphaPolygon=AlphaPolygon,
AutDefineLegendTop=AutDefineLegendTop,BBoxOSMauto=BBoxOSMauto,ColourLinks=ColourLinks,ColoursNumber=ColoursNumber,ColourPlotLocation=ColourPlotLocation,
ColourPlotLocationText=ColourPlotLocationText,ColourScheme=ColourScheme,ColourType=ColourType,ConversionDepthToIntensity=ConversionDepthToIntensity,
CoorSystemInputData=CoorSystemInputData,DateTimeEndRainMaps=DateTimeEndRainMaps,DateTimeStartRainMaps=DateTimeStartRainMaps,ExtraDeg=ExtraDeg,
ExtraText=ExtraText,FigFileLinksDaily=FigFileLinksDaily,FigHeight=FigHeight,FigWidth=FigWidth,FileGrid=FileGrid,FilePolygonsGrid=FilePolygonsGrid,
FolderFigures=FolderFigures,FolderRainMaps=FolderRainMaps,FolderRainEstimates=FolderRainEstimates,FontFamily=FontFamily,
GoogleLocDegSpecified=GoogleLocDegSpecified,GoogleLocLat=GoogleLocLat,GoogleLocLon=GoogleLocLon,GoogleLocName=GoogleLocName,
GoogleLocNameSpecified=GoogleLocNameSpecified,GoogleMapType=GoogleMapType,GoogleZoomlevel=GoogleZoomlevel,LabelAxisLat=LabelAxisLat,
LabelAxisLonGoogle=LabelAxisLonGoogle,LabelAxisLonOSM=LabelAxisLonOSM,LatLocation=LatLocation,LatText=LatText,
LegendTitleLinksDaily=LegendTitleLinksDaily,LonLocation=LonLocation,LonText=LonText,ManualScale=ManualScale,MapBackground=MapBackground,
OSMBottom=OSMBottom,OSMLeft=OSMLeft,OSMRight=OSMRight,OSMScale=OSMScale,OSMTop=OSMTop,PERIOD=PERIOD,PlotLocation=PlotLocation,
PixelBorderCol=PixelBorderCol,PlotBelowScaleBottom=PlotBelowScaleBottom,PlotLocLinks=PlotLocLinks,ScaleBottomDaily=ScaleBottomDaily,
ScaleHigh=ScaleHigh,ScaleLow=ScaleLow,ScaleTopDaily=ScaleTopDaily,SizeLinks=SizeLinks,SizePixelBorder=SizePixelBorder,SizePlotLocation=SizePlotLocation,
SizePlotTitle=SizePlotTitle,SymbolPlotLocation=SymbolPlotLocation,TIMESTEP=TIMESTEP,TitleLinks=TitleLinks,XMiddle=XMiddle,YMiddle=YMiddle)
#############################
# 8.3 RainMapsRadarsTimeStep#
#############################
# Name and path of daily radar input file:
# NetCDF4 file for daily rainfall depths:
# Download from Climate4Impact using R (works at least for Linux):
# Paste contents of file "Radar5min/Climate4ImpactDownloadNETCDF5min.txt" in command shell.
# Path in NetCDF4 file with radar data:
PathRadarRainfallDepth <- "image1_image_data"
# Name of folder which contains 5-min radar rainfall files
FolderRadarRainMapsTimeStep <- "Radar5min"
# Run function RainMapsRadarsTimeStep:
RainMapsRadarsTimeStep(AlphaPlotLocation=AlphaPlotLocation,AlphaPolygon=AlphaPolygon,
AutDefineLegendTop=AutDefineLegendTop,BBoxOSMauto=BBoxOSMauto,ColoursNumber=ColoursNumber,ColourPlotLocation=ColourPlotLocation,
ColourPlotLocationText=ColourPlotLocationText,ColourScheme=ColourScheme,ColourType=ColourType,
CoorSystemInputData=CoorSystemInputData,ExtraDeg=ExtraDeg,ExtraText=ExtraText,FigFileRadarsTimeStep=FigFileRadarsTimeStep,FigHeight=FigHeight,
FigWidth=FigWidth,FileGrid=FileGrid,FilePolygonsGrid=FilePolygonsGrid,FolderFigures=FolderFigures,FolderRadarRainMapsTimeStep=FolderRadarRainMapsTimeStep,
FontFamily=FontFamily,GoogleLocDegSpecified=GoogleLocDegSpecified,GoogleLocLat=GoogleLocLat,
GoogleLocLon=GoogleLocLon,GoogleLocName=GoogleLocName,GoogleLocNameSpecified=GoogleLocNameSpecified,GoogleMapType=GoogleMapType,GoogleZoomlevel=GoogleZoomlevel,
LabelAxisLat=LabelAxisLat,LabelAxisLonGoogle=LabelAxisLonGoogle,LabelAxisLonOSM=LabelAxisLonOSM,LatLocation=LatLocation,LatText=LatText,
LegendTitleRadarsTimeStep=LegendTitleRadarsTimeStep,LonLocation=LonLocation,LonText=LonText,ManualScale=ManualScale,MapBackground=MapBackground,
OSMBottom=OSMBottom,OSMLeft=OSMLeft,OSMRight=OSMRight,OSMScale=OSMScale,OSMTop=OSMTop,PathRadarRainfallDepth=PathRadarRainfallDepth,
PERIOD=PERIOD,PlotLocation=PlotLocation,PixelBorderCol=PixelBorderCol,PlotBelowScaleBottom=PlotBelowScaleBottom,
ScaleBottomTimeStep=ScaleBottomTimeStep,ScaleHigh=ScaleHigh,ScaleLow=ScaleLow,ScaleTopTimeStep=ScaleTopTimeStep,SizePixelBorder=SizePixelBorder,
SizePlotLocation=SizePlotLocation,SizePlotTitle=SizePlotTitle,SymbolPlotLocation=SymbolPlotLocation,TIMESTEP=TIMESTEP,TimeZone=TimeZone,TitleRadars=TitleRadars,XMiddle=XMiddle,
YMiddle=YMiddle)
##########################
# 8.4 RainMapsRadarsDaily#
##########################
DateMap <- "20110911"
# Name and path of daily radar input file:
# NetCDF4 file for daily rainfall depths:
# Download from Climate4Impact (works at least for Linux):
# path <- "http://opendap.knmi.nl/knmi/thredds/fileServer/radarprecipclim/RAD_NL25_RAC_MFBS_24H_NC/2011/09/RAD_NL25_RAC_MFBS_24H_201109110800.nc"
# download.file(path,"RAD_NL25_RAC_MFBS_24H_201109110800.nc",method="wget",quiet=F,mode="wb",cacheOK=T)
FileNameRadarDaily <- "RAD_NL25_RAC_MFBS_24H_201109110800.nc"
# Path in NetCDF4 file with radar data:
PathRadarRainfallDepth <- "image1_image_data"
# Name of folder which contains daily radar rainfall files
FolderRadarRainMapsDaily <- "Radar24H"
# Run function RainMapsRadarsDaily:
RainMapsRadarsDaily(AlphaPlotLocation=AlphaPlotLocation,AlphaPolygon=AlphaPolygon,
AutDefineLegendTop=AutDefineLegendTop,BBoxOSMauto=BBoxOSMauto,ColoursNumber=ColoursNumber,ColourPlotLocation=ColourPlotLocation,
ColourPlotLocationText=ColourPlotLocationText,ColourScheme=ColourScheme,ColourType=ColourType,CoorSystemInputData=CoorSystemInputData,DateMap=DateMap,ExtraDeg=ExtraDeg,
ExtraText=ExtraText,FigFileRadarsDaily=FigFileRadarsDaily,FigHeight=FigHeight,FigWidth=FigWidth,FileGrid=FileGrid,FileNameRadarDaily=FileNameRadarDaily,
FilePolygonsGrid=FilePolygonsGrid,FolderFigures=FolderFigures,FolderRadarRainMapsDaily=FolderRadarRainMapsDaily,FontFamily=FontFamily,
GoogleLocDegSpecified=GoogleLocDegSpecified,GoogleLocLat=GoogleLocLat,GoogleLocLon=GoogleLocLon,GoogleLocName=GoogleLocName,
GoogleLocNameSpecified=GoogleLocNameSpecified,GoogleMapType=GoogleMapType,GoogleZoomlevel=GoogleZoomlevel,LabelAxisLat=LabelAxisLat,
LabelAxisLonGoogle=LabelAxisLonGoogle,LabelAxisLonOSM=LabelAxisLonOSM,LatLocation=LatLocation,LatText=LatText,
LegendTitleRadarsDaily=LegendTitleRadarsDaily,LonLocation=LonLocation,LonText=LonText,ManualScale=ManualScale,MapBackground=MapBackground,
OSMBottom=OSMBottom,OSMLeft=OSMLeft,OSMRight=OSMRight,OSMScale=OSMScale,OSMTop=OSMTop,PathRadarRainfallDepth=PathRadarRainfallDepth,
PERIOD=PERIOD,PlotLocation=PlotLocation,PixelBorderCol=PixelBorderCol,PlotBelowScaleBottom=PlotBelowScaleBottom,
ScaleBottomDaily=ScaleBottomDaily,ScaleHigh=ScaleHigh,ScaleLow=ScaleLow,ScaleTopDaily=ScaleTopDaily,SizePixelBorder=SizePixelBorder,
SizePlotLocation=SizePlotLocation,SizePlotTitle=SizePlotTitle,SymbolPlotLocation=SymbolPlotLocation,TimeZone=TimeZone,TitleRadars=TitleRadars,XMiddle=XMiddle,
YMiddle=YMiddle)
#######################
# 8.5 ReadRainLocation#
#######################
# Load (daily) radar rainfall data:
ncFILE <- nc_open(paste(FolderRadarRainMapsDaily,"/",FileNameRadarDaily,sep=""),verbose=F)
dataf <- c(ncvar_get(ncFILE,varid="image1_image_data"))
dataf <- dataf[!is.na(dataf)]
nc_close(ncFILE)
# File with interpolation grid in same coordinate system as CoorSystemInputData:
FileGrid <- "InterpolationGrid.dat" # WGS84 (longitude, latitude (degrees))
# OR load e.g. 15-min link data:
# Duration of time interval of sampling strategy (min):
TIMESTEP <- 15
# Conversion factor from rainfall intensity (mm/h) to depth (mm):
MinutesHour <- 60
ConversionIntensityToDepth <- TIMESTEP/MinutesHour
# Location of link data:
FolderRainMaps <- paste("RainMapsLinks",TIMESTEP,"min",sep="")
# Make list of input files:
Files <- list.files(path = FolderRainMaps, all.files=FALSE,
full.names=TRUE, recursive=FALSE, pattern="linkmap")
# Select date and time for which links are to be plotted:
DateTime <- "201109110200"
condTime <- grep(DateTime,Files)
# Select file:
Filename <- Files[condTime]
# Read data from input file:
dataf <- read.table(Filename,header=TRUE)
dataf <- ConversionIntensityToDepth * dataf[,1]
# Location for which rainfall depth is to be extracted:
Lon = 5.1214201
Lat = 52.0907374
# Run function ReadRainLocation:
ReadRainLocation(CoorSystemInputData=CoorSystemInputData,dataf=dataf,FileGrid=FileGrid,Lat=Lat,Lon=Lon,XMiddle=XMiddle,YMiddle=YMiddle)
# R provides tools to extract the street name and municipality for a location:
revgeocode(c(Lon,Lat))
# If you would like to know the rainfall depth for a street name and municipality, R can provide you with the location in degrees:
# Give latitude and longitude for location known by street name and municipality:
geocode("Domplein 1, Utrecht")
#######################
# 9. PlotLinkLocations#
#######################
# Duration of time interval of sampling strategy (min):
TIMESTEP <- 15
# Location of link data:
FolderRainEstimates <- paste("LinkPathRainDepths",TIMESTEP,"min",sep="")
# Make list of input files:
Files <- list.files(path = FolderRainEstimates, all.files=FALSE,
full.names=TRUE, recursive=FALSE, pattern="linkdata")
# Select date and time for which links are to be plotted:
DateTime <- "201109110200"
condTime <- grep(DateTime,Files)
# Select file:
Filename <- Files[condTime]
# Read data from input file:
dataf <- read.table(Filename,header=TRUE)
# Plot link locations on a map:
PlotLinkLocations(AlphaLinkLocations=AlphaLinkLocations,BBoxOSMauto=BBoxOSMauto,OSMBottom=OSMBottom,ColourLinks=ColourLinks,
ColourType=ColourType,dataf=dataf,DateTime=DateTime,ExtraTextLinkLocations=ExtraTextLinkLocations,FigFileLinkLocations=FigFileLinkLocations,
FigHeight=FigHeight,FigWidth=FigWidth,FolderFigures=FolderFigures,FontFamily=FontFamily,GoogleLocDegSpecified=GoogleLocDegSpecified,
GoogleLocLat=GoogleLocLat,GoogleLocLon=GoogleLocLon,GoogleLocName=GoogleLocName,GoogleLocNameSpecified=GoogleLocNameSpecified,
GoogleMapType=GoogleMapType,GoogleZoomlevel=GoogleZoomlevel,LabelAxisLat=LabelAxisLat,LabelAxisLonGoogle=LabelAxisLonGoogle,
LabelAxisLonOSM=LabelAxisLonOSM,OSMLeft=OSMLeft,MapBackground=MapBackground,OSMRight=OSMRight,OSMScale=OSMScale,
SizeLinks=SizeLinks,SizePlotTitle=SizePlotTitle,TitleLinkLocations=TitleLinkLocations,OSMTop=OSMTop)