times/dates

Hi all,

I'm new to matplotlib and trying to adapt some of the examples to my own data. Most of the time I read data from a netcdf file using the Scientific.IO.NetCDF module. When I read a time variable it usually has a units attribute that looks something like

"days since 1900-01-01 00:00:00 -5".

The units of measurement (here it was days) can be hours, seconds, weeks, whatever. Most of the examples in the mpl examples directory that deal with dates, start with the time information already parsed into year, month, day etc and then they create a datetime instance. Any pointers on parsing a serial date like the one I have into year, month, day in a somewhat general way? I currently use a package (cdat) which doesn't compile on Windows yet and I need a windows and unix solution.

Finally, I find the documentation for datetime.timedelta to be pretty sparse. I was trying to construct a datetime sequence using matplotlib.dates.drange which had a monthly timestep.

delta = datetime.timedelta(months=1) didn't seem to work. I tried a few variations on this to no avail.

Thanks for any suggestions.
Derrick

Derrick Snowden wrote:

Finally, I find the documentation for datetime.timedelta to be pretty sparse. I was trying to construct a datetime sequence using matplotlib.dates.drange which had a monthly timestep.

delta = datetime.timedelta(months=1) didn't seem to work. I tried a few variations on this to no avail.

Well, the docs for timedelta give this constructor:

···

============================================
class timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)

     All arguments are optional. Arguments may be ints, longs, or floats, and may be positive or negative.

I'd guess that the reason why you don't see years nor months in there is because those can't be uniquely defined in terms of fundamental time units (for the sake of simplicity, in multiples or submultiples of seconds).

I'm not an expert on handling time-based data, so this is just a common sense guess.

Best,

f

Fernando Perez wrote:

Derrick Snowden wrote:

Finally, I find the documentation for datetime.timedelta to be pretty sparse. I was trying to construct a datetime sequence using matplotlib.dates.drange which had a monthly timestep.

delta = datetime.timedelta(months=1) didn't seem to work. I tried a few variations on this to no avail.

Well, the docs for timedelta give this constructor:

============================================
class timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)

    All arguments are optional. Arguments may be ints, longs, or floats, and may be positive or negative.

I'd guess that the reason why you don't see years nor months in there is because those can't be uniquely defined in terms of fundamental time units (for the sake of simplicity, in multiples or submultiples of seconds).

You're probably right about this, months are ambiguously defined. But, I'm even more confused now about the documentation that you found. I'm hoping this is a version issue but I couldn't find a function definition like that. I tried using pydoc and pdoc, pdef, pinfo etc in ipython on a linux machine as well as a Windows machine. The only thing I can come up with is the following

class timedelta(__builtin__.object)
       Difference between two datetime values.

Where am I going wrong?

···

I'm not an expert on handling time-based data, so this is just a common sense guess.

Best,

f

Derrick Snowden wrote:

You're probably right about this, months are ambiguously defined. But, I'm even more confused now about the documentation that you found. I'm hoping this is a version issue but I couldn't find a function definition like that. I tried using pydoc and pdoc, pdef, pinfo etc in ipython on a linux machine as well as a Windows machine. The only thing I can come up with is the following

class timedelta(__builtin__.object)
       Difference between two datetime values.

Where am I going wrong?

I ran into the same problem, the docstring-based docs for that module are really crappy (and that's all ipython can find). So I reverted to the module listing in the HTML python docs to read the full docs for the datetime module. Here's the online version (what I pasted was from the local copy for my version, 2.3.4):

HTH,

f