コード例 #1
0
def sjr_sac(sjr_in, sac_in):
    calsimfile = getAttr("CALSIMFILE")
    f = opendss(calsimfile)  # open CALSIM file
    tw = prepro_window()

    sjr_path = calsim_path("C639")
    sjr_ret_path = calsim_path("R644")
    sjr_ref = findpath(f, sjr_path)
    if not sjr_ref:
        raise "San Joaquin path %s not found" % sjr_path
    sjr_ret_ref = findpath(f, sjr_ret_path)
    if not sjr_ret_ref:
        raise "San Joaquin return flow path %s not found" % sjr_ret_path
    sjr = DataReference.create(sjr_ref[0], tw).getData()
    sjr_ret = DataReference.create(sjr_ret_ref[0], tw).getData()
    sjr_in = sjr + sjr_ret

    sac_path = calsim_path("C169")
    frwa_div1_path = calsim_path("D168B")
    frwa_div2_path = calsim_path("D168C")
    sac_ref = findpath(f, sac_path)
    if not sac_ref:
        raise "Sacramento path %s not found" % sac_path
    frwa_div1_ref = findpath(f, frwa_div1_path)
    if not frwa_div1_ref:
        raise "Freeport Regional Water Authority Diversion path %s not found" % frwa_div1_path
    frwa_div2_ref = findpath(f, frwa_div2_path)
    if not frwa_div2_ref:
        raise "Freeport Regional Water Authority Diversion path %s not found" % frwa_div2_path
    sac = DataReference.create(sac_ref[0], tw).getData()
    frwa_div1 = DataReference.create(frwa_div1_ref[0], tw).getData()
    frwa_div2 = DataReference.create(frwa_div2_ref[0], tw).getData()
    sac_in = sac + frwa_div1 + frwa_div2
    return
コード例 #2
0
def moke_consumnes():
    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 = prepro_window()

    moke_us_path = calsim_path("I504")
    moke_ref = findpath(f, moke_us_path)
    if (moke_ref and len(moke_ref) > 0):
        print "Upstream mokelumne flow found, not calculated"

    consumnes_path = calsim_path("C501")
    moke_ds_path = calsim_path("C504")
    consumnes_ref = findpath(f, consumnes_path)
    if not consumnes_ref:
        raise "Consumnes path %s not found" % consumnes_path
    moke_ds_ref = findpath(f, moke_ds_path)
    if not moke_ds_ref:
        raise "Mokulemne downstream path %s not found" % moke_ds_path
    consumnes = DataReference.create(consumnes_ref[0], tw).getData()
    moke_ds = DataReference.create(moke_ds_ref[0], tw).getData()
    mf = calsim_study_fpart(modify=1)
    moke_us_path = calsim_path("I504", mf)
    moke_us = moke_ds - consumnes

    writedss(outfile, moke_us_path, moke_us)
    return
コード例 #3
0
def sjr_sac(sjr_in, sac_in):
    calsimfile = getAttr("CALSIMFILE")
    f = opendss(calsimfile)  # open CALSIM file
    tw = prepro_window()

    sjr_path = calsim_path("C639")
    sjr_ret_path = calsim_path("R644")
    sjr_ref = findpath(f, sjr_path)
    if not sjr_ref:
        raise "San Joaquin path %s not found" % sjr_path
    sjr_ret_ref = findpath(f, sjr_ret_path)
    if not sjr_ret_ref:
        raise "San Joaquin return flow path %s not found" % sjr_ret_path
    sjr = DataReference.create(sjr_ref[0], tw).getData()
    sjr_ret = DataReference.create(sjr_ret_ref[0], tw).getData()
    sjr_in = sjr + sjr_ret

    sac_path = calsim_path("C169")
    frwa_div1_path = calsim_path("D168B")
    frwa_div2_path = calsim_path("D168C")
    sac_ref = findpath(f, sac_path)
    if not sac_ref:
        raise "Sacramento path %s not found" % sac_path
    frwa_div1_ref = findpath(f, frwa_div1_path)
    if not frwa_div1_ref:
        raise "Freeport Regional Water Authority Diversion path %s not found" % frwa_div1_path
    frwa_div2_ref = findpath(f, frwa_div2_path)
    if not frwa_div2_ref:
        raise "Freeport Regional Water Authority Diversion path %s not found" % frwa_div2_path
    sac = DataReference.create(sac_ref[0], tw).getData()
    frwa_div1 = DataReference.create(frwa_div1_ref[0], tw).getData()
    frwa_div2 = DataReference.create(frwa_div2_ref[0], tw).getData()
    sac_in = sac + frwa_div1 + frwa_div2
    return
コード例 #4
0
def moke_consumnes():
    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 = prepro_window()

    moke_us_path = calsim_path("I504")
    moke_ref = findpath(f, moke_us_path)
    if moke_ref and len(moke_ref) > 0:
        print "Upstream mokelumne flow found, not calculated"

    consumnes_path = calsim_path("C501")
    moke_ds_path = calsim_path("C504")
    consumnes_ref = findpath(f, consumnes_path)
    if not consumnes_ref:
        raise "Consumnes path %s not found" % consumnes_path
    moke_ds_ref = findpath(f, moke_ds_path)
    if not moke_ds_ref:
        raise "Mokulemne downstream path %s not found" % moke_ds_path
    consumnes = DataReference.create(consumnes_ref[0], tw).getData()
    moke_ds = DataReference.create(moke_ds_ref[0], tw).getData()
    mf = calsim_study_fpart(modify=1)
    moke_us_path = calsim_path("I504", mf)
    moke_us = moke_ds - consumnes

    writedss(outfile, moke_us_path, moke_us)
    return
