Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
gregreen committed Aug 11, 2023
2 parents 7879317 + 9869457 commit 88a9bfc
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 9 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The currently supported dust maps are:
11. Leike & Enßlin (2019)
12. Leike, Glatzle & Enßlin (2020)
13. Edenhofer et al. (2023)
14. Chiang (2023; CSFD)

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 @@ -49,7 +50,7 @@ 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",
You can download the other dust maps by changing "sfd" to "csfd", "planck",
"planckGNILC", "bayestar", "iphas", "marshall", "chen2014", "lenz2017",
"pg2010", "leikeensslin2019", "leike2020", "edenhofer2023" or "bh".

Expand All @@ -63,6 +64,9 @@ interpreter and running:
>>> import dustmaps.sfd
>>> dustmaps.sfd.fetch()
>>>
>>> import dustmaps.csfd
>>> dustmaps.csfd.fetch()
>>>
>>> import dustmaps.planck
>>> dustmaps.planck.fetch()
>>>
Expand Down
8 changes: 6 additions & 2 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Start up a python interpreter and type:
import dustmaps.sfd
dustmaps.sfd.fetch()
import dustmaps.csfd
dustmaps.csfd.fetch()
import dustmaps.planck
dustmaps.planck.fetch()
Expand Down Expand Up @@ -55,10 +58,10 @@ Start up a python interpreter and type:
import dustmaps.leike2020
dustmaps.leike2020.fetch()
import dustmaps.edenhofer2023
dustmaps.edenhofer2023.fetch()
import dustmaps.gaia_tge
dustmaps.gaia_tge.fetch()
Expand Down Expand Up @@ -110,6 +113,7 @@ to only download those you think you'll need:
.. code-block :: bash
python setup.py fetch --map-name=sfd
python setup.py fetch --map-name=csfd
python setup.py fetch --map-name=planck
python setup.py fetch --map-name=planckGNILC
python setup.py fetch --map-name=bayestar
Expand Down
21 changes: 17 additions & 4 deletions docs/maps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ conversions provided in
* **Reference**: `Schlegel, Finkbeiner & Davis (1998) <http://adsabs.harvard.edu/abs/1998ApJ...500..525S>`_
* **Recalibration**: `Schlafly & Finkbeiner (2011) <http://adsabs.harvard.edu/abs/2011ApJ...737..103S>`_


CSFD (Chiang 2023)
~~~~~~~~~~~~~~~~~~

"Corrected SFD," a 2D dust map based on a reanalysis of SFD, using
tomographically constrained templates from WISE galaxy density fields to remove
extragalactic contamination from the cosmic infrared background (CIB).

* **Reference**: `Chiang (2023) <https://ui.adsabs.harvard.edu/abs/2023arXiv230603926C/abstract>`_
* **Website**: `Project description <https://idv.sinica.edu.tw/ykchiang/CSFD.html>`_
* **Data**: `Zenodo <https://doi.org/10.5281/zenodo.8207159>`_


Gaia Total Galactic Extinction (2022)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -173,8 +186,8 @@ estimates of Zhang, Green & Rix (2023), and therefore reports extinctions in
their units. Accompanying the main reconstruciton is an additional map that uses
less data but extends out to 2 kpc from the Sun.

* **Reference**: `Edenhofer et al. (2023) <https://arxiv.org/abs/2308.01295>`_
* **Website**: `Zenodo <https://doi.org/10.5281/zenodo.8187943>`_
* **Reference**: `Edenhofer et al. (2023) <https://ui.adsabs.harvard.edu/abs/2023arXiv230801295E/abstract>`_
* **Data**: `Zenodo <https://doi.org/10.5281/zenodo.8187943>`_


IPHAS
Expand All @@ -199,7 +212,7 @@ 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>`_
* **Data**: `Zenodo <https://doi.org/10.5281/zenodo.2542807>`_


Leike, Glatzle & Enßlin (2020)
Expand All @@ -213,7 +226,7 @@ ALLWISE, and is calculated on a Cartesian grid spanning a
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>`_
* **Data**: `Zenodo <https://doi.org/10.5281/zenodo.3993082>`_


Marshall et al. (2006)
Expand Down
7 changes: 7 additions & 0 deletions docs/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ chen2014 (Chen et al. 2014)
:special-members:
:show-inheritance:

csfd (Chiang 2023)
---------------------------
.. automodule:: dustmaps.csfd
:members:
:special-members:
:show-inheritance:

gaia_tge (Delchambre et al. 2022)
---------------------------
.. automodule:: dustmaps.gaia_tge
Expand Down
128 changes: 128 additions & 0 deletions dustmaps/csfd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/usr/bin/env python
#
# csfd.py
# Reads the "Corrected SFD" dust reddening map of Chiang (2023).
#
# Copyright (C) 2023 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 os
import numpy as np
import healpy as hp
import astropy.io.fits as fits
import astropy.units as units

