<%doc>
This Mako template is intended to create a variable specific report page for glance reportGen.

Created by Eva Schiffer Jun 2009.
Copyright (c) 2009 University of Wisconsin SSEC. All rights reserved.
</%doc>

<%!
    import types as types
    import glance.report as report
%>

## we will use this stuff often, so hang on to it
<%
    variableName = runInfo['variable_name']
    variableDisplayName = variableName
    if (runInfo.has_key('display_name')):
        variableDisplayName = runInfo['display_name']
    hideComparisonImages = ('short_circuit_diffs' in runInfo) and runInfo['short_circuit_diffs']
%>

<title>${variableDisplayName} Variable Comparison</title>
</head>
<body>
    
    <h1>${variableDisplayName} Variable Comparison</h1>
    
    <p>
        % if 'version' in runInfo :
            report produced with ${runInfo['version']} <br>
        % endif
        comparison generated ${runInfo['time']} by user ${runInfo['user']} on ${runInfo['machine']}
    </p>
    
    ## show information on each of the files we're comparing (should only be two)
    % for fileKey in sorted(list(files)) :
        <% tempFileInfo = files[fileKey] %>
        <p>
            ${fileKey}:
            % if 'displayName' in tempFileInfo :
                ${tempFileInfo['displayName']}
            % endif
            <blockquote>
                path: ${tempFileInfo['path']} <br>
                md5sum for ${fileKey}: ${tempFileInfo['md5sum']} <br>
                last modified: ${tempFileInfo['lastModifiedTime']}
            </blockquote>
        </p>
    % endfor
    
    ## display info on the config file that was used, if one was
    % if ('config_file_name' in runInfo) and (runInfo['config_file_name'] is not None) :
        <p>
            A configuration file was used to control the production report.<br>
            Please see <a href="${runInfo['config_file_name']}">this copy of the configuration file</a>
            for details.
        </p>
    % endif
    
    ## if the lon/lat variables exist, display info on them
    %if ('latitude' in runInfo) and ('longitude' in runInfo) :
        
        ## display the latitude and longitude variable names
        <p>
            % if ('latitude_alt_name_in_b' in runInfo) :
                latitude in A: ${runInfo['latitude']}<br>
                latitude in B: ${runInfo['latitude_alt_name_in_b']}<br>
            % else :
                latitude: ${runInfo['latitude']} <br>
            % endif
            % if ('longitude_alt_name_in_b' in runInfo) :
                longitude in A: ${runInfo['longitude']}<br>
                longitude in B: ${runInfo['longitude_alt_name_in_b']}<br>
            % else :
                longitude: ${runInfo['longitude']}<br>
            % endif
            
            % if ('lon_lat_epsilon' in runInfo) and (runInfo['lon_lat_epsilon'] > 0.0) :
                longitude/latitude comparison epsilon: ${runInfo['lon_lat_epsilon']}<br>
            % endif
            
            <br>
            ## display information about any data filtering on the lons/lats
            % if ('data_filter_function_lat_in_a' in runInfo) and (not (runInfo['data_filter_function_lat_in_a'] is None)) :
                Note: The latitude in file A was filtered.
                Please see <a href="../${runInfo['config_file_name']}">this copy of
                the original configuration file</a> to view the data filtering function.<br>
            % endif
            % if ('data_filter_function_lat_in_b' in runInfo) and (not (runInfo['data_filter_function_lat_in_b'] is None)) :
                Note: The latitude in file B was filtered.
                Please see <a href="../${runInfo['config_file_name']}">this copy of
                the original configuration file</a> to view the data filtering function.<br>
            % endif
            % if ('data_filter_function_lon_in_a' in runInfo) and (not (runInfo['data_filter_function_lon_in_a'] is None)) :
                Note: The longitude in file A was filtered.
                Please see <a href="../${runInfo['config_file_name']}">this copy of
                the original configuration file</a> to view the data filtering function.<br>
            % endif
            % if ('data_filter_function_lon_in_b' in runInfo) and (not (runInfo['data_filter_function_lon_in_b'] is None)) :
                Note: The longitude in file B was filtered.
                Please see <a href="../${runInfo['config_file_name']}">this copy of
                the original configuration file</a> to view the data filtering function.<br>
            % endif
        </p>
        
        ## if there is a problem with the longitude/latitude correlation between the two files,
        ## make a nice big warning for the user
        % if spatial.has_key('lon_lat_not_equal_points_count') and (spatial['lon_lat_not_equal_points_count'] > 0) :
            <p>
                WARNING: ${spatial['lon_lat_not_equal_points_count']} data points
                (${report.make_formatted_display_string(spatial['lon_lat_not_equal_points_percent'])}% of all data)
                show possible mismatch in values stored in file a
                and file b longitude and latitude values. Depending on the degree of mismatch, some data value comparisons
                in this report may be distorted or spatially nonsensical. Please consider re-running this report and including an
                examination of your longitude and latitude variables with appropriate epsilons in order to analyze the significance
                of the difference.<br>
                ## if we're showing images, link to graphs showing the problem
                % if runInfo['shouldIncludeImages'] :
                    <a href="../LonLatMismatch.A.png">
                        View mismatching points in A's lon/lat system
                    </a><br>
                    <a href="../LonLatMismatch.B.png">
                        View mismatching points in B's lon/lat system
                    </a>
                % endif
            </p>
        % endif
    
    ## end of the if to display lon/lat info
    % endif
    
    % if (len(imageNames['original']) > 0) :
        <h3>Original Data</h3>
        <p>
            % for image in imageNames['original']:
                <a href="./${image}"><img src="small.${image}"></a>
            % endfor
        </p>
    % endif
    
    <h3>Comparison Information</h3>
    
    ## comparison parameters
    <p>
        ## display the variable names
        % if 'alternate_name_in_B' in runInfo :
            variable name in A: ${variableName} <br>
            variable name in B: ${runInfo['alternate_name_in_B']} <br>
        % else :
            variable name: ${variableName} <br>
        % endif
        
        ## display the epsilon
        epsilon value: ${runInfo['epsilon']} <br>
        
        ## display the missing value
        % if ('missing_value_alt_in_b' in runInfo) and (not (runInfo['missing_value_alt_in_b'] is runInfo['missing_value'])) :
            "missing" data value in A: ${str(runInfo['missing_value'])}<br>
            "missing" data value in B: ${str(runInfo['missing_value_alt_in_b'])}<br>
        % else :
            "missing" data value: ${str(runInfo['missing_value'])}<br>
        % endif
        
        <br>
        ## if the data was filtered, say so
        % if ('data_filter_function_a' in runInfo) and (not (runInfo['data_filter_function_a'] is None)) :
            Note: The data for this variable from file A was filtered.
            Please see <a href="../${runInfo['config_file_name']}">this copy of
            the original configuration file</a> to view the data filtering function.<br>
        % endif
        % if ('data_filter_function_b' in runInfo) and (not (runInfo['data_filter_function_b'] is None)) :
            Note: The data for this variable from file B was filtered.
            Please see <a href="../${runInfo['config_file_name']}">this copy of
            the original configuration file</a> to view the data filtering function.<br>
        % endif
    </p>
    
    <h3>Statistical Summary</h3>
    
    ## list out all of the statistics groups we have
    <dl>
    % for setName in sorted(list(statGroups)) :
        <% dataSet = statGroups[setName] %>
            <dt>
                ${setName}
            </dt>
            <dd>
                % for statName, statValue in sorted(list(dataSet.items())) :
                    ${statName}<a href="../doc.html">*</a>: ${report.make_formatted_display_string(statValue)} <br>
                % endfor
                <br>
            <dd>
    % endfor
    </dl>
    
    % if (len(imageNames['compared']) > 0) and (not hideComparisonImages) :
        <p>
            % for image in imageNames['compared'] :
                <a href="./${image}"><img src="./small.${image}"></a>
            % endfor
        </p>
    % endif
    
</body>
</html>