コード例 #5
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
コード例 #6
0
def transfer(infile, outfile, select, window, transform, interval, unique=0):
    f = opendss(infile)
    g = findpath(f, select)
    select = select.upper()
    if not outfile:
        raise "Output file name is None"

    if not g or len(g) == 0:
        raise "No matches for selection [%s] found in file %s" % (select,
                                                                  infile)

    if (unique and len(g) > 1):
        raise "Selection not unique and the unique flag is set true for selection [%s] in file %s" % (
            select, infile)

    for ref in g:
        if window:
            r = DataReference.create(ref, window)
            if not r:
                print "No data in window for reference: %s" % ref
                continue
        else:
            r = DataReference.create(ref)

        d = r.getData()

        if not d or len(d) == 0:
            raise "Data retrieval failed for %s " % ref2
        if transform:
            transform = transform.lower()
            if transform == "period_max":
                d = per_max(d, interval.toString())
            elif transform == "period_min":
                d = per_min(d, interval.toString())
            elif transform == "period_ave":
                d = per_avg(d, interval.toString())
            elif transform == "tidal_ave":
                d = tidal_avg(d)
            elif transform == "godin":
                d = godin(d)
            else:
                raise "Transform %s not recognized" % transform

        p = Pathname.createPathname(d.getName())
        if transform:
            old_c = p.getPart(Pathname.C_PART)
            new_c = old_c + "_" + transform.upper()
            p.setPart(Pathname.C_PART, new_c)
        path = p.toString()
        writedss(outfile, path, d)
        del d
        del r

    #
    return
コード例 #7
0
ファイル: transfer.py プロジェクト: CalSimCalLite/CalLiteGUI
def transfer(infile,outfile,select,window,transform,interval,unique=0):
    f=opendss(infile)
    g=findpath(f,select)
    select=select.upper()
    if not outfile:
        raise "Output file name is None"
    
    if not g or len(g) == 0:
        raise "No matches for selection [%s] found in file %s" % (select,infile)

    if (unique and len(g) > 1):
        raise "Selection not unique and the unique flag is set true for selection [%s] in file %s" % (select,infile)
    
    for ref in g:
        if window:
            r = DataReference.create(ref,window)
            if not r:
                print "No data in window for reference: %s" % ref
                continue
        else:
            r=DataReference.create(ref)
        
        d = r.getData()

        if not d or len(d)==0:
            raise "Data retrieval failed for %s " % ref2
        if transform:
            transform=transform.lower()
            if transform == "period_max":
                d=per_max(d,interval.toString())
            elif transform == "period_min":
                d=per_min(d,interval.toString())
            elif transform == "period_ave":
                d=per_avg(d,interval.toString())
            elif transform == "tidal_ave":
                d=tidal_avg(d)
            elif transform == "godin":
                d=godin(d)
            else:
                raise "Transform %s not recognized" %transform
        
        p=Pathname.createPathname(d.getName())
        if transform:
            old_c=p.getPart(Pathname.C_PART)
            new_c=old_c+"_"+transform.upper()
            p.setPart(Pathname.C_PART,new_c)
        path=p.toString()
        writedss(outfile,path,d)
        del d
        del r

    #
    return
コード例 #8
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)
コード例 #9
0
ファイル: dcc.py プロジェクト: CalSimCalLite/CalLiteGUI
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
コード例 #10
0
def transfer_flow(nodes_to_transfer):
    """ Unsmoothed transfer from CALSIM file to model input file.
    """
    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 = prepro_window()

    for calsimname in nodes_to_transfer:  # Extend the list as needed, but please keep in mind the
        # limitations of the conservative spline, at least at present.
        # Mainly, input flows should be substantially greater than
        # zero at all times (yolo would be inappropriate, for instance)
        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()
        mf = calsim_study_fpart(modify=1)
        dsspath = calsim_path(calsimname, modified_fpart=mf)
        if monthly:
            writedss(outfile, dsspath, monthly)

        else:
            raise "Failure to find CALSIM input data for: " + calsimname
コード例 #11
0
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)
コード例 #12
0
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)
コード例 #13
0
def transfer_flow(nodes_to_transfer):
    """ Unsmoothed transfer from CALSIM file to model input file.
    """
    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 = prepro_window()

    for calsimname in nodes_to_transfer:  # Extend the list as needed, but please keep in mind the
        # limitations of the conservative spline, at least at present.
        # Mainly, input flows should be substantially greater than
        # zero at all times (yolo would be inappropriate, for instance)
        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()
        mf = calsim_study_fpart(modify=1)
        dsspath = calsim_path(calsimname, modified_fpart=mf)
        if monthly:
            writedss(outfile, dsspath, monthly)

        else:
            raise "Failure to find CALSIM input data for: " + calsimname
コード例 #14
0
def transfer_ec():
    """ Unsmoothed transfer from CALSIM file to model input file.
    """
    
    f=opendss(getAttr("CALSIMFILE"))           # open CALSIM file
    outfile=getAttr("BOUNDARYFILE")
    process=getAttr("SJR_PROCESS")
    if not outfile or outfile == "":
        raise "Config variable BOUNDARYFILE not set and needed for prepro output"    
    tw=prepro_window()
    calsimstudy=calsim_study_fpart(modify=0)
    calsimstudyout=calsim_study_fpart(modify=1)
    if not calsimstudy or calsimstudy=="":
        print "CALSIMSTUDY envvar not set"
    dsspath="/CALSIM.*/VERNWQFINAL/SALINITY-EC//1MON/%s/" % calsimstudy
    processedpath=dsspath.replace(".*","-"+process).replace(
        "1MON","1DAY").replace(calsimstudy,calsimstudyout)
    print processedpath
    refs=findpath(f,dsspath)
    if not refs or len(refs)> 1:
        raise "Vernalis EC path %s not found or not unique" % dsspath
    ref=DataReference.create(refs[0],tw)
    monthly=ref.getData()
    daily=interpolate(monthly,"1DAY")
    
    if daily:
        writedss(outfile,processedpath, daily)
    else:
        raise "Failure to find CALSIM input data for: " + calsimname 
    return
