Exemple #1
0
def _test2():
    append=0
    for fpart in ['dxc-op','dxc-cl']:
	g1 = vutils.opendss('anninputs.dss')
	g2 = vutils.opendss('annoutputs.dss')
	g1.filterBy(fpart)
	refs = g1[:]
	tw = vutils.timewindow('01oct1975 0000 - 01sep1991 0000')
        #tw = vutils.timewindow('01oct1975 0000 - 01oct1976 0000')
	inps = []
	for i in range(len(refs)):
	    inps.append(vutils.interpolate(DataReference.create(refs[i],tw).getData(),'1day'))
	inputs = []
	for i in range(len(inps)):
	    print 'Building inputs for ',inps[i]
	    inputs=inputs+buildinput(inps[i],7,10,7) # weekly averages
	print 'Built inputs'
	outputs = []
	ccc_ref = vutils.findpath(g2,'//ccc/ec///%s/'%fpart)[0]
	outputs.append(vutils.interpolate(DataReference.create(ccc_ref,tw).getData(),'1day'))
	print 'Built outputs'
	print 'Dumping patterns'
	if append:
	    dump_patterns(inputs,outputs,'junk',0.75,365,1)
	else:
	    dump_patterns(inputs,outputs,'junk',0.75,365,append)
	    append = 1
Exemple #2
0
def dccOp(infile,outfile,inpath,outpath,allThirty=1,value=1.0,
          tw="01OCT1974 0000 - 01OCT1991 0000"):
  """
  Converts Delta Cross Channel gate operation
  from a CALSIM file containing fraction of days open
  Args:
    infile        CALSIM dss file specifying # days operating
    outfile       output dss file readable by DSM2
    inpath        input path, e.g. /CALSIM/DXC/GATE-DAYS-OPEN//1MON//
    outpath       output path, e.g. /CALSIM/DXC/GATE//IR-YEAR/fpart/ 
    value         time series value when gate is opened (must be 1.0 or 2.0),
                  where 1.0 is used for gate ops and 2.0 is number gates operating.
    tw            time window of output
    allThirty     true if CALSIM input is hardwired to thirty day months
  """  
  from vutils import timewindow
  from vdss import opendss,findpath,writedss
  from vista.time import TimeWindow
  from vista.set import DataReference
  import types
  g=opendss(infile)
  if not (type(outfile) == types.StringType):
    raise TypeError("Argument outfile should be name of a dss file")
  if not isinstance(tw,TimeWindow):
    tw = timewindow(tw)
  if not (value==1.0 or value==2.0):
    raise "Output time series 'on' value should be 1.0 (gate op) or 2.0 (gates operating)"
  x=findpath(g,inpath)[0]
  dxcref = DataReference.create(findpath(g,inpath)[0],tw)
  dxc=dxcref.getData()
  if not dxc:
    raise "Cross channel data not found"
  dxcITS=daysPerMonthToITS(dxc,value,allThirty)
  writedss(outfile,outpath,dxcITS)
  return dxcITS
Exemple #3
0
def testspline():
    from vutils import opendss, findpath, timewindow, tabulate
    infile='/delta/data/dss/dayflo.dss'
    inpath='/DELTA/OUT/FLOW//1day//'
    tw_str='01JAN1999 0000 - 30JUN1999 2400'
    g=opendss(infile)
    ref = findpath(g,inpath)[0]
    ref = DataReference.create(ref,timewindow(tw_str))
    rts=interpolate(ref,outint='15min',offset=48)
    tabulate(rts)
Exemple #4
0
def testlinear():
    from vutils import opendss, findpath, timewindow, tabulate
    infile='h:/data/dss/IEP/hydro.dss'
    inpath='/RLTM\+CHAN/RSAC155/FLOW//1HOUR/CDEC/'
    tw_str='16JAN1999 1200 - 21JAN1999 1600'
    g=opendss(infile)
    ref = findpath(g,inpath)[0]
    ref = DataReference.create(ref,timewindow(tw_str))
    rts=interplinear(ref)
    tabulate(rts,ref.getData())
