def calculate_exports(limit,average_value): """Determines pulse and non-pulse export flows for cvp or swp given the refined limits on the export and the average for one of the projects. This routine assures that the limit is only used if it will reduce pumping and that the pulse and non-pulse flows combine to give the correct total monthly average pumping. Arguments: limit: time series of (refined) limits on exports for the project (cvp or swp) being analyzed. average_value: time series of monthly average pumping for the project Output: export_value: Time series of actual exports. """ total_time_in_month,pulse_time_in_month,non_pulse_time_in_month = \ calculate_vamp_times(limit) # Calculate a volumetrically correct non-pulse flow given that average_value gives # the total volume of pumping for the month and that pulse pumping is at the limit limit_volume=limit*pulse_time_in_month total_volume = average_value*total_time_in_month non_pulse_volume = total_volume - limit_volume non_pulse_flow=non_pulse_volume/non_pulse_time_in_month volume_corrected_limit = replace_vamp(limit, # replace shoulder first non_pulse_flow, include_shoulder=1) volume_corrected_limit=replace_vamp(volume_corrected_limit, #now correct pulse period limit, include_shoulder=0) # Create an indicator time series to show months where the pulse pumping # limit is greater than average (the pulse pumping limit should be a curtailment). # Note that this is converted to daily by "spreading it out" over the days, but it # is an indicator of a monthly condition and every day has the same value. limit_exceeds_average = limit > average_value limit_exceeds_average=interpolate(limit_exceeds_average,'1DAY') average_value=interpolate(average_value,'1DAY') # Now use average_value for months where the pulse limit would lead to an increase # and the volume-corrected pulse/non-pulse combination otherwise. export_value = ts_where(limit_exceeds_average,average_value, volume_corrected_limit) if (DEBUG): writedss("out.dss","/EXP/CVP/EXPORT////",export_value) writedss("out.dss","/EXP/CVP/VCL////",volume_corrected_limit) writedss("out.dss","/EXP/CVP/NONPULSE////",interpolate(non_pulse_flow,'1DAY')) writedss("out.dss","/EXP/CVP/AVE////",average_value) writedss("out.dss","/EXP/CVP/LIM////",interpolate(limit,'1DAY')) writedss("out.dss","/EXP/CVP/LIM_EXCEED_AVE////",limit_exceeds_average) export_value.getAttributes().setYUnits("CFS") export_value.getAttributes().setYType("PER-AVER") return export_value
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
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
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 replace_vamp(non_pulse, pulse, include_shoulder=0): """Creates a new series based on non_pulse values, replacing them with pulse values during the VAMP season (April 15-May 15 inclusive) or April1 - May 31 if include_shoulder is set to true (1) Arguments: non_pulse: monthly or daily series of values to use for non-pulse pulse: pulse values, must have same start, length, interval as non-pulse Output: New series with non-pulse values replaced by pulse during vamp """ if not isinstance(non_pulse, RegularTimeSeries): raise TypeError("Non-Pulse flow must be regular time series") if not isinstance(pulse, RegularTimeSeries): raise TypeError("Pulse flow must be regular time series") if include_shoulder: first_april_day = 1 last_may_day = 31 else: first_april_day = 15 last_may_day = 15 #if non_pulse.getTimeInterval() == timeinterval("1MON"): non_pulse = interpolate(non_pulse, "1DAY") #if pulse.getTimeInterval() == timeinterval("1MON"): pulse = interpolate(pulse, "1DAY") if non_pulse.getStartTime() != pulse.getStartTime() or \ len(non_pulse) != len(pulse): raise ValueError("Pulse and Non-pulse must have the same start time," " interval and length") values = zeros(len(non_pulse), 'd') for np, p, i in zip(non_pulse, pulse, range(len(values))): values[i] = np.getY() xstr = np.getXString() day, month = int(xstr[0:2]), xstr[2:5] if month == "APR" and day >= first_april_day: values[i] = p.getY() elif month == "MAY" and day <= last_may_day: values[i] = p.getY() out = RegularTimeSeries("/vamp//////", non_pulse.getStartTime().toString(), non_pulse.getTimeInterval().toString(), values) out.getAttributes().setYUnits("CFS") out.getAttributes().setYType("PER-AVER") return out
def replace_vamp(non_pulse,pulse,include_shoulder=0): """Creates a new series based on non_pulse values, replacing them with pulse values during the VAMP season (April 15-May 15 inclusive) or April1 - May 31 if include_shoulder is set to true (1) Arguments: non_pulse: monthly or daily series of values to use for non-pulse pulse: pulse values, must have same start, length, interval as non-pulse Output: New series with non-pulse values replaced by pulse during vamp """ if not isinstance(non_pulse,RegularTimeSeries): raise TypeError("Non-Pulse flow must be regular time series") if not isinstance(pulse,RegularTimeSeries): raise TypeError("Pulse flow must be regular time series") if include_shoulder: first_april_day=1 last_may_day=31 else: first_april_day=15 last_may_day=15 #if non_pulse.getTimeInterval() == timeinterval("1MON"): non_pulse=interpolate(non_pulse,"1DAY") #if pulse.getTimeInterval() == timeinterval("1MON"): pulse=interpolate(pulse,"1DAY") if non_pulse.getStartTime() != pulse.getStartTime() or \ len(non_pulse) != len(pulse): raise ValueError("Pulse and Non-pulse must have the same start time," " interval and length") values=zeros(len(non_pulse),'d') for np,p,i in zip(non_pulse,pulse,range(len(values))): values[i]=np.getY() xstr=np.getXString() day,month=int(xstr[0:2]),xstr[2:5] if month=="APR" and day >= first_april_day: values[i]=p.getY() elif month=="MAY" and day <= last_may_day: values[i]=p.getY() out=RegularTimeSeries("/vamp//////", non_pulse.getStartTime().toString(), non_pulse.getTimeInterval().toString(),values) out.getAttributes().setYUnits("CFS") out.getAttributes().setYType("PER-AVER") return out
def calc_vamp_delta_ndo(calsimfile,vamp_dss,fpart,fpart_mod,sjr_process): # sjr flow path="/CALSIM/C639/FLOW-CHANNEL//1MON/fpart/".replace("fpart",fpart) sjr_average_flow = dss_retrieve_ts(calsimfile,path) path = "/CALSIM-VAMP/C639/FLOW//1DAY/fpart/".replace("fpart",fpart_mod) sjr_vamp_flow = dss_retrieve_ts(vamp_dss,path) delta_sjr_flow = sjr_vamp_flow - interpolate(sjr_average_flow,"1DAY") #cvp swp export path="/CALSIM/D419/FLOW-DELIVERY//1MON/fpart/".replace("fpart",fpart) swp_average_exports=dss_retrieve_ts(calsimfile,path) path="/CALSIM/D418/FLOW-DELIVERY//1MON/fpart/".replace("fpart",fpart) cvp_average_exports=dss_retrieve_ts(calsimfile,path) path="/CALSIM-VAMP/D419/FLOW-EXPORT//1DAY/fpart/".replace("fpart",fpart_mod) swp_vamp_exports=dss_retrieve_ts(vamp_dss,path) path="/CALSIM-VAMP/D418/FLOW-EXPORT//1DAY/fpart/".replace("fpart",fpart_mod) cvp_vamp_exports=dss_retrieve_ts(vamp_dss,path) delta_cvp_exports = cvp_vamp_exports - interpolate(cvp_average_exports,"1DAY") delta_swp_exports = swp_vamp_exports - interpolate(swp_average_exports,"1DAY") return delta_sjr_flow - delta_cvp_exports - delta_swp_exports
def calc_vamp_delta_ndo(calsimfile, vamp_dss, fpart, fpart_mod, sjr_process): # sjr flow path = "/CALSIM/C639/FLOW-CHANNEL//1MON/fpart/".replace("fpart", fpart) sjr_average_flow = dss_retrieve_ts(calsimfile, path) path = "/CALSIM-VAMP/C639/FLOW//1DAY/fpart/".replace("fpart", fpart_mod) sjr_vamp_flow = dss_retrieve_ts(vamp_dss, path) delta_sjr_flow = sjr_vamp_flow - interpolate(sjr_average_flow, "1DAY") #cvp swp export path = "/CALSIM/D419/FLOW-DELIVERY//1MON/fpart/".replace("fpart", fpart) swp_average_exports = dss_retrieve_ts(calsimfile, path) path = "/CALSIM/D418/FLOW-DELIVERY//1MON/fpart/".replace("fpart", fpart) cvp_average_exports = dss_retrieve_ts(calsimfile, path) path = "/CALSIM-VAMP/D419/FLOW-EXPORT//1DAY/fpart/".replace( "fpart", fpart_mod) swp_vamp_exports = dss_retrieve_ts(vamp_dss, path) path = "/CALSIM-VAMP/D418/FLOW-EXPORT//1DAY/fpart/".replace( "fpart", fpart_mod) cvp_vamp_exports = dss_retrieve_ts(vamp_dss, path) delta_cvp_exports = cvp_vamp_exports - interpolate(cvp_average_exports, "1DAY") delta_swp_exports = swp_vamp_exports - interpolate(swp_average_exports, "1DAY") return delta_sjr_flow - delta_cvp_exports - delta_swp_exports
def calculate_exports(limit, average_value): """Determines pulse and non-pulse export flows for cvp or swp given the refined limits on the export and the average for one of the projects. This routine assures that the limit is only used if it will reduce pumping and that the pulse and non-pulse flows combine to give the correct total monthly average pumping. Arguments: limit: time series of (refined) limits on exports for the project (cvp or swp) being analyzed. average_value: time series of monthly average pumping for the project Output: export_value: Time series of actual exports. """ total_time_in_month,pulse_time_in_month,non_pulse_time_in_month = \ calculate_vamp_times(limit) # Calculate a volumetrically correct non-pulse flow given that average_value gives # the total volume of pumping for the month and that pulse pumping is at the limit limit_volume = limit * pulse_time_in_month total_volume = average_value * total_time_in_month non_pulse_volume = total_volume - limit_volume non_pulse_flow = non_pulse_volume / non_pulse_time_in_month volume_corrected_limit = replace_vamp( limit, # replace shoulder first non_pulse_flow, include_shoulder=1) volume_corrected_limit = replace_vamp( volume_corrected_limit, #now correct pulse period limit, include_shoulder=0) # Create an indicator time series to show months where the pulse pumping # limit is greater than average (the pulse pumping limit should be a curtailment). # Note that this is converted to daily by "spreading it out" over the days, but it # is an indicator of a monthly condition and every day has the same value. limit_exceeds_average = limit > average_value limit_exceeds_average = interpolate(limit_exceeds_average, '1DAY') average_value = interpolate(average_value, '1DAY') # Now use average_value for months where the pulse limit would lead to an increase # and the volume-corrected pulse/non-pulse combination otherwise. export_value = ts_where(limit_exceeds_average, average_value, volume_corrected_limit) if (DEBUG): writedss("out.dss", "/EXP/CVP/EXPORT////", export_value) writedss("out.dss", "/EXP/CVP/VCL////", volume_corrected_limit) writedss("out.dss", "/EXP/CVP/NONPULSE////", interpolate(non_pulse_flow, '1DAY')) writedss("out.dss", "/EXP/CVP/AVE////", average_value) writedss("out.dss", "/EXP/CVP/LIM////", interpolate(limit, '1DAY')) writedss("out.dss", "/EXP/CVP/LIM_EXCEED_AVE////", limit_exceeds_average) export_value.getAttributes().setYUnits("CFS") export_value.getAttributes().setYType("PER-AVER") return export_value