def do_processing(globals, scalars, var_values, output_values, tw_values):
    compare_mode = globals['COMPARE_MODE']
    time_interval = globals['DEFAULT_TIME_INTERVAL']
    # open files 1 and file 2 and loop over to plot
    from java.util import Date
    dss_group0, dss_group1, dss_group2, refvar, refname = compare_dss_utils.get_group_ref(globals, scalars, var_values)
    # obtain the new output list modified for *_ or _* cases
    output_values = compare_dss_utils.get_ref_list(compare_mode,dss_group0,dss_group1,output_values) 
    output_dir = scalars['OUTDIR'].replace('"','')
    wyt_arr = write_wyt(output_dir, tw_values)  #write the water type JavaScript file
    #out_name = column(output_values,0)
    #out_type = column(output_values,1)
    if compare_mode=='1':
        type_arr = compare_dss_utils.get_cpart_list(dss_group0)
    else:
        type_arr = compare_dss_utils.get_cpart_list(dss_group1)
    compare_dss_utils.chk_cpart_space(type_arr)
    if output_dir[-1]!='/': output_dir=output_dir+"/"
    time_windows = map(lambda val: val[1].replace('"',''), tw_values)
    tws = map(lambda x: vtimeseries.timewindow(x), time_windows)
    dIndex = 0
    dataIndex = {}
    fs_davg = {}
    fs_dmax = {}
    fs_dmin = {}
    fs_mavg = {}
    fs_orig = {}

    tbl_latlng = compare_dss_utils.lines2table(output_dir+"js/latlng.txt")
    fl = open(output_dir+"data/data_list.js",'w')
    for i in type_arr:
        initial_js = output_dir+"data/DSS_compare_spec_davg_"+i+".js"
        initial_pretab = i
        fs_davg[i] = open(output_dir+"data/DSS_compare_spec_davg_"+i+".js",'w')
        fs_dmax[i] = open(output_dir+"data/DSS_compare_spec_dmax_"+i+".js",'w')
        fs_dmin[i] = open(output_dir+"data/DSS_compare_spec_dmin_"+i+".js",'w')
        fs_mavg[i] = open(output_dir+"data/DSS_compare_spec_mavg_"+i+".js",'w')
        print >> fs_davg[i], """/* Comparison Output File Generated on : %s */"""%(str(Date()))
        print >> fs_dmax[i], """/* Comparison Output File Generated on : %s */"""%(str(Date()))
        print >> fs_dmin[i], """/* Comparison Output File Generated on : %s */"""%(str(Date()))
        print >> fs_mavg[i], """/* Comparison Output File Generated on : %s */"""%(str(Date()))        
        dataIndex['spec_davg_'+i] = 0
        dataIndex['spec_dmax_'+i] = 0
        dataIndex['spec_dmin_'+i] = 0
        dataIndex['spec_mavg_'+i] = 0
        js_data.write_begin_data_array(fs_davg[i])
        js_data.write_begin_data_array(fs_dmax[i])
        js_data.write_begin_data_array(fs_dmin[i])
        js_data.write_begin_data_array(fs_mavg[i])
        if globals['PLOT_ORIGINAL_TIME_INTERVAL']=='ON':
            fs_orig[i] = open(output_dir+"data/DSS_compare_spec_orig_"+i+".js",'w')
            print >> fs_orig[i], """/* Comparison Output File Generated on : %s */"""%(str(Date())) 
            dataIndex['spec_orig_'+i] = 0
            js_data.write_begin_data_array(fs_orig[i])
    js_data_list.write_begin_data_array(fl)
    
    wy_types = ['W','AN','BN','D','C']
    if globals['DONOT_SORT_STATION_NAME']=='OFF':
        output_values = compare_dss_utils.sort_alphabetically(output_values)
        refname = compare_dss_utils.sort_alphabetically(refname)
    else:
        refname = compare_dss_utils.get_not_sort_refname(refname,output_values)
        
    for name in refname:
        ref0 = None; ref1 = None; ref2 = None
        try:
            series_name = compare_dss_utils.get_series_name(compare_mode,scalars,refvar[name])
        except Exception,e:
            logging.error("Error building name for :%s and error is %s"%(name,e))
            continue
        if (globals['CALCULATE_SPECIFIED_RMSE_ONLY']=='OFF') or (globals['CALCULATE_SPECIFIED_RMSE_ONLY']=='ON' and name in output_values):
            conti = 0 
            str_refvar = compare_dss_utils.get_str_refvar(refvar[name],compare_mode)
            if compare_mode=='1' or compare_mode=='4' or compare_mode=='5':
                try:
                    if refvar[name][0][4]=='0': dss_group = dss_group0
                    if refvar[name][0][4]=='1': dss_group = dss_group1
                    if refvar[name][0][4]=='2': dss_group = dss_group2
                    ref0 = compare_dss_utils.get_ref(dss_group, refvar[name][0])
                    p = ref0.pathname
                    intv, var_name, data_units, data_type = compare_dss_utils.get_prop_of_ref(ref0)
                except:
                    print "**** Can't find matched time series for "+ name +" ****"
                    conti = 1
            if compare_mode=='3' or compare_mode=='5':
                try:
                    if refvar[name][2][4]=='0': dss_group = dss_group0
                    if refvar[name][2][4]=='1': dss_group = dss_group1
                    if refvar[name][2][4]=='2': dss_group = dss_group2
                    ref2 = compare_dss_utils.get_ref(dss_group, refvar[name][2])
                    p = ref2.pathname
                    intv, var_name, data_units, data_type = compare_dss_utils.get_prop_of_ref(ref2)
                except: 
                    print "**** Can't find matched time series for "+ name +" ****"
                    conti = 1
            if compare_mode=='2' or compare_mode=='3' or compare_mode=='4' or compare_mode=='5':
                try:
                    if refvar[name][1][4]=='0': dss_group = dss_group0
                    if refvar[name][1][4]=='1': dss_group = dss_group1
                    if refvar[name][1][4]=='2': dss_group = dss_group2
                    ref1 = compare_dss_utils.get_ref(dss_group, refvar[name][1])
                    p = ref1.pathname
                    intv, var_name, data_units, data_type = compare_dss_utils.get_prop_of_ref(ref1)
                except:
                    print "**** Can't find matched time series for "+ name +" ****"
                    conti = 1
                        
            if conti == 0: 
                cpart = p.getPart(p.C_PART).encode('ascii')
                if name in output_values:  
                    ref0_davg = None; ref0_dmax = None; ref0_dmin = None; ref0_mavg = None
                    ref1_davg = None; ref1_dmax = None; ref1_dmin = None; ref1_mavg = None
                    ref2_davg = None; ref2_dmax = None; ref2_dmin = None; ref2_mavg = None                    
                    if intv < 1000:
                        dataIndex['spec_davg_'+cpart]=dataIndex['spec_davg_'+cpart]+1
                        dataIndex['spec_dmax_'+cpart]=dataIndex['spec_dmax_'+cpart]+1
                        dataIndex['spec_dmin_'+cpart]=dataIndex['spec_dmin_'+cpart]+1
                        if dataIndex['spec_davg_'+cpart]>1:
                            fs_davg[cpart].write(",") 
                        if dataIndex['spec_dmax_'+cpart]>1:
                            fs_dmax[cpart].write(",")
                        if dataIndex['spec_dmin_'+cpart]>1:
                            fs_dmin[cpart].write(",")
                        if compare_mode=='1' or compare_mode=='4' or compare_mode=='5':    
                            ref0_godin = vtimeseries.godin(ref0)
                            ref0_davg = vtimeseries.per_avg(ref0_godin,'1day')
                            ref0_dmax = vtimeseries.per_max(ref0,'1day')
                            ref0_dmin = vtimeseries.per_min(ref0,'1day')
                        if compare_mode=='2' or compare_mode=='3' or compare_mode=='4' or compare_mode=='5':
                            ref1_godin = vtimeseries.godin(ref1)
                            ref1_davg = vtimeseries.per_avg(ref1_godin,'1day')
                            ref1_dmax = vtimeseries.per_max(ref1,'1day')
                            ref1_dmin = vtimeseries.per_min(ref1,'1day')  
                        if compare_mode=='3' or compare_mode=='5':
                            ref2_godin = vtimeseries.godin(ref2)
                            ref2_davg = vtimeseries.per_avg(ref2_godin,'1day')
                            ref2_dmax = vtimeseries.per_max(ref2,'1day')
                            ref2_dmin = vtimeseries.per_min(ref2,'1day')                                    
                        write_plot_data(fs_davg[cpart], compare_mode, name, str_refvar, compare_dss_utils.build_data_array(ref0_davg,ref1_davg,ref2_davg), dataIndex['spec_davg_'+cpart], "%s"%var_name, series_name, "%s (%s)"%(data_type,data_units), "Time", PlotType.TIME_SERIES, cpart,'Daily Average')           
                        write_plot_data(fs_dmax[cpart], compare_mode, name, str_refvar, compare_dss_utils.build_data_array(ref0_dmax,ref1_dmax,ref2_dmax), dataIndex['spec_dmax_'+cpart], "%s"%var_name, series_name, "%s (%s)"%(data_type,data_units), "Time", PlotType.TIME_SERIES, cpart,'Daily Maximum')           
                        write_plot_data(fs_dmin[cpart], compare_mode, name, str_refvar, compare_dss_utils.build_data_array(ref0_dmin,ref1_dmin,ref2_dmin), dataIndex['spec_dmin_'+cpart], "%s"%var_name, series_name, "%s (%s)"%(data_type,data_units), "Time", PlotType.TIME_SERIES, cpart,'Daily Minimum')
                    elif globals['DEFAULT_TIME_INTERVAL']=='1DAY':
                        ref0_davg = ref0; ref0_dmax = ref0; ref0_dmin = ref0
                        ref1_davg = ref1; ref1_dmax = ref1; ref1_dmin = ref1
                        ref2_davg = ref2; ref2_dmax = ref2; ref2_dmin = ref2
                    elif globals['DEFAULT_TIME_INTERVAL']=='1MON':
                        ref2_mavg = ref2; ref2_mmax = ref2; ref2_mmin = ref2
                    if globals['PLOT_ORIGINAL_TIME_INTERVAL']=='ON':
                        dataIndex['spec_orig_'+cpart]=dataIndex['spec_orig_'+cpart]+1
                        if dataIndex['spec_orig_'+cpart]>1:
                            fs_orig[cpart].write(",")        
                        write_plot_data(fs_orig[cpart], compare_mode, name, str_refvar, compare_dss_utils.build_data_array(ref0,ref1,ref2), dataIndex['spec_orig_'+cpart], "%s"%var_name, series_name, "%s (%s)"%(data_type,data_units), "Time", PlotType.TIME_SERIES, cpart,'Original Time Interval')
                           
                    if intv < 40000:
                        dataIndex['spec_mavg_'+cpart]=dataIndex['spec_mavg_'+cpart]+1
                        if dataIndex['spec_mavg_'+cpart]>1:
                            fs_mavg[cpart].write(",")         
                        if compare_mode=='1' or compare_mode=='4' or compare_mode=='5':      
                            ref0_mavg = vtimeseries.per_avg(ref0,'1month')
                        if compare_mode=='2' or compare_mode=='3' or compare_mode=='4' or compare_mode=='5':
                            ref1_mavg = vtimeseries.per_avg(ref1,'1month')
                        if compare_mode=='3' or compare_mode=='5':
                            ref2_mavg = vtimeseries.per_avg(ref2,'1month')
                        write_plot_data(fs_mavg[cpart], compare_mode, name, str_refvar, compare_dss_utils.build_data_array(ref0_mavg,ref1_mavg,ref2_mavg), dataIndex['spec_mavg_'+cpart], "%s"%var_name, series_name, "%s (%s)"%(data_type,data_units), "Time", PlotType.TIME_SERIES, cpart,'Monthly Average')

                if (globals['CALCULATE_SPECIFIED_RMSE_ONLY']=='OFF') or (globals['CALCULATE_SPECIFIED_RMSE_ONLY']=='ON' and name in output_values):
                    diff_arr = []
                    if compare_mode=='3' or compare_mode=='4' or compare_mode=='5':
                        for i in range(len(tws)):
                            if compare_mode=='3':   
                                rmse_val = vdiff.rmse(ref1, ref2, tws[i], time_interval)
                                perc_rmse_val = vdiff.perc_rmse(ref1, ref2, tws[i], time_interval)
                                diff_arr.append([perc_rmse_val,rmse_val ])
                            if compare_mode=='4':
                                rmse_val = vdiff.rmse(ref0, ref1, tws[i], time_interval)
                                perc_rmse_val = vdiff.perc_rmse(ref0, ref1, tws[i], time_interval)
                                diff_arr.append([perc_rmse_val,rmse_val ])
                            if compare_mode=='5':
                                rmse_val = vdiff.rmse(ref0, ref1, tws[i], time_interval)
                                perc_rmse_val = vdiff.perc_rmse(ref0, ref1, tws[i], time_interval)                    
                                rmse_val2 = vdiff.rmse(ref0, ref2, tws[i], time_interval)
                                perc_rmse_val2 = vdiff.perc_rmse(ref0, ref2, tws[i], time_interval)
                                diff_arr.append([perc_rmse_val,rmse_val,perc_rmse_val2,rmse_val2 ])         
                        for w in wy_types:
                            if compare_mode=='3':
                                diff_arr.append([vdiff.rmse_discrete_tws(ref1,ref2,wyt_arr[w],0), vdiff.rmse_discrete_tws(ref1,ref2,wyt_arr[w],1)])
                            if compare_mode=='4':
                                diff_arr.append([vdiff.rmse_discrete_tws(ref0,ref1,wyt_arr[w],0), vdiff.rmse_discrete_tws(ref0,ref1,wyt_arr[w],1)])
                            if compare_mode=='5':
                                diff_arr.append([vdiff.rmse_discrete_tws(ref0,ref1,wyt_arr[w],0), vdiff.rmse_discrete_tws(ref0,ref1,wyt_arr[w],1), vdiff.rmse_discrete_tws(ref0,ref2,wyt_arr[w],0), vdiff.rmse_discrete_tws(ref0,ref2,wyt_arr[w],1)])
    
                    latlng = compare_dss_utils.get_latlng(tbl_latlng,p.getPart(p.B_PART))
                    if globals['CALCULATE_SPECIFIED_RMSE_ONLY']=='OFF':
                        logging.debug('Working on index: %d/%d '%(dIndex+1,len(refname)))
                    else:
                        logging.debug('Working on index: %d/%d '%(dIndex+1,len(output_values)))
                    dIndex = dIndex + 1
                    if latlng==None:
                        latlng=['nan','nan','nan','nan']
                        print "can't find the Lat/Lng for ",p.getPart(p.B_PART)
                    if dIndex>1: 
                        fl.write(",")
                
                    if  name in output_values:      
                        write_list_data(fl,name, str_refvar, p.getPart(p.B_PART), cpart, 1, diff_arr,latlng)
                    else:
                        write_list_data(fl,name, str_refvar, p.getPart(p.B_PART), cpart, 0, diff_arr,latlng)              
            else:
                logging.debug("*** Please verify the path for "+name+" ***")               
