MWTools
MWTools.Rmd
Introduction
In societal energy analysis and societal exergy analysis (SEA), animals and humans provide energy to society by performing muscle work. A previous study by Steenwyk et al. (2022) developed and standardized ways to estimate muscle work contributed to society by animals and humans. And data exist from the UN’s Food and Agriculture Organization (FAO) and the International Labor Organization (ILO) that could be used for such purposes. However, none of the data are in the PSUT format proposed by Heun, Owen, and Brockway (2018). Computational tools are needed to gather and shape relevant data.
The examples below show how to use MWTools
to address
the needs described above.
Examples
Animal Muscle Work
Raw data for the estimation of animal muscle work is obtained from
the Food and Agriculture Organisation of the United Nations Statistical
Database (FAOSTAT), via the R
package FAOSTAT
as follows.
raw_amw_data <- FAOSTAT::get_faostat_bulk(code = "QCL", data_folder = tempdir())
The helper function calc_amw_pfu
returns a tidy data
frame containing data for the primary, final, and useful energy by
species, country, year and in the agriculture, transport, and total
sectors.
test_amw_data <- read.csv(file = MWTools::amw_test_data_path())
amw_pfu_data <- MWTools::calc_amw_pfu(.df = test_amw_data,
concordance_path = MWTools::fao_concordance_path(),
amw_analysis_data_path = MWTools::amw_analysis_data_path())
tibble::glimpse(amw_pfu_data)
#> Rows: 2,232
#> Columns: 7
#> $ Country <chr> "CHNM", "CHNM", "CHNM", "CHNM", "CHNM", "CHNM", "CHNM", "CHNM"…
#> $ Year <dbl> 1960, 1960, 1960, 1960, 1960, 1960, 1960, 1960, 1960, 1960, 19…
#> $ Species <chr> "Asses", "Asses", "Asses", "Asses", "Asses", "Asses", "Buffalo…
#> $ Stage <chr> "Useful", "Useful", "Final", "Final", "Primary", "Primary", "U…
#> $ Sector <chr> "Agriculture", "Transport", "Agriculture", "Transport", "Agric…
#> $ Unit <chr> "EJ", "EJ", "EJ", "EJ", "EJ", "EJ", "EJ", "EJ", "EJ", "EJ", "E…
#> $ E.dot <dbl> 0.0006684719, 0.0037880073, 0.0102033866, 0.0578191910, 0.0226…
Human Muscle Work
Raw data for the estimation of human muscle work is obtained from the
International Labor Organisation (ILO), via the R
package
Rilostat
as follows:
ilo_working_hours_data <- Rilostat::get_ilostat(id = MWTools::ilo_codes$working_hours_code,
quiet = TRUE) |>
Rilostat::label_ilostat(code = c("ref_area"))
ilo_employment_data <- Rilostat::get_ilostat(id = MWTools::ilo_codes$employment_code,
quiet = TRUE) |>
Rilostat::label_ilostat(code = c("ref_area"))
Using data for the number of employed persons and mean yearly working
hours the primary, final, and useful energy associated with human muscle
work can be estimated using the helper function
MWTools::calc_hmw_pfu
as below.
ilo_working_hours_data <- read.csv(file = MWTools::ilo_working_hours_test_data_path())
ilo_employment_data <- read.csv(file = MWTools::ilo_employment_test_data_path())
preparedILOData <- MWTools::prepareRawILOData(ilo_working_hours_data = ilo_working_hours_data,
ilo_employment_data = ilo_employment_data)
hmw_pfu_data <- MWTools::calc_hmw_pfu(.df = preparedILOData,
concordance_path = MWTools::fao_concordance_path(),
hmw_analysis_data_path = MWTools::hmw_analysis_data_path())
tibble::glimpse(hmw_pfu_data)
#> Rows: 1,098
#> Columns: 7
#> $ Country <chr> "GBR", "GBR", "GBR", "GBR", "GBR", "GBR", "GBR", "GBR", "GBR",…
#> $ Year <dbl> 1960, 1960, 1960, 1960, 1960, 1960, 1960, 1960, 1960, 1960, 19…
#> $ Species <chr> "Human females", "Human females", "Human females", "Human fema…
#> $ Stage <chr> "Final", "Final", "Final", "Primary", "Primary", "Primary", "U…
#> $ Sector <chr> "Agriculture", "Industry", "Services", "Agriculture", "Industr…
#> $ Unit <chr> "EJ", "EJ", "EJ", "EJ", "EJ", "EJ", "EJ", "EJ", "EJ", "EJ", "E…
#> $ E.dot <dbl> 8.681814e-04, 1.539860e-02, 2.819406e-02, 1.400293e-03, 2.4836…
PSUT matrices
PFU data can be converted to PSUT matrices using
prep_psut()
.
mw_psut <- MWTools::prep_psut(.hmw_df = hmw_pfu_data,
.amw_df = amw_pfu_data)
tibble::glimpse(mw_psut)
#> Rows: 246
#> Columns: 13
#> $ Country <chr> "CHNM", "CHNM", "CHNM", "CHNM", "CHNM", "CHNM", "CHNM", "C…
#> $ Year <dbl> 1960, 1960, 1961, 1961, 1962, 1962, 1963, 1963, 1964, 1964…
#> $ Method <chr> "PCM", "PCM", "PCM", "PCM", "PCM", "PCM", "PCM", "PCM", "P…
#> $ Energy.type <chr> "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E"…
#> $ Last.stage <chr> "Final", "Useful", "Final", "Useful", "Final", "Useful", "…
#> $ R <list> <matrix[1 x 1]>, <matrix[1 x 1]>, <matrix[1 x 1]>, <matri…
#> $ U <list> <<matrix[2 x 2]>>, <<matrix[3 x 14]>>, <<matrix[2 x 2]>>,…
#> $ V <list> <<matrix[2 x 2]>>, <<matrix[14 x 14]>>, <<matrix[2 x 2]>>…
#> $ Y <list> <<matrix[1 x 2]>>, <<matrix[12 x 2]>>, <<matrix[1 x 2]>>,…
#> $ S_units <list> <<matrix[2 x 1]>>, <<matrix[4 x 1]>>, <<matrix[2 x 1]>>, …
#> $ U_feed <list> <<matrix[2 x 2]>>, <<matrix[3 x 14]>>, <<matrix[2 x 2]>>,…
#> $ U_EIOU <list> <<matrix[2 x 2]>>, <<matrix[3 x 14]>>, <<matrix[2 x 2]>>,…
#> $ r_EIOU <list> <<matrix[2 x 2]>>, <<matrix[3 x 14]>>, <<matrix[2 x 2]>>,…
Conclusion
The functions in the MWTools
package can streamline and
assist inclusion of animal and human muscle work in societal exergy
analysis.