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
Exemple #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
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
Exemple #4
0
def prepro_window(prepro_window_option=None):
    """ 
    Returns the preprocessing window corresponding to the run
    The prepro_window_option can be set to "RUNDATE" "16yr" or "82yr"
    and the prepro time window will be buffered to the nearest day, 
    the standard 16yr preprocessing window or 82 years accordingly.
    The default is RUNDATE.
    """
    if prepro_window_option == None:
        prepro_window_option == getAttr("PREPRO_WINDOW")
    if not prepro_window_option:
        prepro_window_option = "RUNDATE"
    if (prepro_window_option == "RUNDATE"):
        st = getAttr("START_TIME")
        if st != "0000" and st != "2400": st = "0000"
        et = getAttr("END_TIME")
        if et != "2400" and et != "0000": et = "2400"
        return timewindow(
            getAttr("START_DATE") + " " + st + " - " + getAttr("END_DATE") +
            " " + et)
    elif prepro_window_option.lower() == "16yr":
        return timewindow("01OCT1974 0000 - 01OCT1991 0000")
    elif prepro_window_option.lower() == "82yr":
        return timewindow("01OCT1921 0000 - 01OCT2003 0000")
    else:
        raise "Prepro time window option not understood: %s" % prepro_window_option
Exemple #5
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)
Exemple #6
0
def main():
    if len(sys.argv) == 3 or len(sys.argv) == 4:
        calsimdss = sys.argv[1]
        outdss = sys.argv[2]
        #config=0
        if len(sys.argv) == 4:
            fpart = sys.argv[3]
        else:
            fpart = ""  # will match anything, so duplicates will give unexpected behavior
        fpart_modified = fpart
        if not (calsimdss.endswith(".dss") and outdss.endswith("dss")):
            raise SystemExit(use)
    elif len(sys.argv) == 2:
        configfile = sys.argv[1]
        config.setConfigVars(configfile)
        calsimdss = config.getAttr("CALSIMFILE")
        sjr_process = config.getAttr("SJR_PROCESS")
        outdss = config.getAttr("CALSIM_VAMP")
        fpart = calsim_study_fpart(modify=0)
        fpart_modified = calsim_study_fpart(modify=1)
    else:
        raise "wrong number of arguments in script prep_vamp"

    prep_vamp_vernalis(calsimdss, outdss, fpart, fpart_modified)
    prep_vamp_exports(calsimdss, outdss, fpart, fpart_modified, sjr_process)
    sys.exit()
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
def prepro_window(prepro_window_option = None):
    """ 
    Returns the preprocessing window corresponding to the run
    The prepro_window_option can be set to "RUNDATE" "16yr" or "82yr"
    and the prepro time window will be buffered to the nearest day, 
    the standard 16yr preprocessing window or 82 years accordingly.
    The default is RUNDATE.
    """
    if prepro_window_option == None:
        prepro_window_option == getAttr("PREPRO_WINDOW")
    if not prepro_window_option:
        prepro_window_option = "RUNDATE"
    if (prepro_window_option == "RUNDATE"):
        st = getAttr("START_TIME")
        if st != "0000" and st != "2400": st = "0000"
        et = getAttr("END_TIME")
        if et != "2400" and et != "0000": et = "2400"
        return timewindow(getAttr("START_DATE") + " " + st
                        + " - "
                        + getAttr("END_DATE") + " " + et)
    elif prepro_window_option.lower() == "16yr":
        return timewindow("01OCT1974 0000 - 01OCT1991 0000")
    elif prepro_window_option.lower() == "82yr":
        return timewindow("01OCT1921 0000 - 01OCT2003 0000")
    else:
        raise "Prepro time window option not understood: %s" % prepro_window_option