Exemple #5
0
def toreg(irts, tw=None, ti='1hour'):
    """
    toreg(irts,tw=None,ti='1hour'):
    Converts irregular time series to regular time series with
    a time window and time interval.
    """
    ti = vutils.timeinterval(ti)
    if isinstance(irts, vutils.DataReference):
        irts = irts.getData()  # initialize time window accurately
    if tw == None:
        tw = irts.getTimeWindow()
    else:
        tw = vutils.timewindow(tw)
    st = vutils.time(tw.getStartTime().ceiling(ti))
    et = vutils.time(tw.getEndTime().floor(ti))
    #print 'Start time: ',st
    #print 'End time: ',et
    nvals = st.getNumberOfIntervalsTo(et, ti) + 1
    path = irts.getName()
    parts = string.split(path, '/')
    if len(parts) == 8: parts[6] = parts[6] + '-REG'
    name = string.join(parts, '/')
    #print name
    yvals = jarray.zeros(nvals, 'd')
    flags = jarray.zeros(nvals, 'i')
    index = 0
    iterator = irts.getIterator()
    last_val = vutils.Constants.MISSING_VALUE
    last_flag = 0
    # get first time value in irregular time series
    next_time = vutils.time(long(iterator.getElement().getX()))
    # get starting time of regular time series
    time_val = vutils.time(st)
    # loop to fill values
    while index < nvals:
        #print index,time_val
        #print next_time,last_val,last_flag
        # if time value of rts is >= irts then update values
        if not iterator.atEnd() and time_val.compare(next_time) >= 0:
            last_val = iterator.getElement().getY()
            last_flag = iterator.getElement().getFlag()
            # advance by one & update next time value
            iterator.advance()
            if not iterator.atEnd():
                next_time = vutils.time(long(iterator.getElement().getX()))
        yvals[index] = last_val
        flags[index] = last_flag
        time_val.incrementBy(ti)
        index = index + 1
    attr = irts.getAttributes().createClone()
    attr.setType(vutils.DataType.REGULAR_TIME_SERIES)
    rts = vutils.RegularTimeSeries(name, str(st), str(ti), yvals, flags, attr)
    return rts
def toreg(irts,tw=None,ti='1hour'):
    """
    toreg(irts,tw=None,ti='1hour'):
    Converts irregular time series to regular time series with
    a time window and time interval.
    """
    ti = vutils.timeinterval(ti)
    if isinstance(irts,vutils.DataReference):
	irts = irts.getData() # initialize time window accurately
    if tw == None:
	tw = irts.getTimeWindow()
    else:
	tw = vutils.timewindow(tw)
    st = vutils.time(tw.getStartTime().ceiling(ti))
    et = vutils.time(tw.getEndTime().floor(ti))
    #print 'Start time: ',st
    #print 'End time: ',et
    nvals = st.getNumberOfIntervalsTo(et,ti)+1
    path = irts.getName()
    parts = string.split(path,'/')
    if len(parts) == 8: parts[6] = parts[6]+'-REG'
    name = string.join(parts,'/')
    #print name
    yvals = jarray.zeros(nvals,'d')
    flags = jarray.zeros(nvals,'i')
    index=0
    iterator = irts.getIterator()
    last_val = vutils.Constants.MISSING_VALUE
    last_flag = 0
    # get first time value in irregular time series
    next_time = vutils.time(long(iterator.getElement().getX()))
    # get starting time of regular time series
    time_val = vutils.time(st)
    # loop to fill values
    while index < nvals:
	#print index,time_val
	#print next_time,last_val,last_flag
	# if time value of rts is >= irts then update values
	if not iterator.atEnd() and time_val.compare(next_time) >= 0:
	    last_val = iterator.getElement().getY()
	    last_flag = iterator.getElement().getFlag()
	    # advance by one & update next time value
	    iterator.advance()
	    if not iterator.atEnd():
		next_time = vutils.time(long(iterator.getElement().getX()))
	yvals[index] = last_val
	flags[index] = last_flag
	time_val.incrementBy(ti)
	index=index+1
    attr = irts.getAttributes().createClone()
    attr.setType(vutils.DataType.REGULAR_TIME_SERIES)
    rts = vutils.RegularTimeSeries(name,str(st),str(ti),yvals,flags,attr)
    return rts
