sfdmap2


Namesfdmap2 JSON
Version 0.2.2.post2 PyPI version JSON
download
home_pagehttps://github.com/simeonreusch/sfdmap2
SummaryGet E(B-V) values from SFD dust map data
upload_time2024-04-30 09:22:38
maintainerSimeon Reusch
docs_urlNone
authorKyle Barbary
requires_python<4.0,>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # sfdmap2
This is a fork of [sfdmap](https://github.com/kbarbary/sfdmap), as the original repository is no longer maintained.

[![Build Status](https://github.com/ampelastro/sfdmap2/actions/workflows/continous_integration.yml/badge.svg)](https://github.com/ampelastro/sfdmap2/actions/workflows/continous_integration.yml)
[![Coverage Status](https://coveralls.io/repos/github/AmpelAstro/sfdmap2/badge.svg)](https://coveralls.io/github/AmpelAstro/sfdmap2)
[![PyPI](https://img.shields.io/pypi/v/sfdmap2.svg?style=flat-square)](https://pypi.python.org/pypi/sfdmap2)

A minimal, fast, MIT-licensed Python module for getting E(B-V) values from [Schlegel, Finkbeiner & Davis (1998)](http://adsabs.harvard.edu/abs/1998ApJ...500..525S) dust map FITS files.

```python
from sfdmap2 import sfdmap

m = sfdmap.SFDMap()

m.ebv(100., 40.)  # Get E(B-V) value at RA=100 degrees, Dec=40 degrees
0.10739716819557897
```

## Install

Requirements: numpy and a FITS reader (either fitsio or astropy).

```
pip install sfdmap2
```

The FITS files comprising the map must be downloaded separately. Among other locations, they are available from http://github.com/kbarbary/sfddata. On UNIX systems, run the following to download the maps (93 MB download size):

```
wget https://github.com/kbarbary/sfddata/archive/master.tar.gz
tar xzf master.tar.gz
```

A directory `sfddata-master` will be created. Move or rename as you like.

## Detailed Usage

#### Initialize map:

```python
from sfdmap2 import sfdmap

m = sfdmap.SFDMap('/path/to/dustmap/files')
m = sfdmap.SFDMap()  # get directory from SFD_DIR environment variable
```

By default, a scaling of 0.86 is applied to the map values to reflect the recalibration by Schlafly & Finkbeiner (2011). To get the original values, use `scaling=1.0` when constructing the map:

```python
m = sfdmap.SFDMap(scaling=1.0)
```

Get E(B-V) value at RA, Dec = 0., 0. (ICRS frame)

```python
m.ebv(0., 0.)
0.031814847141504288
```

Get E(B-V) at three locations (first argument is RA, second is Dec):

```python
m.ebv([0., 5., 10.], [0., 1.5, 2.1])
array([ 0.03181879,  0.02374864,  0.01746732])
```

By default the coordinates are assumed to be in degrees in the ICRS coordinate system (e.g., "J2000"). This can be changed with the `frame` and `unit` keywords:

```python
m.ebv(1.68140, -1.0504884, frame='galactic', unit='radian')
0.031820329230751863
```

The dust map values are linearly interpolated by default. Change this with the `interpolate` keyword:

```python
m.ebv(1.68140, -1.0504884, frame='galactic', unit='radian', interpolate=False)
0.031526423990726471
```


You can pass an astropy `SkyCoord` instance:

```python
from astropy.coordinates import SkyCoord

coords = SkyCoord([0., 5., 10.], [0., 1.5, 2.1], frame='icrs', unit='degree')

m.ebv(coords)
array([ 0.03181879,  0.02374864,  0.01746732])
```

Finally, there is a convenience function in the module so that you
don't have to construct a `SFDMap` instance if you just want to query
the map once:

```python
sfdmap.ebv(0., 0.)  # get map directory from SFD_DIR environment variable
0.031818788521008

sfdmap.ebv(0., 0., mapdir='/path/to/dust/files')
0.031818788521008
```

### How do I get extinction at a specific wavelength or in a specific filter?

The E(B-V) values from the map give information about the *amplitude* of dust extinction in a given direction. To get the extinction at a given wavelength or through a given filter, one needs information about the relative extinction between different wavelengths: an "extinction law". One can use the [extinction](http://extinction.readthedocs.io) package for this. For example, the following code gets the extinction in magnitudes at RA, Dec = (0., 0.) and wavelengths (4000, 5000):

```python
import extinction

ebv = m.ebv(0., 0.)

wave = np.array([4000., 5000.])

extinction.fitzpatrick99(wave, 3.1 * ebv)
array([ 0.12074424,  0.09513746])
```

To get the extinction in a given bandpass, one needs to know the source spectrum, as different wavelengths in the bandpass will have different extinction. With an assumed source spectrum, one would integrate the source spectrum with extinction applied through the bandpass and then compare to the unextincted spectrum integrated through the same bandpass. Some papers provide extinction values in a number of common bandpasses; these assume some source spectrum.


### Performance Note

Note that while passing an astropy `SkyCoord` object works, if you have coordinates in the ICRS or FK5 (epoch 2000) (e.g., J2000) systems, it is far faster to pass latitute and longitude directly. This is particularly true for small numbers of coordinates or scalar coordinates:

```python
from astropy.coordinates import SkyCoord

from sfdmap2 import sfdmap

m = sfdmap.SFDMap()

m.ebv(0., 0.)  # evaluate once to trigger reading the FITS file
0.03181878852100873

coord = SkyCoord(0., 0., unit='degree')

%timeit m.ebv(coord)  # time with SkyCoord object
100 loops, best of 3: 18.1 ms per loop

%timeit m.ebv(0., 0., unit='degree')  # pass ra, dec directly
10000 loops, best of 3: 80 µs per loop
```

## Alternatives

There are a couple other packages that support getting dust values from this map. Both these packages have a bigger scope than this one and include several other 2-d or 3-d galactic dust maps. Check them out if you want to compare between different maps or need 3-d maps. Below, I note a few relevant differences from this package.

#### [mwdust](http://github.com/jobovy/mwdust) [[docs](https://pypi.python.org/pypi/mwdust)]

`mwdust.SFD` gives the extinction in a given band rather than E(B-V). The API is geared towards 3-d maps, so a distance must be given. Python 3 is not currently supported. The license is BSD.

#### [dustmaps](http://github.com/gregreen) [[docs](http://dustmaps.readthedocs.io/en/latest/)]

`dustmaps.sfd.SFDQuery` uses astropy's SkyCoord for all coordinate conversions and therefore has suboptimal performance for small numbers of coordinates (see "Performance Note" above). The license is GPLv2.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/simeonreusch/sfdmap2",
    "name": "sfdmap2",
    "maintainer": "Simeon Reusch",
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": "simeon.reusch@desy.de",
    "keywords": null,
    "author": "Kyle Barbary",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/e4/63/e02b8f2da81de92a016a0bba7ff48029ff86e5bde9542df1c286a3c77e5e/sfdmap2-0.2.2.post2.tar.gz",
    "platform": null,
    "description": "# sfdmap2\nThis is a fork of [sfdmap](https://github.com/kbarbary/sfdmap), as the original repository is no longer maintained.\n\n[![Build Status](https://github.com/ampelastro/sfdmap2/actions/workflows/continous_integration.yml/badge.svg)](https://github.com/ampelastro/sfdmap2/actions/workflows/continous_integration.yml)\n[![Coverage Status](https://coveralls.io/repos/github/AmpelAstro/sfdmap2/badge.svg)](https://coveralls.io/github/AmpelAstro/sfdmap2)\n[![PyPI](https://img.shields.io/pypi/v/sfdmap2.svg?style=flat-square)](https://pypi.python.org/pypi/sfdmap2)\n\nA minimal, fast, MIT-licensed Python module for getting E(B-V) values from [Schlegel, Finkbeiner & Davis (1998)](http://adsabs.harvard.edu/abs/1998ApJ...500..525S) dust map FITS files.\n\n```python\nfrom sfdmap2 import sfdmap\n\nm = sfdmap.SFDMap()\n\nm.ebv(100., 40.)  # Get E(B-V) value at RA=100 degrees, Dec=40 degrees\n0.10739716819557897\n```\n\n## Install\n\nRequirements: numpy and a FITS reader (either fitsio or astropy).\n\n```\npip install sfdmap2\n```\n\nThe FITS files comprising the map must be downloaded separately. Among other locations, they are available from http://github.com/kbarbary/sfddata. On UNIX systems, run the following to download the maps (93 MB download size):\n\n```\nwget https://github.com/kbarbary/sfddata/archive/master.tar.gz\ntar xzf master.tar.gz\n```\n\nA directory `sfddata-master` will be created. Move or rename as you like.\n\n## Detailed Usage\n\n#### Initialize map:\n\n```python\nfrom sfdmap2 import sfdmap\n\nm = sfdmap.SFDMap('/path/to/dustmap/files')\nm = sfdmap.SFDMap()  # get directory from SFD_DIR environment variable\n```\n\nBy default, a scaling of 0.86 is applied to the map values to reflect the recalibration by Schlafly & Finkbeiner (2011). To get the original values, use `scaling=1.0` when constructing the map:\n\n```python\nm = sfdmap.SFDMap(scaling=1.0)\n```\n\nGet E(B-V) value at RA, Dec = 0., 0. (ICRS frame)\n\n```python\nm.ebv(0., 0.)\n0.031814847141504288\n```\n\nGet E(B-V) at three locations (first argument is RA, second is Dec):\n\n```python\nm.ebv([0., 5., 10.], [0., 1.5, 2.1])\narray([ 0.03181879,  0.02374864,  0.01746732])\n```\n\nBy default the coordinates are assumed to be in degrees in the ICRS coordinate system (e.g., \"J2000\"). This can be changed with the `frame` and `unit` keywords:\n\n```python\nm.ebv(1.68140, -1.0504884, frame='galactic', unit='radian')\n0.031820329230751863\n```\n\nThe dust map values are linearly interpolated by default. Change this with the `interpolate` keyword:\n\n```python\nm.ebv(1.68140, -1.0504884, frame='galactic', unit='radian', interpolate=False)\n0.031526423990726471\n```\n\n\nYou can pass an astropy `SkyCoord` instance:\n\n```python\nfrom astropy.coordinates import SkyCoord\n\ncoords = SkyCoord([0., 5., 10.], [0., 1.5, 2.1], frame='icrs', unit='degree')\n\nm.ebv(coords)\narray([ 0.03181879,  0.02374864,  0.01746732])\n```\n\nFinally, there is a convenience function in the module so that you\ndon't have to construct a `SFDMap` instance if you just want to query\nthe map once:\n\n```python\nsfdmap.ebv(0., 0.)  # get map directory from SFD_DIR environment variable\n0.031818788521008\n\nsfdmap.ebv(0., 0., mapdir='/path/to/dust/files')\n0.031818788521008\n```\n\n### How do I get extinction at a specific wavelength or in a specific filter?\n\nThe E(B-V) values from the map give information about the *amplitude* of dust extinction in a given direction. To get the extinction at a given wavelength or through a given filter, one needs information about the relative extinction between different wavelengths: an \"extinction law\". One can use the [extinction](http://extinction.readthedocs.io) package for this. For example, the following code gets the extinction in magnitudes at RA, Dec = (0., 0.) and wavelengths (4000, 5000):\n\n```python\nimport extinction\n\nebv = m.ebv(0., 0.)\n\nwave = np.array([4000., 5000.])\n\nextinction.fitzpatrick99(wave, 3.1 * ebv)\narray([ 0.12074424,  0.09513746])\n```\n\nTo get the extinction in a given bandpass, one needs to know the source spectrum, as different wavelengths in the bandpass will have different extinction. With an assumed source spectrum, one would integrate the source spectrum with extinction applied through the bandpass and then compare to the unextincted spectrum integrated through the same bandpass. Some papers provide extinction values in a number of common bandpasses; these assume some source spectrum.\n\n\n### Performance Note\n\nNote that while passing an astropy `SkyCoord` object works, if you have coordinates in the ICRS or FK5 (epoch 2000) (e.g., J2000) systems, it is far faster to pass latitute and longitude directly. This is particularly true for small numbers of coordinates or scalar coordinates:\n\n```python\nfrom astropy.coordinates import SkyCoord\n\nfrom sfdmap2 import sfdmap\n\nm = sfdmap.SFDMap()\n\nm.ebv(0., 0.)  # evaluate once to trigger reading the FITS file\n0.03181878852100873\n\ncoord = SkyCoord(0., 0., unit='degree')\n\n%timeit m.ebv(coord)  # time with SkyCoord object\n100 loops, best of 3: 18.1 ms per loop\n\n%timeit m.ebv(0., 0., unit='degree')  # pass ra, dec directly\n10000 loops, best of 3: 80 \u00b5s per loop\n```\n\n## Alternatives\n\nThere are a couple other packages that support getting dust values from this map. Both these packages have a bigger scope than this one and include several other 2-d or 3-d galactic dust maps. Check them out if you want to compare between different maps or need 3-d maps. Below, I note a few relevant differences from this package.\n\n#### [mwdust](http://github.com/jobovy/mwdust) [[docs](https://pypi.python.org/pypi/mwdust)]\n\n`mwdust.SFD` gives the extinction in a given band rather than E(B-V). The API is geared towards 3-d maps, so a distance must be given. Python 3 is not currently supported. The license is BSD.\n\n#### [dustmaps](http://github.com/gregreen) [[docs](http://dustmaps.readthedocs.io/en/latest/)]\n\n`dustmaps.sfd.SFDQuery` uses astropy's SkyCoord for all coordinate conversions and therefore has suboptimal performance for small numbers of coordinates (see \"Performance Note\" above). The license is GPLv2.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Get E(B-V) values from SFD dust map data",
    "version": "0.2.2.post2",
    "project_urls": {
        "Homepage": "https://github.com/simeonreusch/sfdmap2",
        "Repository": "https://github.com/simeonreusch/sfdmap2"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f9a3699da3632247dc154fcd836cd87ea03538e5c39cd20f40ccd4cc53d46b34",
                "md5": "22f6e489d841f2c3591ad115bf6ab972",
                "sha256": "2ec346a38820ccfd4b2e71545e6d13612e4319ba51f1c39ecfcd45a4115b78cd"
            },
            "downloads": -1,
            "filename": "sfdmap2-0.2.2.post2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "22f6e489d841f2c3591ad115bf6ab972",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 7901,
            "upload_time": "2024-04-30T09:22:37",
            "upload_time_iso_8601": "2024-04-30T09:22:37.226322Z",
            "url": "https://files.pythonhosted.org/packages/f9/a3/699da3632247dc154fcd836cd87ea03538e5c39cd20f40ccd4cc53d46b34/sfdmap2-0.2.2.post2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e463e02b8f2da81de92a016a0bba7ff48029ff86e5bde9542df1c286a3c77e5e",
                "md5": "1656d56a0cf6598a2bf49a2753bd1957",
                "sha256": "44bbe183412e1e18307d72dd1dc1b21a7d21f96bfd2aea22a79bc73602ae8149"
            },
            "downloads": -1,
            "filename": "sfdmap2-0.2.2.post2.tar.gz",
            "has_sig": false,
            "md5_digest": "1656d56a0cf6598a2bf49a2753bd1957",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 7412,
            "upload_time": "2024-04-30T09:22:38",
            "upload_time_iso_8601": "2024-04-30T09:22:38.751807Z",
            "url": "https://files.pythonhosted.org/packages/e4/63/e02b8f2da81de92a016a0bba7ff48029ff86e5bde9542df1c286a3c77e5e/sfdmap2-0.2.2.post2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-30 09:22:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "simeonreusch",
    "github_project": "sfdmap2",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "sfdmap2"
}
        
Elapsed time: 0.27667s