dankelley / oce

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

Beginning in OCE #325

Closed carrierv closed 11 years ago

carrierv commented 11 years ago

Hi, I am a new master candidate and I need to do a TS diagram for water mass origin. I have spotted OCE package, I understood how to create a plot but I actually can't get my CTD data. I have been using a SD204 ctd. I used SD200W software to do a list of parameters. I copied these values in a spreadsheet on excel. As far as I learn at bachelor, we need to convert through excel into .csv code. But when i use read.ctd, it is mentionned the file do not exist.

Thanks for you help!

dankelley commented 11 years ago

The best would be if you could email me your data file. I am used to data privacy, so you don't have to worry about my taking your data. Ideally, send the data in several forms, including the "cdv" form you mention, and any other form that you have. (If you have the "cnv" form, please be sure to send that.)

This should not be too hard.

You can email me the files or put them in dropbox for me.

carrierv commented 11 years ago

Hi Dan,

wow that was a really quick answer! I am out of university until next monday so I do not have access to my data at the moment. But to let you know what I have so far: The CTD I use is the SD204 from SAIV A/S I transferred data using software SD200W (company software) and I got 4 files (.op2, .ox2, .rf2 and .sd2; looks like .sd2 is the file that is read by SD200W) Then I export the list of data from SD200W to .txt (only available format of export) which I then filled it in Excel to get a .csv.

I have not been able to read my .csv file with R but I have been able to read it with ODV (I want to learn OCE package and also ODV ways to have TS diagrams).

Do you want me to send you raw data (.sd2) or .csv I have been able to do?

Tusen takk og med vennlig hilsen,

Vincent Carrier MSc Biology Candidate University Laval, Quebec, Canada University Centre in Svalbard, Norway

dankelley commented 11 years ago

please send both files

On 2013-07-26, at 9:50 AM, carrierv notifications@github.com wrote:

Hi Dan,

wow that was a really quick answer! I am out of university until next monday so I do not have access to my data at the moment. But to let you know what I have so far: The CTD I use is the SD204 from SAIV A/S I transferred data using software SD200W (company software) and I got 4 files (.op2, .ox2, .rf2 and .sd2; looks like .sd2 is the file that is read by SD200W) Then I export the list of data from SD200W to .txt (only available format of export) which I then filled it in Excel to get a .csv.

I have not been able to read my .csv file with R but I have been able to read it with ODV (I want to learn OCE package and also ODV ways to have TS diagrams).

Do you want me to send you raw data (.sd2) or .csv I have been able to do?

Tusen takk og med vennlig hilsen,

Vincent Carrier MSc Biology Candidate University Laval, Quebec, Canada University Centre in Svalbard, Norway

— Reply to this email directly or view it on GitHub.

dankelley commented 11 years ago

I have been able to read your data, and am trying to find an algorithm that will detect descending-phase data automatically. The latter is a bit tricky. Unless you have many hundreds of profiles, you may want to isolate the descending-phase data manually (using plotScan() to see the scan numbers of the appropriate parts).

I will look into this some more in a few hours. In the meantime, you might want to play with the code I have put below. Near the top are some criteria that I am playing with. I think what I really should do is to figure out a good algorithm, and then put that into ctdTrim() to make it easier for other people who are doing tow-yow collection.

NOTE: the code below does not actually chop the data up into profiles. It is just an experiment in reading the data (easy) and detecting descent rate (harder). I may use the criterion called criterion2, for which I have put vertical lines at the start and end of places for chopping. The next step will be to chop them into descending paths, probably with a criterion on descent time or number of points ... these things I will look into in about 4 hours.

 ## tow-yow CTD data, need to be cut into descending portions
dpCriterion <- 0.3
kCriterion <- 21
library(oce)
d <- read.table("Edgeøya04.07csv.csv", sep=";", dec=",", header=TRUE)
cat("'d' has names:", names(d), "\n")
salinity <- d[["Sal."]]
temperature <- d[["Temp"]] # or is it "T"?
pressure <- d[["Press"]]
scan <- d[["Meas"]]
datetime <- paste(d[["Date"]], d[["Time"]]) # 04.07.2013
time <- strptime(datetime, "%d.%m.%Y %H:%M:%S")