def write_summary_table(fh, dss_group1,dss_group2,globals,scalars,tw_values, var_values, output_values):
    compare_mode = globals['COMPARE_MODE']
    if compare_mode=='1': print >> fh, "<h1><center>Observation Time Series Report<br>Data Set: %s </center></h1>"%(scalars['NAME0'])
    if compare_mode=='2': print >> fh, "<h1><center>Model Output Time Series Report<br>Study Name: %s </center></h1>"%(scalars['NAME1'])
    if compare_mode=='3': print >> fh, "<h1><center>DSM2 Output Comparison Report<br> %s <n>vs</n> %s</center></h1>"%(scalars['NAME1'], scalars['NAME2'])
    if compare_mode=='4': print >> fh, "<h1><center>Calibration Report<br> %s <n>vs</n> %s</center></h1>"%(scalars['NAME1'], scalars['NAME0'])
    if compare_mode=='5': print >> fh, "<h1><center>Calibration Report<br>[ %s <n>vs</n> %s ] <n> & </n> [ %s <n>vs</n> %s ]</center></h1>"%(scalars['NAME1'],scalars['NAME0'], scalars['NAME2'],scalars['NAME0'])
    print >> fh, '<div id="note">Note: %s</div>'%(scalars['NOTE'].replace('"',''))
    print >> fh, '<div id="assumptions">Assumptions: %s</div>'%(scalars['ASSUMPTIONS'].replace('"',''))   
    print >> fh, """<div id="control-panel"> 
<form>
Data Conversion for Plot: <select name="datatype" onChange="change_period()" id="data-conversion">
    <option value="davg"> Daily Average</option>
    <option value="dmax"> Daily Maximum</option>
    <option value="dmin"> Daily Minimim</option>
    <option value="mavg"> Monthly Average</option>
""" 
    if globals['PLOT_ORIGINAL_TIME_INTERVAL']=='ON':
        print >> fh, '<option value="orig">Original Data</option>'
    print >> fh, """
</select><br> 

Use Defined Time Window: <select name="tw" id="time-window-select"> 
"""
    for i in range(len(tw_values)):
        if i==0:
            selected = 'selected="selected"'
        else:
            selected = ""
        print >> fh, '<option value="%s" %s>%s</option>'%(compare_dss_utils.timewindow_option_value(vtimeseries.timewindow(tw_values[i][1].replace('"',''))), selected,tw_values[i][0].replace('"','')) 
    print >> fh, """ 
</select> 
<div>
Customize Time Window:
"""
    twstr = compare_dss_utils.timewindow_option_value(vtimeseries.timewindow(tw_values[0][1].replace('"',''))).split("-")
    a1=twstr[0].split(",")
    a2=twstr[1].split(",")
    print >> fh, """Start Date: <input name="SDate" id="SDate" value="%s" onclick="displayDatePicker('SDate');" size=12>"""%(a1[1]+"/"+a1[2]+"/"+a1[0])
    print >> fh, """End Date: <input name="EDate" id="EDate" value="%s" onclick="displayDatePicker('EDate');" size=12>"""%(a2[1]+"/"+a2[2]+"/"+a2[0])
    print >> fh, """
  <input type=button id="calendar" value="Re-draw">
</div>
"""
    if (compare_mode!='1' and compare_mode!='2'):
        print >> fh, '<div>'
        print >> fh, 'Show differences on plot:<input type="checkbox" name="diff_plot" value="1"/> &emsp; (Difference = %s - %s)'%(scalars['NAME2'],scalars['NAME1'])
        print >> fh, '</div>'   
    print >> fh, """
<div>
    Show water year types on plot: <input type="checkbox" name="wyt" value="1"/> &emsp;(<span style="font-size:100%"><span style="background-color:#D9F7CC"> &emsp;&emsp; Wet &emsp;&emsp;</span><span style="background-color:#EBF7E6"> &emsp; Above Normal &emsp;</span><span style="background-color:#F7F8F7">&emsp; Below Normal &emsp;</span><span style="background-color:#FBEEF3"> &emsp;&emsp; Dry &emsp;&emsp; </span><span style="background-color:#FFDFEC"> &emsp; Critical &emsp; </span></span>)
</div>
"""  
    if (compare_mode!='1' and compare_mode!='2'):
        print >> fh, """
<div> 
    Threshold value to highlight percentage differences
    <input type="text" id="threshold" value="50"/> 
</div>
<div>
Table Statistics: <select name="stat" id="stat" onChange="">
<option value=0>Percentage RMS Diff</option><option value=1>RMS Diff</option>
</select>
</div>
"""
    print >> fh, """
<div id="warning" style="color:red;font-weight:bold"></div>
<input type="hidden" name="ta" id="ta" value=""> 
</form> 
</div>"""
    time_windows = map(lambda val: val[1].replace('"',''), tw_values)
    tws = map(lambda x: vtimeseries.timewindow(x), time_windows)
    print >> fh, '<div class="tabber">'
    if globals['CALCULATE_SPECIFIED_RMSE_ONLY']=='ON':
        part_c = compare_dss_utils.get_cpart_from_spec(var_values, output_values)
    else:    
        part_c = compare_dss_utils.get_cpart_list(dss_group1)
    for type_item in part_c:
        print >> fh, '<div class="tabbertab" id="%s"><h2>%s</h2><p id="%s_p">'%(type_item,type_item,type_item)
        print >> fh, '</p></div>'
    print >> fh, '</div>'
    print >> fh, '<br><center><font style="font-family:arial,verdana,sans-serif;">Copyright &copy; 2010 State of California, Department of Water Resources<br>Last Modified: 1/25/2011</font></center>'
    return tws 
  function install_gcf() {
      CFInstall.check({
        mode: "overlay",
        node: "prompt"
      });
      return false;
     }
     window.attachEvent("onload", install_gcf);
  </script>
  <![endif]-->
