read.abares
Adam H. Sparks
2024-09-22
read.abares.Rmd
Working With Estimates
You can download the CSV files directly in your R session as illustrated below.
library(read.abares)
get_hist_nat_est() |>
head()
#> Variable Year Value RSE Industry
#> <char> <int> <num> <int> <char>
#> 1: AI stud fees and herd testing ($) 1990 790 39 All Broadacre
#> 2: Accounting services ($) 1990 2850 4 All Broadacre
#> 3: Advisory services ($) 1990 280 37 All Broadacre
#> 4: Age of owner manager (yrs) 1990 53 1 All Broadacre
#> 5: Age of spouse (yrs) 1990 49 1 All Broadacre
#> 6: Agistment ($) 1990 1950 36 All Broadacre
get_hist_sta_est() |>
head()
#> Variable Year Value RSE State Industry
#> <char> <int> <num> <int> <char> <char>
#> 1: AI stud fees and herd testing ($) 1990 210 118 New South Wales All Broadacre
#> 2: Accounting services ($) 1990 2740 7 New South Wales All Broadacre
#> 3: Advisory services ($) 1990 190 105 New South Wales All Broadacre
#> 4: Age of owner manager (yrs) 1990 55 2 New South Wales All Broadacre
#> 5: Age of spouse (yrs) 1990 52 2 New South Wales All Broadacre
#> 6: Agistment ($) 1990 2790 71 New South Wales All Broadacre
get_hist_reg_est() |>
head()
#> Variable Year ABARES region Value RSE
#> <char> <int> <char> <num> <int>
#> 1: AI stud fees and herd testing ($) 1990 NSW Central West 90 68
#> 2: Accounting services ($) 1990 NSW Central West 2420 19
#> 3: Advisory services ($) 1990 NSW Central West 120 80
#> 4: Age of owner manager (yrs) 1990 NSW Central West 57 5
#> 5: Age of spouse (yrs) 1990 NSW Central West 51 4
#> 6: Agistment ($) 1990 NSW Central West 310 52
Working With AGFD Data
You can download files and pipe directly into the class object that you desire for the Australian Farm Gridded Data (AGFD) data.
Description of the Australian Farm Gridded Data
Directly from the DAFF website:
The Australian Gridded Farm Data are a set of national scale maps containing simulated data on historical broadacre farm business outcomes including farm profitability on an 0.05-degree (approximately 5 km) grid.
These data have been produced by read.abares as part of the ongoing Australian Agricultural Drought Indicator (AADI) project (previously known as the Drought Early Warning System Project) and were derived using read.abares farmpredict model, which in turn is based on read.abares Agricultural and Grazing Industries Survey (AAGIS) data.
These maps provide estimates of farm business profit, revenue, costs and production by location (grid cell) and year for the period 1990-91 to 2022-23. The data do not include actual observed outcomes but rather model predicted outcomes for representative or ‘typical’ broadacre farm businesses at each location considering likely farm characteristics and prevailing weather conditions and commodity prices.
The Australian Gridded Farm Data remain under active development, and as such should be considered experimental.
– Australian Department of Agriculture, Fisheries and Forestry.
library(read.abares)
## A list of {stars} objects
star <- get_agfd(cache = TRUE) |>
read_agfd_stars()
#> Will return stars object with 612226 cells.
#> No projection information found in nc file.
#> Coordinate variable units found to be degrees,
#> assuming WGS84 Lat/Lon.
head(star[[1]])
#> stars object with 2 dimensions and 6 attributes
#> attribute(s):
#> Min. 1st Qu. Median Mean 3rd Qu.
#> farmno 15612.000000 233091.50000000 329567.0000000 324737.7187618 418508.5000000
#> R_total_hat_ha 2.954396 7.88312157 21.7520529 169.5139301 174.8553843
#> C_total_hat_ha 1.304440 4.34079101 9.9449849 93.2210542 95.7221857
#> FBP_fci_hat_ha -143.759785 3.60529967 11.5796641 76.2928759 77.6748501
#> FBP_fbp_hat_ha -349.521639 3.36599833 11.5074294 60.0750936 62.8596117
#> A_wheat_hat_ha 0.000000 0.04062786 0.1114289 0.1365683 0.2112845
#> Max. NA's
#> farmno 669706.0000000 443899
#> R_total_hat_ha 2415.7556059 443899
#> C_total_hat_ha 1853.5385298 443899
#> FBP_fci_hat_ha 1186.5830232 443899
#> FBP_fbp_hat_ha 1240.6003218 443899
#> A_wheat_hat_ha 0.5047761 565224
#> dimension(s):
#> from to refsys values x/y
#> lon 1 886 WGS 84 [886] 112,...,156.2 [x]
#> lat 1 691 WGS 84 [691] -44.5,...,-10 [y]
## A {terra} `rast` object
terr <- get_agfd(cache = TRUE) |>
read_agfd_terra()
head(terr[[1]])
#> class : SpatRaster
#> dimensions : 6, 886, 41 (nrow, ncol, nlyr)
#> resolution : 0.05, 0.05 (x, y)
#> extent : 111.975, 156.275, -10.275, -9.975 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84
#> source(s) : memory
#> names : farmno, R_tot~at_ha, C_tot~at_ha, FBP_f~at_ha, FBP_f~at_ha, A_whe~at_ha, ...
#> min values : NaN, NaN, NaN, NaN, NaN, NaN, ...
#> max values : NaN, NaN, NaN, NaN, NaN, NaN, ...
## A list of {tidync} objects
tdnc <- get_agfd(cache = TRUE) |>
read_agfd_tidync()
head(tdnc[[1]])
#> $source
#> # A tibble: 1 × 2
#> access source
#> <dttm> <chr>
#> 1 2024-09-22 19:47:08 /Users/adamsparks/Library/Caches/org.R-project.R/R/read.abares/histori…
#>
#> $axis
#> # A tibble: 84 × 3
#> axis variable dimension
#> <int> <chr> <int>
#> 1 1 lon 0
#> 2 2 lat 1
#> 3 3 farmno 0
#> 4 4 farmno 1
#> 5 5 R_total_hat_ha 0
#> 6 6 R_total_hat_ha 1
#> 7 7 C_total_hat_ha 0
#> 8 8 C_total_hat_ha 1
#> 9 9 FBP_fci_hat_ha 0
#> 10 10 FBP_fci_hat_ha 1
#> # ℹ 74 more rows
#>
#> $grid
#> # A tibble: 3 × 4
#> grid ndims variables nvars
#> <chr> <int> <list> <int>
#> 1 D0,D1 2 <tibble [41 × 1]> 41
#> 2 D0 1 <tibble [1 × 1]> 1
#> 3 D1 1 <tibble [1 × 1]> 1
#>
#> $dimension
#> # A tibble: 2 × 8
#> id name length unlim coord_dim active start count
#> <int> <chr> <dbl> <lgl> <lgl> <lgl> <int> <int>
#> 1 0 lon 886 FALSE TRUE TRUE 1 886
#> 2 1 lat 691 FALSE TRUE TRUE 1 691
#>
#> $variable
#> # A tibble: 43 × 7
#> id name type ndims natts dim_coord active
#> <int> <chr> <chr> <int> <int> <lgl> <lgl>
#> 1 0 lon NC_DOUBLE 1 2 TRUE FALSE
#> 2 1 lat NC_DOUBLE 1 2 TRUE FALSE
#> 3 2 farmno NC_DOUBLE 2 1 FALSE TRUE
#> 4 3 R_total_hat_ha NC_DOUBLE 2 1 FALSE TRUE
#> 5 4 C_total_hat_ha NC_DOUBLE 2 1 FALSE TRUE
#> 6 5 FBP_fci_hat_ha NC_DOUBLE 2 1 FALSE TRUE
#> 7 6 FBP_fbp_hat_ha NC_DOUBLE 2 1 FALSE TRUE
#> 8 7 A_wheat_hat_ha NC_DOUBLE 2 1 FALSE TRUE
#> 9 8 H_wheat_dot_hat NC_DOUBLE 2 1 FALSE TRUE
#> 10 9 A_barley_hat_ha NC_DOUBLE 2 1 FALSE TRUE
#> # ℹ 33 more rows
#>
#> $attribute
#> # A tibble: 49 × 4
#> id name variable value
#> <int> <chr> <chr> <named list>
#> 1 0 _FillValue lon <dbl [1]>
#> 2 1 units lon <chr [1]>
#> 3 0 _FillValue lat <dbl [1]>
#> 4 1 units lat <chr [1]>
#> 5 0 _FillValue farmno <dbl [1]>
#> 6 0 _FillValue R_total_hat_ha <dbl [1]>
#> 7 0 _FillValue C_total_hat_ha <dbl [1]>
#> 8 0 _FillValue FBP_fci_hat_ha <dbl [1]>
#> 9 0 _FillValue FBP_fbp_hat_ha <dbl [1]>
#> 10 0 _FillValue A_wheat_hat_ha <dbl [1]>
#> # ℹ 39 more rows
## A {data.table} object
get_agfd(cache = TRUE) |>
read_agfd_dt() |>
head()
#> id farmno R_total_hat_ha C_total_hat_ha FBP_fci_hat_ha
#> <char> <num> <num> <num> <num>
#> 1: f2022.c1991.p2022.t2022.nc 15612 7.636519 4.405228 3.231292
#> 2: f2022.c1991.p2022.t2022.nc 21495 14.811169 9.165632 5.645538
#> 3: f2022.c1991.p2022.t2022.nc 23418 24.874456 14.858595 10.015861
#> 4: f2022.c1991.p2022.t2022.nc 24494 15.043653 9.326359 5.717294
#> 5: f2022.c1991.p2022.t2022.nc 32429 23.630099 13.681063 9.949036
#> 6: f2022.c1991.p2022.t2022.nc 32485 15.009926 9.815501 5.194425
#> FBP_fbp_hat_ha A_wheat_hat_ha H_wheat_dot_hat A_barley_hat_ha H_barley_dot_hat
#> <num> <num> <num> <num> <num>
#> 1: 1.766127 NaN NaN NaN NaN
#> 2: 6.178280 NaN NaN NaN NaN
#> 3: 15.504923 NaN NaN NaN NaN
#> 4: 7.212161 NaN NaN NaN NaN
#> 5: 9.612778 NaN NaN NaN NaN
#> 6: 6.582035 NaN NaN NaN NaN
#> A_sorghum_hat_ha H_sorghum_dot_hat A_oilseeds_hat_ha H_oilseeds_dot_hat R_wheat_hat_ha
#> <num> <num> <num> <num> <num>
#> 1: NaN NaN NaN NaN NaN
#> 2: NaN NaN NaN NaN NaN
#> 3: NaN NaN NaN NaN NaN
#> 4: NaN NaN NaN NaN NaN
#> 5: NaN NaN NaN NaN NaN
#> 6: NaN NaN NaN NaN NaN
#> R_sorghum_hat_ha R_oilseeds_hat_ha R_barley_hat_ha Q_wheat_hat_ha Q_barley_hat_ha
#> <num> <num> <num> <num> <num>
#> 1: NaN NaN NaN NaN NaN
#> 2: NaN NaN NaN NaN NaN
#> 3: NaN NaN NaN NaN NaN
#> 4: NaN NaN NaN NaN NaN
#> 5: NaN NaN NaN NaN NaN
#> 6: NaN NaN NaN NaN NaN
#> Q_sorghum_hat_ha Q_oilseeds_hat_ha S_wheat_cl_hat_ha S_sheep_cl_hat_ha
#> <num> <num> <num> <num>
#> 1: NaN NaN NaN 0.000046854152
#> 2: NaN NaN NaN 0.000066325878
#> 3: NaN NaN NaN 0.000007771546
#> 4: NaN NaN NaN 0.000070963917
#> 5: NaN NaN NaN 0.000007780997
#> 6: NaN NaN NaN 0.000059600116
#> S_sheep_births_hat_ha S_sheep_deaths_hat_ha S_beef_cl_hat_ha S_beef_births_hat_ha
#> <num> <num> <num> <num>
#> 1: 0.000048411171 0.000007187978 0.02034820 0.005212591
#> 2: 0.000057753874 0.000009039695 0.02974461 0.007970856
#> 3: 0.000007320093 0.000000000000 0.05393181 0.014745383
#> 4: 0.000062521929 0.000009726773 0.03057606 0.008602196
#> 5: 0.000006834211 0.000000000000 0.04944272 0.011527594
#> 6: 0.000053976389 0.000008478467 0.03322463 0.008456550
#> S_beef_deaths_hat_ha Q_beef_hat_ha Q_sheep_hat_ha Q_lamb_hat_ha R_beef_hat_ha
#> <num> <num> <num> <num> <num>
#> 1: 0.000989490 0.004790528 0.00007117650 0 7.392679
#> 2: 0.001468278 0.009646485 0.00009448864 0 14.281910
#> 3: 0.002867331 0.014401773 0.00001299674 0 24.308574
#> 4: 0.001446424 0.009577272 0.00010191595 0 14.518771
#> 5: 0.002491037 0.014668761 0.00001283228 0 23.060943
#> 6: 0.001627910 0.009281578 0.00008869032 0 14.474964
#> R_sheep_hat_ha R_lamb_hat_ha C_fodder_hat_ha C_fert_hat_ha C_fuel_hat_ha C_chem_hat_ha
#> <num> <num> <num> <num> <num> <num>
#> 1: 0.010222802 0 0.3553107 0.0007795925 0.4282799 0.0002169123
#> 2: 0.014485890 0 0.7040333 0.0670951492 0.5663560 0.0212989625
#> 3: 0.001821158 0 0.9473936 0.1475929946 0.9244438 0.0398376851
#> 4: 0.015352095 0 0.7060111 0.0764850563 0.5688555 0.0223214940
#> 5: 0.001892115 0 1.0269189 0.1592835324 0.8337981 0.0416492516
#> 6: 0.013278806 0 0.7019839 0.0997758317 0.5575842 0.0293469147
#> A_total_cropped_ha FBP_pfe_hat_ha farmland_per_cell lon lat
#> <num> <num> <num> <num> <num>
#> 1: 0.000001588013 2.142158 62.26270 142.60 -10.75
#> 2: 0.000144292922 6.679382 61.71605 136.75 -11.05
#> 3: 0.000296036096 16.185389 61.82964 132.90 -11.15
#> 4: 0.000151675639 7.711993 72.85995 136.70 -11.20
#> 5: 0.000316535762 10.294743 61.82964 133.45 -11.60
#> 6: 0.000201161236 7.101658 61.71605 136.25 -11.60
Working With the Soil Thickness Map
You can download the soil depth map and import it as a {stars} or [terra::rast()] object.
library(read.abares)
get_soil_thickness(cache = TRUE) |>
read_soil_thickness_stars()
#> Error in list_files(file, ignore_missing, TRUE, verbosity): File '' does not exist.
x <- get_soil_thickness(cache = TRUE) |>
read_soil_thickness_terra()
#> Error in list_files(file, ignore_missing, TRUE, verbosity): File '' does not exist.
For your convenience, {read.abares} re-exports [terra::plot()], so you can just use:
plot(x)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'x' not found
Soil Thickness Metadata
By default, a brief bit of metadata is printed to the console when you call the soil thickness object in your R session.
library(read.abares)
get_soil_thickness(cache = TRUE)
#> Error in list_files(file, ignore_missing, TRUE, verbosity): File '' does not exist.
But, {read.abares} provides a function for you to browse the soil thickness metadata in your console.
library(read.abares)
get_soil_thickness(cache = TRUE) |>
display_soil_thickness_metadata()
#> Error in list_files(file, ignore_missing, TRUE, verbosity): File '' does not exist.
But you can also access it directly and use [pander::pander()] to include it in a document like this vignette.
library(read.abares) library(pander) x <- get_soil_thickness(cache = TRUE) #> Error in list_files(file, ignore_missing, TRUE, verbosity): File '' does not exist. y <- x$metadata #> Error: object 'x' not found pander(y) #> Error: object 'y' not found #> Error in if (tail(stdout, 1) == "") {: argument is of length zero