コード例 #15
0
def txfr_flow_day(nodes_to_txfr_day):
    """ Unsmoothed transfer from CALSIM file to model input file.
    """
    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 = prepro_window()

    for calsimname in nodes_to_txfr_day:  # Extend the list as needed
        mf = calsim_study_fpart(modify=1)
        dsspath = calsim_path(calsimname)
        dsspath1 = calsim_path(calsimname, modified_fpart=mf)
        processedpath = dsspath1.replace("1MON", "1DAY")
        print dsspath
        print processedpath
        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()
        daily = interpolate(monthly, "1DAY")
        if daily:
            writedss(outfile, processedpath, daily)
        else:
            raise "Failure to find CALSIM input data for: " + calsimname
コード例 #16
0
def txfr_flow_day(nodes_to_txfr_day):
    """ Unsmoothed transfer from CALSIM file to model input file.
    """
    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 = prepro_window()

    for calsimname in nodes_to_txfr_day:  # Extend the list as needed
        mf = calsim_study_fpart(modify=1)
        dsspath = calsim_path(calsimname)
        dsspath1 = calsim_path(calsimname, modified_fpart=mf)
        processedpath = dsspath1.replace("1MON", "1DAY")
        print dsspath
        print processedpath
        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()
        daily = interpolate(monthly, "1DAY")
        if daily:
            writedss(outfile, processedpath, daily)
        else:
            raise "Failure to find CALSIM input data for: " + calsimname
コード例 #17
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)
コード例 #18
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())
コード例 #19
0
def prep_ndo(calsimf, dss_step, dss_fpart, twstr):
    ndofile = opendss(calsimf)
    TWIND = timewindow(twstr)
    ndo = DataReference.create(
        findpath(ndofile, "/CALSIM/NDO/FLOW-NDO//" + dss_step + "/" +
                 dss_fpart + "/")[0], TWIND).getData()
    ndo15 = conserve.conserveSpline(ndo, "15MIN")
    ndo15.getAttributes().setYUnits("CFS")
    ndo15.getAttributes().setYType("PER-AVER")
    writedss(calsimf, "/CALSIM/NDO/FLOW-NDO//15MIN/" + dss_fpart + "/", ndo15)
    return 0
コード例 #20
0
def calaveras():
    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 = prepro_window()

    cal_path = calsim_path("C508")
    cal_ret_path = calsim_path("R514")
    cal_ref = findpath(f, cal_path)
    if not cal_ref:
        raise "Calaveras path %s not found" % cal_path
    cal_ret_ref = findpath(f, cal_ret_path)
    if not cal_ret_ref:
        raise "Calaveras return flow path %s not found" % cal_ret_path
    cal = DataReference.create(cal_ref[0], tw).getData()
    cal_ret = DataReference.create(cal_ret_ref[0], tw).getData()
    mf = calsim_study_fpart(modify=1)
    cal_in_path = calsim_path("C508_R514", mf)
    cal_in = cal + cal_ret
    writedss(outfile, cal_in_path, cal_in)
    return
コード例 #21
0
def copy_dicu_flow():
    """ Unsmoothed transfer from DICU file to model input file.
    """
    dicufile=getAttr("DICUFLOWFILE") 
    f=opendss(dicufile)           # open CALSIM file
    outfile=getAttr("DICUFILE")
    if not outfile or outfile == "":
        raise "Config variable BOUNDARYFILE not set and needed for prepro output"    
    tw=prepro_window()

    for item in f : 
        ref=DataReference.create(item,tw)
        data=ref.getData()
        writedss(outfile,ref.getPathname().toString(), data)
コード例 #22
0
ファイル: prep_dicu_flow.py プロジェクト: dwr-psandhu/dsm2
def copy_dicu_flow():
    """ Unsmoothed transfer from DICU file to model input file.
    """
    dicufile=getAttr("DICUFLOWFILE") 
    f=opendss(dicufile)           # open CALSIM file
    outfile=getAttr("DICUFILE")
    if not outfile or outfile == "":
        raise "Config variable BOUNDARYFILE not set and needed for prepro output"    
    tw=prepro_window()

    for item in f : 
        ref=DataReference.create(item,tw)
        data=ref.getData()
        writedss(outfile,ref.getPathname().toString(), data)
コード例 #23
0
def calaveras():
    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 = prepro_window()

    cal_path = calsim_path("C508")
    cal_ret_path = calsim_path("R514")
    cal_ref = findpath(f, cal_path)
    if not cal_ref:
        raise "Calaveras path %s not found" % cal_path
    cal_ret_ref = findpath(f, cal_ret_path)
    if not cal_ret_ref:
        raise "Calaveras return flow path %s not found" % cal_ret_path
    cal = DataReference.create(cal_ref[0], tw).getData()
    cal_ret = DataReference.create(cal_ret_ref[0], tw).getData()
    mf = calsim_study_fpart(modify=1)
    cal_in_path = calsim_path("C508_R514", mf)
    cal_in = cal + cal_ret
    writedss(outfile, cal_in_path, cal_in)
    return
コード例 #24
0
def dss_retrieve_ts(file, path, *arg):
    f = opendss(file)
    g = findpath(f, path)
    if g == None or len(g) != 1:
        raise ValueError("Path %s in file s% does not exist or is not unique" %
                         (path, file))

    if len(arg) > 1:
        raise ValueError("usage: file, dss_path, time window")
    elif len(arg) == 1:
        twind = timewindow(arg[0])
        return DataReference.create(g[0], twind).getData()
    else:
        return g[0].getData()