Exemple #9
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
Exemple #10
0
def prep_vamp_ndo(calsimfile, outdss, fpart):

    STEP = string.lower(config.getAttr('CALSIMSTEP'))

    # CALSIM=opendss(calsimfile)
    SJR_PROCESS = config.getAttr("SJR_PROCESS")

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

    if (startyr < 1974 and endyr > 1991):
        twstr = "01NOV1921 0000 - 01OCT2003 0000"
    else:
        twstr = "01OCT1974 0000 - 01OCT1991 0000"

    path = "/CALSIM/NDO/FLOW-NDO//" + STEP + "/" + fpart + "/"
    ndo = dss_retrieve_ts(calsimfile, path, twstr)
    print ndo
    ndo15 = conserve.conserveSpline(ndo, "15MIN")
    if (SJR_PROCESS.upper() == "SINGLE_STEP") or (SJR_PROCESS.upper()
                                                  == "MULTI_STEP"):
        fpart_modified = calsim_study_fpart(modify=1)
        delta_ndo = calc_vamp_delta_ndo(calsimfile, outdss, fpart,
                                        fpart_modified, SJR_PROCESS)
        ndo15_vamp = ndo15 + interpolate(delta_ndo, "15MIN")

    writedss(calsimfile, "/CALSIM/NDO/FLOW-NDO//15MIN/" + fpart + "/",
             ndo15_vamp)
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)
Exemple #12
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
Exemple #13
0
def main():
    if len(sys.argv) == 3 or len(sys.argv) == 4:
        calsimdss=sys.argv[1]
        outdss=sys.argv[2]
        #config=0
        if len(sys.argv) == 4:
            fpart=sys.argv[3]
        else:            
            fpart=""   # will match anything, so duplicates will give unexpected behavior
        fpart_modified=fpart
        if not(calsimdss.endswith(".dss") and outdss.endswith("dss")):
            raise SystemExit(use)
    elif len(sys.argv) == 2:
        configfile=sys.argv[1]
        config.setConfigVars(configfile)
        calsimdss=config.getAttr("CALSIMFILE")
        sjr_process=config.getAttr("SJR_PROCESS")
        outdss=config.getAttr("CALSIM_VAMP")
        fpart=calsim_study_fpart(modify=0)
        fpart_modified=calsim_study_fpart(modify=1)
    else:
	    raise "wrong number of arguments in script prep_vamp"
	
    prep_vamp_vernalis(calsimdss,outdss,fpart,fpart_modified) 
    prep_vamp_exports(calsimdss,outdss,fpart,fpart_modified,sjr_process)
    sys.exit()
Exemple #14
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
def planning_window():
    """ 
    Returns the runtime represented by START_DATE START_TIME END_DATE and END_TIME
    in the config file as a timewindow
    """
    return timewindow(getAttr("START_DATE") + " " + getAttr("START_TIME") 
                + " - " +
                + getAttr("END_DATE") + " " + getAttr("END_TIME"))
Exemple #16
0
def planning_window():
    """ 
    Returns the runtime represented by START_DATE START_TIME END_DATE and END_TIME
    in the config file as a timewindow
    """
    return timewindow(
        getAttr("START_DATE") + " " + getAttr("START_TIME") + " - " +
        +getAttr("END_DATE") + " " + getAttr("END_TIME"))
Exemple #17
0
def calsim_path(calsimname):
    if calsimname.startswith("C"):
        return "/CALSIM/"+calsimname+"/FLOW-CHANNEL//1MON/" \
               + getAttr("CALSIMSTUDY") + "/"
    elif calsimname.startswith("D"):
        return "/CALSIM/"+calsimname+"/FLOW-DELIVERY//1MON/" \
               + getAttr("CALSIMSTUDY") + "/"
    else:
        raise "Unknown CALSIM prefix"
def main():
    from vdisplay import tabulate
    from vdss import opendss,findpath,writedss
    from vtimeseries import timewindow
    import config
    infile=config.getAttr('DICUFILE-ECS')
    outfile=config.getAttr('DICUFILE-ECE')
    tw = prepro_window()

    tabulate(s)  # tabulate last one to check the conversion
    tabulate(ts)
Exemple #19
0
def main():
    from vdisplay import tabulate
    from vdss import opendss,findpath,writedss
    from vtimeseries import timewindow
    import config
    infile=config.getAttr('DICUFILE-ECS')
    outfile=config.getAttr('DICUFILE-ECE')
    tw = prepro_window()

    tabulate(s)  # tabulate last one to check the conversion
    tabulate(ts)
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)
Exemple #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)
Exemple #22
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
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
Exemple #24
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)
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)
def calsim_study_fpart(modify=0):
    """ Safely return the calsim study fpart for a study
        If modify=0 the search will start with CALSIMSTUDY_ORIGINAL and
        then fall back to CALSIMSTUDY

        If modify=1 the search will start with CALSIMSTUDY_MODIFIED and
        then fall back to CALSIMSTUDY
    """
    if modify:
        fpart=config.getAttr('CALSIMSTUDY_MODIFIED')
    else:
        fpart=config.getAttr('CALSIMSTUDY_ORIGINAL')
    if not fpart:
        fpart=config.getAttr('CALSIMSTUDY')
    if not fpart:
        raise "None of CALSIM, CALSIMSTUDY_ORIGINAL or CALSIMSTUDY_MODIFIED provided"
        
    return fpart