c <- as.ctd(salinity, temperature, pressure, scan=scan)
## dp will be delta p / delta t
dp <- diff(pressure) / diff(as.numeric(time))
dp <- c(dp[1], dp)
par(mfrow=c(3,1), mar=c(3,3,1,1), mgp=c(2, 0.75, 0))
descending1 <- dp > quantile(dp, dpCriterion)
oce.plot.ts(time, pressure, type='p', col=ifelse(descending1, "red", "gray"), cex=0.5)
descending2 <- runmed(dp>quantile(dp, dpCriterion), k=kCriterion)
oce.plot.ts(time, pressure, type='p', col=ifelse(descending2, "red", "gray"), cex=0.5)
dpSmoothed <- smooth(dp)
descending3 <- dpSmoothed > quantile(dpSmoothed, dpCriterion)
oce.plot.ts(time, pressure, type='p', col=ifelse(descending3, "red", "gray"), cex=0.5)
carrierv commented 11 years ago

Ok great! Thanks SO much! I will try to fully understand everything thanks!

dankelley commented 11 years ago

Below is some code that seems to work on your data. I have three methods coded into the new function I call ctdFindDescents(). My tests show that method=3 may be best, at least with the values of the other parameters. Maybe you can try this with your datasets, and send me a private email with larger datasets if this doesn't work. I may code this into oce at some point, but I'd like to see it get tested more first, in case it needs changes.

The best way for you to try this is just to run it. It makes two pages. Page 1 is the timeseries of pressure with red lines for 'start' and gray lines for 'end' of the identified descents. Page 2 has profiles of S and T, and a TS diagram.

NOTE: your salinity sensor may be noisy. Notice the spikes in the profiles and the wiggles on the TS diagram. Is it pumped? (I am not familiar with this particular manufacturer.)

## tow-yow CTD data, need to be cut into descending portions
##
## NOTES:
## The following are results from a test dataset, with dpdtCriterion,
## etc. taking default values, and 'method' being adjusted.
##    method=1 only gets 1 descent in a test dataset that clearly has 2
##    method=2 gets too much before and after a visually-identify descents
##    method=3 works well, by visual test

## TO DO: put this in ctdTrim(), with some new args

library(oce)
ctdFindDescents <- function(ctd,
                            dpdtCriterion=0.3, # quantile fraction
                            kCriterion=21, # runmed() criterion for method=2
                            nCriterion=10, # discard descents shorter than this
                            method=3)  # 1=simple 2=runmed 3=smooth (2 or 3 seem best)
{
    ## dpdth is delta p / delta t in dbar/s
    dpdt <- diff(pressure) / diff(as.numeric(time))
    dpdt <- c(dpdt[1], dpdt)
    if (method == 1) {
        descending <- dpdt > quantile(dpdt[dpdt>0], dpdtCriterion)
        start <- which(diff(descending) == 1)
        end <- which(diff(descending) == -1)
    } else if (method == 2) {
        dpdt <- runmed(dpdt, k=kCriterion)
        descending <- dpdt > quantile(dpdt, dpdtCriterion)
        start <- which(diff(descending) == 1)
        end <- which(diff(descending) == -1)
    } else if (method == 3) {
        dpdt <- smooth(dpdt)
        descending <- dpdt > quantile(dpdt, dpdtCriterion)
        start <- which(diff(descending) == 1)
        end <- which(diff(descending) == -1)
    }
    if (start[1] > end[1])
        start <- start[-1]
    if (length(end) > length(start))
        end <- end[1:length(start)]
    keep <- (end - start) >= nCriterion
    indices <- data.frame(start=start[keep], end=end[keep])
    return(indices)
}

## read data
d <- read.table("Edgeøya04.07csv.csv", sep=";", dec=",", header=TRUE)
cat("'d' has names:", names(d), "\n")
salinity <- d[["Sal."]]
temperature <- d[["Temp"]] # or is it "T"?
pressure <- d[["Press"]]
scan <- d[["Meas"]]
datetime <- paste(d[["Date"]], d[["Time"]]) # 04.07.2013
time <- as.POSIXct(strptime(datetime, "%d.%m.%Y %H:%M:%S"))
c <- as.ctd(salinity, temperature, pressure, scan=scan)