コード例 #25
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
コード例 #26
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
コード例 #27
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)
コード例 #28
0
def copy_stage():
    """ Unsmoothed transfer from DICU file to model input file.
    """
    sourcefile=getAttr("STAGE_SOURCE_FILE") 
    f=opendss(sourcefile)
    outfile=getAttr("STAGEFILE")
    stageversion=getAttr("STAGE_VERSION")
    dsspath="/FILL\+CHAN/RSAC054/STAGE//15MIN/%s/" % stageversion
    if not outfile or outfile == "":
        raise "Config variable BOUNDARYFILE not set and needed for prepro output"    
    tw=prepro_window()
    ref = findpath(f,dsspath)
    if len(ref) != 1:
        raise "Stage path not found or not unique. Found refs: %s" % ref
    ref=DataReference.create(ref[0],tw)
    data=ref.getData()
    writedss(outfile,ref.getPathname().toString(), data)
コード例 #29
0
ファイル: prep_stage.py プロジェクト: dwr-psandhu/dsm2
def copy_stage():
    """ Unsmoothed transfer from DICU file to model input file.
    """
    sourcefile = getAttr("STAGE_SOURCE_FILE")
    f = opendss(sourcefile)
    outfile = getAttr("STAGEFILE")
    stageversion = getAttr("STAGE_VERSION")
    dsspath = "/FILL\+CHAN/RSAC054/STAGE//15MIN/%s/" % stageversion
    if not outfile or outfile == "":
        raise "Config variable BOUNDARYFILE not set and needed for prepro output"
    tw = prepro_window()
    ref = findpath(f, dsspath)
    if len(ref) != 1:
        raise "Stage path not found or not unique. Found refs: %s" % ref
    ref = DataReference.create(ref[0], tw)
    data = ref.getData()
    writedss(outfile, ref.getPathname().toString(), data)
コード例 #30
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
コード例 #31
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
コード例 #32
0
def smooth_flow(nodes_to_smooth):
    """ A slightly smoothed version of monthly flows to avoid sharp transitions
        between months. Uses a tension spline.
    """
    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"
    fpart_mod = calsim_study_fpart(modify=1)

    tw = prepro_window()

    for calsimname in nodes_to_smooth:  # Extend the list as needed, but please keep in mind the
        # limitations of the conservative spline, at least at present.
        # Mainly, input flows should be substantially greater than
        # zero at all times (yolo would be inappropriate, for instance)
        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()
        if monthly:
            if len(monthly) < 4:
                raise "Length of monthly data too short for smoothing. Wrong time window?"
            try:
                daily = conserve.conserveSpline(monthly, "1DAY")
            except:
                print "Failure to smooth path: %s over time window: %s" % (
                    paths[0], tw)
                raise

            daily.getAttributes().setYUnits(Units.CFS)
            writedss(outfile,
                     "/CALSIM-SMOOTH/"+calsimname+"/FLOW/1DAY//" \
                     +fpart_mod+"/",
                     daily)
        else:
            raise "Failure to find CALSIM input data for: " + calsimname
コード例 #33
0
def smooth_flow(nodes_to_smooth):
    """ A slightly smoothed version of monthly flows to avoid sharp transitions
        between months. Uses a tension spline.
    """
    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"
    fpart_mod=calsim_study_fpart(modify=1)
    
    tw=prepro_window()


    for calsimname in nodes_to_smooth:      # Extend the list as needed, but please keep in mind the
                                            # limitations of the conservative spline, at least at present.
                                            # Mainly, input flows should be substantially greater than
                                            # zero at all times (yolo would be inappropriate, for instance)
        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()
        if monthly:		
            if len(monthly) < 4:
			    raise "Length of monthly data too short for smoothing. Wrong time window?"
            try:
                daily=conserve.conserveSpline(monthly,"1DAY")
            except:
                print "Failure to smooth path: %s over time window: %s" % (paths[0], tw)
                raise 
                
            daily.getAttributes().setYUnits(Units.CFS)
            writedss(outfile,
                     "/CALSIM-SMOOTH/"+calsimname+"/FLOW/1DAY//" \
                     +fpart_mod+"/",
                     daily)
        else:
            raise "Failure to find CALSIM input data for: " + calsimname 
コード例 #34
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
コード例 #35
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
コード例 #36
0
ファイル: dcc.py プロジェクト: dwr-psandhu/dsm2
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
コード例 #37
0
        else:
            tw = prepro_window("16yr")
        tws = str(tw)
        print "Using time window: %s (dcc processing may exceed your run dates)" % tws
        
        dcc.dccOp(
            getAttr('CALSIMFILE'),              # CALSIM DSS file (input for DSM2)
            getAttr('GATEFILE'),                # processed gate DSS file (will be input for DSM2)
            '/CALSIM/DXC/GATE-DAYS-OPEN//1MON//' + getAttr('CALSIMSTUDY') + '/', # CALSIM DXC pathname
            '/CALSIM-PROCESSED/DCC/OP//IR-YEAR/' +   \
            getAttr('CALSIMSTUDY') + '/', # processed cross channel pathname
            0,                                  # 0: CALSIM input is hardwired to 30-day months
            1,                                  # operate gate between 0 & 1
            tws                                 # time window
            )

        print 'Copying gate ops for Clifton Court'
        path='/PLANNING\+GATE/CHWST000/OP-FROM-NODE//IR-YEAR/%s/' \
              % getAttr("CLIFTONCT_GATEOP")
        f=vdss.opendss(getAttr('CLIFTONCT_GATEFILE')) 
        g=vdss.findpath(f,path)
        if ( not g or len(g) != 1):
            raise "Path not found or not unique: %s" % (path)
        ts=DataReference.create(g[0]).getData()
        vdss.writedss(getAttr('GATEFILE'),path.replace("\\",""),ts)
        print "Finished with clifton court transfer"
        sys.exit(0)
#


