SciPy - download_all() Function



The method download_all is used to get all sample datasets used in SciPy documentation and tutorials. This guarantees that the datasets may be used offline, allowing users to conveniently examine examples without requiring an internet connection.

This will be particularly beneficial for students, researchers, or professionals who want to learn or test codes in a distraction-free setting.

This eliminates the necessity of downloading datasets for each tutorial separately. Instead, it saves time and effort by providing a centralized method to access all required resources at once. For flexibility and accessibility, the downloaded datasets can be stored either in the normal SciPy dataset directory or in a custom directory.

Syntax

Following is the syntax of the SciPy download_all() method −

.download_all(path=None)

Parameters

This method has a single parameter −

  • path(Optional, string or Path object) − The directory to download the datasets to. If not provided, the datasets are saved in the default SciPy dataset directory.

Return Value

This method does not return any value. Datasets are only downloaded to the designated or default directory.

Example

Following is the basic example of download_all() method by using this method all of the SciPy example datasets are downloaded to a designated directory on your local computer −

from scipy.datasets import download_all

# Download all example datasets to a custom directory
download_all(path="my_datasets")

Before executing the above code, ensure the following prerequisites are met −

You need Python 3.8 or higher installed on your system. To verify the Python version, run the following command in command prompt.

python --version

When we run above command, it produces following result −

Python 3.10.11

Ensure, SciPy library is installed in your system. The download_all() function and the datasets module are available in SciPy since version 1.11.0. Install or update SciPy using −

pip install scipy --upgrade

Following is the output of the above command −

Successfully installed pip-24.3.1

You also need to install pooch library because, pooch was created to effectively fetch, download, and cache datasets, guaranteeing that files are only downloaded once and are used repeatedly across sessions.

pip install pooch

To check if the pooch is installed and it's version use the following command.

pip show pooch

Following is the output of the above command −

Name: pooch
Version: 1.8.2

Now to run the script save the file in .py format. Save the file with the name like download_datsets.py. Replace "my_datasets" in the code with the full path to a directory on your laptop where you want the datasets to be saved.

from scipy.datasets import download_all
from pathlib import Path

# Download datasets to the current working directory
download_all(path="my_datasets")
print("downloaded successfully")

Navigate to the directory where the script is saved use cd. For example −

cd /path/to/your/script/directory

Once you are in the correct directory, type to run the Python script.

python download_datasets.py

Following is the output of the above command −

downloaded successfully

This script will download the required datasets from SciPy's datasets module to the directory specified in this case "my_datasets". If you don't specify the directory, the datasets will be saved in the default directory where SciPy stores them.

scipy_reference.htm
Advertisements