[SciPy-user] how to get only complete years from series?
Pierre GM
pgmdevlist@gmail....
Tue Nov 18 10:15:07 CST 2008
Timmie,
There's no generic function to perform what you want as it'll depend
on the frequency. What you can do is:
1. get a list of years
>>> singleyears = set(s_all.years)
2. for each year, check what are the first and last days of the year:
>>> firstandlast = [tuple([year]
+s_all[s_all.years==year].yeardays[[0,-1]].tolist()) for year in
singleyears]
That gives you a list of tuples (year, first day, last day)
3. find the years for which the first day is strictly larger than 1
and the last strictly lower than 365.
>>> maskyears = [y for (y,f,l) in firstandlast if f>1 or l<365]
4. Mask the corresponding years
>>> for y in maskyears:
>>> s_all[s_all.years==y] = ma.masked
That's far from efficient and rather ugly, but that should give you a
generic idea.
Let me know how it goes.
P.
On Nov 17, 2008, at 3:34 PM, Timmie wrote:
> Hello,
> I am unsing the scikit.timeseries to evaluate a long-term
> measurement data set.
>
> How can I extract those years, which have complete measurements?
>
> In the below, years 2004 & 2008 are not complete.
> Is there a generic possibility that all incomplete years get masked?
>
> Thanks & regards,
> Timmie
>
> ###code
>
> import numpy as np
> import numpy.ma as ma
> import scikits.timeseries as ts
>
> data = np.arange(0, 40800)
> start_dt = ts.Date(freq='H', year=2004, month=3, day=1, hour=0)
> s_all = ts.time_series(data, freq='H', start_date=start_dt)
>
>
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
More information about the SciPy-user
mailing list