Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
gregreen committed Oct 5, 2020
2 parents e89bfe0 + eb1594f commit ca693f1
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 12 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The currently supported dust maps are:
8. Lenz, Hensley & Doré (2017)
9. Peek & Graves (2010)
10. Leike & Enßlin (2019)
11. Leike, Glatzle & Enßlin (2020)

To request addition of another dust map in this package, [file an issue on
GitHub](https://github.com/gregreen/dustmaps/issues), or submit a pull request.
Expand All @@ -47,8 +48,8 @@ To fetch the data for the SFD dust map, run:
python setup.py fetch --map-name=sfd

You can download the other dust maps by changing "sfd" to "planck", "bayestar",
"iphas", "marshall", "chen2014", "lenz2017", "pg2010", "leikeensslin2019"
or "bh".
"iphas", "marshall", "chen2014", "lenz2017", "pg2010", "leikeensslin2019",
"leike2020" or "bh".

Alternatively, if you have used `pip` to install `dustmaps`, then you can
configure the data directory and download the data by opening up a python
Expand Down Expand Up @@ -83,6 +84,9 @@ interpreter and running:
>>>
>>> import dustmaps.leike_ensslin_2019
>>> dustmaps.leike_ensslin_2019.fetch()
>>>
>>> import dustmaps.leike2020
>>> dustmaps.leike2020.fetch()


Querying the Maps
Expand Down
4 changes: 4 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ Start up a python interpreter and type:
import dustmaps.leike_ensslin_2019
dustmaps.leike_ensslin_2019.fetch()
import dustmaps.leike2020
dustmaps.leike2020.fetch()
All the dust maps should now be in the path you gave to
:code:`config['data_dir']`. Note that these dust maps can be very large - some
Expand Down Expand Up @@ -105,6 +108,7 @@ to only download those you think you'll need:
python setup.py fetch --map-name=chen2014
python setup.py fetch --map-name=lenz2017
python setup.py fetch --map-name=leikeensslin2019
python setup.py fetch --map-name=leike2020
That's it!

Expand Down
27 changes: 20 additions & 7 deletions docs/maps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ The units of reddening used by each map are slightly different:
should use the conversions provided in
`Table 6 of Schlafly & Finkbeiner (2011) <http://iopscience.iop.org/0004-637X/737/2/103/article#apj398709t6>`_.

* **References**: Green, Schlafly, Finkbeiner et al. (2019),
`Green, Schlafly, Finkbeiner et al. (2018) <http://adsabs.harvard.edu/abs/2018arXiv180103555G>`_,
`Green, Schlafly, Finkbeiner et al. (2015) <http://adsabs.harvard.edu/abs/2015arXiv150701005G>`_
* **References**: `Green, Schlafly, Finkbeiner et al. (2019) <https://ui.adsabs.harvard.edu/abs/2019ApJ...887...93G>`_,
`Green, Schlafly, Finkbeiner et al. (2018) <https://ui.adsabs.harvard.edu/abs/2018MNRAS.478..651G>`_
and `Green, Schlafly, Finkbeiner et al. (2015) <https://ui.adsabs.harvard.edu/abs/2015ApJ...810...25G>`_.
* **Website**: `argonaut.skymaps.info <http://argonaut.skymaps.info>`_


Expand Down Expand Up @@ -149,15 +149,28 @@ monochromatic extinction.
Leike & Enßlin (2019)
~~~~~~~~~~~~~~~~~~~~~~

A three-dimensional map of Milky Way dust extinction, based on the Gaia DR2 catalog
parallaxes and G-band extinctions, and incorporating a Gaussian process prior on
the dust extinction density. The map is calculated on a Cartesian grid, spanning
a (600 pc)³ box centered on the Sun.
A three-dimensional map of Milky Way dust extinction, incorporating a Gaussian
process prior on the dust extinction density. The map is based on the Gaia
DR2 catalog parallaxes and G-band extinctions, and spans a (600 pc)³ box
centered on the Sun.

* **Reference**: `Leike & Enßlin (2019) <https://ui.adsabs.harvard.edu/abs/2019arXiv190105971L/abstract>`_
* **Website**: `Zenodo <https://doi.org/10.5281/zenodo.2542807>`_


Leike, Glatzle & Enßlin (2020)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

A three-dimensional map of Milky Way dust extinction, incorporating a Gaussian
process prior on the dust extinction density, similar to Leike & Enßlin (2019).
The map is based on data from Gaia, 2MASS, Pan-STARRS 1 and ALLWISE, and is
calculated on a Cartesian grid spanning a (740 pc)×(740 pc)×(540 pc) box (in
Galactic *x*, *y* and *z*, respectively) centered on the Sun.

* **References**: `Leike, Glatzle & Enßlin (2020) <https://ui.adsabs.harvard.edu/abs/2020A%26A...639A.138L/abstract>`_
* **Website**: `Zenodo <https://doi.org/10.5281/zenodo.3993082>`_


Marshall et al. (2006)
~~~~~~~~~~~~~~~~~~~~~~

Expand Down
14 changes: 14 additions & 0 deletions docs/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ iphas (Sale et al. 2014)
:special-members:
:show-inheritance:

leike_ensslin_2019 (Leike & Enßlin 2019)
----------------------------------------
.. automodule:: dustmaps.leike_ensslin_2019
:members:
:special-members:
:show-inheritance:

leike2020 (Leike, Glatzle & Enßlin 2020)
----------------------------------------
.. automodule:: dustmaps.leike2020
:members:
:special-members:
:show-inheritance:

lenz2017 (Lenz, Hensley & Doré 2017)
------------------------------------
.. automodule:: dustmaps.lenz2017
Expand Down
154 changes: 154 additions & 0 deletions dustmaps/leike2020.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#!/usr/bin/env python
#
# leike2020.py
#
# The Leike, Glatzle & Ensslin (2020) dust map.
#
# Copyright (C) 2020 Gregory M. Green
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

from __future__ import print_function, division

import numpy as np
import h5py
import astropy.coordinates as coordinates
import astropy.units as units
from astropy.coordinates import Longitude

from .map_base import DustMap, ensure_flat_coords
from .std_paths import *
from . import fetch_utils


class Leike2020Query(DustMap):
"""
A class for querying the Leike, Glatzle & Ensslin (2020) dust map.
For details on how to use this map, see the original paper:
https://ui.adsabs.harvard.edu/abs/2020A%26A...639A.138L/abstract.
The data is deposited at Zenodo: https://doi.org/10.5281/zenodo.3993082.
"""

def __init__(self, map_fname=None):
"""
Args:
map_fname (Optional[str]): Filename of the map. Defaults
to :obj:`None`, meaning that the default location
is used.
"""

if map_fname is None:
map_fname = os.path.join(
data_dir(),
'leike_2020',
'mean_std.h5'
)

self._data = {}

with h5py.File(map_fname) as f:
self._data['mean'] = f['mean'][:]
self._data['std'] = f['std'][:]

self._xyz0 = (-370., -370., -270.) # Lower edge of map, in pc
self._shape = self._data['mean'].shape

def _coords2idx(self, coords):
c = coords.transform_to('galactic').represent_as('cartesian')

idx = np.empty((3,) + c.shape, dtype='i4')
mask = np.zeros(c.shape, dtype=np.bool)

for i,x in enumerate((c.x, c.y, c.z)):
idx[i,...] = np.floor(x.to('pc').value - self._xyz0[i])
mask |= (idx[i] < 0) | (idx[i] >= self._shape[i])

for i in range(3):
idx[i, mask] = -1

return idx, mask

@ensure_flat_coords
def query(self, coords, component='mean'):
"""
Returns the extinction density (in e-foldings / kpc, in Gaia G-band)
at the given coordinates.
Args:
coords (:obj:`astropy.coordinates.SkyCoord`): Coordinates at which
to query the extinction. Must be 3D (i.e., include distance
information).
component (str): Which component to return. Allowable values are
'mean' (for the mean extinction density) and 'std' (for the
standard deviation of extinction density). Defaults to 'mean'.
Returns:
The extinction density, in units of e-foldings / pc, as either a
numpy array or float, with the same shape as the input
:obj:`coords`.
"""
idx,mask = self._coords2idx(coords)

v = self._data[component][idx[0], idx[1], idx[2]]

if np.any(mask):
# Set extinction to NaN for out-of-bounds (x, y, z)
v[mask] = np.nan

return v


def fetch(clobber=False, fetch_samples=False):
"""
Downloads the 3D dust map of Leike & Ensslin (2020).
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.
fetch_samples (Optional[bool]): If ``True``, the samples will also be
downloaded. If ``False`` (the default), only the mean and standard
deviation will be downloaded. The samples take up 14 GB, which is
why the default is not to download them.
"""
dest_dir = fname_pattern = os.path.join(data_dir(), 'leike_2020')

file_spec = [
('mean_std.h5', '1ea998fdaef58f53da639356362223ba')
]
if fetch_samples:
file_spec += [
('samples.h5', '581f9ebc4775d37fd431fc6c0984dcf6')
]

for fn,md5sum in file_spec:
fname = os.path.join(dest_dir, fn)

# Check if the file already exists
if (not clobber) and fetch_utils.check_md5sum(fname, md5sum):
print('File "{}" appears to exist already. Call '.format(fn)+
'`fetch(clobber=True)` to force overwriting of existing '+
'file.')
continue

# Download from the server
url = 'https://zenodo.org/record/3993082/files/{}?download=1'.format(fn)
fetch_utils.download_and_verify(url, md5sum, fname)

11 changes: 8 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def fetch_leikeensslin2019():
import dustmaps.leike_ensslin_2019
dustmaps.leike_ensslin_2019.fetch()

def fetch_leike2020():
import dustmaps.leike2020
dustmaps.leike2020.fetch()

def fetch_lenz2017():
import dustmaps.lenz2017
dustmaps.lenz2017.fetch()
Expand Down Expand Up @@ -116,7 +120,8 @@ class FetchCommand(distutils.cmd.Command):
'chen2014': fetch_chen2014,
'lenz2017': fetch_lenz2017,
'pg2010': fetch_pg2010,
'leikeensslin2019': fetch_leikeensslin2019
'leikeensslin2019': fetch_leikeensslin2019,
'leike2020': fetch_leike2020
}

def initialize_options(self):
Expand All @@ -143,11 +148,11 @@ def readme():

setup(
name='dustmaps',
version='1.0.4',
version='1.0.5',
description='Uniform interface for multiple dust reddening maps.',
long_description=readme(),
url='https://github.com/gregreen/dustmaps',
download_url='https://github.com/gregreen/dustmaps/archive/v1.0.4.tar.gz',
download_url='https://github.com/gregreen/dustmaps/archive/v1.0.5.tar.gz',
author='Gregory M. Green',
author_email='[email protected]',
license='GPLv2',
Expand Down

0 comments on commit ca693f1

Please sign in to comment.