## Find descents
indices <- ctdFindDescents(ctd, dpdtCriterion=0.3, kCriterion=21, nCriterion=10, method=3)

## Plot
par(mfrow=c(1,1), mar=c(3,3,1,1), mgp=c(2, 0.75, 0))
oce.plot.ts(time, pressure)
abline(v=time[indices$start], col='red')
abline(v=time[indices$end], col='gray')
ncasts <- length(indices$start)
casts <- vector("list", ncasts)
for (i in 1:length(casts)) {
    ii <- seq.int(indices$start[i], indices$end[i])
    casts[[i]] <- as.ctd(salinity[ii], temperature[ii], pressure[ii])
}
par(mfrow=c(ncasts, 3))
for (c in casts) {
    plotProfile(c, "salinity")
    plotProfile(c, "temperature")
    plotTS(c, type='o')
}
dankelley commented 11 years ago

I have started transferring the algorithm into oce as a new function named ctdFindDescents(). If you can build from source (it requires a compiler etc) you can get the new code tomorrow. It will not show up in the official CRAN version of oce for a few months, because the R people do not like to see lots of small updates.

dankelley commented 11 years ago

Below is code that will do this, with the updated (develop branch) of oce.

## chop up tow-yow data into a vector of ctd casts

library(oce)

## read data
d <- read.table("Edgeøya04.07csv.csv", sep=";", dec=",", header=TRUE)
cat("'d' has names:", names(d), "\n")
salinity <- d[["Sal."]]
temperature <- d[["Temp"]] # or is it "T"?
pressure <- d[["Press"]]
scan <- d[["Meas"]]
datetime <- paste(d[["Date"]], d[["Time"]]) # 04.07.2013
time <- as.POSIXct(strptime(datetime, "%d.%m.%Y %H:%M:%S"))
ctd <- as.ctd(salinity, temperature, pressure, scan=scan)

## Find descents, and save as a vector of ctd objects
indices <- ctdFindDescents(ctd, dpCriterion=0.3, k=21, smallest=10, method=3)
ncasts <- length(indices$start)
casts <- vector("list", ncasts)
for (i in 1:length(casts)) {
    ii <- seq.int(indices$start[i], indices$end[i])
    casts[[i]] <- as.ctd(salinity[ii], temperature[ii], pressure[ii])
}

## Plot
par(mfrow=c(1,1), mar=c(3,3,1,1), mgp=c(2, 0.75, 0))
oce.plot.ts(time, pressure)
abline(v=time[indices$start], col='red')
abline(v=time[indices$end], col='gray')
par(mfrow=c(ncasts, 3))
for (cast in casts) {
    plotProfile(cast, "salinity")
    plotProfile(cast, "temperature")
    plotTS(cast, type='o')
}
dankelley commented 11 years ago

I've updated develop to let ctdFindDescents() return either indices or a vector of ctd objects. The latter is the default. So, a test code with your data is below.

library(oce)
## Read data
d <- read.table("Edgeøya04.07csv.csv", sep=";", dec=",", header=TRUE)
cat("'d' has names:", names(d), "\n")
## guessing that "F" means turbidity; use this method for other columns if desired
ctd <- as.ctd(salinity=d[["Sal."]], temperature=d[["Temp"]], pressure=d[["Press"]],
              oxygen=d[["Oxy"]], scan=d[["Meas"]],
              other=list(turbidity=d[["F"]]))
## Find descents
casts <- ctdFindDescents(ctd, dpCriterion=0.3, k=21, smallest=10, method=3, debug=3)
## Plot
par(mfrow=c(length(casts), 3))
for (cast in casts) {
    plotProfile(cast, "salinity")
    plotProfile(cast, "temperature")
    plotTS(cast, type='o')
}
carrierv commented 11 years ago

Hi! sorry for no answering! here it is 5 or 6 hours more than in NS! I am going on fieldwork today. I will ask about the salinity if it is pumped. I will be back to work on it in 10 hours! Thanks so much again!

