def variable_set(name): var_sets = fn.read_json(os.path.join(os.path.dirname(__file__), 'ks_vars.json')) try: the_set = var_sets[name.lower()] return set(the_set) except KeyError as e: six.raise_from(argparse.ArgumentTypeError( 'Unknown variable set! Known sets are {}'.format( var_sets.keys() )), e)
def set_up(): global setup setup = functions.read_json(os.path.join(os.path.dirname(__file__), 'ismip.json')) for exp, size in [('ismip-hom-a', '005'), ('ismip-hom-c', '005'), ('ismip-hom-f', '000')]: recreate_file = os.path.join(livvkit.__path__[0], setup[exp]["data_dir"], setup[exp]['pattern'][0].replace('???', size)) setup[exp]['interp_points'] = \ np.genfromtxt(recreate_file, delimiter=',', missing_values='nan', usecols=(0,), unpack=True) if exp == 'ismip-hom-f': setup[exp]['interp_points'] = setup[exp]['interp_points']*100 - 50
def set_up(): global setup setup = functions.read_json(os.path.join(os.path.dirname(__file__), 'ismip.json')) for exp, size in [('ismip-hom-a', '005'), ('ismip-hom-c', '005'), ('ismip-hom-f', '000')]: recreate_file = os.path.join(livvkit.__path__[0], setup[exp]["data_dir"], setup[exp]['pattern'][0].replace('???', size)) setup[exp]['interp_points'] = \ np.genfromtxt(recreate_file, delimiter=',', missing_values='nan', usecols=(0), unpack=True) if exp == 'ismip-hom-f': setup[exp]['interp_points'] = setup[exp]['interp_points']*100 - 50
def test_fn_read_write_json(tmpdir): j_path = tmpdir.join('fn_read_write_json.json') truth = OrderedDict([("ismip-hom-a", OrderedDict([("x", [0.0, 1.0]), ("y", [0.25, 0.25]), ("pattern", ["ExpA_Fig5_???.txt"]), ("xlabel", ["Normalized x"]), ("ylabel", ["Velocity (m/a)"]), ("data_dir", "data/numerics/ismip-hom") ]))]) functions.write_json(truth, j_path.dirname, j_path.basename) test = functions.read_json(str(j_path)) assert test == truth
def main(): datadir = sys.argv[1] outdir = sys.argv[2] functions.mkdir_p(outdir) data_files = glob.glob(datadir + "/**/*.json", recursive=True) data_files = [datadir + '/verification/dome.json'] # data_files = [datadir + '/index.json'] for each in data_files: data = functions.read_json(each) tex = th.translate_page(data) outfile = os.path.join(outdir, os.path.basename(each).replace('json', 'tex')) with open(outfile, 'w') as f: f.write(tex)
def test_fn_read_write_json(tmpdir): j_path = tmpdir.join('fn_read_write_json.json') truth = OrderedDict([("ismip-hom-a", OrderedDict([ ("x", [0.0, 1.0]), ("y", [0.25, 0.25]), ("pattern", ["ExpA_Fig5_???.txt"]), ("xlabel", ["Normalized x"]), ("ylabel", ["Velocity (m/a)"]), ("data_dir", "data/numerics/ismip-hom") ]))]) functions.write_json(truth, j_path.dirname, j_path.basename) test = functions.read_json(str(j_path)) assert test == truth
def main(): datadir = sys.argv[1] outdir = sys.argv[2] functions.mkdir_p(outdir) data_files = glob.glob(datadir + "/**/*.json", recursive=True) data_files = [datadir + '/verification/dome.json'] # data_files = [datadir + '/index.json'] for each in data_files: data = functions.read_json(each) tex = th.translate_page(data) outfile = os.path.join(outdir, os.path.basename(each).replace('json', 'tex')) with open(outfile, 'w') as f: f.write(tex)
def write_tex(): """ Finds all of the output data files, and writes them out to .tex """ datadir = livvkit.index_dir outdir = os.path.join(datadir, "tex") print(outdir) # functions.mkdir_p(outdir) data_files = glob.glob(datadir + "/**/*.json", recursive=True) for each in data_files: data = functions.read_json(each) tex = translate_page(data) outfile = os.path.join(outdir, os.path.basename(each).replace('json', 'tex')) with open(outfile, 'w') as f: f.write(tex)
# 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. from __future__ import absolute_import, division, print_function, unicode_literals import os import sys import glob from livvkit.util import TexHelper as th from livvkit.util import functions datadir = sys.argv[1] outdir = sys.argv[2] functions.mkdir_p(outdir) data_files = glob.glob(datadir + "/**/*.json", recursive=True) data_files = [datadir + '/verification/dome.json'] # data_files = [datadir + '/index.json'] for each in data_files: data = functions.read_json(each) tex = th.translate_page(data) outfile = os.path.join(outdir, os.path.basename(each).replace('json', 'tex')) with open(outfile, 'w') as f: f.write(tex)
def main(cl_args=None): """ Direct execution. """ if cl_args is None and len(sys.argv) > 1: cl_args = sys.argv[1:] args = parse_args(cl_args) print("--------------------------------------------------------------------") print(" ______ __ __ __ __ ") print(" | ____| \ \ / / \ \ / / ") print(" | |__ \ \ / / \ \ / / ") print(" | __| \ \/ / \ \/ / ") print(" | |____ \ / \ / ") print(" |______| \/ \/ ") print(" ") print(" Extended Verification and Validation for Earth System Models ") print("--------------------------------------------------------------------") print("") print(" Current run: " + livvkit.timestamp) print(" User: "******" OS Type: " + livvkit.os_type) print(" Machine: " + livvkit.machine) print(" " + livvkit.comment) from livvkit.components import validation from livvkit import scheduler from livvkit.util import functions from livvkit.util import elements if args.extensions: functions.setup_output(jsd=os.path.join(args.livv_resource_dir, 'js')) summary_elements = [] validation_config = {} print(" -----------------------------------------------------------------") print(" Beginning extensions test suite ") print(" -----------------------------------------------------------------") print("") for conf in livvkit.validation_model_configs: validation_config = functions.merge_dicts(validation_config, functions.read_json(conf)) summary_elements.extend(scheduler.run_quiet(validation, validation_config, group=False)) print(" -----------------------------------------------------------------") print(" Extensions test suite complete ") print(" -----------------------------------------------------------------") print("") result = elements.page("Summary", "", element_list=summary_elements) functions.write_json(result, livvkit.output_dir, "index.json") print("-------------------------------------------------------------------") print(" Done! Results can be seen in a web browser at:") print(" " + os.path.join(livvkit.output_dir, 'index.html')) print("-------------------------------------------------------------------") if args.serve: try: # Python 3 import http.server as server import socketserver as socket except ImportError: # Python 2 # noinspection PyPep8Naming import SimpleHTTPServer as server # noinspection PyPep8Naming import SocketServer as socket httpd = socket.TCPServer(('', args.serve), server.SimpleHTTPRequestHandler) sa = httpd.socket.getsockname() print('\nServing HTTP on {host} port {port} (http://{host}:{port}/)'.format(host=sa[0], port=sa[1])) print('\nView the generated website by navigating to:') print('\n http://{host}:{port}/{path}/index.html'.format(host=sa[0], port=sa[1], path=os.path.relpath(args.out_dir) )) print('\nExit by pressing `ctrl+c` to send a keyboard interrupt.\n') try: httpd.serve_forever() except KeyboardInterrupt: print('\nKeyboard interrupt received, exiting.\n') sys.exit(0)
def main(cl_args=None): """ Direct execution. """ if cl_args is None and len(sys.argv) > 1: cl_args = sys.argv[1:] args = options.parse_args(cl_args) print("-------------------------------------------------------------------") print(" __ _____ ___ ____ _ __ ") print(" / / / _/ | / / | / / /__ (_) /_ ") print(" / /___/ / | |/ /| |/ / '_// / __/ ") print(" /____/___/ |___/ |___/_/\_\/_/\__/ ") print("") print(" Land Ice Verification & Validation ") print("-------------------------------------------------------------------") print("") print(" Current run: " + livvkit.timestamp) print(" User: "******" OS Type: " + livvkit.os_type) print(" Machine: " + livvkit.machine) print(" " + livvkit.comment) from livvkit.components import numerics from livvkit.components import verification from livvkit.components import performance from livvkit.components import validation from livvkit import scheduler from livvkit.util import functions from livvkit.util import elements summary_elements = [] if livvkit.verify or livvkit.validate: functions.setup_output() if livvkit.verify: summary_elements.append(scheduler.run("numerics", numerics, functions.read_json(livvkit.numerics_model_config))) summary_elements.append(scheduler.run("verification", verification, functions.read_json(livvkit.verification_model_config))) summary_elements.append(scheduler.run("performance", performance, functions.read_json(livvkit.performance_model_config))) if livvkit.validate: print(" -----------------------------------------------------------------") print(" Beginning the validation test suite ") print(" -----------------------------------------------------------------") print("") validation_config = {} for conf in livvkit.validation_model_configs: validation_config = functions.merge_dicts(validation_config, functions.read_json(conf)) summary_elements.extend(scheduler.run_quiet(validation, validation_config, group=False)) print(" -----------------------------------------------------------------") print(" Validation test suite complete ") print(" -----------------------------------------------------------------") print("") if livvkit.verify or livvkit.validate: result = elements.page("Summary", "", element_list=summary_elements) functions.write_json(result, livvkit.output_dir, "index.json") print("-------------------------------------------------------------------") print(" Done! Results can be seen in a web browser at:") print(" " + os.path.join(livvkit.output_dir, 'index.html')) print("-------------------------------------------------------------------") if args.serve: try: # Python 3 import http.server as server import socketserver as socket except ImportError: # Python 2 # noinspection PyPep8Naming import SimpleHTTPServer as server # noinspection PyPep8Naming import SocketServer as socket httpd = socket.TCPServer(('', args.serve), server.SimpleHTTPRequestHandler) sa = httpd.socket.getsockname() print('\nServing HTTP on {host} port {port} (http://{host}:{port}/)'.format(host=sa[0], port=sa[1])) print('\nView the generated website by navigating to:') print('\n http://{host}:{port}/{path}/index.html'.format(host=sa[0], port=sa[1], path=os.path.relpath(livvkit.output_dir) )) print('\nExit by pressing `ctrl+c` to send a keyboard interrupt.\n') try: httpd.serve_forever() except KeyboardInterrupt: print('\nKeyboard interrupt received, exiting.\n') sys.exit(0)
def main(cl_args=None): """ Direct execution. """ if cl_args is None and len(sys.argv) > 1: cl_args = sys.argv[1:] args = options.parse_args(cl_args) print( "-------------------------------------------------------------------") print(" __ _____ ___ ____ _ __ ") print(" / / / _/ | / / | / / /__ (_) /_ ") print(" / /___/ / | |/ /| |/ / '_// / __/ ") print(" /____/___/ |___/ |___/_/\_\/_/\__/ ") print("") print(" Land Ice Verification & Validation ") print( "-------------------------------------------------------------------") print("") print(" Current run: " + livvkit.timestamp) print(" User: "******" OS Type: " + livvkit.os_type) print(" Machine: " + livvkit.machine) print(" " + livvkit.comment) from livvkit.components import numerics from livvkit.components import verification from livvkit.components import performance from livvkit.components import validation from livvkit import scheduler from livvkit.util import functions from livvkit.util import elements summary_elements = [] if livvkit.verify or livvkit.validate: functions.setup_output() if livvkit.verify: summary_elements.append( scheduler.run("numerics", numerics, functions.read_json(livvkit.numerics_model_config))) summary_elements.append( scheduler.run( "verification", verification, functions.read_json(livvkit.verification_model_config))) summary_elements.append( scheduler.run( "performance", performance, functions.read_json(livvkit.performance_model_config))) if livvkit.validate: print( " -----------------------------------------------------------------" ) print(" Beginning the validation test suite ") print( " -----------------------------------------------------------------" ) print("") validation_config = {} for conf in livvkit.validation_model_configs: validation_config = functions.merge_dicts( validation_config, functions.read_json(conf)) summary_elements.extend( scheduler.run_quiet(validation, validation_config, group=False)) print( " -----------------------------------------------------------------" ) print(" Validation test suite complete ") print( " -----------------------------------------------------------------" ) print("") if livvkit.verify or livvkit.validate: result = elements.page("Summary", "", element_list=summary_elements) functions.write_json(result, livvkit.output_dir, "index.json") print( "-------------------------------------------------------------------" ) print(" Done! Results can be seen in a web browser at:") print(" " + os.path.join(livvkit.output_dir, 'index.html')) print( "-------------------------------------------------------------------" ) if args.serve: try: # Python 3 import http.server as server import socketserver as socket except ImportError: # Python 2 # noinspection PyPep8Naming import SimpleHTTPServer as server # noinspection PyPep8Naming import SocketServer as socket httpd = socket.TCPServer(('', args.serve), server.SimpleHTTPRequestHandler) sa = httpd.socket.getsockname() print('\nServing HTTP on {host} port {port} (http://{host}:{port}/)'. format(host=sa[0], port=sa[1])) print('\nView the generated website by navigating to:') print('\n http://{host}:{port}/{path}/index.html'.format( host=sa[0], port=sa[1], path=os.path.relpath(livvkit.output_dir))) print('\nExit by pressing `ctrl+c` to send a keyboard interrupt.\n') try: httpd.serve_forever() except KeyboardInterrupt: print('\nKeyboard interrupt received, exiting.\n') sys.exit(0)