Exemple #7
0
def _test3():
    from ANN import fnet_cccec
    fpart = 'dxc-op'
    g1 = vutils.opendss('anninputs.dss')
    g2 = vutils.opendss('annoutputs.dss')
    g1.filterBy(fpart)
    g2.filterBy(fpart)
    refs = g1[:]
    tw = vutils.timewindow('01oct1975 0000 - 01sep1991 0000')
    #tw = vutils.timewindow('01oct1975 0000 - 01oct1976 0000')
    inps = []
    for i in range(len(refs)):
	inps.append(vutils.interpolate(DataReference.create(refs[i],tw).getData(),'1day'))
    inputs = []
    for i in range(len(inps)):
	print 'Building inputs for ',inps[i]
	inputs=inputs+buildinput(inps[i],7,10,7) # weekly averages
    print 'Built inputs'
    outputs = []
    ccc_ref = vutils.findpath(g2,'//ccc/ec///%s/'%fpart)[0]
    outputs.append(vutils.interpolate(DataReference.create(ccc_ref,tw).getData(),'1day'))
    mi = MultiIterator(inputs)
    import jarray
    ninps = len(inputs)
    input = jarray.zeros(ninps,'f')
    output = jarray.zeros(1,'f')
    ann = fnet_cccec()
    ndata = len(inputs[0])
    for input_no in range(365):
	mi.advance()
    outdata = jarray.zeros(ndata,'f')
    while input_no < ndata:
	el = mi.getElement()
	i=0
	while i < ninps:
	    input[i] = el.getY(i)
	    i=i+1
	ann.engine(input,output,0)
	outdata[input_no] = output[0]
	mi.advance()
	input_no=input_no+1
    #
    stime = inputs[0].getStartTime()
    ti = inputs[0].getTimeInterval()
    rtsout = vutils.RegularTimeSeries('/ann/ccc_out/ec///annutils/',str(stime),\
				      str(ti),outdata)
    vutils.plot(rtsout,outputs[0])
    rtsout = (rtsout-0.140516)/0.000396563
    vutils.writedss('annout.dss','/ann/ccc_out/ec///annutils/',rtsout)
Exemple #8
0
def test():
  # test routine for this module
  from vtimeseries import timewindow
  from vdss import opendss,findpath
  from vista.set import DataReference
  from vdisplay import tabulate  
  inpath='/CALSIM/DXC/GATE-DAYS-OPEN//1MON//'
  outpath='/CALSIM_PROCESSED/DCC/GATE//IR-YEAR/TEST/'
  infile="../timeseries/2001d10adv.dss"
  outfile = "d:/delta/gates/dxc.dss"
  val=1.0
  allThirty=1.
  tw=timewindow("01oct1974 0000 - 30SEP1991 2400")
  dccITS=dccOp(infile,outfile,inpath,outpath,allThirty,val,tw)
  tabulate(dxcITS)
Exemple #9
0
def test():
    # test routine for this module
    from vtimeseries import timewindow
    from vdss import opendss, findpath
    from vista.set import DataReference
    from vdisplay import tabulate
    inpath = '/CALSIM/DXC/GATE-DAYS-OPEN//1MON//'
    outpath = '/CALSIM_PROCESSED/DCC/GATE//IR-YEAR/TEST/'
    infile = "../timeseries/2001d10adv.dss"
    outfile = "d:/delta/gates/dxc.dss"
    val = 1.0
    allThirty = 1.
    tw = timewindow("01oct1974 0000 - 30SEP1991 2400")
    dccITS = dccOp(infile, outfile, inpath, outpath, allThirty, val, tw)
    tabulate(dxcITS)