Vincent

carrierv commented 11 years ago

Hi sorry, for the long delay. My knowledge in R is really basic so I will take time to understand clearly each line of scripts but it seems everything is working. I will probably have more questions so please don't close it for now!. And no our CTD is not pumped.

carrierv commented 11 years ago

Ok i already have few questions, it would be really helpfull if you could answer: 1: I tried to find DpCriterion and kCriterion and their role but I didnt find them. And also, why did you choose 0,3 and 21as values?

  1. A tow yow CTD, do you mean a CTD data that collect downcast AND upcast?
  2. In as.ctd, what is the role of scan=scan. I understand you referred it as the identification of the measurments, but why scan= scan?

otherwiste I understand the first script, maybe still a bit confuse about the use of quantile(), runmed() and smooth()

Thanks!

dankelley commented 11 years ago

Are you able to build from source? That is easy on Linux and not too hard on osx but quite hard in windows

carrierv commented 11 years ago

Good I have been through the algorithm and I think if you could answer my last questions and also maybe if you could explain me the three methods and why did you choose method 3, I would a good comprehension. Also, I have seen on some TS diagram default boxes representing caracteristics of water masses. Do we add them through a script or manually with visual effects tools?

dankelley commented 11 years ago

Not sure on the emulator. I ask because I have coded into the develop branch a new function called ctdFindDescents(). If you can get your system to the point where it can build packages (e.g. it needs a C compiler and a fortran compiler) then you can always install the latest version of the oce code, and that way I can help you very quickly, by changing things if needed. (Official releases of oce are kept to a much slower pace of updating, because they require work by the people who run the R community.)

For your interest, the code for ctdFindDescent() starts at http://github.com/dankelley/oce/blob/develop/R/ctd.R#L308 and its documentation is at http://github.com/dankelley/oce/blob/develop/man/ctdFindDescents.Rd

Now for your questions.

1: I tried to find DpCriterion and kCriterion and their role but I didnt find them. And also, why did you choose 0,3 and 21 as values?

They may not be in the code you're looking at, but they are in the new code for ctdFindDescents() and you can see how they work at the above-noted link for that code. The criterion selects a quantile (e.g. 0.3 means the 30% quantiile) for the pressure change from point to point in the data. The idea is to look for rapid descents. The kCriterion value is used for runmed(), a running-median filter. It means to compute a median using 5 data before, and 5 data after, any given point. What this does it to remove outliers. (That is necessary because the instrument might raise mometarily even during a descent.)

2. A tow yow CTD, do you mean a CTD data that collect downcast AND upcast?

Yes. It normally means to tow the instrument with a moving ship, and to pull it in to the ship (to make it rise) and then to release the cable (to make it descend). QUESTION is your ctd being towed or is it going up and down on a mooring? If it is towed, the salinities may be good even when pressure is not changing, but if it is moored, the salinity cell may not be being flushed enough (since no pump) and that might lead to poor S values. As noted, the S values do not look too wonderful to me, based on spikes in profiles and loops in TS.

3. In as.ctd, what is the role of scan=scan. I understand you referred it as the identification of the measurments, but why scan= scan?

That is the serial number of the sample. It's probably not needed in many cases, but it can be very handy in figuring out which cast is which.

PS. if you get a way to build from source, let me know and then we could work more closely on this. For example, I was assuming you only wanted descents, but you may want ascents also.

dankelley commented 11 years ago

In answer to "Good I have been through the algorithm and I think if you could answer my last questions and also maybe if you could explain me the three methods and why did you choose method 3, I would a good comprehension. Also, I have seen on some TS diagram default boxes representing caracteristics of water masses. Do we add them through a script or manually with visual effects tools?", see below. (And, sorry for missing this comment.)

The methods are explained briefly in the help page (see previous posting), but the code is so preliminary that the docs are brief. In other words, to see what it is doing, you should read the code.

I picked #3 because it identified what looked to my eye to be descending phases, without trimming too much at times when pressure was not varying. That is the point of the graphs I was showing in some previous comments.

As for the TS diagrams, these can be added if you know the (S,T) values that create a polygon enclosing the water type. Just use polygon(). However, I do not think you should spend time with this, unless you have a strong reason to (i.e. unless the text you are writing for a paper or a thesis requires such boxes). Your time is better spent thinking of what to do with your data, in terms of some testable hypotheses.

dankelley commented 11 years ago

I have put windows-compiled versions of ocedata and oce at the following link. You should be able to install them (in that order), to get the latest version. (NOTE: it would still be a lot better if you could get your system to build from binaries because then you can get updates without my having to build them, but this may help for now.)

https://www.dropbox.com/sh/awlz31v1jj7w0ct/620Tf2ZkGz

carrierv commented 11 years ago

Hi Thanks for your answer. Yes CTD was towed with a metal wire from the ship. For building from the source, as I cant get Linux, do you think Visual Studio express could be enough?http://www.webmonkey.com/2010/02/compile_software_from_source_code/. Otherwise I have two external hard drives so I could install Linux on of them and run my computer on this external drive. Would it work? Because yes I would like to have also ascents to compare profiles. We usually use only upcast data because salinity is not pumped and apparently salinity might not be representative fully at the beginning of the downcast and it has not been properly rinced with freshwater. In another hand, our echosounder was not working so we used maps to determine the approx depth. So it could have happen that the CTD hit the seafloor and thus maybe change data. I have not been able to answer spikes in salinity but I will try the script with other station if it is still the same pattern.

And related to the polygon, one of my objective is too link eukaryotic assemblages to water masses so I was having in mind after my TS diagram to make a vertical gradient line with different water masses encountered in the water column.

dankelley commented 11 years ago

I don't know about compiling R packages on windows, but I bet a google search will help. Quite a few people use that platform.

In any case, you won't need to compile packages if you look at the Dropbox link

https://www.dropbox.com/sh/awlz31v1jj7w0ct/620Tf2ZkGz

You should be able to just install these, starting with the data one.

NOTE: I have renamed the function ctdGetProfiles() and improved its documentation. I think the latter should be clear but let me know if not. (I prefer to explain things in documentation and not in discussion boards, because the former helps more people.)

dankelley commented 11 years ago

To develop I have added method=4, which I think is a lot better than the other methods, on a test file. Below I am pasting the test code, and I will attach two graphs. Note that on the graph of pressure versus time, the cut-points look close to what you might draw by eye. Note that on the profiles, the up and down casts look to be of similar pressure range, and the data look similar.

library(oce)
profiles <- TRUE
dpCriterion <- 0.5
k <- 11
method <- 4
smallest <- 10

d <- read.table("Edgeøya04.07csv.csv", sep=";", dec=",", header=TRUE)
cat("'d' has names:", names(d), "\n")
## guessing that "F" means turbidity; use this method for other columns if desired
ctd <- as.ctd(salinity=d[["Sal."]], temperature=d[["Temp"]], pressure=d[["Press"]],
              oxygen=d[["Oxy"]], scan=d[["Meas"]],
              other=list(turbidity=d[["F"]]))
if (profiles) {
    upcasts <- ctdFindProfiles(ctd, dpCriterion=dpCriterion, k=k, smallest=smallest, method=method, direction="ascending")
    downcasts <- ctdFindProfiles(ctd, dpCriterion=dpCriterion, k=k, smallest=smallest, method=method, direction="descending")
    par(mfrow=c(length(upcasts)+length(downcasts), 3))
    for (cast in upcasts) {
        plotProfile(cast, "salinity")
        mtext("upcast", side=3, line=-1)
        plotProfile(cast, "temperature")
        plotTS(cast, type='o')
    }
    for (cast in downcasts) {
        plotProfile(ctdTrim(cast), "salinity")
        mtext("downcast", side=3, line=-1)
        plotProfile(cast, "temperature")
        plotTS(cast, type='o')
    }   
} else {
    par(mfrow=c(2,1), mar=c(3,3,2,1), mgp=c(2,0.7,0))
    upcasts <- ctdFindProfiles(ctd, dpCriterion=dpCriterion, k=k, smallest=smallest, method=method, direction="ascending", arr.ind=TRUE)
    downcasts <- ctdFindProfiles(ctd, dpCriterion=dpCriterion, k=k, smallest=smallest, method=method, direction="descending", arr.ind=TRUE)
    plot(ctd[["scan"]], ctd[["pressure"]], type='l')
    legend("topleft", legend="ascending")
    abline(v=ctd[["scan"]][upcasts$start], col='red')
    abline(v=ctd[["scan"]][upcasts$end], col='blue')
    legend("topright", legend="RED=start; BLUE=end\n")
    plot(ctd[["scan"]], ctd[["pressure"]], type='l')
    legend("topleft", legend="descending")
    abline(v=ctd[["scan"]][downcasts$start], col='red')
    abline(v=ctd[["scan"]][downcasts$end], col='blue')
    legend("topright", legend="RED=start; BLUE=end\n")
}

