Skip to content
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 70 additions & 16 deletions dustmaps/sfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,43 +93,84 @@ def query(self, coords, order=1):

class SFDQuery(SFDBase):
"""
Queries the Schlegel, Finkbeiner & Davis (1998) dust reddening map.
Queries maps stored in the same format as Schlegel, Finkbeiner & Davis (1998) dust reddening map, providing results from the Schlegel, Finkbeiner & Davis (1998) dust map by default.
"""

map_name = 'sfd'
map_name_long = "SFD'98"

def __init__(self, map_dir=None):
def __init__(
self,
map_dir=None,
whichparent='SFD',
which='dust'
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we come up with more intuitive names for these keyword arguments? Maybe map_variant instead of whichparent, and component instead of which? Additionally, is it possible to infer whichparent from which? If so, then one option will suffice.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to make the variable name change. It is true that which is unique, and specifies whichparent, but I hadn't wanted to complicate things with the logic. The logic is fully specified by the docstring "Should be either dust (the default), i100, i60, mask, temp, or xmap with whichparent SFD. Should be Beta for whichparent Synch. Should be Rmap for whichparent FINK. Should be clean for whichparent Haslam" if you wanted to push that change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the logic issues come from a naming convention that Finkbeiner et al changed between the different whichparent files. There is a trailing _4096 for the whichparent SFD files, but none of the others

):
"""
Args:
map_dir (Optional[str]): The directory containing the SFD map.
Defaults to `None`, which means that `dustmaps` will look in its
default data directory.
whichparent (Optional[:obj:`str`]): The parent name of the SFD style data product to download.
Should be either ``SFD`` (the default), ``Synch``, ``FINK``, or ``Haslam``.
which (Optional[:obj:`str`]): The name of the SFD style data product to download.
Should be either ``dust`` (the default), ``i100``, ``i60``, ``mask``, ``temp``, or ``xmap`` with whichparent ``SFD``. Should be ``Beta`` for whichparent ``Synch``. Should be ``Rmap`` for whichparent ``FINK``. Should be ``clean`` for whichparent ``Haslam``.
"""

if map_dir is None:
map_dir = os.path.join(data_dir(), 'sfd')

base_fname = os.path.join(map_dir, 'SFD_dust_4096')
if (whichparent == 'SFD') and (which == 'dust' or which == 'i100' or which == 'i60' or which == 'mask'):
Comment thread
andrew-saydjari marked this conversation as resolved.
Outdated
base_fname = os.path.join(map_dir, '{}_{}_4096'.format(whichparent,which))
else:
base_fname = os.path.join(map_dir, '{}_{}'.format(whichparent,which))

super(SFDQuery, self).__init__(base_fname)
self.which = which
self.whichparent = whichparent

