Closed DaveEslinger closed 5 years ago
Hi Dave,
Could you please provide a reproducible example? I just tried this with the elksmwq data set and was able to produce a y-axis in fahrenheit and celsius (you must set converted = T
for english and converted = F
for metric).
Hi Julie,
Yes, that is what I did for the conversion, which worked on the data, but not the labels. Attached are the
raw_boxplot_elknmwq_temp_yr.png file showning the error with elkhorn trtaining data and the Reserve_Level_Plotting_Variables excel file used as input. Only change has been to set converted = F
for temperature, depth, and precipitation.
Be sure to check the water quality parameters. They were the ones I found messed up. Checking others now with elk_training
Labels in met data seem to be working correctly:
I think the problem is in the status report script 01-02_all_plot_analyses.R, line 40:
converted_par <- ifelse(convert_temp && par_inst[j] == 'atemp' || par_inst[j] == 'temp' , T, ifelse(convert_depth && par_inst[j] == 'depth', T, F))
Words are failing me at the moment, but the ifelse evaluates to true even if convert_temp is false, if one of the params is temp:
> par_inst <- c("temp", "depth")
> convert_temp = FALSE
> convert_depth = TRUE
> j <- 1
> par_inst[j]
[1] "temp"
> convert_temp
[1] FALSE
> # want converted_par to be false too
> converted_par <- ifelse(convert_temp && par_inst[j] == 'atemp' || par_inst[j] == 'temp'
+ , T, ifelse(convert_depth && par_inst[j] == 'depth', T, F))
> converted_par
[1] TRUE
> convert_temp && par_inst[j] == 'atemp'
[1] FALSE
> par_inst[j] == 'atemp' || par_inst[j] == 'temp'
[1] TRUE
> convert_temp && par_inst[j] == 'atemp' || par_inst[j] == 'temp'
[1] TRUE
edited many times because I don't know how to show multiple lines of code, apparently
A bit more context for my comment above - converted_par
is used in the functions that generate the plot (e.g. raw_boxplot
, below), so it needs to be true or false to match what we "want" to see. And it's not evaluating quite right, as in my earlier comment.
raw_box <- raw_boxplot(dat
, param = par_inst[j]
, target_yr = target_year
, criteria = par_threshold[[j]]
, log_trans = par_log_transform[j]
, converted = converted_par
, plot_title = include_station_ttl
, season_grps = par_season_grp
, season_names = par_season_names
, season_start = par_season_start[[1]])
Thanks for the detective work, Kim!
That looks like there might be a set of missing parenthesis:
converted_par <- ifelse(convert_temp && (par_inst[j] == 'atemp' || par_inst[j] == 'temp') , T, ifelse(convert_depth && par_inst[j] == 'depth', T, F))
I'll check that.
Indeed, that seems to be the issue. Tripped up by order of operations!
If anyone would check, I would appreciate it.
Add the parenthesis in bold below to line 40 in the status report script 01-02_all_plot_analyses.R, line 40:
converted_par <- ifelse(convert_temp && ( par_inst[j] == 'atemp' || par_inst[j] == 'temp' ) , T, ifelse(convert_depth && par_inst[j] == 'depth', T, F))
If that works for others, I'll update the repo code. Thanks for the help!
Dave, that works for me in the console! Haven't tried running the full status report yet, but it's giving me the right result interactively.
This is fixed in the status report script 01-02_all_plot_analyses.R script that is part of a new repository for the scripts that use SWMPrExtension to produce the status reports. Please enter similar issues in that repo: https://github.com/NOAA-OCM/SWMP_Status_Reports
Plotting units do not change when metric units are used for Water Quality variables (temp & sonde depth), at least. Still running other plots to test. See image; should be labeled as degree C. Values are correct, labels are not.