Closed richardsc closed 1 year ago
I think that the following should be all that is required to convert MTIME to POSIX, providing that startTime
in the object corresponds to the "JULD" field mentioned in the attributes:
time <- ctd[['startTime']] + 86400 * ctd[['MTIME']]
I suspect you're right, but it's odd how they say "Julian Day". There are loads of definitions for Julian Day, so it's tricky ... but the code https://github.com/dankelley/oce/blob/07bf03de57c68b51601c5bba1ca64be105859ce3/R/argo.R#L1417 indicates that the netcdf circumvents the problem of stating which Julian Day is being used!
I looked at the first file in your sequence and see as below
> a<-d[[1]]
> a[["time"]]
[1] "2023-03-09 22:47:40 UTC"
> a[["juld"]]
[1] 26730.95
That confuses me because
> 22+47/60+40/3600
[1] 22.79444
does not end in 0.95 as I would expect. Maybe I'm just confusing myself. but looking at it the other way I get that the time should be 22:48:00 which is 20 seconds off from the stated:
> 0.95*24
[1] 22.8
> 0.95*24 - 22
[1] 0.8
> (0.95*24 - 22)*60
[1] 48
So, 48:00 versus the 47:40 in the other field. Maybe 20 leap seconds explain this. At https://en.wikipedia.org/wiki/Leap_second they list leap seconds. There are more than 20 listed. But maybe there are only 20 seconds since Argo started its definition at some particular date.
This is all a bit rabbit-holey.
The nc attributes say the Argo reference for JULD is 1950-01-01 00:00:00.
But I guess the question is how do we determine the startTime
field from the nc file? (I could look at the code but am on the bus right now)
Our comments are interlaced. In the comment just before yours, I showed how we compute the start time. (It is called data$time
though, not metadata$startTime
.)
res@data$time <- t0 + res@metadata$juld * 86400
Oh, I see that time
is constructed from JULD. So I'm confused as to why they would be different …
I'm planning to fiddle with this tomorrow. If you're at Dal on Wednesday we could talk about it.
Mystery solved:
> options(digits=15)
> a@metadata$juld
[1] 26730.9497685185
> a@metadata$juld - 26730
[1] 0.949768518519704
> (a@metadata$juld - 26730) * 24
[1] 22.7944444444729
> ((a@metadata$juld - 26730) * 24 - 22)*60
[1] 47.6666666683741
> (((a@metadata$juld - 26730) * 24 - 22)*60 - 47)*60
[1] 40.0000001024455
Those steps say that the time of day is 22:47:40 which is what we got. So, no contradiction. I was just being stupid, forgetting I have R set up only to have a certain number of digits.
@richardsc if you're going to be at Dal Wed or Fri (CDOGS day) we could chat more about whether to make oce
[["startTime"]]
as the start time[["time"]]
as a vector of timesor perhaps just store time
as a column. We would want to be consistent with CTD handling, I think. It's easier to hash such things out in person, as compared to comments on GH, I think/find.
One thing to keep in mind -- there may be user code (possible quite a lot of user code since argo has been in oce for a long time) that assumes that [["time"]]
will produce just one value.
I am going to write some code to see how many of the .nc files on my compute has MTIME defined. That would be useful.
I am leaning towards just storing @data$mtime
as it is (fractional days), if the file contains MTIME
. The conversion to get time-of-each-datum is easy and could be documented. That way, any existing code that assumes time is a single value will still work, but users who want more can get it (if it's in the file).
I think I agree with you re: "time" vs "mtime". For the Argo folks "mtime" will be a known thing, which as you say is easy to handle.
One thought though, as an issue for oce
, is that perhaps as.ctd()
on an argo object should know how to interpret time
(metadata) and mtime
to be converted to the standard fields (for a ctd
object) of startTime
(metadata) and time
(data).
Oh, hang on. We already read MTIME, so the user can do as below. I don't think oce
needs changing.
PS to @richardsc do you know why there are so many NA values? They outnumber true values 10:1 for this file.
library(oce)
f <- "R6990512_001.nc"
a <- read.argo(f)
sort(names(a@data))
time <- a[["time"]] + a[["MTIME"]]*86400
# NA values outnumber finite values 10:1 ... WHY?
ok <- is.finite(time)
print(table(ok))
png("01.png")
oce.plot.ts(time[ok], a[["pressure"]][ok], type="o", pch=20, cex=0.7)
I like your idea. (As often seems to be the case, our comments are interlacing.)
Yes, we do read it -- that's the issue title was "Should we interpret it"? 😄
I think the reason there are NAs is because it doesn't necessarily store the time corresponding to every sample (maybe to save space?). It's actually something I plan to look into (this is quite new firmware on a float type that DFO uses).
On the interpretation note -- should it be at least lowercased? Or just left alone?
I also thought about whether to lower-case it. We do that for "standard" things that are known in other objects (e.g. DOXY and similar things all get named oxygen). I want to look in the SBE docs to see if they talk about MTIME there. It rings a bell, but, for the life of me, I am drawing a blank on what the M might stand for.
Hm. I don't see 'MTIME' (upper- or lower-case) in the SBE docs I have available. And that word (either case) does not appear in oce/R/*R
, either. It seems to have a similar meaning to SBE timeJ
(in attached, see p 170).
I guess we could call it "mtime". Frankly, I'm divided on this. If the original name is retained (which it ought to be) then the user could do either of
a[["MTIME"]]
a[["mtime"]]
and get the same result.
I am still blanking on what to call that thing. Maybe I need to look in argo docs now. I imagine "M" means something.
I think the "M" is for "measurement".
See this from the Argo QC manual, that explains the sporadic time returns:
I have about 2000 .nc files in my archive, and I read them all in and see if they have MTIME defined. I found that 67 files had this, and 1863 did not have this. Below is a listing of the files that had it. The last 3 of these files are the ones from the initial comment in this issue.
This makes me think that MTIME is not "standard" enough to get a lower-case name. I could be convinced otherwise, though, if @richardsc has the opposite opinion. (No rush -- I think you'll be in meetings all day and I am having a sign-students-in-to-my-class day.)
I have found something in section 2.6.4 of Ref 1:
I'm closing this because it relates to oce, not directly to argoFloats. See https://github.com/dankelley/oce/issues/2122 for a discussion of another matter relating to MTIME.
I prefer discussing on oce when it's an oce issue, because I get auto-notified about all new oce issues. Plus, I check oce quite a lot, and don't have a habit of looking for issues here on argoFloats.
I noticed when looking at a recently deployed float (ID=6990512) that it contains a field called
MTIME
, which based on the nc file corresponds to:I presume that this field is also described in the relevant Argo manual (but I haven't looked). It certainly could be converted to a POSIX time (using the "JULD" of the station).
A reprex to get data from this float to examine is:
Note that because the float starts at the bottom the profile of MTIME goes negative: