|
| 1 | +How to use the E3SM Diagnostics Output Viewer |
| 2 | +============================================== |
| 3 | + |
| 4 | +In this guide, we will cover: |
| 5 | + |
| 6 | +- The basic framework of the E3SM Diagnostics Output Viewer consisting of indices, pages, groups, rows, and columns. |
| 7 | +- The process of `using the Output Viewer <https://github.com/E3SM-Project/e3sm_diags/blob/main/e3sm_diags/viewer/core_viewer.py>`__ (``CoreViewer``), including explanations and examples related to the relevant functions. |
| 8 | + |
| 9 | + |
| 10 | +The Output Viewer Framework |
| 11 | +--------------------------- |
| 12 | + |
| 13 | +The Output Viewer is a framework that allows for the visualization of files. |
| 14 | +The core API, ``CoreViewer``, wraps the `ESGF Output Viewer <https://github.com/ESGF/output_viewer>`__ |
| 15 | +package (``output_viewer``). It simplifies creating a working viewer specifically for |
| 16 | +the needs of E3SM Diagnostics. |
| 17 | + |
| 18 | +These files include output images from diagnostics, scripts used to run diagnostics, etc. |
| 19 | +It also provides a way to create an HTML file to easily view the results. |
| 20 | + |
| 21 | +Below is an example of a webpage created with the Output Viewer: |
| 22 | + |
| 23 | +.. figure:: _static/viewer_example.png |
| 24 | + :alt: Example of a webpage generated by the Output Viewer. |
| 25 | + |
| 26 | + Figure 1: An example of a webpage generated by the Output Viewer. |
| 27 | + |
| 28 | +The Output Viewer framework consists of five base components that are required for a |
| 29 | +working viewer: `indices, pages, groups, rows, and columns.` |
| 30 | + |
| 31 | +1. Indices |
| 32 | +~~~~~~~~~~ |
| 33 | + |
| 34 | +An index is what you see when you first go on the HTML page created from the Output Viewer. |
| 35 | + |
| 36 | +An index is consists of one or more pages. |
| 37 | +The index name is what appears on the top left hand corner. |
| 38 | + |
| 39 | +.. figure:: _static/viewer_index_page.png |
| 40 | + :alt: Index page of the Output Viewer |
| 41 | + |
| 42 | + Figure 2: The index is the first page one sees. All of the links below 'Output Sets' are individual pages. |
| 43 | + |
| 44 | +2. Pages |
| 45 | +~~~~~~~~ |
| 46 | + |
| 47 | +Pages are where the user can view the output. A page consists of at least one group. |
| 48 | + |
| 49 | +.. figure:: _static/viewer_page.png |
| 50 | + :alt: A page with two groups: 'Results of addition' and 'Results of subtraction' |
| 51 | + |
| 52 | + Figure 3: A page with two groups: 'Results of addition' and 'Results of subtraction'. |
| 53 | + |
| 54 | +The *Jump To* form item is used to jump between groups for really long pages. |
| 55 | + |
| 56 | + |
| 57 | +3. Groups |
| 58 | +~~~~~~~~~ |
| 59 | + |
| 60 | +A group consists of one or more rows. |
| 61 | + |
| 62 | +In Figure 3 above, we see that the page has two groups. |
| 63 | + |
| 64 | +4. Rows |
| 65 | +~~~~~~~ |
| 66 | + |
| 67 | +A row consists of one or more columns. Each row must have at least one column, which represents the name. |
| 68 | + |
| 69 | +The first group in Figure 3 has two rows, while the second group has a single row. All rows in the figure have three columns. |
| 70 | + |
| 71 | +5. Columns |
| 72 | +~~~~~~~~~~ |
| 73 | + |
| 74 | +Columns are the most granular component of the viewer. |
| 75 | + |
| 76 | +You can add columns that are strings or files, like the Description and Generated File columns respectively. |
| 77 | + |
| 78 | +Summary |
| 79 | +~~~~~~~ |
| 80 | + |
| 81 | +To create a viewer with the Output Viewer: |
| 82 | + |
| 83 | +- Have at least one index |
| 84 | +- An index must have at least one page |
| 85 | +- A page must have at least one group |
| 86 | +- A group must have at least one row |
| 87 | +- A row must have at least one column |
| 88 | + |
| 89 | +Using the Output Viewer |
| 90 | +----------------------- |
| 91 | + |
| 92 | +If the `OutputViewer` class is too abstract/limited, you can instead use the |
| 93 | +ESGF Output Viewer package directly (`import output_viewer`) to create your own viewer. |
| 94 | +Please be aware that there is no official documentation for the Output Viewer, so you will need refer to the `codebase <https://github.com/ESGF/output_viewer>`__ directly. |
| 95 | + |
| 96 | +The code below was used to create the figures above. |
| 97 | + |
| 98 | +.. note:: |
| 99 | + If you plan on running this example code, you'll need a file titled ``output.png`` in your current directory. |
| 100 | + |
| 101 | +.. code:: python |
| 102 | +
|
| 103 | + from e3sm_diags.viewer.core_viewer import OutputViewer |
| 104 | +
|
| 105 | + viewer = OutputViewer(index_name='My Cool Results') |
| 106 | + viewer.add_page("My Results", ['Description', 'Generated File']) |
| 107 | +
|
| 108 | + viewer.add_group('Results of addition') |
| 109 | + viewer.add_row('Result of 1 + 1') |
| 110 | + viewer.add_col('Some description for add') |
| 111 | + viewer.add_col('output.png', is_file=True) |
| 112 | + viewer.add_row('Another Result') |
| 113 | + viewer.add_col('Another description for add') |
| 114 | + viewer.add_col('output.png', is_file=True) |
| 115 | +
|
| 116 | + viewer.add_group('Results of subtraction') |
| 117 | + viewer.add_row('Some Result') |
| 118 | + viewer.add_col('Some description for sub') |
| 119 | + viewer.add_col('output.png', is_file=True) |
| 120 | +
|
| 121 | + viewer.generate_viewer() |
| 122 | +
|
| 123 | +
|
| 124 | +.. parsed-literal:: |
| 125 | +
|
| 126 | + Viewer HTML generated at /Users/shaheen2/github/cdp/jupyter/index.html. Would you like to open in a browser? y/[n]: y |
| 127 | +
|
| 128 | +
|
| 129 | +Functions of ``CoreViewer`` |
| 130 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 131 | + |
| 132 | +The ``CoreViewer`` five functions: |
| 133 | + |
| 134 | +- ``add_page(name, columns)`` - Add a page to the viewer's index |
| 135 | + |
| 136 | + - ``name`` (``str``) - the page's title |
| 137 | + - ``columns`` (``List[str]``) - list of strings for each column that will appear on the page. These columns will be the same for every group/row on the page |
| 138 | + |
| 139 | +- ``add_group(group_name)`` - Add a group to the page that was added via ``add_page()`` |
| 140 | + |
| 141 | + - ``group_name`` (``str``) - name of the group |
| 142 | + |
| 143 | +- ``add_row(name)`` - Add a row to the group that was added via ``add_group()`` |
| 144 | + |
| 145 | + - ``name`` (``str``) - name of the row |
| 146 | + |
| 147 | +- ``add_col(col, is_file=False, **kwargs)`` - Add a col to the current row, which was added via ``add_row()`` |
| 148 | + |
| 149 | + - ``col`` (``str``) - col value |
| 150 | + - ``is_file`` (``bool``) - if ``True``, then an ``OutputFile`` will be created with ``**kwargs`` |
| 151 | + - ``**kwargs`` - See the `Output Viewer API <https://github.com/ESGF/output_viewer/blob/master/output_viewer/index.py#L133/>`_ for more details about the ``kwargs`` values that can be passed in |
| 152 | + |
| 153 | +- ``generate_viewer()`` - Generate the webpage and notify the user if they want to view it |
| 154 | + |
| 155 | + - Note that the functions must be called in the order shown in the example |
| 156 | + - For example, calling ``add_group()`` will add a group to the last page that was called via ``add_page()`` |
0 commit comments