Name | bbf JSON |
Version |
0.5.2
JSON |
| download |
home_page | None |
Summary | Fast computation of broadband fluxes and magnitudes |
upload_time | 2024-10-22 13:58:13 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | MIT License Copyright (c) 2024 Nicolas Regnault Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
astronomy
astrophysics
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Broadband fluxes (`bbf`)
[![PyPI - Version](https://img.shields.io/pypi/v/bbf.svg)](https://pypi.org/project/bbf)
[![Conda Version](https://img.shields.io/conda/vn/conda-forge/bbf.svg)](https://anaconda.org/conda-forge/bbf)
[![Conda Platforms](https://img.shields.io/conda/pn/conda-forge/bbf.svg)](https://anaconda.org/conda-forge/bbf)
-----
**Table of contents**
- [Installation](#installation)
- [Getting started](#getting started)
- [License](#license)
A module to evaluate the broadband fluxes and magnitudes of spectrophotometric
standards.
# Installation
The `bbf` package works on `python>=3.9<3.13` for Linux and macos. It should
work on Windows too, but it has not been tested.
| :warning: `bbf` relies for the moment on a [modified version of `sncosmo`](https://github.com/nregnault/sncosmo) that must be installed separatly |
|---|
## Install using conda (recommended)
```bash
conda install -c conda-forge bbf
pip install git+https://github.com/nregnault/sncosmo
```
## Install using pip
* Installing `bbf` from `pip` requires to install
[SuiteSparse](http://www.suitesparse.com) which is not installable from `pip`.
On Debian/Ubuntu systems, the command `sudo apt install libsuitesparse-dev`
suffices. Or you can compile `SuiteSparse` from
[sources](https://github.com/DrTimothyAldenDavis/SuiteSparse). Or a simpler
alternative is to install `scikit-sparse` from `conda`:
```bash
conda install -c conda-forge scikit-sparse
```
* `cmake` and a C++ compiler with `OpenMP` support are required. On Linux, `gcc`
supports `OpenMP` out of the box, and `cmake` is installed as needed during
`bbf` installation. On macos an extra installation is required:
```bash
# for macos only
conda install cmake llvm-openmp
```
* `sncosmo` fork must be installed separatly with:
```bash
pip install bbf git+https://github.com/nregnault/sncosmo
```
* Finally install `bbf`:
```bash
pip install bbf
```
## Install from sources
* If you prefer installing from sources, ensure **git lfs** is installed (have a
`git lfs`, if the command is missing install it with `conda install git-lfs;
git lfs install`).
* Then follow the steps from the [Install using pip](#install using pip)
section, and replace the last step with:
```bash
git clone clone git@gitlab.in2p3.fr:lemaitre/bbf.git
cd bbf
pip install -e .
```
* To run the tests suite, install the required dependencies, then run `pytest`:
```bash
pip install -e .[test]
pytest
```
* If you are a developper and want to work on the `bbf` C/C++ extension,
insall the package with:
```bash
pip install nanobind ninja scikit-build-core[pyproject]
VERBOSE=1 pip install --no-build-isolation -Ceditable.rebuild=true -ve .
```
## Installing the Lemaitre bandpasses
If you plan to use the latest version of the megacam6*, *ztf* and *hsc*
passbands, install the `lemaitre.bandpasses` package:
```bash
pip install lemaitre-bandpasses
```
or
```bash
git clone https://gitlab.in2p3.fr/lemaitre/lemaitre/bandpasses
cd bandpasses
git lfs pull
pip install .
```
# Getting started
The goal of `bbf` is to efficiently compute broadband fluxes and magnitudes,
i.e. quantities of the form:
$$f_{xys} = \int S(\lambda) \lambda T_{xys}(\lambda) d\lambda$$
where $\lambda$ is the SED of an object, $T_{xyz}(\lambda)$ is the bandpass of
the instrument used to observe it. $T$ may depend on the focal plane position of
the object and, if the focal plane is a mosaic of sensors, on the specific
sensor $s$ where the observation is made. In practice, $x,y$ are coordinates, in
pixels, in the sensor frame, and $s$ is a unique sensor index (or amplifier
index).
Computing magnitudes requires an additional ingredient: the flux of a reference
spectrum $S_{ref}(\lambda)$, usually the AB spectrum, integrated in the same
passband (same sensor, same position).
$$m = -2.5 \log_{10} \left(\frac{\int S(\lambda) \lambda T_{xyz}(\lambda) d\lambda}{\int S_{ref}(\lambda) \lambda T_{xyz}(\lambda) d\lambda}\right)$$
To compute these integrales, `bbf` uses the technique implemented in `nacl`,
which consists in projecting the bandpasses and SED on spline bases:
$$S(\lambda) = \sum_i \theta_i {\cal B}_i(\lambda)$$
and
$$T(\lambda) = \sum_j t_j {\cal B}_j(\lambda)$$
If we precompute the products $G_{ij} = \int \lambda {\cal B}_i(\lambda) {\cal B}_j(\lambda) d\lambda$
the integrals above can be expressed as a simple contraction:
$$f = \theta_i G_{ij} t_j$$
where $G$ is very sparse, since the B-Splines ${\cal B}_i$ have a compact
support. If the bandpass $T$ is spatially variable, the $t_j$ coefficients are
themselves developped on a spatial spline basis.
$$t_j = \sum_{kj} \tau_{kj} {\cal K}(x,y)$$
The contraction above is then of the form: ...
## FilterSets and StellarLibs
`bbf` implements two main kind of objects: `FilterLib`, which holds a set of
band passes, projected on spline bases (${\cal K_j(x,y)}$ and ${\cal
B}_i_(\lambda)$), and `StellarLib` which manages a set of spectra, also
projected on a spline basis (not necessily the splines used for the filters).
## Loading a filter lib
Building a complete version of a `FilterLib` requires some care. The standard
`FilterLib` used in the LemaƮtre analysis is build and maintained within the
package `lemaitre.bandpasses`. To access it:
``` python
from lemaitre import bandpasses
flib = bandpasses.get_filterlib()
```
The first time this function is called, the `FilterLib`` is built and cached. The subsequent calls
access the cached version, and never take more than a few milliseconds.
## Loading Stellar Libraries
As of today, `bbf` implements two kinds of StellarLibs: pickles and Calspec. An
interface to gaiaXP is in development.
To load the pickles library:
``` python
import bbf.stellarlib.pickles
pickles = bbf.stellarlib.pickles.fetch()
```
To load the most recent version of Calspec:
``` python
import bbf.stellarlib.calspec
calspec = bbf.stellarlib.calspec.fetch()
```
## Computing Broadband fluxes
With a `FilterSet` and a `StellarLib` in hand, one can compute broadband fluxes
and broadband mags.
### Broadband fluxes
``` python
import bbf.stellarlib.pickles
from lemaitre import bandpasses
flib = bandpasses.get_filterlib()
pickles = bbf.stellarlib.pickles.fetch()
# number of measurements
nmeas = 100_000
# which stars ?
star = np.random.choice(np.arange(0, len(pickles)), size=nmeas)
# in which band ?
band = np.random.choice(['ztf::g', 'ztf::r', 'ztf::I'], size=nmeas)
# observation positions
x = np.random.uniform(0., 3072., size=nmeas)
y = np.random.uniform(0., 3080., size=nmeas)
sensor_id = np.random.choice(np.arange(1, 65), size=nmeas)
fluxes = flib.flux(pickles, star, band, x=x, y=y, sensor_id=sensor_id)
```
### Broadband magnitudes
To convert broadband fluxes into broadband magnitudes, we need to compute the
reference fluxes, in the same effective measurement band passes. This is done
using an auxiliary object called `MagSys`:
``` python
from bbf.magsys import SpecMagSys
import bbf.stellarlib.pickles
from lemaitre import bandpasses
flib = bandpasses.get_filterlib()
pickles = bbf.stellarlib.pickles.fetch()
# number of measurements
nmeas = 100_000
# which stars ?
star = np.random.choice(np.arange(0, len(pickles)), size=nmeas)
# in which band ?
band = np.random.choice(['ztf::g', 'ztf::r', 'ztf::I'], size=nmeas)
# observation positions
x = np.random.uniform(0., 3072., size=nmeas)
y = np.random.uniform(0., 3080., size=nmeas)
sensor_id = np.random.choice(np.arange(1, 65), size=nmeas)
ms = SpecMagSys('AB')
mags = ms.mag(pickles, star, band, x=x, y=y, sensor_id=sensor_id)
```
# License
`bbf` is distributed under the terms of the
[MIT](https://spdx.org/licenses/MIT.html) license.
Raw data
{
"_id": null,
"home_page": null,
"name": "bbf",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "astronomy, astrophysics",
"author": null,
"author_email": "Nicolas Regnault <nicolas.regnault@lpnhe.in2p3.fr>",
"download_url": "https://files.pythonhosted.org/packages/34/18/1023991817dbba3dc49f8424dff4aaeb0b846d8261e1c83e174a42957089/bbf-0.5.2.tar.gz",
"platform": null,
"description": "# Broadband fluxes (`bbf`)\n\n[![PyPI - Version](https://img.shields.io/pypi/v/bbf.svg)](https://pypi.org/project/bbf)\n[![Conda Version](https://img.shields.io/conda/vn/conda-forge/bbf.svg)](https://anaconda.org/conda-forge/bbf)\n[![Conda Platforms](https://img.shields.io/conda/pn/conda-forge/bbf.svg)](https://anaconda.org/conda-forge/bbf)\n\n-----\n\n**Table of contents**\n- [Installation](#installation)\n- [Getting started](#getting started)\n- [License](#license)\n\nA module to evaluate the broadband fluxes and magnitudes of spectrophotometric\nstandards.\n\n\n# Installation\n\nThe `bbf` package works on `python>=3.9<3.13` for Linux and macos. It should\nwork on Windows too, but it has not been tested.\n\n| :warning: `bbf` relies for the moment on a [modified version of `sncosmo`](https://github.com/nregnault/sncosmo) that must be installed separatly |\n|---|\n\n\n## Install using conda (recommended)\n\n```bash\nconda install -c conda-forge bbf\npip install git+https://github.com/nregnault/sncosmo\n```\n\n\n## Install using pip\n\n* Installing `bbf` from `pip` requires to install\n [SuiteSparse](http://www.suitesparse.com) which is not installable from `pip`.\n On Debian/Ubuntu systems, the command `sudo apt install libsuitesparse-dev`\n suffices. Or you can compile `SuiteSparse` from\n [sources](https://github.com/DrTimothyAldenDavis/SuiteSparse). Or a simpler\n alternative is to install `scikit-sparse` from `conda`:\n\n ```bash\n conda install -c conda-forge scikit-sparse\n ```\n\n* `cmake` and a C++ compiler with `OpenMP` support are required. On Linux, `gcc`\n supports `OpenMP` out of the box, and `cmake` is installed as needed during\n `bbf` installation. On macos an extra installation is required:\n\n ```bash\n # for macos only\n conda install cmake llvm-openmp\n ```\n\n* `sncosmo` fork must be installed separatly with:\n\n ```bash\n pip install bbf git+https://github.com/nregnault/sncosmo\n ```\n\n* Finally install `bbf`:\n\n ```bash\n pip install bbf\n ```\n\n## Install from sources\n\n* If you prefer installing from sources, ensure **git lfs** is installed (have a\n `git lfs`, if the command is missing install it with `conda install git-lfs;\n git lfs install`).\n\n* Then follow the steps from the [Install using pip](#install using pip)\n section, and replace the last step with:\n\n ```bash\n git clone clone git@gitlab.in2p3.fr:lemaitre/bbf.git\n cd bbf\n pip install -e .\n ```\n\n* To run the tests suite, install the required dependencies, then run `pytest`:\n\n ```bash\n pip install -e .[test]\n pytest\n ```\n\n* If you are a developper and want to work on the `bbf` C/C++ extension,\n insall the package with:\n\n ```bash\n pip install nanobind ninja scikit-build-core[pyproject]\n VERBOSE=1 pip install --no-build-isolation -Ceditable.rebuild=true -ve .\n ```\n\n## Installing the Lemaitre bandpasses\n\nIf you plan to use the latest version of the megacam6*, *ztf* and *hsc*\npassbands, install the `lemaitre.bandpasses` package:\n\n```bash\npip install lemaitre-bandpasses\n```\n\nor\n\n```bash\ngit clone https://gitlab.in2p3.fr/lemaitre/lemaitre/bandpasses\ncd bandpasses\ngit lfs pull\npip install .\n```\n\n\n# Getting started\n\nThe goal of `bbf` is to efficiently compute broadband fluxes and magnitudes,\ni.e. quantities of the form:\n\n$$f_{xys} = \\int S(\\lambda) \\lambda T_{xys}(\\lambda) d\\lambda$$\n\nwhere $\\lambda$ is the SED of an object, $T_{xyz}(\\lambda)$ is the bandpass of\nthe instrument used to observe it. $T$ may depend on the focal plane position of\nthe object and, if the focal plane is a mosaic of sensors, on the specific\nsensor $s$ where the observation is made. In practice, $x,y$ are coordinates, in\npixels, in the sensor frame, and $s$ is a unique sensor index (or amplifier\nindex).\n\nComputing magnitudes requires an additional ingredient: the flux of a reference\nspectrum $S_{ref}(\\lambda)$, usually the AB spectrum, integrated in the same\npassband (same sensor, same position).\n\n$$m = -2.5 \\log_{10} \\left(\\frac{\\int S(\\lambda) \\lambda T_{xyz}(\\lambda) d\\lambda}{\\int S_{ref}(\\lambda) \\lambda T_{xyz}(\\lambda) d\\lambda}\\right)$$\n\nTo compute these integrales, `bbf` uses the technique implemented in `nacl`,\nwhich consists in projecting the bandpasses and SED on spline bases:\n\n$$S(\\lambda) = \\sum_i \\theta_i {\\cal B}_i(\\lambda)$$\n\nand\n\n$$T(\\lambda) = \\sum_j t_j {\\cal B}_j(\\lambda)$$\n\nIf we precompute the products $G_{ij} = \\int \\lambda {\\cal B}_i(\\lambda) {\\cal B}_j(\\lambda) d\\lambda$\nthe integrals above can be expressed as a simple contraction:\n\n$$f = \\theta_i G_{ij} t_j$$\n\nwhere $G$ is very sparse, since the B-Splines ${\\cal B}_i$ have a compact\nsupport. If the bandpass $T$ is spatially variable, the $t_j$ coefficients are\nthemselves developped on a spatial spline basis.\n\n$$t_j = \\sum_{kj} \\tau_{kj} {\\cal K}(x,y)$$\n\nThe contraction above is then of the form: ...\n\n\n## FilterSets and StellarLibs\n\n`bbf` implements two main kind of objects: `FilterLib`, which holds a set of\nband passes, projected on spline bases (${\\cal K_j(x,y)}$ and ${\\cal\nB}_i_(\\lambda)$), and `StellarLib` which manages a set of spectra, also\nprojected on a spline basis (not necessily the splines used for the filters).\n\n\n## Loading a filter lib\n\nBuilding a complete version of a `FilterLib` requires some care. The standard\n`FilterLib` used in the Lema\u00eetre analysis is build and maintained within the\npackage `lemaitre.bandpasses`. To access it:\n\n``` python\nfrom lemaitre import bandpasses\n\nflib = bandpasses.get_filterlib()\n```\nThe first time this function is called, the `FilterLib`` is built and cached. The subsequent calls\naccess the cached version, and never take more than a few milliseconds.\n\n\n## Loading Stellar Libraries\n\nAs of today, `bbf` implements two kinds of StellarLibs: pickles and Calspec. An\ninterface to gaiaXP is in development.\n\nTo load the pickles library:\n\n``` python\n\nimport bbf.stellarlib.pickles\npickles = bbf.stellarlib.pickles.fetch()\n```\n\nTo load the most recent version of Calspec:\n\n``` python\nimport bbf.stellarlib.calspec\ncalspec = bbf.stellarlib.calspec.fetch()\n```\n\n\n## Computing Broadband fluxes\n\nWith a `FilterSet` and a `StellarLib` in hand, one can compute broadband fluxes\nand broadband mags.\n\n\n### Broadband fluxes\n\n``` python\nimport bbf.stellarlib.pickles\nfrom lemaitre import bandpasses\n\nflib = bandpasses.get_filterlib()\npickles = bbf.stellarlib.pickles.fetch()\n\n# number of measurements\nnmeas = 100_000\n\n# which stars ?\nstar = np.random.choice(np.arange(0, len(pickles)), size=nmeas)\n\n# in which band ?\nband = np.random.choice(['ztf::g', 'ztf::r', 'ztf::I'], size=nmeas)\n\n# observation positions\nx = np.random.uniform(0., 3072., size=nmeas)\ny = np.random.uniform(0., 3080., size=nmeas)\nsensor_id = np.random.choice(np.arange(1, 65), size=nmeas)\n\nfluxes = flib.flux(pickles, star, band, x=x, y=y, sensor_id=sensor_id)\n```\n\n\n### Broadband magnitudes\n\nTo convert broadband fluxes into broadband magnitudes, we need to compute the\nreference fluxes, in the same effective measurement band passes. This is done\nusing an auxiliary object called `MagSys`:\n\n``` python\n\nfrom bbf.magsys import SpecMagSys\nimport bbf.stellarlib.pickles\nfrom lemaitre import bandpasses\n\nflib = bandpasses.get_filterlib()\npickles = bbf.stellarlib.pickles.fetch()\n\n# number of measurements\nnmeas = 100_000\n\n# which stars ?\nstar = np.random.choice(np.arange(0, len(pickles)), size=nmeas)\n\n# in which band ?\nband = np.random.choice(['ztf::g', 'ztf::r', 'ztf::I'], size=nmeas)\n\n# observation positions\nx = np.random.uniform(0., 3072., size=nmeas)\ny = np.random.uniform(0., 3080., size=nmeas)\nsensor_id = np.random.choice(np.arange(1, 65), size=nmeas)\n\nms = SpecMagSys('AB')\nmags = ms.mag(pickles, star, band, x=x, y=y, sensor_id=sensor_id)\n```\n\n\n# License\n\n`bbf` is distributed under the terms of the\n[MIT](https://spdx.org/licenses/MIT.html) license.\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 Nicolas Regnault Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "Fast computation of broadband fluxes and magnitudes",
"version": "0.5.2",
"project_urls": {
"Changelog": "https://gitlab.in2p3.fr/lemaitre/bbf/-/blob/main/CHANGELOG.md",
"Homepage": "https://gitlab.in2p3.fr/lemaitre/bbf",
"Repository": "https://gitlab.in2p3.fr/lemaitre/bbf"
},
"split_keywords": [
"astronomy",
" astrophysics"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "34181023991817dbba3dc49f8424dff4aaeb0b846d8261e1c83e174a42957089",
"md5": "174675ef27856ef47efc43d3b863e0bd",
"sha256": "b0bb6c15df8a7ef417ff9989a60801da924af921671b67ec2f575d0f83188812"
},
"downloads": -1,
"filename": "bbf-0.5.2.tar.gz",
"has_sig": false,
"md5_digest": "174675ef27856ef47efc43d3b863e0bd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 2807218,
"upload_time": "2024-10-22T13:58:13",
"upload_time_iso_8601": "2024-10-22T13:58:13.421724Z",
"url": "https://files.pythonhosted.org/packages/34/18/1023991817dbba3dc49f8424dff4aaeb0b846d8261e1c83e174a42957089/bbf-0.5.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-22 13:58:13",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "bbf"
}