-
Notifications
You must be signed in to change notification settings - Fork 0
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
raster_spaghettiPlot() fails with rasterBricks #35
Comments
I found two issues here:
However, it doesn't look like the So to solve that issue, I think we just need to change how we determine what I'll try:
This makes all the |
Love the detailed explanation!
Thanks for tackling and solving this one.
…On Mon, Jul 13, 2020 at 1:24 PM Tate Brasel ***@***.***> wrote:
I found two issues here:
1. The first had to do with the argument passed to the internal
.meltTargetMonitor() function. This function expects a single
*ws_monitor* as a parameter, and should be called differently
depending on whether monitorList is an actual *list* of *ws_montor*s
or is a single *ws_monitor* object itself:
# Create ggplot dataframes
if ( stringr::str_detect(class(monitorList), 'Raster*') ) {
df <- .meltTargetMonitor(monitorList)
} else {
df <- lapply(monitorList, .meltTargetMonitor) %>%
dplyr::bind_rows()
}
However, it doesn't look like the stringr::str_detect(class(monitorList),
'Raster*') condition tests this properly, since in either case it returns
false and runs the else block. Now this is fine when monitorList is an
actual list of *RasterBrick*s, but it breaks when monitorList is a single
*ws_monitor* because the lapply() call tries to apply .meltTargetMonitor()
to the contents of each of monitorList's contents (meta and data).
Therefore it can't find some of the data it expects.
So to solve that issue, I think we just need to change how we determine
what monitorList is: An actual list of *ws_monitors*, or a single
*ws_monitor* itself. Everything works just fine in the latter case when
the non-else block is run instead.
I'll try: stringr::str_detect(class(monitorList), 'ws_monitor')
1. Unfortunately, there was still a problem. When a single
*RasterBrick* is given as a parameter to the spaghettiPlot function
and converted to a *ws_monitor* it's meta$modelName is in the form of
"DUMMY_525bf68f1703b6ad" instead of
"PNW.1.33km_2019100900_ea97e70f44eaed44". Therefore the
.meltTargetMonitor() function is not able to remove the string pattern
from the modelName:
# Melt the data
moltenTargetDist <-
monitorList$meta %>%
dplyr::select(.data$monitorID, .data$targetDistance) %>%
reshape2::melt(id.vars = 'monitorID') %>%
dplyr::mutate(variable = .data$monitorID, 'monitorID' = NULL) %>%
dplyr::mutate(modelName = stringr::str_remove(.data$variable, '_.+_.+'))
This makes all the model entries in the ggplot data unique, and tries to
render a facet for each one (there could be hundreds!). All that's needed
to fix this is change the pattern to '_.+' so it's works for both versions
of modelName.
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#35 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFYN5OKDPFCBNLOGW5H7DTR3NUQ5ANCNFSM4N2OGKXA>
.
--
Jonathan Callahan, PhD
Mazama Science
206-708-5028
mazamascience.com
|
I think this has to do with the lake of a name for use in the legend.
We have to have a way to name things if the
raster
parameter is a RasterBrick object.Probably just allowing a
rasterName
parameter and checking that this is specified ifraster
is a RasterBrick.Reproducible error
The text was updated successfully, but these errors were encountered: