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 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
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
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"
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"
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
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