Beispiel #1
0
def make_doc_notebooks(notebooks):
    src_path = os.path.dirname(__file__) + "/elements/"
    dst_path = os.path.dirname(__file__) + "/../docs/notebooks/"
    if os.path.isdir(dst_path):
        try:
            shutil.rmtree(dst_path)

        except PermissionError:
            pass
    os.makedirs(dst_path, exist_ok=True)
    for name in notebooks:
        nb = Notebook(src_path + name + ".ipynb")
        t = '[Try this yourself](https://colab.research.google.com/github/DTUWindEnergy/PyWake/blob/master/docs/notebooks/%s.ipynb) (requires google account)'
        nb.insert_markdown_cell(1, t % name)
        code = """%%capture
# Install PyWake if needed
try:
    import py_wake
except ModuleNotFoundError:
    !pip install py_wake"""
        nb.insert_code_cell(2, code)
        #cells = nb.cells

        #cells = cells[:1] + doc_header(name) + cells[1:]
        #nb['cells'] = cells
        nb.save(dst_path + name + ".ipynb")
Beispiel #2
0
def check_notebooks():
    import matplotlib.pyplot as plt

    def no_show(*args, **kwargs):
        pass
    plt.show = no_show  # disable plt show that requires the user to close the plot

    path = os.path.dirname(__file__) + "/elements/"
    for f in [f for f in os.listdir(path) if f.endswith('.ipynb')]:
        nb = Notebook(path + f)
        nb.check_code()
        nb.check_links()
def make_doc_notebooks(notebooks):
    src_path = os.path.dirname(__file__) + "/elements/"
    dst_path = os.path.dirname(__file__) + "/../docs/notebooks/"
    if os.path.isdir(dst_path):
        try:
            shutil.rmtree(dst_path)

        except PermissionError:
            pass
    os.makedirs(dst_path, exist_ok=True)
    for name in notebooks:
        nb = Notebook(src_path + name + ".ipynb")
        t = '[Try this yourself](https://colab.research.google.com/github/DTUWindEnergy/TopFarm2/blob/master/docs/notebooks/%s.ipynb) (requires google account)'
        nb.insert_markdown_cell(1, t % name)
        code = """%%capture
# Install Topfarm if needed
import importlib
if not importlib.util.find_spec("topfarm"):
    !pip install topfarm
"""
        if not name in ['loads', 'wake_steering_and_loads', 'layout_and_loads']:
            nb.insert_code_cell(2, code)
        nb.save(dst_path + name + ".ipynb")
def doc_header(name):
    nb = Notebook(os.path.dirname(__file__) + "/elements/doc_setup.ipynb")
    nb.cells[0]['source'][0] = nb.cells[0]['source'][0].replace('[name]', name)
    return nb.cells
def make_tutorials():
    path = os.path.dirname(__file__) + "/templates/"
    for f in [f for f in os.listdir(path) if f.endswith('.ipynb')]:
        nb = Notebook(path + f)
        nb.replace_include_tag()
        nb.save(os.path.dirname(__file__) + "/../tutorials/" + f)
Beispiel #6
0
def get_notebooks():
    path = os.path.dirname(py_wake.__file__) + "/../_notebooks/elements/"
    return [
        Notebook(path + f)
        for f in [f for f in os.listdir(path) if f.endswith('.ipynb')]
    ]