2019-08-03 18:17:34 +03:00
# toasty
2013-12-06 08:53:38 +04:00
2019-08-02 21:31:13 +03:00
[![Build Status ](https://travis-ci.com/WorldWideTelescope/toasty.svg?branch=master )](https://travis-ci.com/WorldWideTelescope/toasty)
[![Coverage Status ](https://coveralls.io/repos/github/WorldWideTelescope/toasty/badge.svg?branch=master )](https://coveralls.io/github/WorldWideTelescope/toasty?branch=master)
2019-08-02 23:07:05 +03:00
[![Documentation Status ](https://readthedocs.org/projects/toasty/badge/?version=latest )](https://toasty.readthedocs.io/en/latest/?badge=latest)
2019-08-02 21:31:13 +03:00
2019-08-03 18:17:34 +03:00
<!-- pypi - begin -->
[toasty] is a Python library that helps you create [TOAST] “tile pyramids”
from [FITS] astronomical image files. These multi-resolution all-sky maps can
be viewed in software such as the [AAS] [WorldWide Telescope].
2013-12-07 05:30:08 +04:00
2019-08-03 18:17:34 +03:00
[toasty]: https://toasty.readthedocs.io/
[TOAST]: https://doi.org/10.3847/1538-4365/aaf79e
[FITS]: https://en.wikipedia.org/wiki/FITS
[AAS]: https://aas.org/
[WorldWide Telescope]: http://www.worldwidetelescope.org/
[toasty] was originally written by [Chris Beaumont] and is currently maintained
as part of the AAS [WorldWide Telescope] project.
[Chris Beaumont]: https://chrisbeaumont.org/
<!-- pypi - end -->
## Installation
The easiest way to install [toasty] is through [pip]:
```
pip install toasty
```
2019-08-03 20:13:43 +03:00
[pip]: https://pip.pypa.io/
For more information, please see the [toasty installation instructions].
[toasty installation instructions]: https://toasty.readthedocs.io/en/latest/installation.html
2019-08-03 18:17:34 +03:00
## Dependencies
[toasty] is a Python package so, yes, Python is required.
- [astropy]
- [cython]
- [healpy] if using [HEALPix] maps
- [numpy]
- [pillow]
- [pytest] to run the test suite
[astropy]: https://www.astropy.org/
[cython]: https://cython.org/
[healpy]: https://healpy.readthedocs.io/
[HEALPix]: https://healpix.jpl.nasa.gov/
[numpy]: https://numpy.org/
[pillow]: https://pillow.readthedocs.io/
[pytest]: https://docs.pytest.org/
2013-12-07 05:30:08 +04:00
### Usage
2014-03-17 17:34:54 +04:00
```python
2013-12-07 05:30:08 +04:00
from toasty import toast
2016-12-14 22:25:49 +03:00
2019-08-03 18:17:34 +03:00
toast(data_sampler, depth, base_dir, wtml_file=None, merge=True, base_level_only=False,
2016-12-14 22:25:49 +03:00
ra_range=None, dec_range=None, toast_tile=None, restart=False, top_layer=0)
2013-12-07 05:30:08 +04:00
```
where:
2019-08-03 18:17:34 +03:00
* **data_sampler** function or string
2016-12-10 01:10:13 +03:00
- A function of (lon, lat) that samples a datasetat the input 2D coordinate arrays
- A string giving a base toast directory that contains the base level of toasted tiles, using this option, only the merge step takes place, the given directory must contain a "depth" directory for the given depth parameter
* **depth** int
- The depth of the tile pyramid to create (4^d tiles are created at a depth of d)
* **base_dir** str
- The path to create the files at
* **wtml_file** str (optional)
- The path to write a WTML file to. If not present, no file will be written
2019-08-03 18:17:34 +03:00
* **merge** bool or callable (default True)
2016-12-10 01:10:13 +03:00
How to treat lower resolution tiles.
- If True, tiles above the lowest level (highest resolution) will be computed by averaging and downsampling the 4 subtiles.
- If False, sampler will be called explicitly for all tiles
- If a callable object, this object will be passed the 4x oversampled image to downsample
2019-08-03 18:17:34 +03:00
* **base_level_only** bool (default False)
If True only the bottem level of tiles will be created.
2016-12-10 01:10:13 +03:00
In this case merge will be set to True, but no merging will happen, and only the highest resolution layer of images will be created.
* **ra_range** array (optional)
2019-08-03 18:17:34 +03:00
* **dec_range** array (optional)
To toast only a portion of the sky give min and max ras and decs ([minRA,maxRA],[minDec,maxDec]) in degrees.
2016-12-10 01:10:13 +03:00
If these keywords are used base_level_only will be automatically set to true, regardless of its given value.
2019-08-03 18:17:34 +03:00
* **toast_tile** array\[n,x,y\] (optional)
2016-12-10 01:10:13 +03:00
If this keyword is used the output will be all the subtiles of toast_tile at the given depth (base_level_only will be automatically set to true, regardless of its given value.
2019-08-03 18:17:34 +03:00
* **top_layer** int (optional)
2016-12-10 01:10:13 +03:00
If merging this indicates the uppermost layer to be created.
2013-12-07 05:30:08 +04:00
Toasty provides a few basic sampler functions:
* **healpix_sampler** for sampling from healpix arrays
* **cartesian_sampler** for sampling from cartesian-projections
* **normalizer** for applying an intensity normalization after sampling
2014-03-17 17:34:54 +04:00
### Examples
To toast an all-sky, Cartesian projection, 8 byte image:
```python
from toasty import toast, cartesian_sampler
from skimage.io import imread
data = imread('allsky.png')
sampler = cartesian_sampler(data)
2016-12-14 22:25:49 +03:00
toastDirectory = 'toast'
2014-03-17 17:34:54 +04:00
depth = 8 # approximately 0.165"/pixel at highest resolution
2016-12-14 22:25:49 +03:00
# Getting the full toast tile set for the entire sky
toast(sampler, depth, toastDirectory)
# Toasting a specific region of the sky defined by ra/dec bounds
raRange = [208.8,212.2]
decRange = [52.5,56.8]
toast(sampler, depth, outtoastDirectoryput, ra_range=raRange, dec_range=decRange)
# Toasting a specific region of the sky defined by a higher level toast tile
tile=[4,5,9]
toast(sampler, depth, toastDirectory, toast_tile=tile)
# Creating only the bottom layer of toast tiles
toast(sampler, depth, toastDirectory,base_level_only=True)
# Merging from a previously created toast layer up to a specified top layer
topLayer = 4
toast(toastDirectory, depth, toastDirectory, top_layer=topLayer)
2014-03-17 17:34:54 +04:00
```
To apply a log-stretch to an all sky FITS image:
```python
from toasty import toast, cartesian_sampler, normalizer
from astropy.io import fits
data = fits.open('allsky.fits')[0].data
vmin, vmax = 100, 65535
scaling = 'log'
contrast = 1
sampler = normalizer(cartesian_sampler(data), vmin, vmax
scaling, bias, contrast)
output = 'toast'
depth = 8
toast(sampler, depth, output)
```
To perform a custom transformation
```python
from toasty import toast
from astropy.io import fits
data = fits.open('allsky.fits')[0].data
def sampler(x, y):
"""
x and y are arrays, giving the RA/Dec centers
2014-03-18 18:51:01 +04:00
(in radians) for each pixel to extract
2014-03-17 17:34:54 +04:00
"""
... code to extract a tile from `data` here ...
output = 'toast'
depth = 8
toast(sampler, depth, output)
```
2013-12-09 05:42:27 +04:00
See ``toasty.tile`` for documentation on these functions.
2013-12-07 05:30:08 +04:00
### Using with WorldWide Telescope
To quickly preview a toast directory named `test` , navigate to the directory
where `test` exists and run
```
2013-12-09 05:42:27 +04:00
python -m toasty.viewer test
2013-12-07 05:30:08 +04:00
```
This will start a web server, probably at [http://0.0.0.0:8000 ](http://0.0.0:8000 ) (check the output for the actual address). Open this URL in a browser to get a quick look at the data.
For more information about using WorldWide Telescope with custom image data,
see [the official documentation ](http://www.worldwidetelescope.org/Docs/worldwidetelescopedatafilesreference.html ). The function `toasty.gen_wtml` can generate the wtml information for images generated with toasty.
2013-12-07 23:28:24 +04:00
2016-12-14 22:36:14 +03:00
For an example of tiles generated with Toasty, see [The ADS All Sky Survey ](http://adsass.org/wwt ). The code used to generate these images is [here ](https://github.com/ChrisBeaumont/adsass/blob/master/toast/toast.py ).
For an example of tiles generated using the Toasty functionality specific to this fork see [The STScI AstroView Panstarrs Survey ](https://mast.stsci.edu/portal/Mashup/Clients/AstroView/AstroView.html?debug&avSurveyType=PANSTARRS ). The code used to generate these images is [here ](https://github.com/ceb8/toastPanstarrs ).