#FIXME force order to 0 if bit mask (check CFSD)
def query(self, coords, order=1):
"""
Returns E(B-V) at the specified location(s) on the sky. See Table 6 of
Schlafly & Finkbeiner (2011) for instructions on how to convert this
quantity to extinction in various passbands.
Returns value of SFD-style map defined by ``whichparent`` and ``which`` during the intialization of the `SFDQuery` object at the specified location(s) on the sky.

Defaults return E(B-V) at the specified location(s) on the sky. See Table 6 of Schlafly & Finkbeiner (2011) for instructions on how to convert this quantity to extinction in various passbands.

For whichparent ``SFD`` and which ``dust``, the map is the Schlegel, Finkbeiner & Davis (1998) dust reddening map (E(B-V)).

For whichparent ``SFD`` and which ``i100``, the map is the Schlegel, Finkbeiner & Davis (1998) 100 micron intensity map (MJy/sr).

For whichparent ``SFD`` and which ``i60``, the map is the Schlegel, Finkbeiner & Davis (1998) 60 micron intensity map (MJy/sr).

For whichparent ``SFD`` and which ``mask``, the map is the Schlegel, Finkbeiner & Davis (1998) bit mask map.
Bit 0, 1: The first two bits express (in binary) the number of HCONs (0, 1, 2, or 3)
Bit 2: Asteroid removed
Bit 3: Small no-data region replaced
Bit 4: Source removed (any)
Bit 5: No source removal
Bit 6: Large objects - LMC, SMC or M31
Bit 7: No IRAS data (excluded zone OR Saturn)

For whichparent ``SFD`` and which ``temp``, the map is the Schlegel, Finkbeiner & Davis (1998) dust temperature map (K).

For whichparent ``SFD`` and which ``xmap``, the map is the Schlegel, Finkbeiner & Davis (1998) X-factor map. This map contains a temperature correction factor derived from the 100mu/240mu ratio. Multiply the 100mu map by this factor to obtain temperature-corrected emission in regions that are expected to have an unusual dust temperature. In some cases (e.g. high Galactic latitude) this factor is poorly constrained and should be used with caution. The mean value for this quantity in "normal" parts of the sky is 1.

For whichparent ``FINK`` and which ``Rmap``, the map is the Finkbeiner-Davis-Schlegel (1999) DIRBE 100/240mu RATIO map. This map is described in "Extrapolation of Galactic Dust Emission at 100 Microns to CMBR Frequencies using FIRAS" by Finkbeiner, Davis, & Schlegel (1999). Please note that this 100/240mu R map differs from the R map described in Schlegel, Finkbeiner, & Davis, ApJ 500, 525 (1998).

For whichparent ``Haslam`` and which ``clean``, the map is an unpublished version of the Haslam et al. (1982) 408 MHz all-sky continuum survey, cleaned of bright sources (K). The map has bright point sources removed, and has been Fourier destriped using a method similar to that applied to the IRAS/ISSA data in Schlegel, Finkbeiner, & Davis 1998, Apj, 500, 525. Due to this reprocessing, the effective beam (PSF) of the map has increased from 0.85 deg to 1.0 deg. A CMB monopole (2.73K) has been subtracted from the map.

For whichparent ``Synch`` and which ``Beta``, the map is an unpublished work by Finkbeiner & Davis (1999) to derive a synchrotron spectral index map. This map is based on the 408 MHz Haslam et al. (1982) map, 1.42 GHz Reich & Reich (1986) map, and 2.326 GHz Jonas, Baart, & Nicolson (1998) map.

Args:
coords (`astropy.coordinates.SkyCoord`): The coordinates to query.
order (Optional[int]): Interpolation order to use. Defaults to `1`,
for linear interpolation.

Returns:
A float array containing the SFD E(B-V) at every input coordinate.
The shape of the output will be the same as the shape of the
A float array containing the values of SFD-style map at every input coordinate. The shape of the output will be the same as the shape of the
coordinates stored by `coords`.
"""
if self.which == "mask":
order = 0 # interpolating a mask is not allowed!
return super(SFDQuery, self).query(coords, order=order)


Expand All @@ -140,7 +181,8 @@ class SFDWebQuery(WebDustMap):

This query object does not require a local version of the data, but rather
an internet connection to contact the web API. The query functions have the
same inputs and outputs as their counterparts in ``SFDQuery``.
same inputs and outputs as their counterparts in ``SFDQuery``, but
are limited in keywords to the SFD dustmap.
"""

def __init__(self, api_url=None):
Expand All @@ -149,19 +191,31 @@ def __init__(self, api_url=None):
map_name='sfd')


def fetch():
def fetch(whichparent='SFD',which='dust'):
"""
Downloads the Schlegel, Finkbeiner & Davis (1998) dust map, placing it in
the data directory for `dustmap`.
Downloads maps in the format of the Schlegel, Finkbeiner & Davis (1998) dust map, placing them in the data directory for `dustmaps`. By default, it downloads the Schlegel, Finkbeiner & Davis (1998) dust map.

Args:
whichparent (Optional[:obj:`str`]): The parent name of the SFD style data product to download.
Should be either ``SFD`` (the default), ``Synch``, ``FINK``, or ``Haslam``.
which (Optional[:obj:`str`]): The name of the SFD style data product to download.
Should be either ``dust`` (the default), ``i100``, ``i60``, ``mask``, ``temp``, or ``xmap`` with whichparent ``SFD``. Should be ``Beta`` for whichparent ``Synch``. Should be ``Rmap`` for whichparent ``FINK``. Should be ``clean`` for whichparent ``Haslam``.
"""
doi = '10.7910/DVN/EWCNL5'

for pole in ['ngp', 'sgp']:
requirements = {'filename': 'SFD_dust_4096_{}.fits'.format(pole)}
local_fname = os.path.join(
if (whichparent == 'SFD') and (which == 'dust' or which == 'i100' or which == 'i60' or which == 'mask'):
requirements = {'filename': '{}_{}_4096_{}.fits'.format(whichparent,which,pole)}
local_fname = os.path.join(
data_dir(),
'sfd', '{}_{}_4096_{}.fits'.format(whichparent,which,pole))
else:
requirements = {'filename': '{}_{}_{}.fits'.format(whichparent,which,pole)}
local_fname = os.path.join(
data_dir(),
'sfd', 'SFD_dust_4096_{}.fits'.format(pole))
print('Downloading SFD data file to {}'.format(local_fname))
'sfd', '{}_{}_{}.fits'.format(whichparent,which,pole))

print('Downloading {} {} data file to {}'.format(whichparent,which,local_fname))
fetch_utils.dataverse_download_doi(
doi,
local_fname,
Expand Down