dankelley / oce

R package for oceanographic processing
http://dankelley.github.io/oce/
GNU General Public License v3.0
144 stars 42 forks source link

set plot axis limits for custom data in a CTD object #1791

Closed paul736 closed 3 years ago

paul736 commented 3 years ago

Hi Dan - I have a ctd object that I've added fluorescence data to using ctd.object<-oceSetData(ctd.object, name="Fluorescence", value=dat.ctd$fluoro, unit=list(unit=expression(mg/m^3), scale=""))

I'm now building a custom plot from this object and other similar objects such that I can have multiple casts on one plot. . For standard temp, salinity, etc, I can set the x axis limits using Tlim, Slim. When i choose the fluorescence, the x axis limits go to default of the data range. This wouldn't be so bad if i was plotting one cast, but because I'm plotting multiple casts, I will need to set the xlim to accommodate the full range of all casts. I've been using the following to set up the custom plot

plot(ctd.object, which="Fluorescence", Flim=c(0,10), plim=c(10,0), type="n")

This produces the correct axis and axis labels, but it doesn't like the 'Flim' obviously.

Any ideas? work arounds?

Thanks, Paul

richardsc commented 3 years ago

Hi Paul

For "non-standard" plot types you should just be able to use xlim= to set the limits to a desired range.

I'm not at a computer right now so can't check to be sure.

Clark

dankelley commented 3 years ago

I just checked, and xlim is not working for me. But I might be using the CRAN version of oce, because I'm also not getting proper labels on the axis. I'll check into this.

@paul736 are you able to build oce from source? You'll need to do that, if (as might be the case) I need to tweak plotProfile() to obey xlim.

richardsc commented 3 years ago

Are we talking about plot,CTD-method or specifically plotProfile(). Because I feel like the latter works, so would be better to use in a custom plot function anyway.

The business with Tlim and Slim etc was to allow control in a single plot(CTD, which=) call, which is always hard to capture all cases with arguments.

paul736 commented 3 years ago

here is the error. Error: in plot,ctd-method() : 'xlim' not allowed; use Slim, Tlim, etc thanks!

dankelley commented 3 years ago

Oh, I was wrong. plotProfile actually does work. Click the Details token below, to see a detailed example that is created with the reprex::reprex() scheme. Also, @paul736, it would be great if you could use reprex::reprex() to show us what you're doing. (It ought to not use local data ... that's why mine makes up a fake column and adds it to a built-in dataset.)

Note that my test is done with the oce that is on github, not the one on CRAN. You can install this version with

remotes::install_github("dankelley/oce", ref="develop")

if your system is set up to build packages from source.