def calsim_study_fpart(modify=0):
    """ Safely return the calsim study fpart for a study
        If modify=0 the search will start with CALSIMSTUDY_ORIGINAL and
        then fall back to CALSIMSTUDY

        If modify=1 the search will start with CALSIMSTUDY_MODIFIED and
        then fall back to CALSIMSTUDY
    """
    if modify:
        fpart = config.getAttr('CALSIMSTUDY_MODIFIED')
    else:
        fpart = config.getAttr('CALSIMSTUDY_ORIGINAL')
    if not fpart:
        fpart = config.getAttr('CALSIMSTUDY')
    if not fpart:
        raise "None of CALSIM, CALSIMSTUDY_ORIGINAL or CALSIMSTUDY_MODIFIED provided"

    return fpart
Exemple #28
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
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 
Exemple #30
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
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
Exemple #32
0
def main():
    if len(sys.argv) != 2:
        raise SystemExit("""
        Usage: vscript prep_ec.py configfile
        where configfile is the input file for configuration variables
        (give full path if not in current running shell)
        """)
    else:
        print "prep NDO for Martinez EC"
        infile = sys.argv[1]
        config.setConfigVars(infile)
        calsimdss = config.getAttr("CALSIMFILE")
        fpart = calsim_study_fpart(modify=0)

    startyr = int(config.getAttr('START_DATE')[5:])
    endyr = int(config.getAttr('END_DATE')[5:])
    if (startyr < 1974 and endyr > 1991):
        twstr = "01NOV1921 0000 - 01OCT2003 0000"
    else:
        twstr = "01OCT1974 0000 - 01OCT1991 0000"
    STEP = string.lower(config.getAttr('CALSIMSTEP'))

    prep_ndo(calsimdss, STEP, fpart, twstr)
    sys.exit()
Exemple #33
0
from vtimeseries import timewindow
from vista.set import DataReference
import config
from planning_time_window import prepro_window

#
if __name__ == '__main__':
    if len(sys.argv) != 2:
        raise SystemExit("""
        Usage: vscript prep_ec.py configfile
        where configfile is the input file for configuration variables
        (give full path if not in current running shell)
        """)
    else:
        print "IN prep EC"
        infile = sys.argv[1]
        config.setConfigVars(infile)
        tw = prepro_window()
        print "Expanding seasonal DICU EC drainage values"
        expand_seasonal_bst.prep_dicu(
            config.getAttr('DICUFILE_EC'),  # original DICU DSS file for EC
            config.getAttr(
                'DICUFILE_ECE'
            ),  # processed DICU DSS file (will be input for DSM2)
            "DRAIN-EC",
            tw)
        planning_ec_mtz_bst.planning_ec_mtz()
        planning_ec_vernalis.transfer_ec(
        )  #direct copy of planning ec, no vamp
        sys.exit()
Exemple #34
0
import sys
import config
import calendar
import time
import jarray,math
import vutils
import interpolator.ConservativeSpline
import conserve
from vista.time import TimeFactory, TimeInterval,Time
from vista.set import DataReference, Units
from vdss import opendss,findpath,writedss,find
from vtimeseries import timewindow,timeinterval
from config import getAttr,setConfigVars
from calsim_study_fpart import calsim_study_fpart
from planning_time_window import prepro_window
from jarray import zeros,array
from vista.set import RegularTimeSeries,DataSetAttr,DataType,Constants
from vdisplay import plot,tabulate
from vmath import per_avg, per_max, mov_avg
from vutils import Constants, RegularTimeSeries
def path_check(f,dsspath):
	paths = findpath(f,dsspath)
	if not paths or len(paths)>1:
		print "File: %s" % calsimfile
		raise "Path %s not found or not unique" % dsspath
	return paths[0]
