def build_data_array(ref0, ref1, ref2):
    from vista.set import Constants
    from vtimeseries import time
    import math
    if (ref0==None and ref1==None and ref2==None):
        return []
    if (ref0!=None and ref1==None and ref2==None):
        iterator = multi_iterator([ref0.data], Constants.DEFAULT_FLAG_FILTER)
    if (ref0==None and ref1!=None and ref2==None):
        iterator = multi_iterator([ref1.data], Constants.DEFAULT_FLAG_FILTER)
    if (ref0==None and ref1!=None and ref2!=None):
        iterator = multi_iterator([ref1.data,ref2.data], Constants.DEFAULT_FLAG_FILTER)
    if (ref0!=None and ref1!=None and ref2==None):
        iterator = multi_iterator([ref0.data,ref1.data], Constants.DEFAULT_FLAG_FILTER)
    if (ref0!=None and ref1!=None and ref2!=None):
        iterator = multi_iterator([ref0.data,ref1.data,ref2.data], Constants.DEFAULT_FLAG_FILTER)
    darray=[]
    time_str = None
    while not iterator.atEnd():
        index = iterator.getIndex();
        e = iterator.getElement();
        date = convert_to_date(time(e.getXString()))
        if ((ref0!=None and ref1==None and ref2==None) or (ref0==None and ref1!=None and ref2==None)):
            darray.append((date.time, e.getY(0),-999.99))
        if ((ref0==None and ref1!=None and ref2!=None) or (ref0!=None and ref1!=None and ref2==None)):
            darray.append((date.time, e.getY(0),e.getY(1)))
        if (ref0!=None and ref1!=None and ref2!=None):
            darray.append((date.time, e.getY(0),e.getY(1),e.getY(2)))
        iterator.advance();
    return darray
Example #2
0
def build_data_array(ref0, ref1, ref2):
    from vista.set import Constants
    from vtimeseries import time
    import math
    if (ref0==None and ref1==None and ref2==None):
        return []
    if (ref0!=None and ref1==None and ref2==None):
        iterator = multi_iterator([ref0.data], Constants.DEFAULT_FLAG_FILTER)
    if (ref0==None and ref1!=None and ref2==None):
        iterator = multi_iterator([ref1.data], Constants.DEFAULT_FLAG_FILTER)
    if (ref0==None and ref1!=None and ref2!=None):
        iterator = multi_iterator([ref1.data,ref2.data], Constants.DEFAULT_FLAG_FILTER)
    if (ref0!=None and ref1!=None and ref2==None):
        iterator = multi_iterator([ref0.data,ref1.data], Constants.DEFAULT_FLAG_FILTER)
    if (ref0!=None and ref1!=None and ref2!=None):
        iterator = multi_iterator([ref0.data,ref1.data,ref2.data], Constants.DEFAULT_FLAG_FILTER)
    darray=[]
    time_str = None
    while not iterator.atEnd():
        index = iterator.getIndex();
        e = iterator.getElement();
        date = convert_to_date(time(e.getXString()))
        if ((ref0!=None and ref1==None and ref2==None) or (ref0==None and ref1!=None and ref2==None)):
            darray.append((date.time, e.getY(0),-999.99))
        if ((ref0==None and ref1!=None and ref2!=None) or (ref0!=None and ref1!=None and ref2==None)):
            darray.append((date.time, e.getY(0),e.getY(1)))
        if (ref0!=None and ref1!=None and ref2!=None):
            darray.append((date.time, e.getY(0),e.getY(1),e.getY(2)))
        iterator.advance();
    return darray
def build_obs_array(ref):
    from vista.set import Constants
    from vtimeseries import time
    import math
    if (ref==None):
        return []
    iterator = multi_iterator([ref.data], Constants.DEFAULT_FLAG_FILTER)
    darray=[]
    time_str = None
    while not iterator.atEnd():
        index = iterator.getIndex();
        e = iterator.getElement();
        date = convert_to_date(time(e.getXString()))
        darray.append((date.time, e.getY(0)))
        iterator.advance();
    return darray    