``` r # issue 1791: plotProfile() ignoring xlim for a user-supplied data field library(oce) #> Loading required package: gsw #> Loading required package: testthat #> Loading required package: sf #> Linking to GEOS 3.8.1, GDAL 3.1.4, PROJ 6.3.1 data(ctd) p <- ctd[["pressure"]] F <- sin(p/max(p)*pi/2) # fake something as a test ctdNew <- oceSetData(ctd, "F", F, list(unit=expression(mg/m^3), scale="")) plotProfile(ctdNew, xtype="F", xlim=c(0,2)) ``` ![](https://i.imgur.com/pJc0rMk.png) ``` r summary(ctdNew) #> CTD Summary #> ----------- #> #> * Instrument: SBE 25 #> * Temp. serial no.: 1140 #> * Cond. serial no.: 832 #> * File: "/Users/kelley/git/oce/create_data/ctd/ctd.cnv" #> * Original file: c:\seasoft3\basin\bed0302.hex #> * Start time: 2003-10-15 15:38:38 #> * Sample interval: 1 s #> * Cruise: Halifax Harbour #> * Vessel: Divcom3 #> * Station: Stn 2 #> * Location: 44.684N 63.644W #> * Data Overview #> #> Min. Mean Max. Dim. NAs OriginalName #> scan 130 220 310 181 0 scan #> timeS [s] 129 219 309 181 0 timeS #> pressure [dbar] 1.48 22.885 44.141 181 0 pr #> depth [m] 1.468 22.698 43.778 181 0 depS #> temperature [°C, IPTS-68] 2.919 7.5063 14.237 181 0 t068 #> salinity [PSS-78] 29.916 31.219 31.498 181 0 sal00 #> flag 0 0 0 181 0 flag #> F [mg/m³] 0.052643 0.65816 1 181 0 - #> #> * Processing Log #> #> - 2018-11-14 20:03:47 UTC: `create 'ctd' object` #> - 2018-11-14 20:03:47 UTC: `read.ctd.sbe(file = file, debug = 10, processingLog = processingLog)` #> - 2018-11-14 20:03:47 UTC: `oce.edit(x = ctd, item = "startTime", value = as.POSIXct(gsub("1903", "2003", format(ctd[["startTime"]])), tz = "UTC") + 4 * 3600, reason = "file had year=1903, instead of 2003", person = "Dan Kelley")` #> - 2021-03-12 20:19:20 UTC: `oceSetData(object = ctd, name = "F", value = F, unit = list(unit = expression(mg/m^3), scale = ""))` ``` Created on 2021-03-12 by the [reprex package](https://reprex.tidyverse.org) (v1.0.0)
richardsc commented 3 years ago

The problem with xlim in the plot,ctd-method is that with multi panels the xlim is too ambiguous. Hence the advice to just use eg par(mfrow=c(2, 2)) and then a series of plotProfile() calls.

paul736 commented 3 years ago

richardsc / dan - You're right - I've got plotProfile working - almost...

plotProfile(ctd.object, xtype = "Fluorescence", xlim=c(0,10), plim=c(10,0), type="n")

But type="n" does not supress the plot? Is there a different setting?

but the

dankelley commented 3 years ago

I might need to alter it to make type work. Give me 15 minutes.

richardsc commented 3 years ago

What about type"l", lwd=NA?

paul736 commented 3 years ago

Ah, I see I can add=T, so I'm good for now. Thanks.

Just to note that in plot,CTD-method the x axis label comes up nicely with [units] that I've added to the metadata. PlotProfile does not seem to. But I assume I can build a xlab from scratch. Reading through the rest of PlotProfile details now.

dankelley commented 3 years ago

I have plotProfile(...,type="n") working on the "develop" branch commit 66305183b603b920e6bad677fa6c2a97b3fc1753 now; a reprex is below.

``` r # issue 1791: plotProfile() ignoring xlim for a user-supplied data field library(oce) #> Loading required package: gsw #> Loading required package: testthat #> Loading required package: sf #> Linking to GEOS 3.8.1, GDAL 3.1.4, PROJ 6.3.1 data(ctd) p <- ctd[["pressure"]] F <- sin(p/max(p)*pi/2) # fake something as a test ctdNew <- oceSetData(ctd, "F", F, list(unit=expression(mg/m^3), scale="")) plotProfile(ctdNew, xtype="F", xlim=c(0,2), type="n") ``` ![](https://i.imgur.com/8rql2mG.png) Created on 2021-03-12 by the [reprex package](https://reprex.tidyverse.org) (v1.0.0)
dankelley commented 3 years ago

The comment I just posted demonstrates that plotProfile() names the axis. Again, this is the oce on github.

richardsc commented 3 years ago

Yes add=TRUE is a lifesaver (I recommend using TRUE and not T ... you might actually code a variable named T at some point).

The xlab in plotProfile I think was just fixed, so might require the develop version from GitHub.

richardsc commented 3 years ago

Yes it was just fixed in #1785

paul736 commented 3 years ago

Thanks very much to you both for fixes and advice. Grabbing the github version now. A productive Friday night. cheers.

paul736 commented 3 years ago

Hi Dan - looks like I can't grab from github - getting errors after several attempts. Can I send you a private message?

paul736 commented 3 years ago

Hi @dankelley - looks like I can't grab from github - getting errors after several attempts. Can I send you a private message?

dankelley commented 3 years ago

It's best to post the errors here (put a line containing the string <details>, then a blank line then the long output) because then other users might see the problem with your system. I only use oce on one machine (macos) and I have no problems so I am unlikely to know how to help.

richardsc commented 3 years ago

Hi Paul -- what OS are you on? Did you try the instructions using the remotes package posted at

https://dankelley.github.io/oce/

If you're on Windows, you should only need to install RTools from the r-project website and it should work.

On Linux (Ubuntu or similar) the below instructions might help:

https://github.com/dankelley/oce/wiki/Configuring-a-Linux-Mint-20-system-to-be-able-to-build-oce-from-source

If OSX, we might need Dan to weigh in.

paul736 commented 3 years ago

OK. I 've pasted the error below (Windows 10. R 4.0.4, Rstudio). When it asks to update packages, I've tried all options - in the example below I've chose to update none. I've updated everything else. This has worked in the past, so not sure whats going on now. @richardsc I tried loading Rtools but it seems its not compatible with R4.0.4, and I've stepped back to 4.0.0 but still no joy.

> library(devtools) > remotes::install_github("dankelley/oce", ref="develop") Downloading GitHub repo dankelley/oce@develop These packages have more recent versions available. It is recommended to update all of them. Which would you like to update? 1: All 2: CRAN packages only 3: None 4: utf8 (1.1.4 -> 1.2.1) [CRAN] Enter one or more numbers, or an empty line to skip updates:3 √ checking for file 'C:\Users\Paul B\AppData\Local\Temp\RtmpC8ARvZ\remotes1e644c4d2d0b\dankelley-oce-6630518/DESCRIPTION' (334ms) - preparing 'oce': (18.9s) √ checking DESCRIPTION meta-information ... - cleaning src - installing the package to process help pages (4.5s) - saving partial Rd database (2m 47.7s) - cleaning src Warning in as.POSIXlt.POSIXct(x, tz) : unable to identify current timezone 'M': please set environment variable 'TZ' - checking for LF line-endings in source and make files and shell scripts - checking for empty or unneeded directories (336ms) - looking to see if a 'data/datalist' file should be added - building 'oce_1.4-0.tar.gz' Installing package into ‘C:/Users/Paul B/Documents/R/win-library/4.0’ (as ‘lib’ is unspecified) Error in strptime(xx, f, tz = tz) : (converted from warning) unable to identify current timezone 'M': please set environment variable 'TZ' Error: Failed to install 'oce' from GitHub: (converted from warning) installation of package ‘C:/Users/PAULB~1/AppData/Local/Temp/RtmpC8ARvZ/file1e645beb6a74/oce_1.4-0.tar.gz’ had non-zero exit status >
richardsc commented 3 years ago

Huh, that's not one I've seen before, but I tend to be a few versions behind on R (because I'm lazy/conservative ...).

You're definitely going to need Rtools, since it has the compilers required to build from source. You'll have to download from here and follow the install instructions:

https://cloud.r-project.org/bin/windows/Rtools/

Another option you can try is that the POSIX thing seems to only be a warning, which devtools/remotes converts to errors (to be nice and cautious), and that behaviour can be changed by doing the following in the R console before installing:

Sys.setenv("R_REMOTES_NO_ERRORS_FROM_WARNINGS"=TRUE)

Hope that works

paul736 commented 3 years ago

Thank for pointing the way there. Installing RTools40 (plus had to set the path), and setting the TZ worked. Thanks!

richardsc commented 3 years ago

Yes! Glad to hear it.

If you think that the issue (as described by the title) has been addressed, feel free to close (we like to leave that up to the reporters to make sure everything is addressed). If something related comes up, you can always re-open this issue, or open a new one if it's a different problem.

Have a great weekend!