from .std_paths import *
from .healpix_map import HEALPixQuery
from . import fetch_utils
from . import dustexceptions


class CSFDQuery(HEALPixQuery):
"""
Queries the Corrected SFD dust map of Chiang (2023). This map is based
on SFD, but contains a correction to remove contamination from
large-scale structure (i.e., external galaxies).
"""

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

if map_fname is None:
map_fname = os.path.join(data_dir(), 'csfd', 'csfd_ebv.fits')
if mask_fname is None:
mask_fname = os.path.join(data_dir(), 'csfd', 'mask.fits')

try:
with fits.open(map_fname) as hdulist:
ebv_data = hdulist['xtension'].data[:]['T'].flatten()
with fits.open(mask_fname) as hdulist:
mask_data = hdulist['xtension'].data[:]['T'].flatten()
except IOError as error:
print(dustexceptions.data_missing_message('csfd',
'CSFD (Chiang 2023)'))
raise error

super(CSFDQuery, self).__init__(ebv_data, False, 'galactic',
flags=mask_data)

def query(self, coords, **kwargs):
"""
Returns CSFD reddening on the same scale as SFD (similar to E(B-V)) at
the specified location(s) on the sky. Also optionally returns a
bit mask, where the bits (ordered from least to most significant) have
the following meanings::
Bit 0: 'LSS_corr' - This bit is set in the footprint within which
the LSS is reconstructed, and CSFD = SFD - LSS (otherwise
CSFD = SFD).
Bit 1: 'no_IRAS' - Set in the area with no IRAS data (DIRBE data
filled in SFD); LSS removal in CSFD is done using a 1 deg
smoothed LSS.
Bit 2: 'cosmology' - Set in the area where both the LSS and CSFD
are most reliable for precision cosmology analyses.
Args:
coords (:obj:`astropy.coordinates.SkyCoord`): The coordinates to
query.
return_flags (Optional[:obj:`bool`]): If ``True``, then a
bit mask is returned as well, indicating where CSFD
has been corrected for large-scale structure, where IRAS data
was used, and where the map is suitable for cosmology. See
above description of bits. Defaults to ``False``.
Returns:
A float array of the reddening, at the given coordinates. The
shape of the output is the same as the shape of the input
coordinate array, ``coords``. If ``return_flags`` is ``True``,
a second array (a bit mask) of the same shape is returned. See
above description of the meaning of each bit.
"""
return super(CSFDQuery, self).query(coords, **kwargs)


def fetch(clobber=False):
"""
Downloads the Corrected SFD dust map of Chiang (2023).
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.
"""
file_spec = [
('csfd_ebv.fits', '31cd2eec51bcb5f106af84a610ced53c'),
('mask.fits', '9142f5a5d184125836a68b6f48d1113f')
]
for fn,md5sum in file_spec:
fname = os.path.join(data_dir(), 'csfd', fn)
# Download from Zenodo
url = 'https://zenodo.org/record/8207175/files/{}'.format(fn)
fetch_utils.download_and_verify(url, md5sum, fname, clobber=clobber)

2 changes: 1 addition & 1 deletion dustmaps/leike2020.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def query(self, coords, component='mean'):
standard deviation of extinction density). Defaults to 'mean'.
Returns:
The extinction density, in units of e-foldings / pc, as either a
The extinction density, in units of e-foldings / kpc, as either a
numpy array or float, with the same shape as the input
:obj:`coords`.
"""
Expand Down
2 changes: 1 addition & 1 deletion dustmaps/leike_ensslin_2019.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def query(self, coords, component='mean'):
standard deviation of extinction density). Defaults to 'mean'.
Returns:
The extinction density, in units of e-foldings / pc, as either a
The extinction density, in units of e-foldings / kpc, as either a
numpy array or float, with the same shape as the input
:obj:`coords`.
"""
Expand Down
5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def fetch_sfd():
import dustmaps.sfd
dustmaps.sfd.fetch()

def fetch_csfd():
import dustmaps.csfd
dustmaps.csfd.fetch()

def fetch_planck():
import dustmaps.planck
dustmaps.planck.fetch()
Expand Down Expand Up @@ -121,6 +125,7 @@ class FetchCommand(distutils.cmd.Command):

map_funcs = {
'sfd': fetch_sfd,
'csfd': fetch_csfd,
'planck': fetch_planck,
'planckGNILC': fetch_planck_GNILC,
'bayestar': fetch_bayestar,
Expand Down

0 comments on commit 88a9bfc

Please sign in to comment.