コード例 #38
0
def planning_ec_mtz(): # MTZ = RSAC054 BC for the qual
    DEBUG = 0
    OUTPUT=config.getAttr('QUALBOUNDARYFILE')
    calsimfile = config.getAttr('CALSIMFILE')
    vamp_corrected_dss = config.getAttr('CALSIM_VAMP')
    CALSIM=opendss(calsimfile)
    PLANNINGTIDE=opendss(config.getAttr('STAGE_SOURCE_FILE'))
    STEP=string.lower(config.getAttr('CALSIMSTEP'))
    SJR_PROCESS=config.getAttr("SJR_PROCESS")    
    outputpath="/FILL+CHAN/RSAC054/EC//15MIN/"+config.getAttr("DSM2MODIFIER")+"/"
    if not(OUTPUT and os.path.exists(OUTPUT)):
        raise "Envvar QUALBOUNDARYFILE must exist as destination for EC"
        
    startyr=int(config.getAttr('START_DATE')[5:])
    endyr=int(config.getAttr('END_DATE')[5:])
    
    if (startyr < 1974 and endyr > 1991):
#        blocks= [ "01NOV1921 0000 - 01OCT1940 0000",
        blocks= [ "01FEB1921 0000 - 01OCT1940 0000",
             "01OCT1940 0000 - 01OCT1960 0000",
             "01OCT1960 0000 - 01OCT1974 0000",
             "01OCT1974 0000 - 01OCT1991 0000",
             "01OCT1991 0000 - 01OCT2003 0000"
                ]
    else: 
        blocks = [ "01OCT1974 0000 - 01OCT1991 0000" ]
                                                      # for memory reasons (year 2001).

    g0=5000.                                          # initial value of g (antecedent outflow) for the beginning
                                                      # of the first year. This is pretty arbitrary and makes little difference
    if DEBUG:
        g0_no_vamp = 5000.

    for twstr in blocks:    
        TWIND=timewindow(twstr)        # Actual period to be estimated
        print "Calculating boundary salinity for the period "+TWIND.toString()
        TWINDBUF=grow_window(TWIND,"1MON","1MON")     # Conservative buffered period for retrieval
                                                      # so that after prelimiary operations (e.g. time average)
                                                      # time series will still span at least TWIND
        fpart=calsim_study_fpart(modify=0)
        ndo=DataReference.create(findpath(CALSIM,"/CALSIM/NDO/FLOW-NDO//"+STEP+"/"
                                  +fpart+"/")[0],TWIND).getData()
        ndo15=conserve.conserveSpline(ndo,"15MIN")
        ndo15_no_vamp = 0
        if DEBUG:
            ndo15_no_vamp = ndo15
# removed since currently there is no difference between vamp and monthly average.
            # calc  vamp caused ndo change
#        if (SJR_PROCESS.upper()=="SINGLE_STEP") or (SJR_PROCESS.upper()=="MULTI_STEP"):
#            fpart_modified=calsim_study_fpart(modify=1)
#            delta_ndo = vamp_ndo.calc_vamp_delta_ndo(calsimfile,vamp_corrected_dss,fpart,fpart_modified,SJR_PROCESS)
#            ndo15 = ndo15 + interpolate(delta_ndo, "15MIN")
		
        astro_stage_version = config.getAttr("ASTRO_STAGE_VERSION")
        mtzastro=DataReference.create(findpath(PLANNINGTIDE,"/FILL\+CHAN/RSAC054/STAGE//15MIN/"+astro_stage_version + "/")[0],TWINDBUF).getData()

        astrorms=godin((mtzastro*mtzastro)**0.5)           # RMS energy of tide (used to predict filling and draining)
        dastrorms=(  (astrorms-(astrorms>>1))*96. ).createSlice(TWIND)    
        fifteenflo2=ndo15  - 40000*(dastrorms)

        # call to ec estimator. all parameters are included. g0 is an
        [mtzecest, g1]=ec_boundary.ECEst(mtzastro,fifteenflo2,beta=600,npow1=0.75,npow2=1,g0=g0,zrms=astrorms)
       
        if DEBUG:
            fifteenflo2_no_vamp = ndo15_no_vamp  - 40000*(dastrorms)
            [mtzecest_no_vamp, g1_no_vamp]=ec_boundary.ECEst(mtzastro,fifteenflo2_no_vamp,beta=600,npow1=0.75,npow2=1,g0=g0_no_vamp,zrms=astrorms)
            g0_no_vamp = g1_no_vamp
            writedss("out_ec_check","/CALC/ndo_no_vamp/ndo////", ndo15_no_vamp)
            writedss("out_ec_check","/CALC/ndo_with_vamp/ndo////", ndo15)
            writedss("out_ec_check","/CALC/ndo_no_vamp/ec////", mtzecest_no_vamp)
            writedss("out_ec_check","/CALC/ndo_with_vamp/ec////", mtzecest)
        writedss(OUTPUT,outputpath,mtzecest)

        g0=g1
    return 0