Example #4
0
def build_obs_array(ref):
    from vista.set import Constants
    from vtimeseries import time
    import math
    if (ref==None):
        return []
    iterator = multi_iterator([ref.data], Constants.DEFAULT_FLAG_FILTER)
    darray=[]
    time_str = None
    while not iterator.atEnd():
        index = iterator.getIndex();
        e = iterator.getElement();
        date = convert_to_date(time(e.getXString()))
        darray.append((date.time, e.getY(0)))
        iterator.advance();
    return darray    
Example #5
0
def expand_seasonal(seasonal, tw):
    """
    Given an input time series with seasonal (monthly) values,
    create a larger monthly time series
    recycling the seasonal values over and over.
    Arguments:
        seasonal: input time series with seasonal 
        tw: time window of output
    """
    from vtimeseries import time, timewindow, timeinterval
    import string
    from vista.set import Constants, RegularTimeSeries
    ti = timeinterval("1MON")
    seasonalVal = {}
    filter = Constants.DEFAULT_FLAG_FILTER
    for el in seasonal:
        if el and filter.isAcceptable(el):
            xval = el.getX()
            xdate = time(long(xval))
            xstr = xdate.toString()
            yval = el.getY()
            month = string.lower(xstr[2:5])
            if seasonalVal.has_key(month):
                raise "Ambiguous seasonal values for month of: %s " % month
            seasonalVal[month] = yval
        #
    #
    if len(seasonalVal) != 12:
        raise "Not all seasonal values found"
    t = tw.getStartTime()
    t = t.create(t.floor(ti))  # need copy
    start = t.create(tw.getStartTime().floor(ti))
    end = tw.getEndTime().ceiling(ti)
    n = start.getNumberOfIntervalsTo(end, ti)
    from jarray import zeros
    y = zeros(n + 1, 'd')
    i = 0
    while (t.getTimeInMinutes() <= end.getTimeInMinutes()):
        xstr = t.toString()
        month = string.lower(xstr[2:5])
        y[i] = seasonalVal[month]
        t.incrementBy(ti)
        i = i + 1
    out = RegularTimeSeries(seasonal.getName(), start.toString(),
                            timeinterval("1MON").toString(), y, None,
                            seasonal.getAttributes())
    return out
def expand_seasonal(seasonal, tw):
    """
    Given an input time series with seasonal (monthly) values,
    create a larger monthly time series
    recycling the seasonal values over and over.
    Arguments:
        seasonal: input time series with seasonal 
        tw: time window of output
    """
    from vtimeseries import time,timewindow,timeinterval
    import string
    from vista.set import Constants,RegularTimeSeries
    ti=timeinterval("1MON")
    seasonalVal={}
    filter=Constants.DEFAULT_FLAG_FILTER
    for el in seasonal:
        if el and filter.isAcceptable(el):
            xval = el.getX()
            xdate=time(long(xval))
            xstr=xdate.toString()
            yval = el.getY()
            month = string.lower(xstr[2:5])
            if seasonalVal.has_key(month):
                raise "Ambiguous seasonal values for month of: %s " % month
            seasonalVal[month]=yval
        #
    #
    if len(seasonalVal) != 12:
        raise "Not all seasonal values found"
    t=tw.getStartTime()
    t=t.create(t.floor(ti)) # need copy
    start=t.create(tw.getStartTime().floor(ti))
    end=tw.getEndTime().ceiling(ti)
    n=start.getNumberOfIntervalsTo(end,ti)
    from jarray import zeros
    y=zeros(n+1,'d')
    i=0
    while(t.getTimeInMinutes() <= end.getTimeInMinutes() ):
       xstr=t.toString()
       month=string.lower(xstr[2:5])
       y[i]=seasonalVal[month]
       t.incrementBy(ti)
       i=i+1
    out=RegularTimeSeries(seasonal.getName(),start.toString(),
                          timeinterval("1MON").toString(),y,None,seasonal.getAttributes())
    return out
Example #7
0
def conserveSpline(avedata, interval):
    if not isinstance(interval, TimeInterval):
        interval = timeinterval(interval)
    start = avedata.getStartTime()
    try:
        nout = start.getExactNumberOfIntervalsTo(avedata.getEndTime(),
                                                 interval) + 1
    except:
        nout = start.getNumberOfIntervalsTo(avedata.getEndTime(), interval)

    n = avedata.size()
    from jarray import zeros
    x = zeros(n + 1, 'd')
    y = zeros(n + 1, 'd')
    i = 0
    start2 = time(start.toString())  # Pain in the neck way to clone
    rev = timeinterval("-" + interval.toString())
    start2.incrementBy(avedata.getTimeInterval(), -1)
    x[0] = start2.getTimeInMinutes()
    for el in avedata:
        x[i + 1] = el.getX()
        y[i] = el.getY()
        i = i + 1
        if not Constants.DEFAULT_FLAG_FILTER.isAcceptable(el):
            raise "Missing or bad data not allowed in conservative spline"
    p = map(lambda x: splineparam, y)
    spline = interpolator.ConservativeSpline(x, y, p, y[0], y[n - 1])
    ynew = zeros(nout, 'd')
    newseries = RegularTimeSeries(
        '/Smooth/Data///' + interval.toString() + '//', start.toString(),
        interval.toString(), ynew)
    dsi = newseries.getIterator()
    while not dsi.atEnd():
        el = dsi.getElement()
        if spline.rh2val(el.getX()) < 0:
            # useY=y(el.getX())
            useY = spline.rh2val(el.getX())
        else:
            useY = spline.rh2val(el.getX())
        #
        el.setY(useY)
        dsi.putElement(el)
        dsi.advance()

    #tabulate(newseries,avedata)
    return newseries
Example #8
0
def build_data_array(ref1, ref2, tw=None):
    from vista.set import Constants
    from vtimeseries import time
    import math
    if (ref1==None and ref2==None):
        return []
    if tw != None:
        data1=ref1.data.createSlice(tw)
        data2=ref2.data.createSlice(tw)
    iterator = multi_iterator([data1, data2], Constants.DEFAULT_FLAG_FILTER)
    darray=[]
    time_str = None
    while not iterator.atEnd():
        index = iterator.getIndex();
        e = iterator.getElement();
        date = convert_to_date(time(e.getXString()))
        darray.append((date.time, e.getY(0), e.getY(1)))
        iterator.advance();
    return darray
Example #9
0
def build_data_array(ref1, ref2, tw=None):
    from vista.set import Constants
    from vtimeseries import time
    import math
    if (ref1==None and ref2==None):
        return []
    if tw != None:
        data1=ref1.data.createSlice(tw)
        data2=ref2.data.createSlice(tw)
    iterator = multi_iterator([data1, data2], Constants.DEFAULT_FLAG_FILTER)
    darray=[]
    time_str = None
    while not iterator.atEnd():
        index = iterator.getIndex();
        e = iterator.getElement();
        date = convert_to_date(time(e.getXString()))
        darray.append((date.time, e.getY(0), e.getY(1)))
        iterator.advance();
    return darray
Example #10
0
def conserveSpline(avedata, interval):
    if not isinstance(interval,TimeInterval):
        interval=timeinterval(interval)
    start=avedata.getStartTime()
    try:
       nout=start.getExactNumberOfIntervalsTo(avedata.getEndTime(),interval)+1
    except:
       nout=start.getNumberOfIntervalsTo(avedata.getEndTime(), interval)

    n=avedata.size()
    from jarray import zeros
    x=zeros(n+1,'d')
    y=zeros(n+1,'d')
    i=0
    start2=time(start.toString())    # Pain in the neck way to clone
    rev=timeinterval("-"+interval.toString())
    start2.incrementBy(avedata.getTimeInterval(),-1)
    x[0]=start2.getTimeInMinutes()
    for el in avedata:
        x[i+1]=el.getX()
        y[i]=el.getY()
        i=i+1
        if not Constants.DEFAULT_FLAG_FILTER.isAcceptable(el):
            raise "Missing or bad data not allowed in conservative spline"
    p=map(lambda x: splineparam, y)
    spline=interpolator.ConservativeSpline(x,y,p,y[0],y[n-1])
    ynew=zeros(nout,'d')
    newseries=RegularTimeSeries('/Smooth/Data///'+interval.toString()+'//',start.toString(),interval.toString(),ynew)
    dsi=newseries.getIterator()
    while not dsi.atEnd():
        el=dsi.getElement()
        if spline.rh2val(el.getX()) < 0:
            useY=y(el.getX())
        else:
            useY=spline.rh2val(el.getX())
        #
        el.setY(useY)
        dsi.putElement(el)
        dsi.advance()

    #tabulate(newseries,avedata)
    return newseries