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

Easy Map Generator for VWP Projects #369

Open
jdkleiner opened this issue Feb 17, 2023 · 12 comments
Open

Easy Map Generator for VWP Projects #369

jdkleiner opened this issue Feb 17, 2023 · 12 comments

Comments

@jdkleiner
Copy link
Member

jdkleiner commented Feb 17, 2023

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

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

  • Original: https://github.com/HARPgroup/hydro-tools/blob/master/GIS_functions/EasyMapGen.R
  • This is the most updated version of the mapping script
  • This file currenlty contains the updated function definitions for mapgen() and model_geoprocessor() as updates were needed during development and I didn't want to update those functions located in hydro-tools/GIS_functions/ just yet in case you needed them
  • To generate a map, a user only needs to supply a point location to base the map on (i.e. the intake location) and a dataframe of all the additional points they want mapped (See EasyMapGen.R)

Result:
fig location_map_test

@rburghol rburghol moved this from Tasks & Related Issues to Data Visualization/Prototypes in Mapping Models and Features May 4, 2023
@jdkleiner
Copy link
Member Author

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
Copy link
Contributor

rburghol commented May 5, 2023

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 :) )

  • remove the SQL segs_where portion from the function (function should either retrieve data or display the map)
  • use the function fn_extract_basin() to grab those that we want. Example: see below (note: dataframe funkiness requires that you have 2 columns, riverseg and anything else for one of the syntaxes to work)
# 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
Copy link
Contributor

rburghol commented May 5, 2023

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 rburghol closed this as completed May 5, 2023
@rburghol rburghol reopened this May 5, 2023
@rburghol
Copy link
Contributor

rburghol commented May 5, 2023

@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
Copy link
Contributor

rburghol commented May 5, 2023

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
Copy link
Contributor

rburghol commented May 8, 2023

Rivanna version:
image

@jdkleiner
Copy link
Member Author

@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
Copy link
Contributor

rburghol commented May 8, 2023

@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 --

fn_extract_basin <- function(cia_data_frame, end_seg){

Thanks for taking a look!!!

@rburghol
Copy link
Contributor

rburghol commented May 8, 2023

@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
Copy link
Member Author

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

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

@rburghol
Copy link
Contributor

rburghol commented May 9, 2023

@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
Copy link
Contributor

rburghol commented May 9, 2023

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Data Visualization/Prototypes
Development

No branches or pull requests

2 participants