earthpy.io
File Input/Output utilities.
- class earthpy.io.Data(path=None)[source]
Bases:
object
Data storage and retrieval functionality for Earthlab.
An object of this class is available upon importing earthpy as
earthpy.data
that writes data files to the path:~/earth-analytics/data/
.- Parameters
path (string | None) – The path where data is stored. NOTE: this defaults to the directory
~/earth-analytics/data/
.
Examples
List datasets that are available for download, using default object:
>>> import earthpy as et >>> et.data Available Datasets: ['california-rim-fire', ...]
Specify a custom directory for data downloads:
>>> et.data.path = "." >>> et.data Available Datasets: ['california-rim-fire', ...]
- get_data(key=None, url=None, replace=False, verbose=True)[source]
Retrieve the data for a given week and return its path.
This will retrieve data from the internet if it isn’t already downloaded, otherwise it will only return a path to that dataset.
- Parameters
key (str) – The dataset to retrieve. Possible options can be found in
self.data_keys
. Note:key
andurl
are mutually exclusive.url (str) – A URL to fetch into the data directory. Use this for ad-hoc dataset downloads. Note:
key
andurl
are mutually exclusive.replace (bool) – Whether to replace the data for this key if it is already downloaded.
verbose (bool) – Whether to print verbose output while downloading files.
- Returns
path_data – The path to the downloaded data.
- Return type
str
Examples
Download a dataset using a key:
>>> et.data.get_data('california-rim-fire')
Or, download a dataset using a figshare URL:
>>> url = 'https://ndownloader.figshare.com/files/12395030' >>> et.data.get_data(url=url)
- earthpy.io.path_to_example(dataset)[source]
Construct a file path to an example dataset.
This file defines helper functions to access data files in this directory, to support examples. Adapted from the PySAL package.
- Parameters
dataset (string) – Name of a dataset to access (e.g., “epsg.json”, or “RGB.byte.tif”)
- Returns
- Return type
A file path (string) to the dataset
Example
>>> import earthpy.io as eio >>> eio.path_to_example('rmnp-dem.tif') '...rmnp-dem.tif'