"""%(scalars['NAME1'],scalars['NAME2'],initial_js,initial_pretab)
    tws = write_summary_table(fh,dss_group1, dss_group2, globals, scalars, tw_values, var_values, output_values)
    if globals['CALCULATE_SPECIFIED_RMSE_ONLY']=='ON':
        part_c = compare_dss_utils.get_cpart_from_spec(var_values, output_values)
    else:    
        part_c = compare_dss_utils.get_cpart_list(dss_group1)
    dt_arr = "dt_arr=["
    peri_name = "period_name=["
    peri_range = "period_range=["    
    for type_item in part_c:
        dt_arr+= "'"+type_item+"',"
    for i in range(len(tws)):
        peri_name+= '"'+tw_values[i][0].replace('"','')+'",'
    for tw in tws:
        peri_range+= '"'+compare_dss_utils.format_timewindow(tw)+'",'
    print >> fh, '<script type="text/javascript">'+dt_arr+"];"  
    print >> fh, peri_name+"];"
    print >> fh, peri_range+"]; </script>" 
    write_js_block(fh,globals,scalars)
    fh.close()
    #fireup(output_dir+scalars['OUTFILE'])
Exemple #4
0
def do_processing(globals, scalars, var_values, output_values, tw_values):
    compare_mode = globals['COMPARE_MODE']
    time_interval = globals['DEFAULT_TIME_INTERVAL']
    # open files 1 and file 2 and loop over to plot
    from java.util import Date
    dss_group0, dss_group1, dss_group2, refvar, refname = compare_dss_utils.get_group_ref(
        globals, scalars, var_values)
    # obtain the new output list modified for *_ or _* cases
    output_values = compare_dss_utils.get_ref_list(compare_mode, dss_group0,
                                                   dss_group1, output_values)
    output_dir = scalars['OUTDIR'].replace('"', '')
    wyt_arr = write_wyt(output_dir,
                        tw_values)  #write the water type JavaScript file
    #out_name = column(output_values,0)
    #out_type = column(output_values,1)
    if compare_mode == '1':
        type_arr = compare_dss_utils.get_cpart_list(dss_group0)
    else:
        type_arr = compare_dss_utils.get_cpart_list(dss_group1)
    compare_dss_utils.chk_cpart_space(type_arr)
    if output_dir[-1] != '/': output_dir = output_dir + "/"
    time_windows = map(lambda val: val[1].replace('"', ''), tw_values)
    tws = map(lambda x: vtimeseries.timewindow(x), time_windows)
    dIndex = 0
    dataIndex = {}
    fs_davg = {}
    fs_dmax = {}
    fs_dmin = {}
    fs_mavg = {}
    fs_orig = {}

    tbl_latlng = compare_dss_utils.lines2table(output_dir + "js/latlng.txt")
    fl = open(output_dir + "data/data_list.js", 'w')
    for i in type_arr:
        initial_js = output_dir + "data/DSS_compare_spec_davg_" + i + ".js"
        initial_pretab = i
        fs_davg[i] = open(
            output_dir + "data/DSS_compare_spec_davg_" + i + ".js", 'w')
        fs_dmax[i] = open(
            output_dir + "data/DSS_compare_spec_dmax_" + i + ".js", 'w')
        fs_dmin[i] = open(
            output_dir + "data/DSS_compare_spec_dmin_" + i + ".js", 'w')
        fs_mavg[i] = open(
            output_dir + "data/DSS_compare_spec_mavg_" + i + ".js", 'w')
        print >> fs_davg[
            i], """/* Comparison Output File Generated on : %s */""" % (str(
                Date()))
        print >> fs_dmax[
            i], """/* Comparison Output File Generated on : %s */""" % (str(
                Date()))
        print >> fs_dmin[
            i], """/* Comparison Output File Generated on : %s */""" % (str(
                Date()))
        print >> fs_mavg[
            i], """/* Comparison Output File Generated on : %s */""" % (str(
                Date()))
        dataIndex['spec_davg_' + i] = 0
        dataIndex['spec_dmax_' + i] = 0
        dataIndex['spec_dmin_' + i] = 0
        dataIndex['spec_mavg_' + i] = 0
        js_data.write_begin_data_array(fs_davg[i])
        js_data.write_begin_data_array(fs_dmax[i])
        js_data.write_begin_data_array(fs_dmin[i])
        js_data.write_begin_data_array(fs_mavg[i])
        if globals['PLOT_ORIGINAL_TIME_INTERVAL'] == 'ON':
            fs_orig[i] = open(
                output_dir + "data/DSS_compare_spec_orig_" + i + ".js", 'w')
            print >> fs_orig[
                i], """/* Comparison Output File Generated on : %s */""" % (
                    str(Date()))
            dataIndex['spec_orig_' + i] = 0
            js_data.write_begin_data_array(fs_orig[i])
    js_data_list.write_begin_data_array(fl)

    wy_types = ['W', 'AN', 'BN', 'D', 'C']
    if globals['DONOT_SORT_STATION_NAME'] == 'OFF':
        output_values = compare_dss_utils.sort_alphabetically(output_values)
        refname = compare_dss_utils.sort_alphabetically(refname)
    else:
        refname = compare_dss_utils.get_not_sort_refname(
            refname, output_values)

    for name in refname:
        ref0 = None
        ref1 = None
        ref2 = None
        try:
            series_name = compare_dss_utils.get_series_name(
                compare_mode, scalars, refvar[name])
        except Exception, e:
            logging.error("Error building name for :%s and error is %s" %
                          (name, e))
            continue
        if (globals['CALCULATE_SPECIFIED_RMSE_ONLY']
                == 'OFF') or (globals['CALCULATE_SPECIFIED_RMSE_ONLY'] == 'ON'
                              and name in output_values):
            conti = 0
            str_refvar = compare_dss_utils.get_str_refvar(
                refvar[name], compare_mode)
            if compare_mode == '1' or compare_mode == '4' or compare_mode == '5':
                try:
                    if refvar[name][0][4] == '0': dss_group = dss_group0
                    if refvar[name][0][4] == '1': dss_group = dss_group1
                    if refvar[name][0][4] == '2': dss_group = dss_group2
                    ref0 = compare_dss_utils.get_ref(dss_group,
                                                     refvar[name][0])
                    p = ref0.pathname
                    intv, var_name, data_units, data_type = compare_dss_utils.get_prop_of_ref(
                        ref0)
                except:
                    print "**** Can't find matched time series for " + name + " ****"
                    conti = 1
            if compare_mode == '3' or compare_mode == '5':
                try:
                    if refvar[name][2][4] == '0': dss_group = dss_group0
                    if refvar[name][2][4] == '1': dss_group = dss_group1
                    if refvar[name][2][4] == '2': dss_group = dss_group2
                    ref2 = compare_dss_utils.get_ref(dss_group,
                                                     refvar[name][2])
                    p = ref2.pathname
                    intv, var_name, data_units, data_type = compare_dss_utils.get_prop_of_ref(
                        ref2)
                except:
                    print "**** Can't find matched time series for " + name + " ****"
                    conti = 1
            if compare_mode == '2' or compare_mode == '3' or compare_mode == '4' or compare_mode == '5':
                try:
                    if refvar[name][1][4] == '0': dss_group = dss_group0
                    if refvar[name][1][4] == '1': dss_group = dss_group1
                    if refvar[name][1][4] == '2': dss_group = dss_group2
                    ref1 = compare_dss_utils.get_ref(dss_group,
                                                     refvar[name][1])
                    p = ref1.pathname
                    intv, var_name, data_units, data_type = compare_dss_utils.get_prop_of_ref(
                        ref1)
                except:
                    print "**** Can't find matched time series for " + name + " ****"
                    conti = 1

            if conti == 0:
                cpart = p.getPart(p.C_PART).encode('ascii')
                if name in output_values:
                    ref0_davg = None
                    ref0_dmax = None
                    ref0_dmin = None
                    ref0_mavg = None
                    ref1_davg = None
                    ref1_dmax = None
                    ref1_dmin = None
                    ref1_mavg = None
                    ref2_davg = None
                    ref2_dmax = None
                    ref2_dmin = None
                    ref2_mavg = None
                    if intv < 1000:
                        dataIndex['spec_davg_' +
                                  cpart] = dataIndex['spec_davg_' + cpart] + 1
                        dataIndex['spec_dmax_' +
                                  cpart] = dataIndex['spec_dmax_' + cpart] + 1
                        dataIndex['spec_dmin_' +
                                  cpart] = dataIndex['spec_dmin_' + cpart] + 1
                        if dataIndex['spec_davg_' + cpart] > 1:
                            fs_davg[cpart].write(",")
                        if dataIndex['spec_dmax_' + cpart] > 1:
                            fs_dmax[cpart].write(",")
                        if dataIndex['spec_dmin_' + cpart] > 1:
                            fs_dmin[cpart].write(",")
                        if compare_mode == '1' or compare_mode == '4' or compare_mode == '5':
                            ref0_godin = vtimeseries.godin(ref0)
                            ref0_davg = vtimeseries.per_avg(ref0_godin, '1day')
                            ref0_dmax = vtimeseries.per_max(ref0, '1day')
                            ref0_dmin = vtimeseries.per_min(ref0, '1day')
                        if compare_mode == '2' or compare_mode == '3' or compare_mode == '4' or compare_mode == '5':
                            ref1_godin = vtimeseries.godin(ref1)
                            ref1_davg = vtimeseries.per_avg(ref1_godin, '1day')
                            ref1_dmax = vtimeseries.per_max(ref1, '1day')
                            ref1_dmin = vtimeseries.per_min(ref1, '1day')
                        if compare_mode == '3' or compare_mode == '5':
                            ref2_godin = vtimeseries.godin(ref2)
                            ref2_davg = vtimeseries.per_avg(ref2_godin, '1day')
                            ref2_dmax = vtimeseries.per_max(ref2, '1day')
                            ref2_dmin = vtimeseries.per_min(ref2, '1day')
                        write_plot_data(
                            fs_davg[cpart], compare_mode, name, str_refvar,
                            compare_dss_utils.build_data_array(
                                ref0_davg, ref1_davg,
                                ref2_davg), dataIndex['spec_davg_' + cpart],
                            "%s" % var_name, series_name,
                            "%s (%s)" % (data_type, data_units), "Time",
                            PlotType.TIME_SERIES, cpart, 'Daily Average')
                        write_plot_data(
                            fs_dmax[cpart], compare_mode, name, str_refvar,
                            compare_dss_utils.build_data_array(
                                ref0_dmax, ref1_dmax,
                                ref2_dmax), dataIndex['spec_dmax_' + cpart],
                            "%s" % var_name, series_name,
                            "%s (%s)" % (data_type, data_units), "Time",
                            PlotType.TIME_SERIES, cpart, 'Daily Maximum')
                        write_plot_data(
                            fs_dmin[cpart], compare_mode, name, str_refvar,
                            compare_dss_utils.build_data_array(
                                ref0_dmin, ref1_dmin,
                                ref2_dmin), dataIndex['spec_dmin_' + cpart],
                            "%s" % var_name, series_name,
                            "%s (%s)" % (data_type, data_units), "Time",
                            PlotType.TIME_SERIES, cpart, 'Daily Minimum')
                    elif globals['DEFAULT_TIME_INTERVAL'] == '1DAY':
                        ref0_davg = ref0
                        ref0_dmax = ref0
                        ref0_dmin = ref0
                        ref1_davg = ref1
                        ref1_dmax = ref1
                        ref1_dmin = ref1
                        ref2_davg = ref2
                        ref2_dmax = ref2
                        ref2_dmin = ref2
                    elif globals['DEFAULT_TIME_INTERVAL'] == '1MON':
                        ref2_mavg = ref2
                        ref2_mmax = ref2
                        ref2_mmin = ref2
                    if globals['PLOT_ORIGINAL_TIME_INTERVAL'] == 'ON':
                        dataIndex['spec_orig_' +
                                  cpart] = dataIndex['spec_orig_' + cpart] + 1
                        if dataIndex['spec_orig_' + cpart] > 1:
                            fs_orig[cpart].write(",")
                        write_plot_data(
                            fs_orig[cpart], compare_mode, name, str_refvar,
                            compare_dss_utils.build_data_array(
                                ref0, ref1, ref2),
                            dataIndex['spec_orig_' + cpart], "%s" % var_name,
                            series_name, "%s (%s)" % (data_type, data_units),
                            "Time", PlotType.TIME_SERIES, cpart,
                            'Original Time Interval')

                    if intv < 40000:
                        dataIndex['spec_mavg_' +
                                  cpart] = dataIndex['spec_mavg_' + cpart] + 1
                        if dataIndex['spec_mavg_' + cpart] > 1:
                            fs_mavg[cpart].write(",")
                        if compare_mode == '1' or compare_mode == '4' or compare_mode == '5':
                            ref0_mavg = vtimeseries.per_avg(ref0, '1month')
                        if compare_mode == '2' or compare_mode == '3' or compare_mode == '4' or compare_mode == '5':
                            ref1_mavg = vtimeseries.per_avg(ref1, '1month')
                        if compare_mode == '3' or compare_mode == '5':
                            ref2_mavg = vtimeseries.per_avg(ref2, '1month')
                        write_plot_data(
                            fs_mavg[cpart], compare_mode, name, str_refvar,
                            compare_dss_utils.build_data_array(
                                ref0_mavg, ref1_mavg,
                                ref2_mavg), dataIndex['spec_mavg_' + cpart],
                            "%s" % var_name, series_name,
                            "%s (%s)" % (data_type, data_units), "Time",
                            PlotType.TIME_SERIES, cpart, 'Monthly Average')

                if (globals['CALCULATE_SPECIFIED_RMSE_ONLY']
                        == 'OFF') or (globals['CALCULATE_SPECIFIED_RMSE_ONLY']
                                      == 'ON' and name in output_values):
                    diff_arr = []
                    if compare_mode == '3' or compare_mode == '4' or compare_mode == '5':
                        for i in range(len(tws)):
                            if compare_mode == '3':
                                rmse_val = vdiff.rmse(ref1, ref2, tws[i],
                                                      time_interval)
                                perc_rmse_val = vdiff.perc_rmse(
                                    ref1, ref2, tws[i], time_interval)
                                diff_arr.append([perc_rmse_val, rmse_val])
                            if compare_mode == '4':
                                rmse_val = vdiff.rmse(ref0, ref1, tws[i],
                                                      time_interval)
                                perc_rmse_val = vdiff.perc_rmse(
                                    ref0, ref1, tws[i], time_interval)
                                diff_arr.append([perc_rmse_val, rmse_val])
                            if compare_mode == '5':
                                rmse_val = vdiff.rmse(ref0, ref1, tws[i],
                                                      time_interval)
                                perc_rmse_val = vdiff.perc_rmse(
                                    ref0, ref1, tws[i], time_interval)
                                rmse_val2 = vdiff.rmse(ref0, ref2, tws[i],
                                                       time_interval)
                                perc_rmse_val2 = vdiff.perc_rmse(
                                    ref0, ref2, tws[i], time_interval)
                                diff_arr.append([
                                    perc_rmse_val, rmse_val, perc_rmse_val2,
                                    rmse_val2
                                ])
                        for w in wy_types:
                            if compare_mode == '3':
                                diff_arr.append([
                                    vdiff.rmse_discrete_tws(
                                        ref1, ref2, wyt_arr[w], 0),
                                    vdiff.rmse_discrete_tws(
                                        ref1, ref2, wyt_arr[w], 1)
                                ])
                            if compare_mode == '4':
                                diff_arr.append([
                                    vdiff.rmse_discrete_tws(
                                        ref0, ref1, wyt_arr[w], 0),
                                    vdiff.rmse_discrete_tws(
                                        ref0, ref1, wyt_arr[w], 1)
                                ])
                            if compare_mode == '5':
                                diff_arr.append([
                                    vdiff.rmse_discrete_tws(
                                        ref0, ref1, wyt_arr[w], 0),
                                    vdiff.rmse_discrete_tws(
                                        ref0, ref1, wyt_arr[w], 1),
                                    vdiff.rmse_discrete_tws(
                                        ref0, ref2, wyt_arr[w], 0),
                                    vdiff.rmse_discrete_tws(
                                        ref0, ref2, wyt_arr[w], 1)
                                ])

                    latlng = compare_dss_utils.get_latlng(
                        tbl_latlng, p.getPart(p.B_PART))
                    if globals['CALCULATE_SPECIFIED_RMSE_ONLY'] == 'OFF':
                        logging.debug('Working on index: %d/%d ' %
                                      (dIndex + 1, len(refname)))
                    else:
                        logging.debug('Working on index: %d/%d ' %
                                      (dIndex + 1, len(output_values)))
                    dIndex = dIndex + 1
                    if latlng == None:
                        latlng = ['nan', 'nan', 'nan', 'nan']
                        print "can't find the Lat/Lng for ", p.getPart(
                            p.B_PART)
                    if dIndex > 1:
                        fl.write(",")

                    if name in output_values:
                        write_list_data(fl, name, str_refvar,
                                        p.getPart(p.B_PART), cpart, 1,
                                        diff_arr, latlng)
                    else:
                        write_list_data(fl, name, str_refvar,
                                        p.getPart(p.B_PART), cpart, 0,
                                        diff_arr, latlng)
            else:
                logging.debug("*** Please verify the path for " + name +
                              " ***")
Exemple #5
0
def write_summary_table(fh, dss_group1, dss_group2, globals, scalars,
                        tw_values, var_values, output_values):
    compare_mode = globals['COMPARE_MODE']
    if compare_mode == '1':
        print >> fh, "<h1><center>Observation Time Series Report<br>Data Set: %s </center></h1>" % (
            scalars['NAME0'])
    if compare_mode == '2':
        print >> fh, "<h1><center>Model Output Time Series Report<br>Study Name: %s </center></h1>" % (
            scalars['NAME1'])
    if compare_mode == '3':
        print >> fh, "<h1><center>DSM2 Output Comparison Report<br> %s <n>vs</n> %s</center></h1>" % (
            scalars['NAME1'], scalars['NAME2'])
    if compare_mode == '4':
        print >> fh, "<h1><center>Calibration Report<br> %s <n>vs</n> %s</center></h1>" % (
            scalars['NAME1'], scalars['NAME0'])
    if compare_mode == '5':
        print >> fh, "<h1><center>Calibration Report<br>[ %s <n>vs</n> %s ] <n> & </n> [ %s <n>vs</n> %s ]</center></h1>" % (
            scalars['NAME1'], scalars['NAME0'], scalars['NAME2'],
            scalars['NAME0'])
    print >> fh, '<div id="note">Note: %s</div>' % (scalars['NOTE'].replace(
        '"', ''))
    print >> fh, '<div id="assumptions">Assumptions: %s</div>' % (
        scalars['ASSUMPTIONS'].replace('"', ''))
    print >> fh, """<div id="control-panel"> 
