Commit ba4e50ae authored by Kennedy, Joseph H's avatar Kennedy, Joseph H
Browse files

Begin dynamics module for CISMA

parent bc057874
import pybtex.database
import pybtex.io
from pybtex.backends.html import Backend as BaseBackend
from pybtex.style.formatting.plain import Style as PlainStyle
class HTMLBackend(BaseBackend):
def __init__(self, *args, **kwargs):
super(HTMLBackend, self).__init__(*args, **kwargs)
self._html = ''
def output(self, html):
self._html += html
def format_protected(self, text):
if text[:4] == 'http':
return self.format_href(text, text)
else:
return r'<span class="bibtex-protected">{}</span>'.format(text)
def write_prologue(self):
self.output('<div class="bibliography"><dl>')
def write_epilogue(self):
self.output('</dl></div>')
def _repr_html(self, formatted_bibliography):
self.write_prologue()
for entry in formatted_bibliography:
self.write_entry(entry.key, entry.label, entry.text.render(self))
self.write_epilogue()
return self._html.replace('\n', ' ').replace('\\url <a', '<a')
def bib2html(bib_file):
style = PlainStyle()
backend = HTMLBackend()
bib = pybtex.database.parse_file(bib_file)
fbib = style.format_bibliography(bib)
return backend._repr_html(fbib)
@article {Kennedy2017,
AUTHOR = {Kennedy, Joseph H. and Bennett, Andrew R. and Evans, Katherine J. and Price, Stephen and Hoffman, Matthew and Lipscomb, William H. and Fyke, Jeremy and Vargo, Lauren and Boghozian, Adrianna and Norman, Matthew and Worley, Patrick H.},
TITLE = {LIVVkit: An extensible, python-based, land ice verification and validation toolkit for ice sheet models},
JOURNAL = {Journal of Advances in Modeling Earth Systems},
VOLUME = {9},
NUMBER = {2},
ISSN = {1942-2466},
DOI = {10.1002/2017MS000916},
PAGES = {854--869},
YEAR = {2017},
}
{
"dynamics_cisma" : {
"module" : "dynamics/dynamics_cisma.py",
"references" : "dynamics/dynamics_cisma.bib",
"image_height" : 300
}
}
# Copyright (c) 2015,2016, UT-BATTELLE, LLC
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""An analysis of CESM's cloud cover over Greenland."""
from __future__ import absolute_import, division, print_function, unicode_literals
import os
import livvkit
from livvkit.util import elements as el
from livvkit.util import functions as fn
with fn.temp_sys_path(os.path.dirname(__file__)):
import dynamics.utils as utils
import dynamics.cesm_cldhgh_ann as clouds_high
import dynamics.cesm_cldlow_ann as clouds_low
import dynamics.cesm_cldtot_ann as clouds_total
import dynamics.yearly_cycle_cldhgh as yrly_high
import dynamics.yearly_cycle_cldlow as yrly_low
import dynamics.yearly_cycle_cldtot as yrly_total
def run(name, config):
"""
Runs the extension.
Args:
name: The name of the extension
config: A dictionary representation of the configuration file
Returns:
A LIVVkit page element containing the LIVVkit elements to display on a webpage
"""
img_dir = os.path.join(livvkit.output_dir, 'validation', 'imgs', name)
fn.mkdir_p(img_dir)
# PLOTS
img_list = []
img_list.extend(clouds_high.make_plot(config, out_path=img_dir))
img_list.extend(clouds_low.make_plot(config, out_path=img_dir))
img_list.extend(clouds_total.make_plot(config, out_path=img_dir))
img_list.extend(yrly_high.make_plot(config, out_path=img_dir))
img_list.extend(yrly_low.make_plot(config, out_path=img_dir))
img_list.extend(yrly_total.make_plot(config, out_path=img_dir))
element_list = [el.gallery('Figures', img_list)]
ref_bib = utils.bib2html(config['references'])
element_list.append(el.html(' '.join(['<div class="references"><h3>References</h3>',
'If you use this LIVVkit extension for any part of your',
'modeling or analyses, please cite:' + ref_bib + '</div>',
])
))
return el.page(name, __doc__, element_list)
def print_summary(summary):
"""
Print out a summary generated by this module's summarize_result method
"""
raise NotImplementedError
def summarize_result(result):
"""
Provides a snapshot of the extension's results to be provided on the
summary webpage and printed to STDOUT via the print_summary method
"""
raise NotImplementedError
def populate_metadata():
"""
Generates the metadata needed for the output summary page
"""
raise NotImplementedError
channels:
- conda-forge
- defaults
dependencies:
- pybtex
- pyngl
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment