def grow_window(tw,left,right=None): if right == None: right = left st = tw.getStartTime() - timeinterval(left) et = tw.getEndTime() + timeinterval(right) return TimeFactory.getInstance().createTimeWindow(st,et)
def extend_flow(nodes_to_extend): """ Copying WY1922 data to WY1921 for allowing to preprocessing and running DSM2 from 01Jan1921. """ calsimfile=getAttr("CALSIMFILE") f=opendss(calsimfile) # open CALSIM file outfile=getAttr("BOUNDARYFILE") if not outfile or outfile == "": raise "Config variable BOUNDARYFILE not set and needed for prepro output" tw=timewindow("01OCT1921 0000 - 01OCT1922 0000") for calsimname in nodes_to_extend: print calsimname dsspath = calsim_path(calsimname) paths = findpath(f,dsspath) if not paths or len(paths)>1: print "File: %s" % calsimfile raise "Path %s not found or not unique" % dsspath ref=DataReference.create(paths[0],tw) monthly=ref.getData() itr = monthly.getIterator() d=zeros(len(monthly),'d') count=0 while not itr.atEnd(): el = itr.getElement() d[count] = el.getY() count = count + 1 itr.advance() stime = "01OCT1920 0000" rts = RegularTimeSeries(monthly.getName(),stime, \ timeinterval("1MON").toString(), d, None, monthly.getAttributes()) writedss(calsimfile,ref.getPathname().toString(),rts)
def extend_flow(nodes_to_extend): """ Copying WY1922 data to WY1921 for allowing to preprocessing and running DSM2 from 01Jan1921. """ calsimfile = getAttr("CALSIMFILE") f = opendss(calsimfile) # open CALSIM file outfile = getAttr("BOUNDARYFILE") if not outfile or outfile == "": raise "Config variable BOUNDARYFILE not set and needed for prepro output" tw = timewindow("01OCT1921 0000 - 01OCT1922 0000") for calsimname in nodes_to_extend: print calsimname dsspath = calsim_path(calsimname) paths = findpath(f, dsspath) if not paths or len(paths) > 1: print "File: %s" % calsimfile raise "Path %s not found or not unique" % dsspath ref = DataReference.create(paths[0], tw) monthly = ref.getData() itr = monthly.getIterator() d = zeros(len(monthly), 'd') count = 0 while not itr.atEnd(): el = itr.getElement() d[count] = el.getY() count = count + 1 itr.advance() stime = "01OCT1920 0000" rts = RegularTimeSeries(monthly.getName(),stime, \ timeinterval("1MON").toString(), d, None, monthly.getAttributes()) writedss(calsimfile, ref.getPathname().toString(), rts)
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
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
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
select = "///////" window = None transform = None interval = None for o, a in opts: if o in ("-h", "--help"): usage() return if o in ("-o", "--out"): outfile = a if o in ("-s", "--selection"): select = a if o in ("-w", "--window"): window = timewindow(a) if o in ("-t", "--transform"): transform = a if o in ("-i", "--interval"): interval = timeinterval(a) if not infile: raise "No input file specified" transfer(infile,outfile,select, \ window,transform,interval) # # if __name__ == '__main__': main() sys.exit()
outfile="out.dss" select="///////" window=None transform=None interval=None for o, a in opts: if o in ("-h", "--help"): usage() return if o in ("-o", "--out"): outfile=a if o in ("-s", "--selection"): select=a if o in ("-w", "--window"): window=timewindow(a) if o in ("-t", "--transform"): transform=a if o in ("-i", "--interval"): interval = timeinterval(a) if not infile: raise "No input file specified" transfer(infile,outfile,select, \ window,transform,interval) # # if __name__=='__main__': main() sys.exit()
def grow_window(tw, left, right=None): if right == None: right = left st = tw.getStartTime() - timeinterval(left) et = tw.getEndTime() + timeinterval(right) return TimeFactory.getInstance().createTimeWindow(st, et)