<form>
Data Conversion for Plot: <select name="datatype" onChange="change_period()" id="data-conversion">
    <option value="davg"> Daily Average</option>
    <option value="dmax"> Daily Maximum</option>
    <option value="dmin"> Daily Minimim</option>
    <option value="mavg"> Monthly Average</option>
"""
    if globals['PLOT_ORIGINAL_TIME_INTERVAL'] == 'ON':
        print >> fh, '<option value="orig">Original Data</option>'
    print >> fh, """
</select><br> 

Use Defined Time Window: <select name="tw" id="time-window-select"> 
"""
    for i in range(len(tw_values)):
        if i == 0:
            selected = 'selected="selected"'
        else:
            selected = ""
        print >> fh, '<option value="%s" %s>%s</option>' % (
            compare_dss_utils.timewindow_option_value(
                vtimeseries.timewindow(tw_values[i][1].replace(
                    '"', ''))), selected, tw_values[i][0].replace('"', ''))
    print >> fh, """ 
</select> 
<div>
Customize Time Window:
"""
    twstr = compare_dss_utils.timewindow_option_value(
        vtimeseries.timewindow(tw_values[0][1].replace('"', ''))).split("-")
    a1 = twstr[0].split(",")
    a2 = twstr[1].split(",")
    print >> fh, """Start Date: <input name="SDate" id="SDate" value="%s" onclick="displayDatePicker('SDate');" size=12>""" % (
        a1[1] + "/" + a1[2] + "/" + a1[0])
    print >> fh, """End Date: <input name="EDate" id="EDate" value="%s" onclick="displayDatePicker('EDate');" size=12>""" % (
        a2[1] + "/" + a2[2] + "/" + a2[0])
    print >> fh, """
  <input type=button id="calendar" value="Re-draw">
</div>
"""
    if (compare_mode != '1' and compare_mode != '2'):
        print >> fh, '<div>'
        print >> fh, 'Show differences on plot:<input type="checkbox" name="diff_plot" value="1"/> &emsp; (Difference = %s - %s)' % (
            scalars['NAME2'], scalars['NAME1'])
        print >> fh, '</div>'
    print >> fh, """
<div>
    Show water year types on plot: <input type="checkbox" name="wyt" value="1"/> &emsp;(<span style="font-size:100%"><span style="background-color:#D9F7CC"> &emsp;&emsp; Wet &emsp;&emsp;</span><span style="background-color:#EBF7E6"> &emsp; Above Normal &emsp;</span><span style="background-color:#F7F8F7">&emsp; Below Normal &emsp;</span><span style="background-color:#FBEEF3"> &emsp;&emsp; Dry &emsp;&emsp; </span><span style="background-color:#FFDFEC"> &emsp; Critical &emsp; </span></span>)
</div>
"""
    if (compare_mode != '1' and compare_mode != '2'):
        print >> fh, """
<div> 
    Threshold value to highlight percentage differences
    <input type="text" id="threshold" value="50"/> 
</div>
<div>
Table Statistics: <select name="stat" id="stat" onChange="">
<option value=0>Percentage RMS Diff</option><option value=1>RMS Diff</option>
</select>
</div>
"""
    print >> fh, """
