-
Notifications
You must be signed in to change notification settings - Fork 5
/
weatherOz_for_DPIRD.Rmd
1419 lines (1282 loc) · 63.4 KB
/
weatherOz_for_DPIRD.Rmd
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
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "weatherOz for DPIRD"
author: "Rodrigo Pires, Anna Hepworth, Rebecca O'Leary and Adam H. Sparks"
output:
rmarkdown::html_vignette:
toc: true
vignette: >
%\VignetteIndexEntry{weatherOz for DPIRD}
%\VignetteEngine{knitr::rmarkdown_notangle}
%\VignetteEncoding{UTF-8}
---
## About DPIRD Data
From the DPIRD Weather Website's ["About" Page](https://weather.agric.wa.gov.au/about).
> The Department of Primary Industries and Regional Development's (DPIRD) network of automatic weather stations and radars throughout the state provide timely, relevant and local weather data to assist growers and regional communities make more-informed decisions.
>
> The weather station data includes air temperature, humidity, rainfall, wind speed and direction, with most stations also measuring incoming solar radiation to calculate evaporation. This website includes dashboards for each station to visualise this data.
Data from the DPIRD API are licenced under the [Creative Commons Attribution 3.0 Licence (CC BY 3.0 AU)](https://creativecommons.org/licenses/by/3.0/au/deed.en).
## A Note on API Keys
All examples in this vignette assume that you have stored your API key in your .Renviron file.
See [Chapter 8](https://rstats.wtf/r-startup.html#renviron) in "What They Forgot to Teach You About R" by Bryan _et al._ for more on storing details in your .Renviron if you are unfamiliar.
## Working With DPIRD Data
Three functions are provided to streamline fetching data from the DPIRD Weather 2.0 API endpoints.
* `get_dpird_extremes()`, which returns the recorded extreme values for the given station in the DPIRD weather station network.;
* `get_dpird_minute()`, which returns weather data in minute increments for stations in the DPIRD weather station network with only the past two years being available; and
* `get_dpird_summaries()`, which returns weather data in 15 and 30 minute, hourly, daily, monthly or yearly summary values for stations in the DPIRD weather station network.
## Getting Extreme Weather Values
The `get_dpird_extremes()` function fetches and returns nicely formatted individual extreme weather summaries from the DPIRD Weather 2.0 API.
You must provide a `station_code` and `API_key`, the other arguments, `values` and `include_closed` are optional.
### Available Values for Extreme Weather
* all (which will return all of the following values),
* erosionCondition,
* erosionConditionLast7Days,
* erosionConditionLast7DaysDays,
* erosionConditionLast7DaysMinutes,
* erosionConditionLast14Days,
* erosionConditionLast14DaysDays,
* erosionConditionLast14DaysMinutes,
* erosionConditionMonthToDate,
* erosionConditionMonthToDateDays,
* erosionConditionMonthToDateMinutes,
* erosionConditionMonthToDateStartTime,
* erosionConditionSince12AM,
* erosionConditionSince12AMMinutes,
* erosionConditionSince12AMStartTime,
* erosionConditionYearToDate,
* erosionConditionYearToDateDays,
* erosionConditionYearToDateMinutes,
* erosionConditionYearToDateStartTime,
* frostCondition,
* frostConditionLast7Days,
* frostConditionLast7DaysDays,
* frostConditionLast7DaysMinutes,
* frostConditionLast14Days,
* frostConditionLast14DaysDays,
* frostConditionLast14DaysMinutes,
* frostConditionMonthToDate,
* frostConditionMonthToDateDays,
* frostConditionMonthToDateMinutes,
* frostConditionMonthToDateStartTime,
* frostConditionSince9AM,
* frostConditionSince9AMMinutes,
* frostConditionSince9AMStartTime,
* frostConditionTo9AM,
* frostConditionTo9AMMinutes,
* frostConditionTo9AMStartTime,
* frostConditionYearToDate,
* frostConditionYearToDate,
* frostConditionYearToDateMinutes,
* frostConditionYearToDateStartTime,
* heatCondition,
* heatConditionLast7Days,
* heatConditionLast7DaysDays,
* heatConditionLast7DaysMinutes,
* heatConditionLast14Days,
* heatConditionLast14DaysDays,
* heatConditionLast14DaysMinutes,
* heatConditionMonthToDate,
* heatConditionMonthToDateDays,
* heatConditionMonthToDateMinutes,
* heatConditionMonthToDateStartTime,
* heatConditionSince12AM,
* heatConditionSince12AMMinutes,
* heatConditionSince12AMStartTime,
* heatConditionYearToDate,
* heatConditionYearToDateDays,
* heatConditionYearToDateMinutes, and
* heatConditionYearToDateStartTime
### Example 1: Get All Extremes for Northam, WA
In the first example, we illustrate how to fetch all extreme values available for Northam.
``` r
library(weatherOz)
(extremes <- get_dpird_extremes(
station_code = "NO",
api_key = Sys.getenv("DPIRD_API_KEY")
))
```
### Example 2: Get Selected Extremes for Northam, WA
Fetch only soil erosion extreme conditions for Northam, WA.
The documentation for `get_dpird_extremes()` contains a full listing of the values that are available to query from this API endpoint.
``` r
library(weatherOz)
(
extremes <- get_dpird_extremes(
station_code = "NO",
values = "erosionCondition",
api_key = Sys.getenv("DPIRD_API_KEY")
)
)
```
## Getting Minute Data
This function fetches nicely formatted minute weather station data from the DPIRD Weather 2.0 API for a maximum 24-hour period.
You must provide a `station_code` and `API_key`, the other arguments, `start_date_time`, `minutes` and `values` are optional.
### Available Values for Minute Data
* all (which will return all of the following values),
* airTemperature,
* dateTime,
* dewPoint,
* rainfall,
* relativeHumidity,
* soilTemperature,
* solarIrradiance,
* wetBulb,
* wind,
* windAvgSpeed,
* windMaxSpeed, and
* windMinSpeed
### Example 3: Get All Minute Data for the Past 24 Hours
``` r
library(weatherOz)
(
min_dat <- get_dpird_minute(
station_code = "NO",
api_key = Sys.getenv("DPIRD_API_KEY")
)
)
#> Key: <station_code>
#> station_code date_time air_temperature relative_humidity
#> <fctr> <POSc> <num> <num>
#> 1: NO 2024-06-05 14:35:00 22.5 41.6
#> 2: NO 2024-06-05 14:36:00 22.5 41.0
#> 3: NO 2024-06-05 14:37:00 22.4 40.9
#> 4: NO 2024-06-05 14:38:00 22.3 42.4
#> 5: NO 2024-06-05 14:39:00 22.4 41.2
#> ---
#> 1432: NO 2024-06-06 14:26:00 24.9 38.5
#> 1433: NO 2024-06-06 14:27:00 24.8 39.0
#> 1434: NO 2024-06-06 14:28:00 24.9 38.5
#> 1435: NO 2024-06-06 14:29:00 24.9 38.4
#> 1436: NO 2024-06-06 14:30:00 24.9 38.6
#> soil_temperature solar_irradiance rainfall dew_point wet_bulb
#> <lgcl> <int> <int> <num> <num>
#> 1: NA 441 0 8.8 15.3
#> 2: NA 431 0 8.6 15.2
#> 3: NA 428 0 8.5 15.1
#> 4: NA 426 0 8.9 15.2
#> 5: NA 425 0 8.6 15.1
#> ---
#> 1432: NA 452 0 9.8 16.6
#> 1433: NA 450 0 9.9 16.6
#> 1434: NA 448 0 9.8 16.6
#> 1435: NA 444 0 9.8 16.6
#> 1436: NA 440 0 9.8 16.6
#> wind_height wind_avg_speed wind_avg_direction_compass_point
#> <int> <num> <char>
#> 1: 3 9.22 NNE
#> 2: 3 12.71 N
#> 3: 3 13.21 N
#> 4: 3 11.74 N
#> 5: 3 11.74 NNW
#> ---
#> 1432: 3 22.28 NNW
#> 1433: 3 22.28 NNW
#> 1434: 3 18.25 NNW
#> 1435: 3 18.76 NNW
#> 1436: 3 15.73 NW
#> wind_avg_direction_degrees wind_min_speed wind_max_speed
#> <int> <num> <num>
#> 1: 14 6.696 11.74
#> 2: 352 10.728 15.73
#> 3: 349 11.232 15.73
#> 4: 349 8.712 15.73
#> 5: 340 10.728 14.22
#> ---
#> 1432: 346 17.244 28.84
#> 1433: 335 12.204 34.38
#> 1434: 334 14.220 22.28
#> 1435: 327 14.724 23.29
#> 1436: 325 10.728 21.78
```
### Example 4: Get Specific Time and Date Data for Specific Values
If you wish to supply a specific start date and time and values, you may do so as shown here.
``` r
library(weatherOz)
(
min_dat_t_rad_wind <- get_dpird_minute(
station_code = "NO",
start_date_time = "2023-02-01 13:00:00",
minutes = 1440,
values = c("airTemperature",
"solarIrradiance",
"wind"),
api_key = Sys.getenv("DPIRD_API_KEY")
)
)
#> Key: <station_code>
#> station_code date_time air_temperature solar_irradiance
#> <fctr> <POSc> <num> <int>
#> 1: NO 2023-02-01 13:00:00 29.7 1087
#> 2: NO 2023-02-01 13:00:50 29.4 1086
#> 3: NO 2023-02-01 13:01:40 29.5 1084
#> 4: NO 2023-02-01 13:02:30 29.5 1084
#> 5: NO 2023-02-01 13:03:20 29.6 1084
#> ---
#> 1436: NO 2023-02-02 12:55:00 30.2 1105
#> 1437: NO 2023-02-02 12:55:50 30.1 1104
#> 1438: NO 2023-02-02 12:56:40 30.0 1102
#> 1439: NO 2023-02-02 12:57:30 29.9 1102
#> 1440: NO 2023-02-02 12:58:20 30.1 1104
#> wind_height wind_avg_speed wind_avg_direction_compass_point
#> <int> <num> <char>
#> 1: 3 11.66 SE
#> 2: 3 10.80 SE
#> 3: 3 11.81 SSE
#> 4: 3 12.71 SE
#> 5: 3 12.96 SE
#> ---
#> 1436: 3 9.54 ESE
#> 1437: 3 9.90 ESE
#> 1438: 3 13.03 ESE
#> 1439: 3 10.91 E
#> 1440: 3 10.40 E
#> wind_avg_direction_degrees wind_min_speed wind_max_speed
#> <int> <num> <num>
#> 1: 139 4.176 26.82
#> 2: 136 4.176 19.26
#> 3: 156 6.696 19.26
#> 4: 133 6.696 26.82
#> 5: 139 6.696 19.26
#> ---
#> 1436: 112 4.176 16.74
#> 1437: 120 4.176 19.26
#> 1438: 121 4.176 24.30
#> 1439: 93 6.696 21.78
#> 1440: 97 4.176 16.74
```
## Getting Summary Data
The function, `get_dpird_summary()`, fetches nicely formatted minute weather station data from the DPIRD Weather 2.0 API for a maximum 24-hour period.
You must provide a `station_code` and `API_key`, the other arguments, `start_date_time`, `minutes` and `values` are optional.
### Available Values for Summary Data
* all (which will return all of the following values),
* airTemperature,
* airTemperatureAvg,
* airTemperatureMax,
* airTemperatureMaxTime,
* airTemperatureMin,
* airTemperatureMinTime,
* apparentAirTemperature,
* apparentAirTemperatureAvg,
* apparentAirTemperatureMax,
* apparentAirTemperatureMaxTime,
* apparentAirTemperatureMin,
* apparentAirTemperatureMinTime,
* barometricPressure,
* barometricPressureAvg,
* barometricPressureMax,
* barometricPressureMaxTime,
* barometricPressureMin,
* barometricPressureMinTime,
* battery,
* batteryMinVoltage,
* batteryMinVoltageDateTime,
* chillHours,
* deltaT,
* deltaTAvg,
* deltaTMax,
* deltaTMaxTime,
* deltaTMin,
* deltaTMinTime,
* dewPoint,
* dewPointAvg,
* dewPointMax,
* dewPointMaxTime,
* dewPointMin,
* dewPointMinTime,
* erosionCondition,
* erosionConditionMinutes,
* erosionConditionStartTime,
* errors,
* etoShortCrop,
* etoTallCrop,
* evapotranspiration,
* frostCondition,
* frostConditionMinutes,
* frostConditionStartTime,
* heatCondition,
* heatConditionMinutes,
* heatConditionStartTime,
* observations,
* observationsCount,
* observationsPercentage,
* panEvaporation,
* rainfall,
* relativeHumidity,
* relativeHumidityAvg,
* relativeHumidityMax,
* relativeHumidityMaxTime,
* relativeHumidityMin,
* relativeHumidityMinTime,
* richardsonUnits,
* soilTemperature,
* soilTemperatureAvg,
* soilTemperatureMax,
* soilTemperatureMaxTime,
* soilTemperatureMin,
* soilTemperatureMinTime,
* solarExposure,
* wetBulb,
* wetBulbAvg,
* wetBulbMax,
* wetBulbMaxTime,
* wetBulbMin,
* wetBulbMinTime,
* wind,
* windAvgSpeed, and
* windMaxSpeed
### What You Get Back
This function returns a `data.table` with `station_code` and the date interval queried together with the requested weather variables in alphabetical order. Please note this function converts date-time columns from Coordinated Universal Time 'UTC'} to Australian Western Standard Time 'AWST'. The first ten columns will always be:
* `station_code`,
* `station_name`,
* `longitude`,
* `latitude`,
* `year`,
* `month`,
* `day`,
* `hour`,
* `minute`, and if `month` or finer is present,
* `date` (a combination of year, month, day, hour, minute as appropriate)
### Example 5: Get Annual Rainfall Since 2017
Use the default value for end date (current system date) to get annual rainfall since 2017 until current year for Capel.
``` r
library(weatherOz)
(
annual_rain <- get_dpird_summaries(
station_code = "CL001",
start_date = "20170101",
api_key = Sys.getenv("DPIRD_API_KEY"),
interval = "yearly",
values = "rainfall"
)
)
#> Key: <station_code>
#> station_code station_name longitude latitude year rainfall
#> <fctr> <char> <num> <num> <int> <num>
#> 1: CL001 Capel 115.6376 -33.61576 2017 711.4
#> 2: CL001 Capel 115.6376 -33.61576 2018 822.0
#> 3: CL001 Capel 115.6376 -33.61576 2019 660.6
#> 4: CL001 Capel 115.6376 -33.61576 2020 862.4
#> 5: CL001 Capel 115.6376 -33.61576 2021 928.0
#> 6: CL001 Capel 115.6376 -33.61576 2022 670.4
#> 7: CL001 Capel 115.6376 -33.61576 2023 570.0
#> 8: CL001 Capel 115.6376 -33.61576 2024 135.0
```
### Example 6: Get Monthly Rainfall Since 2017
Use the default value for end date (current system date) to get monthly rainfall since 2017 until current year for Capel.
``` r
library(weatherOz)
(
monthly_rain <- get_dpird_summaries(
station_code = "CL001",
start_date = "20170101",
api_key = Sys.getenv("DPIRD_API_KEY"),
interval = "monthly",
values = "rainfall"
)
)
#> Key: <station_code>
#> station_code station_name longitude latitude year month date
#> <fctr> <char> <num> <num> <int> <int> <Date>
#> 1: CL001 Capel 115.6376 -33.61576 2017 1 2017-01-01
#> 2: CL001 Capel 115.6376 -33.61576 2017 2 2017-02-01
#> 3: CL001 Capel 115.6376 -33.61576 2017 3 2017-03-01
#> 4: CL001 Capel 115.6376 -33.61576 2017 4 2017-04-01
#> 5: CL001 Capel 115.6376 -33.61576 2017 5 2017-05-01
#> 6: CL001 Capel 115.6376 -33.61576 2017 6 2017-06-01
#> 7: CL001 Capel 115.6376 -33.61576 2017 7 2017-07-01
#> 8: CL001 Capel 115.6376 -33.61576 2017 8 2017-08-01
#> 9: CL001 Capel 115.6376 -33.61576 2017 9 2017-09-01
#> 10: CL001 Capel 115.6376 -33.61576 2017 10 2017-10-01
#> 11: CL001 Capel 115.6376 -33.61576 2017 11 2017-11-01
#> 12: CL001 Capel 115.6376 -33.61576 2017 12 2017-12-01
#> 13: CL001 Capel 115.6376 -33.61576 2018 1 2018-01-01
#> 14: CL001 Capel 115.6376 -33.61576 2018 2 2018-02-01
#> 15: CL001 Capel 115.6376 -33.61576 2018 3 2018-03-01
#> 16: CL001 Capel 115.6376 -33.61576 2018 4 2018-04-01
#> 17: CL001 Capel 115.6376 -33.61576 2018 5 2018-05-01
#> 18: CL001 Capel 115.6376 -33.61576 2018 6 2018-06-01
#> 19: CL001 Capel 115.6376 -33.61576 2018 7 2018-07-01
#> 20: CL001 Capel 115.6376 -33.61576 2018 8 2018-08-01
#> 21: CL001 Capel 115.6376 -33.61576 2018 9 2018-09-01
#> 22: CL001 Capel 115.6376 -33.61576 2018 10 2018-10-01
#> 23: CL001 Capel 115.6376 -33.61576 2018 11 2018-11-01
#> 24: CL001 Capel 115.6376 -33.61576 2018 12 2018-12-01
#> 25: CL001 Capel 115.6376 -33.61576 2019 1 2019-01-01
#> 26: CL001 Capel 115.6376 -33.61576 2019 2 2019-02-01
#> 27: CL001 Capel 115.6376 -33.61576 2019 3 2019-03-01
#> 28: CL001 Capel 115.6376 -33.61576 2019 4 2019-04-01
#> 29: CL001 Capel 115.6376 -33.61576 2019 5 2019-05-01
#> 30: CL001 Capel 115.6376 -33.61576 2019 6 2019-06-01
#> 31: CL001 Capel 115.6376 -33.61576 2019 7 2019-07-01
#> 32: CL001 Capel 115.6376 -33.61576 2019 8 2019-08-01
#> 33: CL001 Capel 115.6376 -33.61576 2019 9 2019-09-01
#> 34: CL001 Capel 115.6376 -33.61576 2019 10 2019-10-01
#> 35: CL001 Capel 115.6376 -33.61576 2019 11 2019-11-01
#> 36: CL001 Capel 115.6376 -33.61576 2019 12 2019-12-01
#> 37: CL001 Capel 115.6376 -33.61576 2020 1 2020-01-01
#> 38: CL001 Capel 115.6376 -33.61576 2020 2 2020-02-01
#> 39: CL001 Capel 115.6376 -33.61576 2020 3 2020-03-01
#> 40: CL001 Capel 115.6376 -33.61576 2020 4 2020-04-01
#> 41: CL001 Capel 115.6376 -33.61576 2020 5 2020-05-01
#> 42: CL001 Capel 115.6376 -33.61576 2020 6 2020-06-01
#> 43: CL001 Capel 115.6376 -33.61576 2020 7 2020-07-01
#> 44: CL001 Capel 115.6376 -33.61576 2020 8 2020-08-01
#> 45: CL001 Capel 115.6376 -33.61576 2020 9 2020-09-01
#> 46: CL001 Capel 115.6376 -33.61576 2020 10 2020-10-01
#> 47: CL001 Capel 115.6376 -33.61576 2020 11 2020-11-01
#> 48: CL001 Capel 115.6376 -33.61576 2020 12 2020-12-01
#> 49: CL001 Capel 115.6376 -33.61576 2021 1 2021-01-01
#> 50: CL001 Capel 115.6376 -33.61576 2021 2 2021-02-01
#> 51: CL001 Capel 115.6376 -33.61576 2021 3 2021-03-01
#> 52: CL001 Capel 115.6376 -33.61576 2021 4 2021-04-01
#> 53: CL001 Capel 115.6376 -33.61576 2021 5 2021-05-01
#> 54: CL001 Capel 115.6376 -33.61576 2021 6 2021-06-01
#> 55: CL001 Capel 115.6376 -33.61576 2021 7 2021-07-01
#> 56: CL001 Capel 115.6376 -33.61576 2021 8 2021-08-01
#> 57: CL001 Capel 115.6376 -33.61576 2021 9 2021-09-01
#> 58: CL001 Capel 115.6376 -33.61576 2021 10 2021-10-01
#> 59: CL001 Capel 115.6376 -33.61576 2021 11 2021-11-01
#> 60: CL001 Capel 115.6376 -33.61576 2021 12 2021-12-01
#> 61: CL001 Capel 115.6376 -33.61576 2022 1 2022-01-01
#> 62: CL001 Capel 115.6376 -33.61576 2022 2 2022-02-01
#> 63: CL001 Capel 115.6376 -33.61576 2022 3 2022-03-01
#> 64: CL001 Capel 115.6376 -33.61576 2022 4 2022-04-01
#> 65: CL001 Capel 115.6376 -33.61576 2022 5 2022-05-01
#> 66: CL001 Capel 115.6376 -33.61576 2022 6 2022-06-01
#> 67: CL001 Capel 115.6376 -33.61576 2022 7 2022-07-01
#> 68: CL001 Capel 115.6376 -33.61576 2022 8 2022-08-01
#> 69: CL001 Capel 115.6376 -33.61576 2022 9 2022-09-01
#> 70: CL001 Capel 115.6376 -33.61576 2022 10 2022-10-01
#> 71: CL001 Capel 115.6376 -33.61576 2022 11 2022-11-01
#> 72: CL001 Capel 115.6376 -33.61576 2022 12 2022-12-01
#> 73: CL001 Capel 115.6376 -33.61576 2023 1 2023-01-01
#> 74: CL001 Capel 115.6376 -33.61576 2023 2 2023-02-01
#> 75: CL001 Capel 115.6376 -33.61576 2023 3 2023-03-01
#> 76: CL001 Capel 115.6376 -33.61576 2023 4 2023-04-01
#> 77: CL001 Capel 115.6376 -33.61576 2023 5 2023-05-01
#> 78: CL001 Capel 115.6376 -33.61576 2023 6 2023-06-01
#> 79: CL001 Capel 115.6376 -33.61576 2023 7 2023-07-01
#> 80: CL001 Capel 115.6376 -33.61576 2023 8 2023-08-01
#> 81: CL001 Capel 115.6376 -33.61576 2023 9 2023-09-01
#> 82: CL001 Capel 115.6376 -33.61576 2023 10 2023-10-01
#> 83: CL001 Capel 115.6376 -33.61576 2023 11 2023-11-01
#> 84: CL001 Capel 115.6376 -33.61576 2023 12 2023-12-01
#> 85: CL001 Capel 115.6376 -33.61576 2024 1 2024-01-01
#> 86: CL001 Capel 115.6376 -33.61576 2024 2 2024-02-01
#> 87: CL001 Capel 115.6376 -33.61576 2024 3 2024-03-01
#> 88: CL001 Capel 115.6376 -33.61576 2024 4 2024-04-01
#> 89: CL001 Capel 115.6376 -33.61576 2024 5 2024-05-01
#> 90: CL001 Capel 115.6376 -33.61576 2024 6 2024-06-01
#> station_code station_name longitude latitude year month date
#> rainfall
#> <num>
#> 1: 0.0
#> 2: 0.0
#> 3: 59.6
#> 4: 0.0
#> 5: 84.0
#> 6: 57.8
#> 7: 194.4
#> 8: 175.8
#> 9: 49.8
#> 10: 34.0
#> 11: 14.2
#> 12: 41.8
#> 13: 14.4
#> 14: 0.2
#> 15: 15.4
#> 16: 42.8
#> 17: 115.2
#> 18: 168.8
#> 19: 214.6
#> 20: 156.8
#> 21: 29.6
#> 22: 45.8
#> 23: 11.2
#> 24: 7.2
#> 25: 6.0
#> 26: 0.0
#> 27: 29.4
#> 28: 33.0
#> 29: 27.0
#> 30: 239.6
#> 31: 85.4
#> 32: 117.8
#> 33: 45.8
#> 34: 67.0
#> 35: 7.8
#> 36: 1.8
#> 37: 2.0
#> 38: 31.8
#> 39: 40.8
#> 40: 41.6
#> 41: 156.2
#> 42: 132.4
#> 43: 125.8
#> 44: 96.0
#> 45: 110.0
#> 46: 32.6
#> 47: 88.0
#> 48: 5.2
#> 49: 0.0
#> 50: 76.2
#> 51: 27.4
#> 52: 92.0
#> 53: 160.6
#> 54: 81.2
#> 55: 187.6
#> 56: 90.4
#> 57: 93.4
#> 58: 109.4
#> 59: 5.4
#> 60: 4.4
#> 61: 0.0
#> 62: 4.4
#> 63: 4.6
#> 64: 44.0
#> 65: 105.6
#> 66: 103.8
#> 67: 169.0
#> 68: 121.4
#> 69: 69.4
#> 70: 29.0
#> 71: 18.0
#> 72: 1.2
#> 73: 0.8
#> 74: 0.0
#> 75: 27.8
#> 76: 81.2
#> 77: 31.8
#> 78: 130.0
#> 79: 123.2
#> 80: 74.8
#> 81: 80.2
#> 82: 17.2
#> 83: 2.4
#> 84: 0.6
#> 85: 1.4
#> 86: 0.6
#> 87: 0.2
#> 88: 0.0
#> 89: 60.6
#> 90: 72.2
#> rainfall
```
### Example 7: Get Daily Rainfall and Wind From Beginning of 2017 to End of 2018
Use the default value for end date (current system date) to get daily rainfall and wind records from 2017-01-01 to 2018-12-31 for Binnu.
Note that the Binnu station has two wind heights, 3m and 10m.
``` r
library(weatherOz)
(
daily_wind_rain <- get_dpird_summaries(
station_code = "BI",
start_date = "20170101",
end_date = "2018-12-31",
api_key = Sys.getenv("DPIRD_API_KEY"),
interval = "daily",
values = c("rainfall",
"wind")
)
)
#> Key: <station_code>
#> station_code station_name longitude latitude year month day
#> <fctr> <char> <num> <num> <int> <int> <int>
#> 1: BI Binnu 114.6958 -28.051 2017 1 1
#> 2: BI Binnu 114.6958 -28.051 2017 1 1
#> 3: BI Binnu 114.6958 -28.051 2017 1 2
#> 4: BI Binnu 114.6958 -28.051 2017 1 2
#> 5: BI Binnu 114.6958 -28.051 2017 1 3
#> ---
#> 1456: BI Binnu 114.6958 -28.051 2018 12 29
#> 1457: BI Binnu 114.6958 -28.051 2018 12 30
#> 1458: BI Binnu 114.6958 -28.051 2018 12 30
#> 1459: BI Binnu 114.6958 -28.051 2018 12 31
#> 1460: BI Binnu 114.6958 -28.051 2018 12 31
#> date rainfall wind_avg_speed wind_height
#> <Date> <num> <num> <int>
#> 1: 2017-01-01 0 4.28 3
#> 2: 2017-01-01 0 6.85 10
#> 3: 2017-01-02 0 4.53 3
#> 4: 2017-01-02 0 7.39 10
#> 5: 2017-01-03 0 4.74 3
#> ---
#> 1456: 2018-12-29 0 35.63 10
#> 1457: 2018-12-30 0 29.19 3
#> 1458: 2018-12-30 0 36.70 10
#> 1459: 2018-12-31 0 32.52 3
#> 1460: 2018-12-31 0 41.51 10
#> wind_max_direction_compass_point wind_max_direction_degrees
#> <char> <int>
#> 1: NNE 31
#> 2: ESE 121
#> 3: NE 41
#> 4: N 1
#> 5: WSW 247
#> ---
#> 1456: SE 134
#> 1457: ESE 105
#> 1458: ESE 113
#> 1459: SSE 163
#> 1460: SSE 167
#> wind_max_speed wind_max_time
#> <num> <POSc>
#> 1: 17.57 2018-07-17 11:51:00
#> 2: 23.18 2017-07-30 11:38:00
#> 3: 21.78 2017-08-10 13:29:00
#> 4: 19.55 2018-07-17 12:16:00
#> 5: 18.40 2017-06-14 09:05:00
#> ---
#> 1456: 60.91 2017-02-09 15:56:00
#> 1457: 62.03 2018-01-14 22:55:00
#> 1458: 69.77 2018-01-14 22:45:00
#> 1459: 58.64 2017-02-08 09:12:00
#> 1460: 64.40 2017-02-08 04:48:00
```
### Example 8: Get Hourly Rainfall and Wind From Beginning of 2022 to Current
Use the default value for end date (current system date) to get hourly rainfall and wind records from 2022-01-01 to Current Date for Binnu.
Note that the Binnu station has two wind heights, 3m and 10m.
``` r
library(weatherOz)
(
hourly_wind_rain <- get_dpird_summaries(
station_code = "BI",
start_date = "20220101",
api_key = Sys.getenv("DPIRD_API_KEY"),
interval = "hourly",
values = c("rainfall",
"wind")
)
)
#> Key: <station_code>
#> station_code station_name longitude latitude year month day
#> <fctr> <char> <num> <num> <int> <int> <int>
#> 1: BI Binnu 114.6958 -28.051 2022 1 1
#> 2: BI Binnu 114.6958 -28.051 2022 1 1
#> 3: BI Binnu 114.6958 -28.051 2022 1 1
#> 4: BI Binnu 114.6958 -28.051 2022 1 1
#> 5: BI Binnu 114.6958 -28.051 2022 1 1
#> ---
#> 42574: BI Binnu 114.6958 -28.051 2024 6 5
#> 42575: BI Binnu 114.6958 -28.051 2024 6 5
#> 42576: BI Binnu 114.6958 -28.051 2024 6 5
#> 42577: BI Binnu 114.6958 -28.051 2024 6 6
#> 42578: BI Binnu 114.6958 -28.051 2024 6 6
#> hour date rainfall
#> <int> <POSc> <num>
#> 1: 0 2022-01-01 00:00:00 0
#> 2: 0 2022-01-01 00:00:00 0
#> 3: 1 2022-01-01 01:00:00 0
#> 4: 1 2022-01-01 01:00:00 0
#> 5: 2 2022-01-01 02:00:00 0
#> ---
#> 42574: 22 2024-06-05 22:00:00 0
#> 42575: 23 2024-06-05 23:00:00 0
#> 42576: 23 2024-06-05 23:00:00 0
#> 42577: 0 2024-06-06 00:00:00 0
#> 42578: 0 2024-06-06 00:00:00 0
#> wind_avg_direction_compass_point wind_avg_direction_degrees
#> <char> <int>
#> 1: NNE 18
#> 2: <NA> NA
#> 3: NNE 33
#> 4: <NA> NA
#> 5: ENE 58
#> ---
#> 42574: WNW 286
#> 42575: NW 313
#> 42576: NW 312
#> 42577: NW 317
#> 42578: NW 315
#> wind_avg_speed wind_height wind_max_direction_compass_point
#> <num> <int> <char>
#> 1: 0.00 3 N
#> 2: NA 10 <NA>
#> 3: 0.00 3 NNE
#> 4: NA 10 <NA>
#> 5: 0.00 3 N
#> ---
#> 42574: 55.23 10 WNW
#> 42575: 43.20 3 NW
#> 42576: 57.27 10 NW
#> 42577: 44.32 3 NW
#> 42578: 58.52 10 NW
#> wind_max_direction_degrees wind_max_speed wind_max_time
#> <int> <num> <POSc>
#> 1: 1 0.00 2023-01-20 05:01:00
#> 2: NA NA <NA>
#> 3: 22 0.00 2022-07-23 01:01:00
#> 4: NA NA <NA>
#> 5: 11 0.00 2023-02-04 22:01:00
#> ---
#> 42574: 282 78.37 2023-09-13 14:25:00
#> 42575: 318 72.94 2023-09-13 12:39:00
#> 42576: 314 90.58 2023-09-13 12:24:00
#> 42577: 311 73.76 2023-09-13 11:40:00
#> 42578: 311 91.19 2023-09-13 11:34:00
```
## Getting APSIM-ready Data
For work with APSIM, you can use `get_dpird_apsim()` to get an object of DPIRD weather data in your R session that's ready for saving using `write_apsim_met()`, which is re-exported from the CRAN package [apsimx] for your convenience.
This function only needs the `station_code`, `start_date`, `end_date` and your `api_key` values to return the necessary values.
### What You Get Back
An object of {apsimx} 'met' class, compatible with a `data.frame`, that has daily data that include year, day, radiation, max temperature, min temperature, rainfall, relative humidity, evaporation and windspeed.
### Example 9: Get APSIM Formatted Data for Binnu From 2022-04-01 to 2022-11-01
``` r
library(weatherOz)
(
binnu <- get_dpird_apsim(
station_code = "BI",
start_date = "20220101",
end_date = "20221231",
api_key = Sys.getenv("DPIRD_API_KEY")
)
)
#> weather.met.met
#> site = Binnu
#> latitude = -28.051
#> longitude = 114.69575
#> tav = 20.5987671232877 (oC) ! calculated annual average ambient temperature 2024-06-06 14:35:25.830044
#> amp = 15.3 !calculated with the apsimx R package: 2024-06-06 14:35:25.83311
#> year day radn maxt mint rain evap rh windspeed
#> () () (MJ/m2/day) (oC) (oC) (mm) (mm) (%) (m/s)
#> year day radn maxt mint rain evap rh windspeed
#> 1 2022 1 33137.3 35.3 18.5 10.6 0 63.9 3.66
#> 2 2022 2 33419.1 38.3 15.2 11.1 0 54.6 3.82
#> 3 2022 3 33467.9 34.8 17.1 11.0 0 65.6 4.28
#> 4 2022 4 32784.2 39.9 17.6 11.2 0 64.2 4.43
#> 5 2022 5 32981.1 45.7 19.1 14.4 0 37.1 4.53
#> 6 2022 6 33182.6 39.1 18.3 11.3 0 60.5 4.70
#> Warning in check_apsim_met(x): Radiation is greater than 40 (MJ/m2/day)
#> weather.met.met
#> site = Binnu
#> latitude = -28.051
#> longitude = 114.69575
#> tav = 20.5987671232877 (oC) ! calculated annual average ambient temperature 2024-06-06 14:35:25.830044
#> amp = 15.3 !calculated with the apsimx R package: 2024-06-06 14:35:25.83311
#> year day radn maxt mint rain evap rh windspeed
#> () () (MJ/m2/day) (oC) (oC) (mm) (mm) (%) (m/s)
#> year day radn maxt mint rain evap rh windspeed
#> 1 2022 1 33137.3 35.3 18.5 10.6 0 63.9 3.66
#> 2 2022 2 33419.1 38.3 15.2 11.1 0 54.6 3.82
#> 3 2022 3 33467.9 34.8 17.1 11.0 0 65.6 4.28
#> 4 2022 4 32784.2 39.9 17.6 11.2 0 64.2 4.43
#> 5 2022 5 32981.1 45.7 19.1 14.4 0 37.1 4.53
#> 6 2022 6 33182.6 39.1 18.3 11.3 0 60.5 4.70
```
## Working With DPIRD Metadata
Three functions are provided to assist in fetching metadata about the stations.
* `find_nearby_stations()`, which returns a `data.table` with the nearest weather stations to a given geographic point or known station in either the DPIRD or BOM (from SILO) networks.
* `find_stations_in()`, which returns a `data.table` with the weather stations falling within a given geographic area in either the DPIRD or BOM (from SILO) networks.
* `get_dpird_availability()`, which returns a `data.table` with the availability for weather stations in the DPIRD network providing the up time and data availability for a given period of time.
* `get_stations_metadata()`, which returns a `data.table` with the latest and most up-to-date information available from the Weather 2.0 API on the stations' geographic locations, hardware details, *e.g.,* wind mast height, and recording capabilities.
### Finding Nearby Stations
### Example 10: Finding Stations Nearby a Known Station
Query WA only stations and return DPIRD's stations nearest to the Northam, WA station, "NO", returning stations with 50 km of this station.
``` r
library(weatherOz)
(
wa_stn <- find_nearby_stations(
station_code = "NO",
distance_km = 50,
api_key = Sys.getenv("DPIRD_API_KEY"),
which_api = "dpird"
)
)
#> station_code station_name longitude latitude state elev_m
#> <fctr> <char> <num> <num> <char> <int>
#> 1: NO Northam 116.6942 -31.65161 WA 163
#> 2: MK Muresk 116.6913 -31.72772 WA 251
#> 3: YE001 York East 116.9211 -31.83588 WA 229
#> 4: BTSB DFES-B Talbot West 116.6898 -31.96060 WA 357
#> 5: ROGR Rolling Green 116.3184 -31.69527 WA 315
#> 6: BCAA DBCA-A Portable 116.2560 -31.84210 WA 265
#> owner
#> <char>
#> 1: WA Department of Primary Industries and Regional Development (DPIRD)
#> 2: WA Department of Primary Industries and Regional Development (DPIRD)
#> 3: WA Department of Primary Industries and Regional Development (DPIRD)
#> 4: WA Department of Fire and Emergency Services (DFES)
#> 5: WA Department of Biodiversity, Conservation and Attractions (DBCA)
#> 6: WA Department of Biodiversity, Conservation and Attractions (DBCA)
#> distance_km
#> <num>
#> 1: 0.00
#> 2: 7.62
#> 3: 29.23
#> 4: 30.90
#> 5: 37.83
#> 6: 47.78
```
### Example 11: Finding Stations Nearby a Given Longitude and Latitude
Using the longitude and latitude for Northam, WA, find all DPIRD stations within a 50km radius of this geographic point.
``` r
library(weatherOz)
(
wa_stn_lonlat <- find_nearby_stations(
longitude = 116.6620,
latitude = -31.6540,
distance_km = 50,
api_key = Sys.getenv("DPIRD_API_KEY"),
which_api = "dpird"
)
)
#> station_code station_name longitude latitude state elev_m
#> <fctr> <char> <num> <num> <char> <int>
#> 1: NO Northam 116.6942 -31.65161 WA 163
#> 2: MK Muresk 116.6913 -31.72772 WA 251
#> 3: BTSB DFES-B Talbot West 116.6898 -31.96060 WA 357
#> 4: YE001 York East 116.9211 -31.83588 WA 229
#> 5: ROGR Rolling Green 116.3184 -31.69527 WA 315
#> 6: BCAA DBCA-A Portable 116.2560 -31.84210 WA 265
#> owner
#> <char>
#> 1: WA Department of Primary Industries and Regional Development (DPIRD)
#> 2: WA Department of Primary Industries and Regional Development (DPIRD)
#> 3: WA Department of Fire and Emergency Services (DFES)
#> 4: WA Department of Primary Industries and Regional Development (DPIRD)
#> 5: WA Department of Biodiversity, Conservation and Attractions (DBCA)
#> 6: WA Department of Biodiversity, Conservation and Attractions (DBCA)
#> distance_km
#> <num>
#> 1: 3.23
#> 2: 7.93
#> 3: 30.79
#> 4: 31.65
#> 5: 34.61
#> 6: 44.75
```
### Example 12: Finding Stations in Both the DPIRD and SILO Data Sets
Query stations nearest DPIRD's Northam, WA station, "NO" and return both DPIRD and SILO/BOM stations within 50 km of this station.
``` r
library(weatherOz)
(
wa_stn_all <- find_nearby_stations(
station_code = "NO",
distance_km = 50,
api_key = Sys.getenv("DPIRD_API_KEY"),
which_api = "all"
)
)
#> station_code station_name longitude latitude state elev_m
#> <fctr> <char> <num> <num> <char> <num>
#> 1: NO Northam 116.6942 -31.65161 WA 163
#> 2: 010111 Northam 116.6586 -31.65080 WA 170
#> 3: MK Muresk 116.6913 -31.72772 WA 251
#> 4: 010150 Grass Valley 116.7969 -31.63580 WA 200
#> 5: 010152 Muresk Institute 116.6833 -31.75000 WA 166
#> 6: 010115 Quellington 116.8647 -31.77140 WA 220
#> 7: 010125 Toodyay 116.4703 -31.55170 WA 140
#> 8: 010244 Bakers Hill 116.4561 -31.74690 WA 330
#> 9: 010311 York 116.7650 -31.89970 WA 179
#> 10: 010023 Warradong Farm 116.9411 -31.50030 WA 240
#> 11: YE001 York East 116.9211 -31.83588 WA 229
#> 12: 010091 Meckering 117.0081 -31.63220 WA 195
#> 13: BTSB DFES-B Talbot West 116.6898 -31.96060 WA 357
#> 14: ROGR Rolling Green 116.3184 -31.69527 WA 315
#> 15: 010138 Wooroloo 116.3413 -31.81500 WA 277
#> 16: 010058 Goomalling 116.8269 -31.29940 WA 239
#> 17: 010134 Wattening 116.5150 -31.31190 WA 240
#> 18: 010165 Green Hills 116.9839 -31.94080 WA 244
#> 19: 010163 Jaroma 117.1433 -31.77060 WA 265
#> 20: 010009 Bolgart 116.5092 -31.27440 WA 240
#> 21: 010160 Quella Park 117.1194 -31.45330 WA 265
#> 22: 009007 Chidlow 116.2658 -31.86220 WA 300
#> 23: 010120 Doodenanning 117.0986 -31.90920 WA 290
#> 24: BCAA DBCA-A Portable 116.2560 -31.84210 WA 265
#> 25: 009066 Gidgegannup 116.1976 -31.79060 WA 290
#> station_code station_name longitude latitude state elev_m
#> owner
#> <char>
#> 1: WA Department of Primary Industries and Regional Development (DPIRD)
#> 2: BOM
#> 3: WA Department of Primary Industries and Regional Development (DPIRD)
#> 4: BOM
#> 5: BOM
#> 6: BOM
#> 7: BOM
#> 8: BOM
#> 9: BOM
#> 10: BOM
#> 11: WA Department of Primary Industries and Regional Development (DPIRD)
#> 12: BOM
#> 13: WA Department of Fire and Emergency Services (DFES)
#> 14: WA Department of Biodiversity, Conservation and Attractions (DBCA)
#> 15: BOM
#> 16: BOM
#> 17: BOM
#> 18: BOM
#> 19: BOM
#> 20: BOM