コード例 #39
0
def smooth_flow2():
    """ A slightly smoothed version of monthly flows to avoid sharp transitions
        between months. Uses a tension spline.
    """
    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"
    fpart_mod = calsim_study_fpart(modify=1)

    tw = prepro_window()

    print "Preparing SAC and SJR Inflows"

    sjr_path = calsim_path("C639")
    sjr_ret_path = calsim_path("R644")
    sjr_ref = findpath(f, sjr_path)
    if not sjr_ref:
        raise "San Joaquin path %s not found" % sjr_path
    sjr_ret_ref = findpath(f, sjr_ret_path)
    if not sjr_ret_ref:
        raise "San Joaquin return flow path %s not found" % sjr_ret_path
    sjr = DataReference.create(sjr_ref[0], tw)  #.getData()
    sjr_ret = DataReference.create(sjr_ret_ref[0], tw)  #.getData()
    sjr_in = sjr + sjr_ret

    sac_path = calsim_path("C169")
    frwa_div1_path = calsim_path("D168B")
    frwa_div2_path = calsim_path("D168C")
    sac_ref = findpath(f, sac_path)
    if not sac_ref:
        raise "Sacramento path %s not found" % sac_path
    frwa_div1_ref = findpath(f, frwa_div1_path)
    if not frwa_div1_ref:
        raise "Freeport Regional Water Authority Diversion path %s not found" % frwa_div1_path
    frwa_div2_ref = findpath(f, frwa_div2_path)
    if not frwa_div2_ref:
        raise "Freeport Regional Water Authority Diversion path %s not found" % frwa_div2_path
    sac = DataReference.create(sac_ref[0], tw)  #.getData()
    frwa_div1 = DataReference.create(frwa_div1_ref[0], tw)  #.getData()
    frwa_div2 = DataReference.create(frwa_div2_ref[0], tw)  #.getData()
    sac_in = sac + frwa_div1 + frwa_div2

    #    sjr_sac(sjr_inf,sac_inf)

    print "smoothing SAC"
    sac_mon = sac_in.getData()
    if sac_mon:
        if len(sac_mon) < 4:
            raise "Length of monthly data too short for smoothing. Wrong time window?"
        try:
            sac_day = conserve.conserveSpline(sac_mon, "1DAY")
        except:
            print "Failure to smooth path: %s over time window: %s" % (
                "C169_D168B_D168C", tw)
            raise

        sac_day.getAttributes().setYUnits(Units.CFS)
        writedss(outfile,
                 "/CALSIM-SMOOTH/C169_D168B_D168C/FLOW/1DAY//" \
                     +fpart_mod+"/",sac_day)
    else:
        raise "Failure to find monthly data for C169+D168B+D168C"

    print "smoothing SJR"
    sjr_mon = sjr_in.getData()
    if sjr_mon:
        if len(sjr_mon) < 4:
            raise "Length of monthly data too short for smoothing. Wrong time window?"
        try:
            sjr_day = conserve.conserveSpline(sjr_mon, "1DAY")
        except:
            print "Failure to smooth path: %s over time window: %s" % (
                "C639_R644", tw)
            raise

        sjr_day.getAttributes().setYUnits(Units.CFS)
        writedss(outfile,
             "/CALSIM-SMOOTH/C639_R644/FLOW/1DAY//" \
                 +fpart_mod+"/",sjr_day)
    else:
        raise "Failure to find monthly data for C639+R644"
コード例 #40
0
from vutils import *
from vtimeseries import *


def writecsv(filename, ts):
    h = open(filename, 'w')
    h.write(ts.name + '\n')
    for e in ts:
        h.write("%s,%s\n" % (e.getXString(), e.getYString()))
    h.close()


#
g = opendss('../testdata/ex3-base.dss')
bpart = 'CLFCT'
cpart = 'STAGE'
epart = '15MIN'
refs = findparts(g, b=bpart, c=cpart, e=epart)
if refs == None or len(refs) == 0:
    print 'No data found for %s/%s//%s/' % (bpart, cpart, epart)
ref = refs[0]
from vista.set import DataReference
twstr = '01DEC1987 0100-05DEC1987 2400'
ref = DataReference.create(ref, timewindow(twstr))
ts = ref.data
filename = '%s_%s.txt' % (bpart, cpart)
#writeascii(filename,ts)
writecsv(filename, ts)
print 'Done'
コード例 #41
0
ファイル: prep_gates.py プロジェクト: dwr-psandhu/dsm2
        if int(sdate[5:]) < 1974:
            tw = prepro_window("82yr")
        else:
            tw = prepro_window("16yr")
        tws = str(tw)
        print "Using time window: %s (dcc processing may exceed your run dates)" % tws

        dcc.dccOp(
            getAttr('CALSIMFILE'),              # CALSIM DSS file (input for DSM2)
            getAttr('GATEFILE'),                # processed gate DSS file (will be input for DSM2)
            '/CALSIM/DXC/GATE-DAYS-OPEN//1MON//' + getAttr('CALSIMSTUDY') + '/', # CALSIM DXC pathname
            '/CALSIM-PROCESSED/DCC/OP//IR-YEAR/' +   \
            getAttr('CALSIMSTUDY') + '/', # processed cross channel pathname
            0,                                  # 0: CALSIM input is hardwired to 30-day months
            1,                                  # operate gate between 0 & 1
            tws                                 # time window
            )

        print 'Copying gate ops for Clifton Court'
        path='/PLANNING\+GATE/CHWST000/OP-FROM-NODE//IR-YEAR/%s/' \
              % getAttr("CLIFTONCT_GATEOP")
        f = vdss.opendss(getAttr('CLIFTONCT_GATEFILE'))
        g = vdss.findpath(f, path)
        if (not g or len(g) != 1):
            raise "Path not found or not unique: %s" % (path)
        ts = DataReference.create(g[0]).getData()
        vdss.writedss(getAttr('GATEFILE'), path.replace("\\", ""), ts)
        print "Finished with clifton court transfer"
        sys.exit(0)
