def test_abilab(self): """Testing abilab""" abilab.abiopen_ext2class_table() assert abilab.abifile_subclass_from_filename("GSR.nc") is not None assert len(abilab.dir2abifiles(top=abidata.dirpath)) assert len(abilab.dir2abifiles(top=abidata.dirpath, recurse=False)) == 1 with self.assertRaises(ValueError): abilab.abifile_subclass_from_filename("foobar") assert abilab.isabifile("foo_GSR.nc") assert not abilab.isabifile("foobar") import pandas df = pandas.DataFrame({"a": [1, 2], "b": [3, 4]}) abilab.print_dataframe(df, title="foo") d = abilab.software_stack() assert d assert not abilab.abicheck(verbose=1) abilab.abipy_logo1() abilab.abipy_logo2() abilab.abipy_logo3() assert not abilab.in_notebook() abilab.enable_notebook(with_seaborn=True) assert abilab.in_notebook() abilab.disable_notebook() assert not abilab.in_notebook()
def test_abilab(self): """Testing abilab""" abilab.abiopen_ext2class_table() assert abilab.abifile_subclass_from_filename("GSR.nc") is not None assert len(abilab.dir2abifiles(top=abidata.dirpath)) assert len(abilab.dir2abifiles(top=abidata.dirpath, recurse=False)) == 1 with self.assertRaises(ValueError): abilab.abifile_subclass_from_filename("foobar") assert abilab.isabifile("foo_GSR.nc") assert not abilab.isabifile("foobar") import pandas df = pandas.DataFrame({"a": [1, 2], "b": [3, 4]}) abilab.print_dataframe(df, title="foo") d = abilab.software_stack() assert d assert not abilab.abicheck(verbose=1) abilab.abipy_logo1() abilab.abipy_logo2() abilab.abipy_logo3() assert not abilab.in_notebook() abilab.enable_notebook(with_seaborn=True) assert abilab.in_notebook() abilab.disable_notebook() assert not abilab.in_notebook()
def test_abilab(self): """Testing abilab""" abilab.abiopen_ext2class_table() assert abilab.abifile_subclass_from_filename("GSR.nc") is not None assert len(abilab.dir2abifiles(top=abidata.dirpath)) assert len(abilab.dir2abifiles(top=abidata.dirpath, recurse=False)) == 1 with self.assertRaises(ValueError): abilab.abifile_subclass_from_filename("foobar") assert abilab.isabifile("foo_GSR.nc") assert not abilab.isabifile("foobar") import pandas df = pandas.DataFrame({"a": [1, 2], "b": [3, 4]}) abilab.print_dataframe(df, title="foo") d = abilab.software_stack() assert d filepath = self.get_tmpname(text=True, suffix=".json") data = {"foo": "bar"} abilab.mjson_write(data, filepath, indent=4) data = abilab.mjson_load(filepath) assert data["foo"] == "bar" same_data = abilab.mjson_loads(json.dumps(data)) assert len(same_data) == len(data) assert same_data["foo"] == data["foo"] assert not abilab.abicheck(verbose=1) abilab.abipy_logo1() abilab.abipy_logo2() abilab.abipy_logo3() assert not abilab.in_notebook() abilab.enable_notebook(with_seaborn=True) assert abilab.in_notebook() abilab.disable_notebook() assert not abilab.in_notebook() assert abilab.install_config_files(workdir=self.mkdtemp()) == 0
def ipw_listdir(top=".", recurse=True, widget_type="dropdown"): # pragma: no cover """ Return an ipython widget listing all the files located within the directory ``top`` that can be inspected with :ref:`abiopen.py`. The user can select the file in the widget and print info on the corresponding file inside the notebook. Args: top: Initial directory. recurse: False to ignore directories within ``top``. widget_type: Specify the widget to create. Possible values in: ["tooglebuttons", "dropdown", "radiobuttons"] """ from abipy import abilab from IPython.display import display, clear_output import ipywidgets as ipw # Select the widget class from widget_type d = dict( tooglebuttons=ipw.ToggleButtons, dropdown=ipw.Dropdown, radiobuttons=ipw.RadioButtons, ) try: widget_class = d[widget_type] except KeyError: raise KeyError("Invalid `widget_type`: %s, Choose among: %s" % (widget_type, str(list(d.keys())))) def on_value_change(change): """Callback""" clear_output() path = change["new"] #print(change) with abilab.abiopen(path) as abifile: print(abifile) #display(abifile) # Get dict: dirname --> list_of_files supported by abiopen. dir2files = abilab.dir2abifiles(top, recurse=recurse) children = [] for dirname, files in dir2files.items(): w = widget_class(options=files, description="%s:" % dirname) # TODO: Should register the callback of "selected" but I didn't find the event type! w.observe(on_value_change, names='value', type="change") children.append(w) box = ipw.VBox(children=children) return display(box)
def ipw_listdir(top=".", recurse=True, widget_type="dropdown"): """ Return an ipython widget listing all the files located within the directory `top` that can be inspected with `abiopen`. The user can select the file in the widget and print info on the corresponding file inside the notebook. Args: top: Initial directory. recurse: False to ignore directories within `top`. widget_type: Specify the widget to create. Possible values in: ["tooglebuttons", "dropdown", "radiobuttons"] """ from abipy import abilab from IPython.display import display, clear_output import ipywidgets as ipw # Select the widget class from widget_type d = dict( tooglebuttons=ipw.ToggleButtons, dropdown=ipw.Dropdown, radiobuttons=ipw.RadioButtons, ) try: widget_class = d[widget_type] except KeyError: raise KeyError("Invalid `widget_type`: %s, Choose among: %s" % (widget_type, str(list(d.keys())))) def on_value_change(change): """Callback""" clear_output() path = change["new"] #print(change) with abilab.abiopen(path) as abifile: print(abifile) #display(abifile) # Get dict: dirname --> list_of_files supported by abiopen. dir2files = abilab.dir2abifiles(top, recurse=recurse) children = [] for dirname, files in dir2files.items(): w = widget_class(options=files, description="%s:" % dirname) # TODO: Should register the callback of "selected" but I didn't find the event type! w.observe(on_value_change, names='value', type="change") children.append(w) box = ipw.VBox(children=children) return display(box)
def test_abilab(self): """Testing abilab""" abilab.abiopen_ext2class_table() assert abilab.abifile_subclass_from_filename("GSR.nc") is not None assert len(abilab.dir2abifiles(top=abidata.dirpath)) with self.assertRaises(ValueError): abilab.abifile_subclass_from_filename("foobar") assert abilab.isabifile("foo_GSR.nc") assert not abilab.isabifile("foobar") d = abilab.software_stack() assert d assert not abilab.abicheck(verbose=1) abilab.abipy_logo1() abilab.abipy_logo2() abilab.abipy_logo3()