How to correct timestamp after time linear interpolation (inttime) in cdo - nco

I have a dataset at hourly timesteps and I am interpolating it to 30-min with 'inttime' in cdo. However, the timestamp outputted is not correct, it is just duplicated from the original data. How can I correct that using cdo (or nco)?
I am interpolating the data with 'cdo inttime,date,time,inc ifile.nc ofile.nc'.
This is what I have after the interpolation...
2000-01-01 01:00:00, 2000-01-01 01:00:00, 2000-01-01 02:00:00, 2000-01-01 02:00:00, etc.
But this is what I want to have after the interpolation...
2000-01-01 01:00:00, 2000-01-01 01:30:00, 2000-01-01 02:00:00, 2000-01-01 02:30:00, etc.
Thanks in advance for all the help!
Cheers,
M.

You can correct the time variable after its mis-interpolation by assigning it to an arithmetically increasing array with ncap2, e.g., if units are hours since start day, then something like the following...
ncap2 -s 'time=array(1.0,0.5,$time)' in.nc out.nc
ncap2 can also interpolate using GSL, but the CDO formulation appears much simpler so I wouldn't bother trying to change that.

Related

Is there a way to replace existing values with NaN

I'm experimenting with the algorithms in iPython Notebooks and would like to know if I can replace the existing values in a dataset with Nan (about 50% or more) at random positions with each column having different proportions of Nan values.
I'm using the Iris dataset for this experimentation to see how the algorithms work and which one works the best.
Thanks in advance for the help.
There is a replace function in python.
Link to answer

how to calculate UTC timestamps difference in OpenOffice?

I've two columns with start and ending timeStamps in UTC format as follow '2016-06-24T18:22:52.918Z' & '2016-06-24T18:25:03.621Z'. I've around 10K values in each column, but I'm not able to find any clue to calculate the difference between those timestamps in OpenOffice. Please let me know if you know a way to achieve this?
Subtract the later value from the earlier one, something like:
=B1-A1
Format to suit.

Clarification regarding gmtoff

I have two line below
%let dl="06jul2016"
date=dhms("&dl",d,00,00,00);
date1=dhms("&dl",d,00,00,00)-gmtoff();
date2=dhms("&dl",d,24,00,00)-gmtoff();
Output
date=2016-07-06T00:00:00
date1=2016-07-06T04:00:00
date2=2016-07-06T04:00:00
Could anyone explain me the result.
Thannkyou
I was not able to reproduce your output. After tidying up your code, I got some slightly different output:
Code:
%let dl="06jul2016"d;
data _null_;
date=dhms(&dl,00,00,00);
date1=dhms(&dl,00,00,00)-gmtoff();
date2=dhms(&dl,24,00,00)-gmtoff();
format date: is8601dt.;
put (_all_) (=/);
run;
Output:
date=2016-07-06T00:00:00
date1=2016-07-06T00:00:00
date2=2016-07-07T00:00:00
Is that closer to what you were expecting?
gmtoff() is a correction function for Greenwich Mean Time. So depending on your computers timezone, the results will differ. The input time is GMT and depending on your local timezone x hours are added/substracted. As you are using-gmtoff() you are subtracting the correction factor. That may produce unwanted results.
Also date1 & date2 should produce a difference of one day. Something seems off with your output.

how to get previous day date using boost?

I have a set of dates represented as strings and whilst it is easy to convert these to date types, I must perform calculations which will require the previous days date. So for example if I have the date 13-09-2013 I will need to derive the date 12-09-2013. Is there a clean way of achieving this? Ideally using boost.
thanks un advance
using namespace boost::gregorian;
date d(2013,Sep,13);
d -= days(1);
demo
Just get the current date, subtract one day, and you have yesterday.

how to choose SQLite date format

Sqlite has a different approach in storing time than other databases:
SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:
**TEXT** as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
**REAL** as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
**INTEGER** as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.
Applications can chose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions.
what is the best way to store date data in a sqlite database ?. TEXT, REAL or INTEGER ?
I'm interested in something like "using TEXT is space space consuming, using INTEGER is fine but you will have a big problem in the year 2038"
Integers are stored on 64 bits since SQLite 3.0 so year 2038 is not really a problem.
With REAL or INTEGER, you must perform calculations in fractions of days or fractions of seconds when you insert. With Integer, the resolution will be one second. With TEXT, it is one millisecond.
If you are concerned about total space and do not need any milliseconds or dates prior to 1970, then go for INTEGERs.
Is this correct?
Format Resolution Min Year Max Year Bytes/Date
Text Milliseconds 0 AD 9999 AD 23 or 46
Real Milliseconds? 4713 BC ???? 8
Integer Seconds 1970 AD ???? 8
The easiest way if you don't need fractions of seconds is epoch (integer number of seconds before or after 1970-01-01 00:00) accurate from -4714-11-24 until 5352-11-01 10:52:47
For calculation to human readable dates there is the function strftime