Skip to content

Commit

Permalink
Add missing load parameter to some example downloads (#6078)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkoyama010 committed May 14, 2024
1 parent 5057ff5 commit e6f31fd
Showing 1 changed file with 60 additions and 17 deletions.
77 changes: 60 additions & 17 deletions pyvista/examples/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -2642,12 +2642,18 @@ def download_kitchen(split=False, load=True): # pragma: no cover
return kitchen


def download_tetra_dc_mesh(): # pragma: no cover
def download_tetra_dc_mesh(load=True): # pragma: no cover
"""Download two meshes defining an electrical inverse problem.
This contains a high resolution forward modeled mesh and a coarse
inverse modeled mesh.
Parameters
----------
load : bool, default: True
Load the dataset after downloading it when ``True``. Set this
to ``False`` and only the filename will be returned.
Returns
-------
pyvista.MultiBlock
Expand All @@ -2666,7 +2672,7 @@ def download_tetra_dc_mesh(): # pragma: no cover
fwd.set_active_scalars('Resistivity(log10)-fwd')
inv = pyvista.read(file_from_files('mesh-inverse.vtu', fnames))
inv.set_active_scalars('Resistivity(log10)')
return pyvista.MultiBlock({'forward': fwd, 'inverse': inv})
return pyvista.MultiBlock({'forward': fwd, 'inverse': inv}) if load else fnames


def download_model_with_variance(load=True): # pragma: no cover
Expand Down Expand Up @@ -3113,9 +3119,15 @@ def download_vtk_logo(load=True): # pragma: no cover
return _download_and_read("vtk.png", texture=True, load=load)


def download_sky_box_cube_map(): # pragma: no cover
def download_sky_box_cube_map(load=True): # pragma: no cover
"""Download a skybox cube map texture.
Parameters
----------
load : bool, default: True
Load the dataset after downloading it when ``True``. Set this
to ``False`` and only the filename will be returned.
Returns
-------
pyvista.Texture
Expand All @@ -3140,10 +3152,10 @@ def download_sky_box_cube_map(): # pragma: no cover
for image in images:
download_file(image)

return pyvista.cubemap(str(FETCHER.path), prefix)
return pyvista.cubemap(str(FETCHER.path), prefix) if load else images


def download_cubemap_park(): # pragma: no cover
def download_cubemap_park(load=True): # pragma: no cover
"""Download a cubemap of a park.
Downloaded from http://www.humus.name/index.php?page=Textures
Expand All @@ -3154,6 +3166,12 @@ def download_cubemap_park(): # pragma: no cover
This work is licensed under a Creative Commons Attribution 3.0 Unported
License.
Parameters
----------
load : bool, default: True
Load the dataset after downloading it when ``True``. Set this
to ``False`` and only the filename will be returned.
Returns
-------
pyvista.Texture
Expand All @@ -3174,10 +3192,10 @@ def download_cubemap_park(): # pragma: no cover
"""
fnames = download_file('cubemap_park/cubemap_park.zip')
return pyvista.cubemap(os.path.dirname(fnames[0]))
return pyvista.cubemap(os.path.dirname(fnames[0])) if load else fnames


def download_cubemap_space_4k(): # pragma: no cover
def download_cubemap_space_4k(load=True): # pragma: no cover
"""Download the 4k space cubemap.
This cubemap was generated by downloading the 4k image from: `Deep Star
Expand All @@ -3188,6 +3206,12 @@ def download_cubemap_space_4k(): # pragma: no cover
<https://github.com/pyvista/vtk-data/tree/master/Data/cubemap_space#readme>`_
for more details.
Parameters
----------
load : bool, default: True
Load the dataset after downloading it when ``True``. Set this
to ``False`` and only the filename will be returned.
Returns
-------
pyvista.Texture
Expand All @@ -3211,10 +3235,10 @@ def download_cubemap_space_4k(): # pragma: no cover
"""
fnames = download_file('cubemap_space/4k.zip')
return pyvista.cubemap(os.path.dirname(fnames[0]))
return pyvista.cubemap(os.path.dirname(fnames[0])) if load else fnames


def download_cubemap_space_16k(): # pragma: no cover
def download_cubemap_space_16k(load=True): # pragma: no cover
"""Download the 16k space cubemap.
This cubemap was generated by downloading the 16k image from: `Deep Star
Expand All @@ -3225,6 +3249,12 @@ def download_cubemap_space_16k(): # pragma: no cover
<https://github.com/pyvista/vtk-data/tree/master/Data/cubemap_space#readme>`_ for
more details.
Parameters
----------
load : bool, default: True
Load the dataset after downloading it when ``True``. Set this
to ``False`` and only the filename will be returned.
Returns
-------
pyvista.Texture
Expand Down Expand Up @@ -3254,7 +3284,7 @@ def download_cubemap_space_16k(): # pragma: no cover
"""
fnames = download_file('cubemap_space/16k.zip')
return pyvista.cubemap(os.path.dirname(fnames[0]))
return pyvista.cubemap(os.path.dirname(fnames[0])) if load else fnames


def download_backward_facing_step(load=True): # pragma: no cover
Expand Down Expand Up @@ -3892,7 +3922,7 @@ def download_dual_sphere_animation(load=True): # pragma: no cover
return pyvista.PVDReader(filename).read()


def download_osmnx_graph(): # pragma: no cover
def download_osmnx_graph(load=True): # pragma: no cover
"""Load a simple street map from Open Street Map.
Generated from:
Expand All @@ -3908,6 +3938,12 @@ def download_osmnx_graph(): # pragma: no cover
... graph, open('osmnx_graph.p', 'wb')
... ) # doctest:+SKIP
Parameters
----------
load : bool, default: True
Load the dataset after downloading it when ``True``. Set this
to ``False`` and only the filename will be returned.
Returns
-------
networkx.classes.multidigraph.MultiDiGraph
Expand All @@ -3929,7 +3965,7 @@ def download_osmnx_graph(): # pragma: no cover
raise ImportError('Install `osmnx` to use this example')

filename = download_file('osmnx_graph.p')
return pickle.load(open(filename, 'rb'))
return pickle.load(open(filename, 'rb')) if load else filename


def download_cavity(load=True): # pragma: no cover
Expand Down Expand Up @@ -5292,11 +5328,17 @@ def download_sea_vase(load=True): # pragma: no cover
return filename


def download_dikhololo_night(): # pragma: no cover
def download_dikhololo_night(load=True): # pragma: no cover
"""Download and read the dikholo night hdr texture example.
Files hosted at https://polyhaven.com/
Parameters
----------
load : bool, default: True
Load the dataset after downloading it when ``True``. Set this
to ``False`` and only the filename will be returned.
Returns
-------
pyvista.Texture
Expand All @@ -5314,10 +5356,11 @@ def download_dikhololo_night(): # pragma: no cover
>>> pl.show()
"""
texture = _download_and_read('dikhololo_night_4k.hdr', texture=True)
texture.SetColorModeToDirectScalars()
texture.SetMipmap(True)
texture.SetInterpolate(True)
texture = _download_and_read('dikhololo_night_4k.hdr', texture=True, load=load)
if load:
texture.SetColorModeToDirectScalars()
texture.SetMipmap(True)
texture.SetInterpolate(True)
return texture


Expand Down

0 comments on commit e6f31fd

Please sign in to comment.