Skip to content

Commit

Permalink
check exisiting files for historical means
Browse files Browse the repository at this point in the history
  • Loading branch information
emmamendelsohn committed Oct 13, 2023
1 parent 4ef3b4d commit a5b6c4a
Show file tree
Hide file tree
Showing 4 changed files with 1,020 additions and 800 deletions.
1 change: 0 additions & 1 deletion R/calculate_weather_anomalies.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ calculate_weather_anomalies <-
save_filename <- glue::glue("weather_anomaly_{date_selected}.gz.parquet")
message(paste0("Calculating weather anomalies for ", date_selected))


# Check if file already exists
existing_files <- list.files(weather_anomalies_directory)
if(save_filename %in% existing_files & !overwrite) {
Expand Down
14 changes: 10 additions & 4 deletions R/calculate_weather_historical_means.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,26 @@
calculate_weather_historical_means <- function(nasa_weather_transformed,
nasa_weather_directory_transformed,
weather_historical_means_directory,
days_of_year) {
days_of_year,
overwrite = FALSE) {

# Set filename
doy <- days_of_year
doy_frmt <- str_pad(doy,width = 3, side = "left", pad = "0")
save_filename <- glue::glue("historical_weather_mean_doy_{doy_frmt}.gz.parquet")

message(paste("calculating historical weather means and standard deviations for doy", doy_frmt))

# Check if file already exists
existing_files <- list.files(weather_historical_means_directory)
if(save_filename %in% existing_files & !overwrite) {
message("file already exists, skipping download")
return(file.path(weather_historical_means_directory, save_filename))
}
# Open dataset to transformed data
weather_dataset <- open_dataset(nasa_weather_directory_transformed)
weather_transformed_dataset <- open_dataset(nasa_weather_directory_transformed)

# Filter for day of year and calculate historical means and standard deviations
historical_means <- weather_dataset |>
historical_means <- weather_transformed_dataset |>
filter(day_of_year == doy) |>
group_by(x, y, day_of_year) |>
summarize(historical_relative_humidity_mean = mean(relative_humidity),
Expand Down
3 changes: 2 additions & 1 deletion _targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ data_targets <- tar_plan(
tar_target(weather_historical_means, calculate_weather_historical_means(nasa_weather_transformed, # enforce dependency
nasa_weather_directory_transformed,
weather_historical_means_directory,
days_of_year),
days_of_year,
overwrite = FALSE),
pattern = days_of_year,
format = "file",
repository = "local"),
Expand Down
1,802 changes: 1,008 additions & 794 deletions _targets/meta/meta

Large diffs are not rendered by default.

0 comments on commit a5b6c4a

Please sign in to comment.