notprofiles profiles

carrierv commented 11 years ago

Ok! Good, I understand the dpCriterion about 30%. But did you choose 0.3, 21 and 10 empirically? Could I have for example another CTD data raw where i have less measurements not part of the downcast and upcast and I should instead use 0.2 to do not take out too much data? And why can't we use as well quantile instead of runmed?

Thank you a lot! I also saw you have been doing a study north of Svalbard. It will be probably really usefull to compare water masses over the year in this region with my data.

dankelley commented 11 years ago

Yes, I picked these values empirically, in order to get the graph of p=p(t) to be categorized into upcast and downcast as my eye would judge them.

As noted two comments above, my present plan is to remove methods 1, 2 and 3, in favour of method 4, which I think works better and is simpler. This is often the case when a function is first written -- a few things are tried, and the best selected for the next release. This is why being able to build from source is so important: it makes it a lot easier for the user and I to interact quickly on calibrating things or deciding on best practices.

dankelley commented 11 years ago

I just updated develop. The methods 1, 2 and 3 are now gone. Indeed, the argument named method is gone. Gone too is the k argument. The new functioning is documented in the package, so there is no need to explain it here, I think. Below is test code that works with the new function. The graphs it produces look the same as those in the comment above.

library(oce)
profiles <- TRUE
cutoff <- 0.5
smallest <- 10

d <- read.table("Edgeøya04.07csv.csv", sep=";", dec=",", header=TRUE)
cat("'d' has names:", names(d), "\n")
## guessing that "F" means turbidity; use this method for other columns if desired
ctd <- as.ctd(salinity=d[["Sal."]], temperature=d[["Temp"]], pressure=d[["Press"]],
              oxygen=d[["Oxy"]], scan=d[["Meas"]], other=list(turbidity=d[["F"]]))
if (profiles) {
    upcasts <- ctdFindProfiles(ctd, cutoff=cutoff, smallest=smallest,
                               direction="ascending")
    downcasts <- ctdFindProfiles(ctd, cutoff=cutoff, smallest=smallest,
                                 direction="descending")
    par(mfrow=c(length(upcasts)+length(downcasts), 3))
    for (cast in upcasts) {
        plotProfile(cast, "salinity")
        mtext("upcast", side=3, line=-1)
        plotProfile(cast, "temperature")
        plotTS(cast, type='o')
    }
    for (cast in downcasts) {
        plotProfile(ctdTrim(cast), "salinity")
        mtext("downcast", side=3, line=-1)
        plotProfile(cast, "temperature")
        plotTS(cast, type='o')
    }   
} else {
    par(mfrow=c(2,1), mar=c(3,3,2,1), mgp=c(2,0.7,0))
    upcasts <- ctdFindProfiles(ctd, cutoff=cutoff, smallest=smallest,
                               direction="ascending", arr.ind=TRUE)
    downcasts <- ctdFindProfiles(ctd, cutoff=cutoff, smallest=smallest,
                                 direction="descending", arr.ind=TRUE)
    plot(ctd[["scan"]], ctd[["pressure"]], type='l')
    legend("topleft", legend="ascending")
    abline(v=ctd[["scan"]][upcasts$start], col='red')
    abline(v=ctd[["scan"]][upcasts$end], col='blue')
    legend("topright", legend="RED=start; BLUE=end\n")
    plot(ctd[["scan"]], ctd[["pressure"]], type='l')
    legend("topleft", legend="descending")
    abline(v=ctd[["scan"]][downcasts$start], col='red')
    abline(v=ctd[["scan"]][downcasts$end], col='blue')
    legend("topright", legend="RED=start; BLUE=end\n")
}
carrierv commented 11 years ago

