AstroPaint
AstroPaint: A Python Package for Painting Halo Catalogs into Celestial Maps - Published in JOSS (2020)
Science Score: 95.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 7 DOI reference(s) in README and JOSS metadata -
✓Academic publication links
Links to: joss.theoj.org, zenodo.org -
✓Committers with academic emails
2 of 6 committers (33.3%) from academic institutions -
○Institutional organization owner
-
✓JOSS paper metadata
Published in Journal of Open Source Software
Keywords
Keywords from Contributors
Scientific Fields
Repository
A python package for creating mock maps of astrophysical signals from a halo catalog
Basic Info
Statistics
- Stars: 48
- Watchers: 3
- Forks: 13
- Open Issues: 19
- Releases: 1
Topics
Metadata Files
README.md
AstroPaint
A python package for painting the sky
You can install AstroPaint by running the following in the command line:
git clone https://github.com/syasini/AstroPaint.git
cd AstroPaint
pip install -e .
the -e argument will install the package in editable mode which is suitable for development. If you want to modify the code use this option.
Important Note:
If you want the sample catalogs to be cloned automatically
along with the
rest of the repository, make sure you have Git Large File Storage (git lfs) installed.
If you are a conda user, please consider creating a new environment before installation:
conda create -n astropaint python=3.7
conda activate astropaint
Workflow
Converting catalogs to mock maps with AstroPaint is extremely simple. Here is what an example session looks like:
```python from astropaint import Catalog, Canvas, Painter
catalog = Catalog(data=yourinputdata)
canvas = Canvas(catalog, nside)
painter = Painter(template=yourradialprofile)
painter.spray(canvas) ```
That's it! Now you can check out your masterpiece using
canvas.show_map()

What is AstroPaint?
AstroPaint is a python package for generating and visualizing sky maps of a wide range of astrophysical signals originating from dark matter halos or the gas that they host. AstroPaint creates a whole-sky mock map of the target signal/observable, at a desired resolution, by combining an input halo catalog and the radial/angular profile of the astrophysical effect. The package also provides a suite of tools that can facilitate analysis routines such as catalog filtering, map manipulation, and cutout stacking. The simulation suite has an Object-Oriented design and runs in parallel, making it both easy to use and readily scalable for production of high resolution maps with large underlying catalogs. Although the package has been primarily developed to simulate signals pertinent to galaxy clusters, its application extends to halos of arbitrary size or even point sources.
Package Structure
See our documentation and this chart to understand the package structure and see what methods are available so far.
Examples
Nonsense Template
Here's an example script that paints a nonsense template on a 10 x 10 [sqr deg]
patch of the Sehgal catalog:
```python import numpy as np from astropaint import Catalog, Canvas, Painter
Load the Sehgal catalog
catalog = Catalog("Sehgal")
cutout a 10x10 sqr degree patch of the catalog
catalog.cutlonlat(lonrange=[0,10], latrange=[0,10])
pass the catalog to canvas
canvas = Canvas(catalog, nside=4096, R_times=5)
define a nonsense template and plot it
def anonsensetemplate(R, R_200c, x, y, z):
return np.exp(-(R/R_200c/3)**2)*(x+y+z)
pass the template to the painter
painter = Painter(template=anonsensetemplate)
plot the template for halos #0, #10, and #100 for R between 0 to 5 Mpc
R = np.linspace(0,5,100)
painter.plottemplate(R, catalog, halolist=[0,10,100])
``
<p align="center">
<img src="images/a_random_template.png" alt="template" height="300"/>
</p>
The painter automatically extracts the parametersR_200candx,y,z
` coordinates of the halo from the catalog that the canvas was initialized
with. Let's spray ths canvas now:
```python
spray the template over the canvas
painter.spray(canvas)
show the results
canvas.showmap("cartview", lonra=[0,10], latra=[0,10])
```
<img src="images/a
Voila!
You can use the n_cpus argument in the spray function to paint in parallel and speed things up!
Setting n_cpus=-1 uses all the available cpus.
Stacking
You can easily stack cutouts of the map using the following:
```python degrange = [-0.2, 0.2] # deg halolist = np.arange(5000) # stack the first 5000 halos
stack the halos and save the results in canvas.stack
stack = canvas.stackcutouts(halolist=halolist, lonrange=degrange, latrange=deg_range)
plt.imshow(canvas.stack)
``
<p align="center">
<img src="images/a_random_stack.png" alt="stack" height="300"/>
</p>
If this is taking too long, useparallel=True` for parallel stacking.
Line-Of-Sight integration of 3D profiles
AstroPaint only allows you to paint 2D (line-of-sight integrated) profiles on
your catalog halos, so if you already have the analytical expression of
the projected profile you want to paint, we are in business. However, not
all 3D profiles can be LOS integrated analytically (e.g. generalized NFW
or Einasto, etc), and integrating profiles numerically along every
single LOS is generally expensive. In order to alleviate this problem, AstroPaint offers two python decorators
@LOS_integrate and @interpolate which make 3D -> 2D projections effortless.
To convert a 3D profile into a 2D LOS integrated profile, all you need to do
is add the @LOS_integrate to the definition.
For example, here's how you can turn a 3D top hat profile
```python def tophat3D(r, R200c): """Equals 1 inside R_200c and 0 outside"""
tophat = np.ones_like(r)
tophat[r > R_200c]=0
return tophat
```
into a 2D projected one:
```python
from astropaint.lib.utilities import LOS_integrate
@LOSintegrate def tophat2D(R, R200c): """project tophat3D along the line of sight"""
return tophat_3D(R, R_200c)
``
This function integrates thetophat3Dfunction along every single line of
sight. If you have many halos in a high resolution map, this can take
forever. The trick to make this faster would be to integrate along a
several LOSs and interpolate the values in between. This is what the
@interpolatedecorator does. So, a faster version of thetophat2D
` function can be constructed as the following:
```python
from astropaint.lib.utilities import interpolate
@interpolate(nsamples=20) @LOSintegrate def tophat2Dinterp(R, R200c): """project and interpolate tophat3D along the line of sight"""
return tophat_3D(R, R_200c)
``
This is much faster, but the speed comes at a small price. If your 3D profile
is not smooth, the interpolated 2D projection will slightly deviate from the
exact integration.
<p align="center">
<img src="images/tophat_interp.png" alt="interp" height="300"/>
</p>
You can minimize this deviation by increasing then_samplesargument of the
@interpolate` decorator, but that will obviously decrease the painting speed.
Does this plot agree with what you would expect a LOS integrated top hat profile (a.k.a. a solid sphere) to look like?
Painting Optical Depth and kSZ Profiles on the WebSky Catalog
Let's use the Battaglia16 gas profiles to paint tau (optical depth) and
kinetic Sunyaev-Zeldovich (kSZ) on the WebSky catalog halos.
```python from astropaint.profiles import Battaglia16
taupainter = Painter(Battaglia16.tau2D_interp) ```
Since the shape of the profile is smooth, we won't lose accuracy by using the interpolator.
Let's paint this on a 5x5 sqr deg patch of the WebSky catalog with a mass cut of 8E13 M_sun.
```python catalog = Catalog("WebSkylite") catalog.cutlonlat(lonrange=[5,10], latrange=[5,10]) catalog.cutM_200c(8E13)
canvas = Canvas(catalog, nside=8192, R_times=3)
taupainter.spray(canvas)
```
<img src="images/tau
Battaglia16.kSZ_T function uses this tau and multiplies it by the
dimensionless velocity of the halos to get the kSZ signal.
python
kSZ_painter = Painter(Battaglia16.kSZ_T)
kSZ_painter.spray(canvas)
And here is what it looks like:
Art Gallery
Just because AstroPaint is developed for probing new science and doing serious stuff, it doesn't mean you can't have fun with it! Check out our cool web app to get your hands dirty with some paint.
Made with AstroPaint