def transpose_day(var_list):
# reads an array of bparts of 31 calsim monnthly timeseries and tranposes data in to single daily timeseries
# returns array of transposed daily timeseries data
# "varlist" => array of bparts of 31 CALSIM monthly timeseries data (e.g QSAC169_1DV, QSAC169_2DV etc)
Exemple #35
0
#
if __name__ == '__main__':
    if len(sys.argv) != 2:
        raise SystemExit("""
        Usage: vscript prep_doc.py configfile
        where configfile is the input file for configuration variables
        (give full path if not in current running shell)
        """)
    else:
        print "IN prep DOC"
        infile = sys.argv[1]
        config.setConfigVars(infile)
        tw = prepro_window()
        print "Expanding seasonal DICU DOC drainage values"
        expand_seasonal_bst.prep_dicu(
            config.getAttr('DICUFILE_DOC'),  # original DICU DSS file for EC
            config.getAttr(
                'DICUFILE_DOCE'
            ),  # processed DICU DSS file (will be input for DSM2)
            "DRAIN-DOC",
            tw)
        print "Expanding seasonal boundary DOC values"
#        expand_seasonal_bst.prep_dicu(
#            config.getAttr('TSFILE_DOC'),        # original DICU DSS file for EC
#            config.getAttr('DICUFILE_DOCE'),       # processed DICU DSS file (will be input for DSM2)
#            "DOC",tw)

    f = opendss(config.getAttr("TSFILE_DOC"))  # open DOC boundary file
    outfile = config.getAttr("BOUNDARYFILE")
    f2 = find(f, 'DOC', 'c')
    for ref in f2:
Exemple #36
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
Exemple #37
0
from vista.set import DataReference
from planning_time_window import prepro_window
#
if __name__ == '__main__':
    if len(sys.argv) != 2:
        raise SystemExit("""
        Usage: vscript dsm2.py infile-for-envvars
        where infile-for-envvars is the input file for env variables
        (give full path if not in current running shell)
        """)
    else:
        infile = sys.argv[1]

        c = setConfigVars(infile)
        print 'Creating Delta Cross Channel daily ops from monthly...'
        sdate = getAttr('START_DATE')
        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
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"
Exemple #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"
#
if __name__ == '__main__':
    if len(sys.argv) != 2:
        raise SystemExit("""
        Usage: vscript prep_doc.py configfile
        where configfile is the input file for configuration variables
        (give full path if not in current running shell)
        """)
    else:
        print "IN prep DOC"
        infile = sys.argv[1]
        config.setConfigVars(infile)
        tw=prepro_window()
        print "Expanding seasonal DICU DOC drainage values"
        expand_seasonal_bst.prep_dicu(
            config.getAttr('DICUFILE_DOC'),        # original DICU DSS file for EC
            config.getAttr('DICUFILE_DOCE'),       # processed DICU DSS file (will be input for DSM2)
            "DRAIN-DOC",tw)
        print "Expanding seasonal boundary DOC values"
#        expand_seasonal_bst.prep_dicu(
#            config.getAttr('TSFILE_DOC'),        # original DICU DSS file for EC
#            config.getAttr('DICUFILE_DOCE'),       # processed DICU DSS file (will be input for DSM2)
#            "DOC",tw)
    
    f=opendss(config.getAttr("TSFILE_DOC"))           # open DOC boundary file
    outfile=config.getAttr("BOUNDARYFILE")
    f2=find(f,'DOC','c')
    for ref in f2:
        path = ref.getPathname()
        daily = vutils.interpolate(ref.getData(),"1DAY")
        path.setPart(Pathname.E_PART, '1DAY')
import config
import interpolate
from vtimeseries import timewindow
from vista.set import DataReference
import config
from planning_time_window import prepro_window

#
if __name__ == '__main__':
    if len(sys.argv) != 2:
        raise SystemExit("""
        Usage: vscript prep_ec.py configfile
        where configfile is the input file for configuration variables
        (give full path if not in current running shell)
        """)
    else:
        print "IN prep EC"
        infile = sys.argv[1]
        config.setConfigVars(infile)
        tw=prepro_window()
        print "Expanding seasonal DICU WQ drainage values"
        expand_seasonal.prep_dicu(
            config.getAttr('DICUFILE_EC'),        # original DICU DSS file for EC
            config.getAttr('DICUFILE_ECE'),       # processed DICU DSS file (will be input for DSM2)
            tw)
        planning_ec_mtz.planning_ec_mtz()
        planning_ec_vernalis.transfer_ec()  #direct copy of planning ec, no vamp
        sys.exit()


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
from vista.set import DataReference
from planning_time_window import prepro_window
#
if __name__ == '__main__':
    if len(sys.argv) != 2:
        raise SystemExit("""
        Usage: vscript dsm2.py infile-for-envvars
        where infile-for-envvars is the input file for env variables
        (give full path if not in current running shell)
        """)
    else:
        infile = sys.argv[1]

        c=setConfigVars(infile)
        print 'Creating Delta Cross Channel daily ops from monthly...'
        sdate = getAttr('START_DATE')
        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