I have been installing the two packages, but I always end with "can't find ctdFindProfiles".

library(ocedata)
library(maps)
library(oce)
profiles <- TRUE
cutoff <- 0.5
smallest <- 10

d <- read.table("C:/Users/vincentc/Desktop/Edgeøya04.07csv.csv", sep=";", dec=",", header=TRUE)
cat("'d' has names:", names(d), "\n")
'd' has names: Ser Meas Sal. Temp Ox mg.l F T Density Press Date Time 
ctd <- as.ctd(salinity=d[["Sal."]], temperature=d[["Temp"]], pressure=d[["Press"]],
                   oxygen=d[["Oxy"]], scan=d[["Meas"]], other=list(turbidity=d[["F"]]))
if (profiles) {
    upcasts <- ctdFindProfiles(ctd, cutoff=cutoff, smallest=smallest,
                               direction="ascending")
    downcasts <- ctdFindProfiles(ctd, cutoff=cutoff, smallest=smallest,
                                 direction="descending")
    par(mfrow=c(length(upcasts)+length(downcasts), 3))
    for (cast in upcasts) {
        plotProfile(cast, "salinity")
        mtext("upcast", side=3, line=-1)
        plotProfile(cast, "temperature")
       plotTS(cast, type='o')
    }
    for (cast in downcasts) {
        plotProfile(ctdTrim(cast), "salinity")
        mtext("downcast", side=3, line=-1)
        plotProfile(cast, "temperature")
        plotTS(cast, type='o')
    }   
} else {
    par(mfrow=c(2,1), mar=c(3,3,2,1), mgp=c(2,0.7,0))
    upcasts <- ctdFindProfiles(ctd, cutoff=cutoff, smallest=smallest,
                               direction="ascending", arr.ind=TRUE)
    downcasts <- ctdFindProfiles(ctd, cutoff=cutoff, smallest=smallest,
                                 direction="descending", arr.ind=TRUE)
    plot(ctd[["scan"]], ctd[["pressure"]], type='l')
    legend("topleft", legend="ascending")
    abline(v=ctd[["scan"]][upcasts$start], col='red')
    abline(v=ctd[["scan"]][upcasts$end], col='blue')
    legend("topright", legend="RED=start; BLUE=end\n")
    plot(ctd[["scan"]], ctd[["pressure"]], type='l')
    legend("topleft", legend="descending")
    abline(v=ctd[["scan"]][downcasts$start], col='red')
    abline(v=ctd[["scan"]][downcasts$end], col='blue')
    legend("topright", legend="RED=start; BLUE=end\n")
}
Error: could not find function "ctdFindProfiles"
dankelley commented 11 years ago

I re-edited the comment to make it readable. Code should be indented by 4 spaces.

I don't quite understand this. Did you install the libraries from the Dropbox site as instructed? Because the function is in the version that is stored there, I think. If you unzip the file and look in oce/NAMESPACE you will see the desired file, which tells me that it is up-to-date.

I do not know how to advise, other than by getting your machine working so it can compile packages. Have you tried googling? I found the following, which may help: http://www.biostat.wisc.edu/~kbroman/Rintro/Rwinpack.html

carrierv commented 11 years ago

I downloaded the link you just sent me. I think it is well installed. Im not familiar with building from source. Do you recommand any introduction pdf?

dankelley commented 11 years ago

Sorry, I am not familiar with anything relating to windows. Millions of people use R on windows so you should be able to find help on the web.

carrierv commented 11 years ago

Okay I start up the computer again and reinstalling packages and now it seems working. But two new problems appeared:

profiles <- TRUE cutoff <- 0.5 smallest <- 10

