def test_js_dump(self): self.json_content[self.key] = self.value web = Webviz('title', theme='minimal') page = Page('pagetitle') page.add_content(self.json_content) web.add(page) tempdir = tempfile.mkdtemp() web.write_html(tempdir, overwrite=True, display=False)
def test_special_character_title(self): web = Webviz("øæåõ", theme='minimal') web.add(Page("øæå~")) web.add(Page("øæå~ÆÆÆAAAÅÅÅ")) folder = tempfile.mkdtemp() web.write_html(folder, overwrite=True, display=False) shutil.rmtree(folder)
def test_js_dump(self): self.json_content[self.key] = self.value web = Webviz('title', theme='minimal') page = Page('pagetitle') page.add_content(self.json_content) web.add(page) tempdir = tempfile.mkdtemp() web.write_html(tempdir, overwrite=True, display=False) js_deps = self.json_content.get_js_dep() path.isfile(path.join(tempdir, 'resources', 'js', js_deps[0].name))
def setUp(self): self.page = Page('test page') self.content = MagicMock(PageElement) self.css = '/path/to/file.css' self.content.get_css_dep.return_value = [self.css] self.js = '/path/to/file.js' self.content.get_js_dep.return_value = [self.js] self.json = 'json_store["123-456-789"] = "test_string"' self.json_content = MagicMock(JSONPageElement) self.json_content.dump_all_jsons.return_value = {'key': self.json} self.writer = MagicMock() self.writer.write_json = MagicMock()
def test_multiple_dumps(self): content1 = JSONContent() content2 = JSONContent() content1['data1'] = {'name': 'value'} content2['data2'] = {'name2': 'value2'} page1 = Page('1') page1.add_content(content1) page2 = Page('2') page2.add_content(content2) jsdeps1 = [x.name for x in page1.js_dep] jsdeps2 = [x.name for x in page2.js_dep] self.assertEqual(len(set(jsdeps1 + jsdeps2)), 3)
def test_multiple_dumps(self): content1 = JSONContent() content2 = JSONContent() content1['data1'] = {'name': 'value'} content2['data2'] = {'name2': 'value2'} page1 = Page('1') page1.add_content(content1) page2 = Page('2') page2.add_content(content2) content1.dump_all_jsons() content2.dump_all_jsons() e1 = page1.header_elements e2 = page2.header_elements self.assertEqual(len(e1.union(e2)), 3)
class TestPage(unittest.TestCase): def setUp(self): self.page = Page('test page') self.content = MagicMock(PageElement) self.css = '/path/to/file.css' self.content.get_css_dep.return_value = [self.css] self.js = '/path/to/file.js' self.content.get_js_dep.return_value = [self.js] self.json = 'json_store["123-456-789"] = "test_string"' self.json_content = MagicMock(JSONPageElement) self.json_content.dump_all_jsons.return_value = {'key': self.json} self.writer = MagicMock() self.writer.write_json = MagicMock() def tearDown(self): self.page = Page('test page') def test_add_non_content_raises(self): with self.assertRaises(ValueError): self.page.add_content('explodes') def test_add_content(self): self.page.add_content(self.content) self.assertIn(self.content, self.page.contents) def test_css_dep(self): self.page.add_content(self.content) css_deps = self.page.css_dep for css in self.content.get_css_dep(): self.assertIn(css, css_deps) def test_js_dep(self): self.page.add_content(self.content) js_deps = self.page.js_dep for js in self.content.get_js_dep(): self.assertIn(js, js_deps)
class TestPage(unittest.TestCase): def setUp(self): self.page = Page('test page') self.content = MockContent() def test_add_non_content_raises(self): with self.assertRaises(ValueError): self.page.add_content('explodes') def test_add_content(self): self.page.add_content(self.content) self.assertIn(self.content, self.page.contents) def test_dep(self): self.page.add_content(self.content) elements = self.page.header_elements for element in self.content.header_elements: self.assertIn(element, elements)
from webviz import Webviz, Page from webviz.page_elements import Histogram import pandas as pd import numpy as np web = Webviz('Histogram Example') page = Page('Histogram') normal = [x for x in np.random.normal(size=1000).tolist()] poisson = [x for x in np.random.poisson(10, 1000).tolist()] triangular = [x for x in np.random.triangular(0, 10, 20, 1000).tolist()] data = pd.DataFrame({ 'normal': normal, 'poisson': poisson, 'triangular': triangular }) page.add_content(Histogram(data, nbinsx=20)) web.add(page) web.write_html("./webviz_example", overwrite=True, display=False)
from webviz import Webviz, Page from webviz.page_elements import HeatMap import pandas as pd web = Webviz('Heat Map Example') page = Page('Heat Map') lines = pd.DataFrame( [[1, 20, 30, 50, 1], [20, 1, 60, 80, 30], [30, 60, 1, -10, 20]], columns=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'], index=['Morning', 'Afternoon', 'Evening'], ) page.add_content(HeatMap(lines)) web.add(page) web.write_html("./webviz_example", overwrite=True, display=False)
from webviz import Webviz, Page from webviz.page_elements import Plotly web = Webviz('Line Chart Example') page = Page('Line Chart') line1 = { 'x': [1, 2, 3, 4], 'y': [10, 15, 13, 17], 'type': 'scatter' } line2 = { 'x': [1, 2, 3, 4], 'y': [16, 5, 11, 9], 'type': 'scatter' } lines = [line1, line2] plot = Plotly(lines) plot.add_annotation(x=1, y=10, text='label') page.add_content(plot) web.add(page) web.write_html("./webviz_example", overwrite=True, display=False)
from webviz import Webviz, Page from webviz_default_theme import default_theme from six import iteritems web = Webviz('Icon example', theme='default') for name, _ in iteritems(default_theme.icons): web.add(Page(name, icon=name)) web.write_html("./webviz_example", overwrite=True, display=False)
def setUp(self): self.page = Page('test page') self.submenu = SubMenu('test page') self.webviz = Webviz('test portal', theme='minimal')
from webviz import Webviz, Page, SubMenu web = Webviz('Main title', theme='default') ex1 = Page('Example 1') ex2 = Page('Example 2') submenu1 = SubMenu('Menu 1') submenu2 = SubMenu('Menu 2') submenu1.add_page(ex1) submenu2.add_page(ex2) web.add(submenu1) web.add(submenu2) page3 = Page('Example 3') web.add(page3) web.write_html("./webviz_tutorial", overwrite=True, display=False)
from webviz import Webviz, Page from webviz.page_elements import LineChart import pandas as pd web = Webviz('Line Chart Example') page = Page('Line Chart') line1 = [10, 15, 13, 17] line2 = [16, 5, 11, 9] lines = pd.DataFrame({ 'line 1': line1, 'line 2': line2, 'line 3': line2, 'line 4': line2, 'line 5': line2, 'line 6': line2, }) page.add_content(LineChart(lines, check_box=True)) web.add(page) web.write_html("./webviz_example", overwrite=True, display=False)
def setUp(self): self.page = Page('test page') self.content = MockContent()
def tearDown(self): self.page = Page('test page') self.sub_menu = SubMenu('test submenu')
from webviz import Webviz, Page from webviz.page_elements import TornadoPlot import pandas as pd web = Webviz('Tornado Plot Example') page = Page('Tornado Plot') high = [0.8, 1, 0.3, 0.4] low = [0.5, -0.7, -.5, -0.1] index = ['A', 'B', 'C', 'D'] bars = pd.DataFrame({'low': low, 'high': high}, index=index) plot = TornadoPlot(bars) plot.add_annotation(x=low[1], y=index[1], ay=0, ax=-20, text='label') page.add_content(plot) web.add(page) web.write_html("./webviz_example", overwrite=True, display=False)
def setUp(self): self.page = Page('test page') self.sub_menu = SubMenu('test submenu')
from webviz import Webviz, Page from webviz_scatter_plot import ScatterPlot import pandas as pd web = Webviz('Scatter Plot Example') page = Page('Scatter Plot') point1 = [10, 15, 13, 17], point2 = [16, 5, 11, 9] points = pd.DataFrame([point1, point2]) page.add_content(ScatterPlot(points)) web.add(page) web.write_html("./webviz_example", overwrite=True, display=False)
from webviz import Webviz, Page, SubMenu web = Webviz('Title', theme='default') page = Page('Page') menu = SubMenu('Menu') menu.add_page(page) web.add(menu) web.write_html("./webviz_example", overwrite=True, display=False)
from webviz import Webviz, Page from webviz.page_elements import FanChart import pandas as pd web = Webviz('Fan Chart Example') page = Page('Fan Chart') index = ['2012-01-01', '2012-01-02', '2012-01-03', '2012-01-04'] name = ['line-1', 'line-1', 'line-1', 'line-1'] mean = [10, 15, 13, 17] p10 = [11, 16, 13, 18] p90 = [9, 14, 12, 16] areaMax = [16, 17, 16, 19] areaMin = [4, 1, 9, 8] lines = pd.DataFrame({ 'index': index, 'name': name, 'mean': mean, 'p10': p10, 'p90': p90, 'max': areaMax, 'min': areaMin })
def add_webviz_tornadoplots(web, configfile): """ Generating a set of TornadoPlots for webviz on webviz Pages Args: web: webportal where submenu should be added configfile(str): yaml configuration file for tornado calculations Returns: object: Set of webviz.Pages with tornado plots Example: >>> from fmu.tools.sensitivities import add_webviz_tornadoplots >>> from webviz import Webviz >>> html_foldername = './webportal_example' >>> title = 'Snorreberg' >>> web = Webviz(title) >>> configfile ='../input/config/config_filename.yaml' >>> add_webviz_tornadoplots(web, configfile) >>> web.write_html(html_foldername, overwrite=True, display=True) """ if not HAS_WEBVIZ_STATIC: print("ERROR: Cannot make Tornado plots without Webviz static") return None print(WEBVIZ_STATIC_DEPRECIATION_WARNING) yamlfile = configfile # input inputfile = yconfig(yamlfile) config = yconfig_set_defaults(inputfile) # assign parameters from config designpath = config["design"]["designpath"] designname = config["design"]["designname"] designsheet = config["design"]["designsheet"] response = config["calculations"]["responses"] selections = OrderedDict(config["calculations"]["selections"]) selectors = selections.keys() reference = str(config["tornadooptions"]["reference"]) scale = config["tornadooptions"]["scale"] cutbyref = config["tornadooptions"]["cutbyref"] menuprefix = config["calculations"]["menuprefix"] # Option: results from single realisation csv files needs gathering first if config["results"]["gatherresults"]: results = gatherresults(config) # Default: concatenated result file already exists as csv if not config["results"]["gatherresults"]: resultpath = config["results"]["resultpath"] resultname = config["results"]["resultname"] resultfile = os.path.join(resultpath, resultname) results = pd.read_csv(resultfile) # Option: renaming of columns in resultfile, e.g. from CSV_EXPORT1 if config["results"]["renamecolumns"]: results.rename(columns=config["results"]["renaming"], inplace=True) # Read design matrix and find realisation numbers for each sensitivity designname = os.path.join(designpath, designname) designtable = summarize_design(designname, designsheet) print("Summary of design matrix:") with pd.option_context("expand_frame_repr", False): print(designtable) # Find all combinations of selections to generate plots for comb = find_combinations(selections) # Grouping calculation of tornado plots per response. # One list of plots under each response for res in response: smn = SubMenu(menuprefix + " " + res) for cmb in comb: pagetitle = res for ksel in range(len(selections)): pagetitle += " , " + str(selections.keys()[ksel]) pagetitle += " = " + str(cmb[ksel]).strip("[]") pge = Page(pagetitle) (tornadotable, ref_value) = calc_tornadoinput( designtable, results, res, selectors, cmb, reference, scale, cutbyref ) print("For response and selections: ") print(pagetitle) print("reference average: ", ref_value) print( "Calculation settings: ", scale, ", Cut by reference: ", cutbyref, ", Reference: ", reference, ) with pd.option_context("expand_frame_repr", False): print(tornadotable) print("\n") # While waiting for webviz issues 84 and 85 to be solved # xlabel = make_xlabel(ref_value, scale, reference) # tornado_plot = \ # tornado_plot = TornadoPlot(tornadotable, xlabel, pagetitle) tornado_plot = TornadoPlot(tornadotable) pge.add_content(tornado_plot) smn.add_page(pge) web.add(smn)
from webviz import Webviz, Page from webviz.page_elements import BarChart import pandas as pd web = Webviz('Bar Chart Example') page = Page('Bar Chart') bars1 = [10, 15, 13, 17] bars2 = [16, 5, 11, 9] bars = pd.DataFrame({'bars1': bars1, 'bars2': bars2}) page.add_content(BarChart(bars)) web.add(page) web.write_html("./webviz_example", overwrite=True, display=False)
from webviz import Webviz, Page import pandas as pd from webviz.page_elements import PieChart web = Webviz('Pie Chart Example') page = Page('Pie Chart') frame = pd.DataFrame([[19, 26, 55], [33, 14, 55]], columns=['sector 1', 'sector 2', 'sector 3']) page.add_content(PieChart(frame)) web.add(page) web.write_html("./webviz_example", overwrite=True, display=False)
from webviz import Webviz, Page from webviz.page_elements import ScatterPlotMatrix import pandas as pd web = Webviz('Scatter Plot Matrix Example') page = Page('Scatter Plot Matrix') point1 = [10.6, 15, 13.4, 17] point2 = [16, 5, 11, 9.7] point3 = [51, 25.6, 51, 23] point4 = [19, 75.1, 23, 49] name = ['name1', 'name1', 'name2', 'name2'] points = pd.DataFrame({ 'point1': point1, 'point2': point2, 'point3': point3, 'point4': point4, 'name': name }) page.add_content(ScatterPlotMatrix(points)) web.add(page) web.write_html("./webviz_example", overwrite=True, display=False)
from webviz import Webviz, Page from webviz.page_elements import LineChart import pandas as pd web = Webviz('Line Chart Example') page = Page('Line Chart') line1 = [10, 15, 13, 17] line2 = [16, 5, 11, 9] lines = pd.DataFrame({ 'line 1': line1, 'line 2': line2, 'line 3': line2, 'line 4': line2, 'line 5': line2, 'line 6': line2, }) page.add_content(LineChart(lines)) web.add(page) web.write_html("./webviz_example", overwrite=True, display=False)
def tearDown(self): self.page = Page('test page')
from webviz import Webviz, Page, SubMenu, Markdown web = Webviz('Main title', theme='minimal') ex1 = Page('Example 1') ex2 = Page('Example 2') ex3 = Page('Markdown example') some_content = (r""" # Markdown support *** > __You can pass markdown wihin a triple-quotes__<br> > _Also known as multiline comments_ |First Header | Second Header | Third Header | |:-------------|:-------------: | ------------:| |Content Cell | `Content Cell` | Content | |Content Cell | Content Cell | Content | --- #!python def hello(): print('Hello World') --- If you want to use math formulas, you have several different options. You can use double dollar signs: ```
from webviz import Webviz, Page from webviz.page_elements import Histogram import pandas as pd import numpy as np web = Webviz('Histogram Example') page = Page('Histogram') normal = [x for x in np.random.normal(size=1000).tolist()] poisson = [x for x in np.random.poisson(10, 1000).tolist()] triangular = [x for x in np.random.triangular(0, 10, 20, 1000).tolist()] data = pd.DataFrame({ 'normal': normal, 'poisson': poisson, 'triangular': triangular }) page.add_content(Histogram(data, xlabel='x-label', nbinsx=20)) web.add(page) web.write_html("./webviz_example", overwrite=True, display=False)