HARPgroup / hydro-tools

Houses sets of commonly used hydrologic tools
0 stars 0 forks source link

Easy Map Generator for VWP Projects #369

Open jdkleiner opened 1 year ago

jdkleiner commented 1 year ago

Easiest Map Generation (Rev. 5/4/23):

Everything needed to generate a "fig.locationmap.png" is housed in this file:

Result: fig location_map_test

jdkleiner commented 1 year ago

Stashing pre-5/4/23 items below:

Scripts:

example_map

Example:

source("https://raw.githubusercontent.com/HARPgroup/hydro-tools/master/GIS_functions/mapgen.R")

# User Inputs: 
export_path <- "C:/Users/nrf46657/Desktop/VWP Modeling/Magnolia Green"
filename <- paste0("MagnoliaGreen_nhdplus_map.png")

# specify start point (typically intake location), map buffer is based on this point
start_point <- data.frame(lat = 37.415128974720155, lon = -77.7271085761693, label = "Intake")

# specify additional points to plot
points <- data.frame(lat=double(),lon=double(),label=character())
points <- rbind(points,data.frame(lat = 37.40402068694781, lon = -77.74288001411728, label = "12MG Pond"))
points <- rbind(points,data.frame(lat = 37.402823839033694, lon = -77.74452198900777, label = "7MG Pond"))

# specify usgs gage to plot
gageid <- "02036500"

# specify which rsegs to plot
segswhere <- "hydrocode LIKE 'vahydrosw_wshed_J%'"

# generate map gg object (simple example, using defaults)
# map_gg <- mapgen()

# generate map gg object (simple example, overriding defaults)
map_gg <- mapgen(start_point=start_point,
                 points=points,
                 gageid=gageid,
                 segswhere=segswhere)

# output map as png file
png(file=paste(export_path,filename,sep="/"), width=1500, height=1500)
map_gg
dev.off()

Magnolia Green Example:

DEMO_MAP_2 0

Salem WTP Example:

map_gg <- mapgen(start_point=data.frame(lat = 37.286388888900, lon = -80.075833333300, label = "Intake"))

TEST_map

rburghol commented 1 year ago

Hey - the new model_geoprocessor function looks very good. I propose the following: (Not really proposing that you do it, just proposing that we do it some time :) )

# Three ways to get the list of segments:
# 1. Use the dataframe returned from om_vahydro_metric_grid()
#   - can be useful as it will ONLY get segments that have been modeled for the scenario
#   - can be problematic cause it ONLY gets segments that have been modeled :)
# GET RIVERSEG l90_Qout DATA
conf <- data.frame( model_version ='vahydro-1.0',  runid = 'runid_600', metric='l90_Qout', runlabel='l90_prop')
om_data <- om_vahydro_metric_grid(
  metric = False, runids = conf, 
  base_url = paste(site,'entity-model-prop-level-export',sep="/"),
  ds = ds
)
seglist <- data.frame(riverseg = wshed_data$riverseg, propname = wshed_data$propname)
# 2. Use ds$get() call
#    - this is a touch slower, but very concise
seglist <- ds$get('dh_feature', config=list(ftype='vahydro',bundle='watershed'))
# 3. There is also a views public query available which should be super fast

# Then, extract the basin using fn_extract_basin()
app_segs <- fn_extract_basin(seglist, 'JA5_7480_0001')
rburghol commented 1 year ago

The above works well, however, I observed that both your original (in hydrotools) and my update render these in black and white, so the nice JK color scheme is lacking... any ideas?

image

rburghol commented 1 year ago

@jdkleiner I have done some more dev here. Bringing in the points with existing tools (facilities can ALSO be retrieved with om_vahydro_metric_grid()), that can soon be used to do the bubble sizes as you mentioned above.

Also, I updated the bounding box to use the riersegments that are included, not the starting point with a zoom. The only rub is that in a HUC8 size watershed things start to get kinda busy, though perhaps they wouldn't look so bad if I could figure out why my color scheme is lacking your earthtones? Any ideas on this? Surely you all conquered this during WSP.

The only real obstacle I see is that the labels overlap, which is a bit of a pain:

image

rburghol commented 1 year ago

Now, I have gone an alternate route for the container, and lost the busy stuff, as I used a variation on plot_nhdplus() that uses comids as input (instead of bbox) for the set of flowlines. IT is less busy, but I can't get the catchment boundaries to show up crisply.

image

rburghol commented 1 year ago

Rivanna version: image

jdkleiner commented 1 year ago

@rburghol This is great, glad to see you pushing this forward. Taking a look at some of this now, is your latest code housed here?: https://github.com/HARPgroup/vahydro/blob/master/R/mapping/EasyMapGen.R

Also, running into a snag, where is the function fn_extract_basin() defined?

rburghol commented 1 year ago

@jdkleiner yup that's the one (it's linked at the top of the issue below your original to trace the source).

The fn_extract_basin() is in the cia_utils.R set in hydrotools, you may need to update hydrotools? It was developed in 2021 but the linkage may not work in the module, so maybe you need to include cia_utils.R source link -- https://github.com/HARPgroup/hydro-tools/blob/d6ee09041c835aece8a338587c3473f4c28c6b2c/R/cia_utils.R#L174

Thanks for taking a look!!!

rburghol commented 1 year ago

@jdkleiner If you can verify your original version gets all those colors, my first B&W troubles happened with that one which makes me wonder if there is some config that I may lack?

jdkleiner commented 1 year ago

Thanks, looked like cia_utils.R got updated recently, needed to do a pull.

Just did a test of my earlier map version and your new version, both have color in the terrain layer. Maybe you need to update one of the spatial packages? (ggmap, ggsn, ggspatial)

fig location_map_rb

rburghol commented 1 year ago

@jdkleiner

If we go the route of map extents based on watershed, we'll have to think of some smart ways to scale/zoom

Doesn't setting the extents eliminate the need to think about scale and zoom? The extent becomes the scale... no?

rburghol commented 1 year ago

Still no colors. I did a remove.packages() for ggmap, ggspatial, ggplot2 and ggsn then reinstalled. Running R-4.2.2 -- and these color schemes have been with us for a lonnggg time. tried the option for get_map(...color = c('color') to no avail...