Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regions outside CONUS to the map! #43

Merged
merged 8 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions 1_fetch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,8 @@ targets:
'1_fetch/out/gw_data_dv.csv',
'1_fetch/out/gw_data_uv.csv',
'1_fetch/out/gw_data_uv_addl.csv')

##-- Download higher resolution spatial data for SVG mapping --##
# Data from the National Weather Service https://www.weather.gov/gis/USStates
1_fetch/out/nws_states.zip:
command: download.file(destfile = target_name, I("https://www.weather.gov/source/gis/Shapefiles/County/s_11au16.zip"))
14 changes: 14 additions & 0 deletions 2_process.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ sources:
- 2_process/src/categorize_quantiles.R
- 2_process/src/process_spatial.R
- 2_process/src/prep_data_for_visualizing.R
- 3_visualize/src/sf_utils_shift.R

targets:

Expand Down Expand Up @@ -46,6 +47,12 @@ targets:
# Create spatial objects to use in mapping
gw_sites_sf:
command: convert_to_spatial_obj(gw_quantile_site_info, proj_str)
# Apply shifting to the sites
gw_sites_sf_shifted:
command: apply_shifts_to_sites(
sites_sf = gw_sites_sf,
sites_info = gw_quantile_site_info,
proj_str = proj_str)

# Prepare data for peaks SVG
gw_anomaly_data:
Expand All @@ -58,3 +65,10 @@ targets:
command: add_paths_to_data(gw_anomaly_data)
gw_anomaly_data_w_colors:
command: add_colors_to_data(gw_anomaly_data_w_paths, scico_palette, gw_time)

# Unzip and prepare higher resolution spatial data for territories outside of CONUS
2_process/out/nws_states.shp:
command: open_highres_spatial_zip(
out_file = target_name,
in_zip = '1_fetch/out/nws_states.zip',
tmp_dir = I('2_process/tmp'))
17 changes: 17 additions & 0 deletions 2_process/src/process_spatial.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,20 @@ convert_to_spatial_obj <- function(gw_site_info, proj_str) {
crs = 4326) %>%
st_transform(proj_str)
}

open_highres_spatial_zip <- function(out_file, in_zip, tmp_dir) {
if(!dir.exists(tmp_dir)) dir.create(tmp_dir)

# Unzip the file
files_tmp <- unzip(in_zip, exdir = tmp_dir)

# Copy to the out location and name based on what was passed in to `out_file`
current_name_pattern <- unique(tools::file_path_sans_ext(files_tmp))
out_name_pattern <- tools::file_path_sans_ext(out_file)
files_out <- gsub(current_name_pattern, out_name_pattern, files_tmp)
file.copy(files_tmp, files_out)

# Find and return the specific `.shp` file from the unzipped folder
files_out_shp <- files_out[grepl(".shp", files_out)]
return(files_out_shp)
}
5 changes: 4 additions & 1 deletion 3_visualize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ sources:
- 3_visualize/src/svg_utils_mapping.R
- 3_visualize/src/svg_utils_paths.R
- 3_visualize/src/svg_utils_vue.R
- 3_visualize/src/sf_utils_shift.R

targets:

Expand All @@ -31,6 +32,8 @@ targets:
target_name,
svg_width = svg_width,
svg_height = svg_height)
depends:
- '2_process/out/nws_states.shp'

public/gw-conditions-wy20.csv:
command: gwl_to_peak(
Expand All @@ -40,7 +43,7 @@ targets:
public/gw-conditions-site-coords.csv:
command: get_site_coords(
target_name,
sites_sf = gw_sites_sf)
sites_sf = gw_sites_sf_shifted)

public/gw-conditions-daily-proportions.csv:
command: site_prop_timeseries(target_name,
Expand Down
Loading