Skip to content

Commit

Permalink
Merge pull request #43 from lindsayplatt/expand_beyond_conus
Browse files Browse the repository at this point in the history
Add regions outside CONUS to the map!
  • Loading branch information
cnell-usgs authored Dec 17, 2021
2 parents 877c1f1 + 5b3c736 commit db3d9bd
Show file tree
Hide file tree
Showing 7 changed files with 378 additions and 14 deletions.
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

0 comments on commit db3d9bd

Please sign in to comment.