Exemple #10
0
def _test1():
    g=vutils.opendss('/delta2/ann/hydrologies/sim809anndv.dss')
    refs = vutils.findpath(g,'//ndo/flow-ndo///')
    tw = vutils.timewindow('01jan1974 0000 - 01jan1992 0000')
    inps = []
    for i in range(len(refs)):
	inps.append(vutils.interpolate(DataReference.create(refs[i],tw).getData(),'1day'))
    print 'Got data for ',tw
    scaling = 8.99649e-07
    shift = 0.233677
    crush(inps[0],scaling,shift)
    print 'Crushed data'
    inputs = buildinput(inps[0],8,10,7)
    print 'Built inputs'
    outputs = inps[:]
    print 'Dumping patterns'
    dump_patterns(inputs,outputs,'junk',0.75)
def get_data(tidefile, twstr, filter):
    tf = opentidefile(tidefile)
    if twstr != None:
        print 'Timewindow: %s' % twstr
        tw = timewindow(twstr)
    else:
        tw = None
    refs = tf.find(filter)
    if refs and len(refs) == 1:
        print "Getting data..."
        if tw != None:
            ref = DataReference.create(refs[0], tw)
        else:
            ref = refs[0]
        return ref.data
    else:
        print 'No data found for filter: %s' % filter
Exemple #12
0
def get_data(tidefile, twstr, filter):
    tf = opentidefile(tidefile)
    if twstr != None:
        print 'Timewindow: %s' % twstr
        tw = timewindow(twstr)
    else:
        tw = None
    refs = tf.find(filter)
    if refs and len(refs) == 1:
        print "Getting data..."
        if tw != None:
            ref = DataReference.create(refs[0], tw)
        else:
            ref = refs[0]
        return ref.data
    else:
        print 'No data found for filter: %s' % filter
Exemple #13
0
def get_flows(tidefile, chan, twstr):
    tf = opentidefile(tidefile)
    flows = []
    if twstr != None:
        print 'Timewindow: %s' % twstr
        tw = timewindow(twstr)
    else:
        tw = None
    refs = tf.find(['', '^%s$' % chan, 'FLOW'])
    if refs and len(refs) == 1:
        print "Getting data %s" % (str(chan))
        if tw != None:
            ref = DataReference.create(refs[0], tw)
        else:
            ref = refs[0]
        flows.append(ref.data)
    return flows
def get_flows(tidefile, chan, twstr):
    tf=opentidefile(tidefile)
    flows=[]
    if twstr != None:
        print 'Timewindow: %s'%twstr
        tw=timewindow(twstr)
    else:
        tw=None
    refs=tf.find(['','^%s$'%chan,'FLOW'])
    if refs and len(refs)==1:
        print "Getting data %s"%(str(chan))
        if tw!=None:
            ref=DataReference.create(refs[0],tw)
        else:
            ref=refs[0]
        flows.append(ref.data)
    return flows
def get_reservoir_volumes_data(tidefile,reservoir_names, twstr):
    tf=opentidefile(tidefile)
    volumes=[]
    if twstr != None:
        print 'Timewindow: %s'%twstr
        tw=timewindow(twstr)
    else:
        tw=None
    for name in reservoir_names:
        print 'Reservoir: %s'%name
        refs=tf.find(['','^%s$'%name,'VOLUME'])
        if refs and len(refs)==1:
            print "Getting data %s"%(str(name))
            if tw!=None:
                ref=DataReference.create(refs[0],tw)
            else:
                ref=refs[0]
            volumes.append(ref.data)
    return volumes