import sys
import config
import time
import jarray,math
import vutils
from vista.time import TimeFactory, TimeInterval,Time
from vista.set import DataReference, Units, Pathname
from vdss import opendss,findpath,writedss,find
from vtimeseries import timewindow,timeinterval
from config import getAttr,setConfigVars
from calsim_study_fpart import calsim_study_fpart
from planning_time_window import prepro_window
from jarray import zeros,array
from vista.set import RegularTimeSeries,DataSetAttr,DataType,Constants
from vdisplay import plot,tabulate
from vmath import per_avg, per_max, mov_avg, godin, per_min
from vutils import Constants, RegularTimeSeries
from transfer import transfer
configfile = sys.argv[1]      # configuration file
param = sys.argv[2]       # param is the second argument and can be "VOL_FP","EC_FP","200nodes_FP"
sind = int(sys.argv[3])   # start index of DSS Records
eind = int(sys.argv[4])   # end index of DSS Records
setConfigVars(configfile)
DSSENVVAR = "QUAL_OUTDSS_%s" % param
infile  = getAttr(DSSENVVAR)
g = opendss(infile)
outfile = "%s_PostPro.DSS"% infile[:-4]
print "Processing Results for..."
for n in range(sind-1,eind,1):
	ref = g[n]
Exemple #45
0
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
Exemple #46
0
        and  both|hydro|qual indicates which DSM2 module
        to run, default is both
        """)
    else:
        dsm2module = sys.argv[1]
        infile = sys.argv[2]
    if dsm2module != "both" and dsm2module != "hydro" and dsm2module != "qual" and dsm2module != "ptm" and dsm2module != "qual_do" and dsm2module != "qual_ec":
        print 'Inputs: ' + sys.argv[1] + ' ' + sys.argv[2]
        raise SystemExit("""Must specify both, hydro, qual or ptm""")
    print 'Loading configuration file'
    setConfigVars(infile)

if dsm2module == "both" or dsm2module == "hydro":
    print 'Running Hydro'
################some change  made by Jon#####################    
    hydroexe=getAttr('hydroexe')
    hydroinp=getAttr('hydroinp')

    if hydroexe:
        command=getAttr('hydroexe')
        from os.path import exists
        if not exists(command):
            raise command+' is not a valid path'

    else:
        command='hydro.exe'
        
    if hydroinp:
        command=command+" "+hydroinp
    else:
        command=getAttr('hydroexe') + ' hydro.inp '
Exemple #47
0
import sys
import config
import time
import jarray, math
import vutils
from vista.time import TimeFactory, TimeInterval, Time
from vista.set import DataReference, Units, Pathname
from vdss import opendss, findpath, writedss, find
from vtimeseries import timewindow, timeinterval
from config import getAttr, setConfigVars
from calsim_study_fpart import calsim_study_fpart
from planning_time_window import prepro_window
from jarray import zeros, array
from vista.set import RegularTimeSeries, DataSetAttr, DataType, Constants
from vdisplay import plot, tabulate
from vmath import per_avg, per_max, mov_avg, godin, per_min
from vutils import Constants, RegularTimeSeries
from transfer import transfer
configfile = sys.argv[1]  # configuration file
param = sys.argv[
    2]  # param is the second argument and can be "VOL_FP","EC_FP","200nodes_FP"
sind = int(sys.argv[3])  # start index of DSS Records
eind = int(sys.argv[4])  # end index of DSS Records
setConfigVars(configfile)
DSSENVVAR = "QUAL_OUTDSS_%s" % param
infile = getAttr(DSSENVVAR)
g = opendss(infile)
outfile = "%s_PostPro.DSS" % infile[:-4]
print "Processing Results for..."
for n in range(sind - 1, eind, 1):