How to contribute
If you would like to contribute to AstroPaint, take the following steps:
1) Fork this repository 2) Clone it on your local machine 3) Create a new branch (be as explicit as possible with the branch name) 4) Add and Commit your changes to the local branch 5) Push the branch to your forked repository 6) Submit a pull request on this repository
See this repository or Kevin Markham's step-by-step guide for more detailed instructions.
Developement happens on the develop branch, so make sure you are always in sync with the latest version and submit your pull requests to this branch.
Owner
- Name: Siavash Yasini
- Login: syasini
- Kind: user
- Location: Los Angeles, CA
- Company: Fanatics Inc
- Website: siavashyasini.com
- Repositories: 36
- Profile: https://github.com/syasini
Senior Data Scientist @ Fanatics
JOSS Publication
AstroPaint: A Python Package for Painting Halo Catalogs into Celestial Maps
Authors
Lawrence Berkeley National Laboratory, University of California, Berkeley
University of Southern California, Argonne National Lab
Aetna Inc.
University of Southern California
University of Southern California
Tags
python astrophysics simulation visualization extragalactic foregroundsGitHub Events
Total
- Watch event: 1
Last Year
- Watch event: 1
Committers
Last synced: 5 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Siavash Yasini | y****i@u****u | 362 |
| maamari | m****i@u****u | 5 |
| Shobeir K. S. Mazinani | s****i@g****m | 3 |
| dependabot[bot] | 4****] | 1 |
| Zachary Pace | z****1@g****m | 1 |
| Arfon Smith | a****n | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 4 months ago
All Time
- Total issues: 37
- Total pull requests: 59
- Average time to close issues: 24 days
- Average time to close pull requests: 7 days
- Total issue authors: 3
- Total pull request authors: 7
- Average comments per issue: 1.32
- Average comments per pull request: 0.27
- Merged pull requests: 50
- Bot issues: 0
- Bot pull requests: 5
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- syasini (31)
- AshKelly (3)
- zpace (3)
Pull Request Authors
- syasini (45)
- dependabot[bot] (4)
- S-KSM (3)
- arfon (2)
- maamari (2)
- zpace (1)
- NaregM (1)
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- astropy ==4.0.0
- decorator ==4.4.1
- healpy ==1.13.0
- joblib ==0.14.0
- jupyter *
- matplotlib ==3.1.2
- numpy ==1.19.1
- pandas ==1.0.1
- pytest ==5.3.1
- pyyaml ==5.1.2
- requests ==2.24.0
- scipy ==1.3.0
- seaborn ==0.9.0
- tqdm ==4.48.0
- astropy >=4.0.0
- decorator >=4.4.1
- healpy ==1.13.0
- joblib >=0.14.0
- jupyter *
- matplotlib >=3.1.2
- numpy >=1.19.1
- pandas >=1.0.1
- pytest >=5.3.1
- pyyaml >=5.1.2
- requests >=2.24.0
- scipy >=1.3.0
- seaborn >=0.9.0
- tqdm >=4.48.0
- actions/checkout v2 composite
- actions/setup-python v2 composite
