[SciPy-user] calculations using the datetime information of timeseries

Timmie timmichelsen@gmx-topmail...
Thu Nov 13 03:49:49 CST 2008

Hello Pierre,
first, thanks for the fast reply. I really appreciate it.
As note on my last email I may add that I simplyfied the functions (method 1-3).
The different methods were only created to illustrate how I handle/access the

> Your `snew` object is only a reference to `series_dummy`. When you  
> modify an element of snew, you're in fact modifying the corresponding  
> element of `series_dummy`.  That's a feature of Python, you would get  
> the same result with lists:
>  >>> a = [0,0,0]
>  >>> b = a
>  >>> b[0] = 1
>  >>> a
> [1,0,0]
> If you want to avoid that, you can make snew a copy of series_dummy
> snew = series_dummy.copy()
OK, thanks for this gentle hint. I must re-read this in my basic python books...

> Finally, some comments for method #3:
> You want to create a new timeseries based on the result of some  
> calculation on the data part, but still using the dates of the initial  
> series ?
> If you don't have any missing values, perform the computation on  
> series._data, that'll be faster. If you have mssing values, use the  
> series._series instead to access directly the MaskedArray methods, and  
> not the timeseries ones (you don't want to carry the dates around if  
> you don't need them).

> As a wrap-up:
> Try to avoid looping if you can. 
Yes, I noticed that.
But I couldn't find another way to pass the individual datetimes to my
calculation function which expects only one value at once (i.e. it is not
designed to calculate full arrays).

>You said a generic form of your function is:
> >
> > def myfunction(datetime_obj, scaling_factor):
> >    pass
> Do you really need datetime objects ?
Yes, in geoscience/earthscience and engineering it's quite normal to have
parameters which are date/your of your dependent like: position of planets,
state of the ocean, etc.

> In your example, you were using  
> series.dates[i].datetime.hour, a list. You should have used  
> series.dates.hour, which is an array. Using functions on an array as a  
> whole is far more efficient than using the same functions on each  
> element of the array.
I will try to adjust the function in order to let it calculate the directly with

But the basic problem I haven't solved yet is to pass a signle datetime_obj to
the myfunction along with further parameters.


More information about the SciPy-user mailing list