earthpy.io

File Input/Output utilities.

earthpy.io.ALLOWED_FILE_TYPES = ['file', 'tar', 'tar.gz', 'zip']
earthpy.io.DATA_NAME = 'earth-analytics/data'
earthpy.io.DATA_URLS = {'california-rim-fire': ('https://ndownloader.figshare.com/files/14419310', '.', 'zip'), 'co-flood-extras': [('https://ndownloader.figshare.com/files/7010681', 'boulder-precip.csv', 'file'), ('https://ndownloader.figshare.com/files/7010681', 'temperature_example.csv', 'file')], 'cold-springs-fire': ('https://ndownloader.figshare.com/files/10960109', '.', 'zip'), 'cold-springs-modis-h5': ('https://ndownloader.figshare.com/files/10960112', '.', 'zip'), 'colorado-flood': ('https://ndownloader.figshare.com/files/12395030', '.', 'zip'), 'cs-test-landsat': ('https://ndownloader.figshare.com/files/10960214?private_link=fbba903d00e1848b423e', '.', 'zip'), 'cs-test-naip': ('https://ndownloader.figshare.com/files/10960211?private_link=18f892d9f3645344b2fe', '.', 'zip'), 'ndvi-automation': ('https://ndownloader.figshare.com/files/13431344', '.', 'zip'), 'spatial-vector-lidar': ('https://ndownloader.figshare.com/files/12459464', '.', 'zip'), 'twitter-flood': ('https://ndownloader.figshare.com/files/10960175', '.', 'zip'), 'vignette-elevation': ('https://ndownloader.figshare.com/articles/8259098/versions/2', '.', 'zip'), 'vignette-landsat': ('https://ndownloader.figshare.com/files/15197339', '.', 'zip')}
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 and url are mutually exclusive.

  • url (str) – A URL to fetch into the data directory. Use this for ad-hoc dataset downloads. Note: key and url 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') # doctest: +SKIP

Or, download a dataset using a figshare URL:

>>> url = 'https://ndownloader.figshare.com/files/12395030'
>>> et.data.get_data(url=url)  # doctest: +SKIP
earthpy.io.HOME = '/home/docs'
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'