Exemple #16
0
def get_reservoir_volumes_data(tidefile, reservoir_names, twstr):
    tf = opentidefile(tidefile)
    volumes = []
    if twstr != None:
        print 'Timewindow: %s' % twstr
        tw = timewindow(twstr)
    else:
        tw = None
    for name in reservoir_names:
        print 'Reservoir: %s' % name
        refs = tf.find(['', '^%s$' % name, 'VOLUME'])
        if refs and len(refs) == 1:
            print "Getting data %s" % (str(name))
            if tw != None:
                ref = DataReference.create(refs[0], tw)
            else:
                ref = refs[0]
            volumes.append(ref.data)
    return volumes
Exemple #17
0
def get_volumes_data(tidefile, channel_ranges, twstr):
    tf = opentidefile(tidefile)
    volumes = []
    if twstr != None:
        print 'Timewindow: %s' % twstr
        tw = timewindow(twstr)
    else:
        tw = None
    for chan_range in channel_ranges:
        lo, hi = chan_range
        print lo, hi
        for chan in range(int(lo), int(hi + 1)):
            refs = tf.find(['', '^%s$' % chan, 'VOLUME'])
            if refs and len(refs) == 1:
                print "Getting data %s" % (str(chan))
                if tw != None:
                    ref = DataReference.create(refs[0], tw)
                else:
                    ref = refs[0]
                volumes.append(ref.data)
    return volumes
def get_volumes_data(tidefile,channel_ranges, twstr):
    tf=opentidefile(tidefile)
    volumes=[]
    if twstr != None:
        print 'Timewindow: %s'%twstr
        tw=timewindow(twstr)
    else:
        tw=None
    for chan_range in channel_ranges:
        lo,hi=chan_range
        print lo,hi
        for chan in range(int(lo),int(hi+1)):
            refs=tf.find(['','^%s$'%chan,'VOLUME'])
            if refs and len(refs)==1:
                print "Getting data %s"%(str(chan))
                if tw!=None:
                    ref=DataReference.create(refs[0],tw)
                else:
                    ref=refs[0]
                volumes.append(ref.data)
    return volumes
Exemple #19
0
def dccOp(infile,
          outfile,
          inpath,
          outpath,
          allThirty=1,
          value=1.0,
          tw="01OCT1974 0000 - 01OCT1991 0000"):
    """
  Converts Delta Cross Channel gate operation
  from a CALSIM file containing fraction of days open
  Args:
    infile        CALSIM dss file specifying # days operating
    outfile       output dss file readable by DSM2
    inpath        input path, e.g. /CALSIM/DXC/GATE-DAYS-OPEN//1MON//
    outpath       output path, e.g. /CALSIM/DXC/GATE//IR-YEAR/fpart/ 
    value         time series value when gate is opened (must be 1.0 or 2.0),
                  where 1.0 is used for gate ops and 2.0 is number gates operating.
    tw            time window of output
    allThirty     true if CALSIM input is hardwired to thirty day months
  """
    from vutils import timewindow
    from vdss import opendss, findpath, writedss
    from vista.time import TimeWindow
    from vista.set import DataReference
    import types
    g = opendss(infile)
    if not (type(outfile) == types.StringType):
        raise TypeError("Argument outfile should be name of a dss file")
    if not isinstance(tw, TimeWindow):
        tw = timewindow(tw)
    if not (value == 1.0 or value == 2.0):
        raise "Output time series 'on' value should be 1.0 (gate op) or 2.0 (gates operating)"
    x = findpath(g, inpath)[0]
    dxcref = DataReference.create(findpath(g, inpath)[0], tw)
    dxc = dxcref.getData()
    if not dxc:
        raise "Cross channel data not found"
    dxcITS = daysPerMonthToITS(dxc, value, allThirty)
    writedss(outfile, outpath, dxcITS)
    return dxcITS