d <- read.table("C:/Users/vincentc/Desktop/TS diagrams/RawCSVdata/Edgeøya0407.csv", sep=";", dec=",", header=TRUE) cat("'d' has names:", names(d), "\n") 'd' has names: Ser Meas Sal. Temp Ox.. mg.l F..µg.l. T..FTU. Density Depth.d. Date Time ctd <- as.ctd(salinity=d[["Sal."]], temperature=d[["Temp"]], Depth=d[["Depth"]],

  • oxygen=d[["Oxy"]], scan=d[["Meas"]], other=list(turbidity=d[["F"]])) Error in abs(data$pressure) : non-numeric argument to mathematical function if (profiles) {
  • upcasts <- ctdFindProfiles(ctd, cutoff=cutoff, smallest=smallest,
  • direction="ascending")
  • downcasts <- ctdFindProfiles(ctd, cutoff=cutoff, smallest=smallest,
  • direction="descending")
  • par(mfrow=c(length(upcasts)+length(downcasts), 3))
  • for (cast in upcasts) {
  • plotProfile(cast, "salinity")
  • mtext("upcast", side=3, line=-1)
  • plotProfile(cast, "temperature")
  • plotTS(cast, type='o')
  • }
  • for (cast in downcasts) {
  • plotProfile(ctdTrim(cast), "salinity")
  • mtext("downcast", side=3, line=-1)
  • plotProfile(cast, "temperature")
  • plotTS(cast, type='o')
  • }
  • } else {
  • par(mfrow=c(2,1), mar=c(3,3,2,1), mgp=c(2,0.7,0))
  • upcasts <- ctdFindProfiles(ctd, cutoff=cutoff, smallest=smallest,
  • direction="ascending", arr.ind=TRUE)
  • downcasts <- ctdFindProfiles(ctd, cutoff=cutoff, smallest=smallest,
  • direction="descending", arr.ind=TRUE)
  • plot(ctd[["scan"]], ctd[["pressure"]], type='l')
  • legend("topleft", legend="ascending")
  • abline(v=ctd[["scan"]][upcasts$start], col='red')
  • abline(v=ctd[["scan"]][upcasts$end], col='blue')
  • legend("topright", legend="RED=start; BLUE=end\n")
  • plot(ctd[["scan"]], ctd[["pressure"]], type='l')
  • legend("topleft", legend="descending")
  • abline(v=ctd[["scan"]][downcasts$start], col='red')
  • abline(v=ctd[["scan"]][downcasts$end], col='blue')
  • legend("topright", legend="RED=start; BLUE=end\n")
  • } Error in if (start[1] < end[1]) start <- start[-1] : missing value where TRUE/FALSE needed
carrierv commented 11 years ago

Okay no i understand the first error. It's because I switched to Depth instead of Pressure.

carrierv commented 11 years ago

Okay now everything work. The thing is that I need to use name "pressure" for depth data. Do you think, from your point of view, it's relevant to convert data to depth as 1m depth = 09,999 of pressure?

dankelley commented 11 years ago

You mentioned two problems a while back but I only saw one.

In any case, please bear in mind that if your data file contains non-ascii characters, an encoding will need to be set. Also, if your file sometimes has depth, you can test for that. So, although this does not address your question about the profiles (more on that tomorrow), I can give you these hints:

file <- "hornsund0207.csv"
d <- read.table(file, sep=";", dec=",", header=TRUE, fileEncoding="latin1")
if ("Press" %in% names(d)) {
    p <- d[["Press"]]
} else {
    if ("Depth" %in% names(d)) {
        p <- d[["Depth"]]
    }
}
ctd <- as.ctd(salinity=d[["Sal."]], temperature=d[["Temp"]], pressure=p,
              oxygen=d[["Oxy"]], scan=d[["Meas"]], other=list(turbidity=d[["F"]]))
dankelley commented 11 years ago

I think the problem (noted in a personal email, since data from active analysis should not be shared on github) is now fixed in the develop branch. Please try building from source and checking.

dankelley commented 11 years ago

Please try building from source and checking, and close the issue if things are ok. Thanks.

dankelley commented 11 years ago

This issue seems to have been addressed, so I am closing it