Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/example.py: 100%
12 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-04 09:52 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-04 09:52 +0000
1# http://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
6'''
7Example data download helpers.
8'''
10import os
11from pyrocko import util
12import logging
15logger = logging.getLogger('pyrocko.example')
18def get_example_data(filename, url=None, recursive=False):
19 '''
20 Download example data file needed in tutorials.
22 The file is downloaded to given ``filename``. If there already exists a
23 file with that name, nothing is done.
25 :param filename: name of the required file
26 :param url: if not ``None`` get file from given URL otherwise fetch it from
27 http://data.pyrocko.org/examples/<filename>.
28 :returns: ``filename``
29 '''
31 if not os.path.exists(filename):
32 url = 'http://data.pyrocko.org/examples/' + filename
33 if recursive:
34 util.download_dir(url, filename)
35 else:
36 util.download_file(url, filename)
38 return filename