Downloads the IPHAS 3D dust map of Sale et al. (2014).

    Args:
        clobber (Optional[bool]): If ``True``, any existing file will be
            overwritten, even if it appears to match. If ``False`` (the
            default), ``fetch()`` will attempt to determine if the dataset
            already exists. This determination is not 100\% robust against data
            corruption.

def fetch(clobber=False):
    """
    Downloads the IPHAS 3D dust map of Sale et al. (2014).

    Args:
        clobber (Optional[bool]): If ``True``, any existing file will be
            overwritten, even if it appears to match. If ``False`` (the
            default), ``fetch()`` will attempt to determine if the dataset
            already exists. This determination is not 100\% robust against data
            corruption.
    """

    dest_dir = fname_pattern = os.path.join(data_dir(), 'iphas')
    url_pattern = 'http://www.iphas.org/data/extinction/A_samp_{:03d}.tar.gz'
    fname_pattern = os.path.join(dest_dir, 'A_samp_') + '{:03d}.tar.gz'

    # Check if file already exists
    if not clobber:
        h5_fname = os.path.join(dest_dir, 'iphas.h5')
        h5_size = 227817543 # Guess, in Bytes
        h5_dsets = {
            'samples': (61130,)
        }
        if fetch_utils.h5_file_exists(h5_fname, h5_size, dsets=h5_dsets):
            print('File appears to exist already. Call `fetch(clobber=True)` '
                  'to force overwriting of existing file.')
            return

    # Expected MD5 sums of .samp files
    file_md5sum = {
        30:  'dd531e397622bc97d4ff92b6c7863ade',
        40:  'b0f925eb3e46b77876e4054a26ad5b52',
        50:  'ea3b9500f0419d66dd92d9f9c127c2b5',
        60:  'cccf136f4e2306a6038e8093499216fd',
        70:  'a05fe2f815086686056c18087cc5410b',
        80:  '799bf618c8827b3d7250c884ec66ec49',
        90:  'd2a302d917da768bacf6ea74cb9dcfad',
        100: '2c75e31ad9320818556c4c9964b6af65',
        110: '742ea8de6f5f8a7e549f6c56b0088789',
        120: '9beabfa2c9634f953adadb5016eab072',
        130: '7cd7313f466eb60e8318d0f1bd32e035',
        140: 'fb6d09e4d939081b891e245c30b791f1',
        150: '8e9b6dc1561183aeadc64f41c85a64a8',
        160: '8a35828457b7b1d53d06998114553674',
        170: '7ffb29ec23e2f625dcfaaa84c293821d',
        180: 'c737da479d132b88483d6ddab5b25fc8',
        190: '9bc5fc7f7ba55f36a167473bb3679601',
        200: '7d8ffc4aa2f7c7026d8aa3ffb670d48e',
        210: 'e31b04964b7970b81fc90c120b4ebc24'
    }

    # Download the .samp files
    for key in file_md5sum:
        url = url_pattern.format(key)
        print('Downloading {}'.format(url))

        fetch_utils.download_and_verify(
            url,
            file_md5sum[key],
            fname_pattern.format(key))

    # Convert from ASCII to HDF5 format
    print('Repacking files...')
    ascii2h5(dest_dir, os.path.join(dest_dir, 'iphas.h5'))

    # Cleanup
    print('Removing original files...')
    for key in file_md5sum:
        os.remove(fname_pattern.format(key))