<div id="warning" style="color:red;font-weight:bold"></div>
<input type="hidden" name="ta" id="ta" value=""> 
</form> 
</div>"""
    time_windows = map(lambda val: val[1].replace('"', ''), tw_values)
    tws = map(lambda x: vtimeseries.timewindow(x), time_windows)
    print >> fh, '<div class="tabber">'
    if globals['CALCULATE_SPECIFIED_RMSE_ONLY'] == 'ON':
        part_c = compare_dss_utils.get_cpart_from_spec(var_values,
                                                       output_values)
    else:
        part_c = compare_dss_utils.get_cpart_list(dss_group1)
    for type_item in part_c:
        print >> fh, '<div class="tabbertab" id="%s"><h2>%s</h2><p id="%s_p">' % (
            type_item, type_item, type_item)
        print >> fh, '</p></div>'
    print >> fh, '</div>'
    print >> fh, '<br><center><font style="font-family:arial,verdana,sans-serif;">Copyright &copy; 2010 State of California, Department of Water Resources<br>Last Modified: 1/25/2011</font></center>'
    return tws
Exemple #6
0
        mode: "overlay",
        node: "prompt"
      });
      return false;
     }
     window.attachEvent("onload", install_gcf);
  </script>
  <![endif]-->
""" % (scalars['NAME1'], scalars['NAME2'], initial_js, initial_pretab)
    tws = write_summary_table(fh, dss_group1, dss_group2, globals, scalars,
                              tw_values, var_values, output_values)
    if globals['CALCULATE_SPECIFIED_RMSE_ONLY'] == 'ON':
        part_c = compare_dss_utils.get_cpart_from_spec(var_values,
                                                       output_values)
    else:
        part_c = compare_dss_utils.get_cpart_list(dss_group1)
    dt_arr = "dt_arr=["
    peri_name = "period_name=["
    peri_range = "period_range=["
    for type_item in part_c:
        dt_arr += "'" + type_item + "',"
    for i in range(len(tws)):
        peri_name += '"' + tw_values[i][0].replace('"', '') + '",'
    for tw in tws:
        peri_range += '"' + compare_dss_utils.format_timewindow(tw) + '",'
    print >> fh, '<script type="text/javascript">' + dt_arr + "];"
    print >> fh, peri_name + "];"
    print >> fh, peri_range + "]; </script>"
    write_js_block(fh, globals, scalars)
    fh.close()
    #fireup(output_dir+scalars['OUTFILE'])