#
コード例 #42
0
ファイル: planning_ec_mtz.py プロジェクト: dwr-psandhu/dsm2
def planning_ec_mtz():  # MTZ = RSAC054 BC for the qual
    DEBUG = 0
    OUTPUT = config.getAttr('QUALBOUNDARYFILE')
    calsimfile = config.getAttr('CALSIMFILE')
    CALSIM = opendss(calsimfile)
    PLANNINGTIDE = opendss(config.getAttr('STAGE_SOURCE_FILE'))
    outputpath = "/FILL+CHAN/RSAC054/EC//15MIN/" + config.getAttr(
        "DSM2MODIFIER") + "/"
    if not (OUTPUT and os.path.exists(OUTPUT)):
        raise "Envvar QUALBOUNDARYFILE must exist as destination for EC"

    startyr = int(config.getAttr('START_DATE')[5:])
    endyr = int(config.getAttr('END_DATE')[5:])

    if (startyr < 1974 and endyr > 1991):
        blocks = [
            "01NOV1921 0000 - 01OCT1940 0000",
            "01OCT1940 0000 - 01OCT1960 0000",
            "01OCT1960 0000 - 01OCT1974 0000",
            "01OCT1974 0000 - 01OCT1991 0000",
            "01OCT1991 0000 - 01OCT2003 0000"
        ]  # for memory reasons (year 2001).
    else:
        blocks = ["01OCT1974 0000 - 01OCT1991 0000"]

    g0 = 5000.  # initial value of g (antecedent outflow) for the beginning
    # of the first year. This is pretty arbitrary and makes little difference

    for twstr in blocks:
        TWIND = timewindow(twstr)  # Actual period to be estimated
        print "Calculating boundary salinity for the period " + TWIND.toString(
        )
        TWINDBUF = grow_window(
            TWIND, "1MON",
            "1MON")  # Conservative buffered period for retrieval
        # so that after prelimiary operations (e.g. time average)
        # time series will still span at least TWIND
        fpart = calsim_study_fpart(modify=0)

        ndo15 = DataReference.create(
            findpath(CALSIM, "/CALSIM/NDO/FLOW-NDO//15MIN/" + fpart + "/")[0],
            TWIND).getData()

        astro_stage_version = config.getAttr("ASTRO_STAGE_VERSION")
        mtzastro = DataReference.create(
            findpath(
                PLANNINGTIDE, "/FILL\+CHAN/RSAC054/STAGE//15MIN/" +
                astro_stage_version + "/")[0], TWINDBUF).getData()
        if 'NAVD' in astro_stage_version:
            mtzastro = mtzastro - 2.68
            writedss(
                CALSIM, "/FILL\+CHAN/RSAC054/STAGE//15MIN/" +
                astro_stage_version.replace('NAVD', 'NGVD') + "/", mtzastro)

        astrorms = godin(
            (mtzastro * mtzastro)**
            0.5)  # RMS energy of tide (used to predict filling and draining)
        dastrorms = ((astrorms - (astrorms >> 1)) * 96.).createSlice(TWIND)
        fifteenflo2 = ndo15 - 53411.1 * (dastrorms)

        # call to ec estimator. all parameters are included.
        so, sb = 37196, 2328.1
        c = [
            -6.00E-05, 7.30E-05, -1.00E-05, -3.00E-05, 1.70E-06, -1.00E-04,
            4.50E-05, -1.00E-04
        ]
        [mtzecest, g1] = ec_boundary.ECEst(mtzastro,
                                           fifteenflo2,
                                           so,
                                           sb,
                                           beta=420.5205,
                                           npow1=0.7750588,
                                           npow2=1,
                                           g0=g0,
                                           zrms=astrorms,
                                           c=c)

        writedss(OUTPUT, outputpath, mtzecest)

        g0 = g1
    return 0
コード例 #43
0
def planning_ec_mtz(): # MTZ = RSAC054 BC for the qual
    DEBUG = 0
    OUTPUT=config.getAttr('QUALBOUNDARYFILE')
    calsimfile = config.getAttr('CALSIMFILE')
    vamp_corrected_dss = config.getAttr('CALSIM_VAMP')
    CALSIM=opendss(calsimfile)
    PLANNINGTIDE=opendss(config.getAttr('STAGE_SOURCE_FILE'))
    STEP=string.lower(config.getAttr('CALSIMSTEP'))
    SJR_PROCESS=config.getAttr("SJR_PROCESS")    
    outputpath="/FILL+CHAN/RSAC054/EC//15MIN/"+config.getAttr("DSM2MODIFIER")+"/"
    if not(OUTPUT and os.path.exists(OUTPUT)):
        raise "Envvar QUALBOUNDARYFILE must exist as destination for EC"
        
    startyr=int(config.getAttr('START_DATE')[5:])
    endyr=int(config.getAttr('END_DATE')[5:])
    
    if (startyr < 1974 and endyr > 1991):
        blocks= [ "01NOV1921 0000 - 01OCT1940 0000",
             "01OCT1940 0000 - 01OCT1960 0000",
             "01OCT1960 0000 - 01OCT1974 0000",
             "01OCT1974 0000 - 01OCT1991 0000",
             "01OCT1991 0000 - 01OCT2003 0000"
                ]
    else: 
        blocks = [ "01OCT1974 0000 - 01OCT1991 0000" ]
                                                      # for memory reasons (year 2001).

    g0=5000.                                          # initial value of g (antecedent outflow) for the beginning
                                                      # of the first year. This is pretty arbitrary and makes little difference
    if DEBUG:
        g0_no_vamp = 5000.

    for twstr in blocks:    
        TWIND=timewindow(twstr)        # Actual period to be estimated
        print "Calculating boundary salinity for the period "+TWIND.toString()
        TWINDBUF=grow_window(TWIND,"1MON","1MON")     # Conservative buffered period for retrieval
                                                      # so that after prelimiary operations (e.g. time average)
                                                      # time series will still span at least TWIND
        fpart=calsim_study_fpart(modify=0)
        ndo=DataReference.create(findpath(CALSIM,"/CALSIM/NDO/FLOW-NDO//"+STEP+"/"
                                  +fpart+"/")[0],TWIND).getData()
        ndo15=conserve.conserveSpline(ndo,"15MIN")
        ndo15_no_vamp = 0
        if DEBUG:
            ndo15_no_vamp = ndo15
        # calc  vamp caused ndo change
        if (SJR_PROCESS.upper()=="SINGLE_STEP") or (SJR_PROCESS.upper()=="MULTI_STEP"):
            fpart_modified=calsim_study_fpart(modify=1)
            delta_ndo = vamp_ndo.calc_vamp_delta_ndo(calsimfile,vamp_corrected_dss,fpart,fpart_modified,SJR_PROCESS)
            ndo15 = ndo15 + interpolate(delta_ndo, "15MIN")
		
        astro_stage_version = config.getAttr("ASTRO_STAGE_VERSION")
        mtzastro=DataReference.create(findpath(PLANNINGTIDE,"/FILL\+CHAN/RSAC054/STAGE//15MIN/"+astro_stage_version + "/")[0],TWINDBUF).getData()

        astrorms=godin((mtzastro*mtzastro)**0.5)           # RMS energy of tide (used to predict filling and draining)
        dastrorms=(  (astrorms-(astrorms>>1))*96. ).createSlice(TWIND)    
        fifteenflo2=ndo15  - 40000*(dastrorms)

        # call to ec estimator. all parameters are included. g0 is an
        [mtzecest, g1]=ec_boundary.ECEst(mtzastro,fifteenflo2,beta=600,npow1=0.75,npow2=1,g0=g0,zrms=astrorms)
        
        if DEBUG:
            fifteenflo2_no_vamp = ndo15_no_vamp  - 40000*(dastrorms)
            [mtzecest_no_vamp, g1_no_vamp]=ec_boundary.ECEst(mtzastro,fifteenflo2_no_vamp,beta=600,npow1=0.75,npow2=1,g0=g0_no_vamp,zrms=astrorms)
            g0_no_vamp = g1_no_vamp
            writedss("out_ec_check","/CALC/ndo_no_vamp/ndo////", ndo15_no_vamp)
            writedss("out_ec_check","/CALC/ndo_with_vamp/ndo////", ndo15)
            writedss("out_ec_check","/CALC/ndo_no_vamp/ec////", mtzecest_no_vamp)
            writedss("out_ec_check","/CALC/ndo_with_vamp/ec////", mtzecest)
        writedss(OUTPUT,outputpath,mtzecest)
            
        g0=g1
    return 0
