Closed sckott closed 2 years ago
@sckott:
Just for the record, I will post the request the user made, and some examples that I hope will make it clear.
The user made the request:
wind <- griddap( 'erdQMwindmday', time = c('last-5', 'last'), latitude = c(30, 50), longitude = c(210, 240), fields = 'x_wind' )
If do that and look in the attributes of the object wind, you will see it produced the URL:
Put that in a browser, and use ncdump to look at the time variable, you get:
time = 1500163200
That is because the time coordinate is given in (), which means in coordinate space, and the units if time are seconds, so the time difference is 5 seconds for monthly data.
Now do the same for this URL:
You get for the times in the netcdf file:
time = 1487116800, 1489622400, 1492300800, 1494892800, 1497571200, 1500163200
That is because the the time dimension is not given in coordinate space but index space, so it references the time from indices from the end to the end , like [n-5:n] in R, where n is the length of the array.
Now let's look at this URL:
You get:
time = 1489622400, 1492300800, 1494892800, 1497571200, 1500163200 ;
Now the time coordinate is in parenthesis, so it is given in time coordinates, which is seconds, and this is monthly data, so
606024*120 = 10368000
Most people when they do arithmetic using last are thinking in terms of index space - it is monthly data, but they want 5 "time indices" before. Particularly for things like months, converting that into seconds correctly can be difficult, so my solution has been to treat the request as being in index space, finding the values, and sending the request in coordinate space, so for that dataset I find that the value for the last time is 2017-07-16, and five time indices before that has a value 2017-02-15, and then use that in my request.
HTH
thanks @rmendels !
from the emailer: