Skip to content

Commit

Permalink
DRY: extract summarise_over_all_grids()
Browse files Browse the repository at this point in the history
  • Loading branch information
hsonne committed Sep 29, 2022
1 parent a31bbd2 commit 68e6983
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
11 changes: 7 additions & 4 deletions R/read_daily_data_over_shape.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,14 @@ get_daily_data_from_grid_files <- function(grid_files, shape, scale)
# Mask the full grid over Germany with the shape and crop the grid
grids <- mask_and_crop_grids(grids, shape)

# Calculate statistics, considering the conversion factor "scale"
data <- do.call(rbind, lapply(grids, raster_stats, scale = scale))
# Calculate statistics, considering the scaling factor, add metadata
cbind(metadata, summarise_over_all_grids(grids, scale))
}

# Add metadata
cbind(metadata, data)
# summarise_over_all_grids -----------------------------------------------------
summarise_over_all_grids <- function(grids, scale)
{
do.call(rbind, lapply(grids, raster_stats, scale = scale))
}

# extract_metadata_from_files_daily --------------------------------------------
Expand Down
7 changes: 2 additions & 5 deletions R/read_monthly_data_over_shape.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,9 @@ read_monthly_data_over_shape <- function(
grids <- mask_and_crop_grids(grids, shape)
}

# Calculate statistics, considering the conversion factor "scale"
data <- do.call(rbind, lapply(grids, raster_stats, scale = scale))

# Provide file metadata (file, year, month)
metadata <- extract_metadata_from_files_monthly(files = grid_files)

# Add metadata
cbind(metadata, data)
# Calculate statistics, considering the scaling factor, add metadata
cbind(metadata, summarise_over_all_grids(grids, scale))
}

0 comments on commit 68e6983

Please sign in to comment.