コード例 #44
0
import sys
コード例 #45
0
def smooth_flow2():
    """ A slightly smoothed version of monthly flows to avoid sharp transitions
        between months. Uses a tension spline.
    """
    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"
    fpart_mod = calsim_study_fpart(modify=1)

    tw = prepro_window()

    print "Preparing SAC and SJR Inflows"

    sjr_path = calsim_path("C639")
    sjr_ret_path = calsim_path("R644")
    sjr_ref = findpath(f, sjr_path)
    if not sjr_ref:
        raise "San Joaquin path %s not found" % sjr_path
    sjr_ret_ref = findpath(f, sjr_ret_path)
    if not sjr_ret_ref:
        raise "San Joaquin return flow path %s not found" % sjr_ret_path
    sjr = DataReference.create(sjr_ref[0], tw)  # .getData()
    sjr_ret = DataReference.create(sjr_ret_ref[0], tw)  # .getData()
    sjr_in = sjr + sjr_ret

    sac_path = calsim_path("C169")
    frwa_div1_path = calsim_path("D168B")
    frwa_div2_path = calsim_path("D168C")
    sac_ref = findpath(f, sac_path)
    if not sac_ref:
        raise "Sacramento path %s not found" % sac_path
    frwa_div1_ref = findpath(f, frwa_div1_path)
    if not frwa_div1_ref:
        raise "Freeport Regional Water Authority Diversion path %s not found" % frwa_div1_path
    frwa_div2_ref = findpath(f, frwa_div2_path)
    if not frwa_div2_ref:
        raise "Freeport Regional Water Authority Diversion path %s not found" % frwa_div2_path
    sac = DataReference.create(sac_ref[0], tw)  # .getData()
    frwa_div1 = DataReference.create(frwa_div1_ref[0], tw)  # .getData()
    frwa_div2 = DataReference.create(frwa_div2_ref[0], tw)  # .getData()
    sac_in = sac + frwa_div1 + frwa_div2

    #    sjr_sac(sjr_inf,sac_inf)

    print "smoothing SAC"
    sac_mon = sac_in.getData()
    if sac_mon:
        if len(sac_mon) < 4:
            raise "Length of monthly data too short for smoothing. Wrong time window?"
        try:
            sac_day = conserve.conserveSpline(sac_mon, "1DAY")
        except:
            print "Failure to smooth path: %s over time window: %s" % ("C169_D168B_D168C", tw)
            raise

        sac_day.getAttributes().setYUnits(Units.CFS)
        writedss(outfile, "/CALSIM-SMOOTH/C169_D168B_D168C/FLOW/1DAY//" + fpart_mod + "/", sac_day)
    else:
        raise "Failure to find monthly data for C169+D168B+D168C"

    print "smoothing SJR"
    sjr_mon = sjr_in.getData()
    if sjr_mon:
        if len(sjr_mon) < 4:
            raise "Length of monthly data too short for smoothing. Wrong time window?"
        try:
            sjr_day = conserve.conserveSpline(sjr_mon, "1DAY")
        except:
            print "Failure to smooth path: %s over time window: %s" % ("C639_R644", tw)
            raise

        sjr_day.getAttributes().setYUnits(Units.CFS)
        writedss(outfile, "/CALSIM-SMOOTH/C639_R644/FLOW/1DAY//" + fpart_mod + "/", sjr_day)
    else:
        raise "Failure to find monthly data for C639+R644"
コード例 #46
0
from vutils import *
from vtimeseries import *
def writecsv(filename,ts):
    h=open(filename,'w')
    h.write(ts.name+'\n')
    for e in ts:
        h.write("%s,%s\n"%(e.getXString(),e.getYString()))
    h.close()
#
g=opendss('../testdata/ex3-base.dss')
bpart='CLFCT'
cpart='STAGE'
epart='15MIN'
refs=findparts(g,b=bpart,c=cpart,e=epart)
if refs == None or len(refs)==0:
    print 'No data found for %s/%s//%s/'%(bpart,cpart,epart)
ref=refs[0]
from vista.set import DataReference
twstr='01DEC1987 0100-05DEC1987 2400'
ref=DataReference.create(ref,timewindow(twstr))
ts=ref.data
filename='%s_%s.txt'%(bpart,cpart)
#writeascii(filename,ts)
writecsv(filename,ts)
print 'Done'