gmag


Namegmag JSON
Version 2.1.6 PyPI version JSON
download
home_page
SummaryGive Me A Galaxy! | Fast SDSS Galaxy Image Download
upload_time2022-12-13 17:04:07
maintainer
docs_urlNone
authorJunyu Chen
requires_python>=3.7
licenseMIT License Copyright (c) 2022 Junyu Chen 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 sdss fits galaxy image processing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # GMAG

_Give Me A Galaxy! | Fast SDSS Galaxy Image Download_

[Documentation](https://junyu474.github.io/GMAG/index.html) | 
[Notebooks](https://github.com/Junyu474/GMAG/tree/main/notebooks)

---

GMAG is a simple and fast way to download and cutout SDSS images using multiprocessing. 
It communicates directly with SDSS servers with SQL commands to get galaxy info and download images.
Download speed is about <span style="color:#93CAED">**6x faster**</span> than the standard astroquery SDSS module 
(see comparison [here](https://github.com/Junyu474/GMAG/blob/main/notebooks/Download_Time_Comparison.ipynb)).


```python
# Download multi-band galaxy image data
from gmag import sdss

sdss.download_images('galaxies_coord_table.fit')

# ---example output---
# Searching galaxies: 100%|██████████| 10/10 [00:02<00:00,  3.73obj/s]
# ...Found 7 out of 10 galaxies
# ...Created directories for images at /images_2022-11-26_11-01-05
# Downloading images: 100%|██████████| 35/35 [00:19<00:00,  1.84img/s]
# ...Saving info file at /images_2022-11-26_11-01-05/info.csv
# ALL DONE!
```

GMAG was originally intended to quickly get a random galaxy image (ugriz) in one line of code
(you can tell by the naming "Give Me A Galaxy"). 
Now the `download_images` function shown above is clearly more practical, 
but the old function is still kept, 
not intended for professional use, but as a fun little tool to get a random galaxy to play with.

```python
galaxy = sdss.get_random_galaxy()
galaxy.show()
```

![output](https://user-images.githubusercontent.com/48139961/203444526-e9b367b4-2d9a-45e4-8147-4e50ac384e9c.png)


---

### Table of Contents

- [Installation](#installation)
- [Usage](#usage)
    - [Download Galaxy Images](#download-galaxy-images)
    - [Get a Random Galaxy](#get-a-random-galaxy)

## Installation

<a name="installation"></a>

```bash
pip install gmag
```

## Usage

<a name="usage"></a>

### Download Galaxy Images

<a name="download-galaxy-images"></a>

<span style="color:#93CAED">_A tutorial notebook is available [here](https://github.com/Junyu474/GMAG/blob/main/notebooks/Tutorial_Download_Images.ipynb)._</span>

Provide a table with `ra` and `dec` columns,
and `gmag` will download galaxy multi-bands images for you accelerated by multiprocessing.
Images can even be cutout instead of the full frame provided by SDSS.

```python
from gmag import sdss

sdss.download_images(
    "some_galaxies.fit",  # file containing ra and dec for galaxies
    bands="ugriz",        # bands to download
    cutout=True,          # crop the galaxy out of the standard sdss frame
    num_workers=8,        # number of processes to use
    # ...
)
```

Downloaded images will be organized in a directory with the following structure:

```
images_<YYYY-MM-DD>_<Hr-Min-Sec>
├── info.csv
├── <galaxy_name or rowid_objid>
│   ├── u.fits
│   ├── g.fits
│   ├── r.fits
│   ├── i.fits
│   └── z.fits
└── <galaxy_name or rowid_objid>
│   ├── u.fits
│   ├── g.fits
│   ├── r.fits
│   ├── i.fits
│   └── z.fits
└── ...
```

### Get a Random Galaxy

<a name="get-a-random-galaxy"></a>

<span style="color:#93CAED">_A tutorial notebook is available [here](https://github.com/Junyu474/GMAG/blob/main/notebooks/Tutorial_Get_Random_Galaxy.ipynb)._</span>

```python
from gmag.sdss import get_random_galaxy

galaxy = get_random_galaxy()
```

Get galaxy information:

```python
galaxy.info()

# ---example output---
# SDSS DR17 ObjID:       1237655370354851898
# RA(deg):                         152.99248
# DEC(deg):                         58.86462
```

Show galaxy (jpg image):

```python
galaxy.show()
```

![main](https://user-images.githubusercontent.com/48139961/203444598-947ec45f-7e43-4a45-9ca0-a6e99e1770b2.png)

### Plotting

Other than the `show()` method to plot the jpg image,
you can also plot each of the bands (u, g, r, i, z) using the `show_band()` method:

```python
galaxy.show_band('r')
```

![r](https://user-images.githubusercontent.com/48139961/203445080-1bc738aa-bd44-46ae-bca6-64211e53201e.png)

more control over the plot:

```python
galaxy.show_band('r', cmap='viridis', high_contrast=True, colorbar=True)
```

![r_more](https://user-images.githubusercontent.com/48139961/203445176-5219608e-1a99-4e92-8ffb-23959460f94d.png)

or show all bands:

```python
galaxy.show_all_bands(high_contrast=True)
```

![all](https://user-images.githubusercontent.com/48139961/203445308-a2ad538c-847a-4dbd-9b28-70f8c13d4187.png)

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "gmag",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "astronomy,sdss,fits,galaxy,image processing",
    "author": "Junyu Chen",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/7b/76/660f2f2afed1e7f46daba36c38fbab7c5a9ae1c72c26d0e9d2b6dac870a5/gmag-2.1.6.tar.gz",
    "platform": null,
    "description": "# GMAG\n\n_Give Me A Galaxy! | Fast SDSS Galaxy Image Download_\n\n[Documentation](https://junyu474.github.io/GMAG/index.html) | \n[Notebooks](https://github.com/Junyu474/GMAG/tree/main/notebooks)\n\n---\n\nGMAG is a simple and fast way to download and cutout SDSS images using multiprocessing. \nIt communicates directly with SDSS servers with SQL commands to get galaxy info and download images.\nDownload speed is about <span style=\"color:#93CAED\">**6x faster**</span> than the standard astroquery SDSS module \n(see comparison [here](https://github.com/Junyu474/GMAG/blob/main/notebooks/Download_Time_Comparison.ipynb)).\n\n\n```python\n# Download multi-band galaxy image data\nfrom gmag import sdss\n\nsdss.download_images('galaxies_coord_table.fit')\n\n# ---example output---\n# Searching galaxies: 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 10/10 [00:02<00:00,  3.73obj/s]\n# ...Found 7 out of 10 galaxies\n# ...Created directories for images at /images_2022-11-26_11-01-05\n# Downloading images: 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 35/35 [00:19<00:00,  1.84img/s]\n# ...Saving info file at /images_2022-11-26_11-01-05/info.csv\n# ALL DONE!\n```\n\nGMAG was originally intended to quickly get a random galaxy image (ugriz) in one line of code\n(you can tell by the naming \"Give Me A Galaxy\"). \nNow the `download_images` function shown above is clearly more practical, \nbut the old function is still kept, \nnot intended for professional use, but as a fun little tool to get a random galaxy to play with.\n\n```python\ngalaxy = sdss.get_random_galaxy()\ngalaxy.show()\n```\n\n![output](https://user-images.githubusercontent.com/48139961/203444526-e9b367b4-2d9a-45e4-8147-4e50ac384e9c.png)\n\n\n---\n\n### Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n    - [Download Galaxy Images](#download-galaxy-images)\n    - [Get a Random Galaxy](#get-a-random-galaxy)\n\n## Installation\n\n<a name=\"installation\"></a>\n\n```bash\npip install gmag\n```\n\n## Usage\n\n<a name=\"usage\"></a>\n\n### Download Galaxy Images\n\n<a name=\"download-galaxy-images\"></a>\n\n<span style=\"color:#93CAED\">_A tutorial notebook is available [here](https://github.com/Junyu474/GMAG/blob/main/notebooks/Tutorial_Download_Images.ipynb)._</span>\n\nProvide a table with `ra` and `dec` columns,\nand `gmag` will download galaxy multi-bands images for you accelerated by multiprocessing.\nImages can even be cutout instead of the full frame provided by SDSS.\n\n```python\nfrom gmag import sdss\n\nsdss.download_images(\n    \"some_galaxies.fit\",  # file containing ra and dec for galaxies\n    bands=\"ugriz\",        # bands to download\n    cutout=True,          # crop the galaxy out of the standard sdss frame\n    num_workers=8,        # number of processes to use\n    # ...\n)\n```\n\nDownloaded images will be organized in a directory with the following structure:\n\n```\nimages_<YYYY-MM-DD>_<Hr-Min-Sec>\n\u251c\u2500\u2500 info.csv\n\u251c\u2500\u2500 <galaxy_name or rowid_objid>\n\u2502   \u251c\u2500\u2500 u.fits\n\u2502   \u251c\u2500\u2500 g.fits\n\u2502   \u251c\u2500\u2500 r.fits\n\u2502   \u251c\u2500\u2500 i.fits\n\u2502   \u2514\u2500\u2500 z.fits\n\u2514\u2500\u2500 <galaxy_name or rowid_objid>\n\u2502   \u251c\u2500\u2500 u.fits\n\u2502   \u251c\u2500\u2500 g.fits\n\u2502   \u251c\u2500\u2500 r.fits\n\u2502   \u251c\u2500\u2500 i.fits\n\u2502   \u2514\u2500\u2500 z.fits\n\u2514\u2500\u2500 ...\n```\n\n### Get a Random Galaxy\n\n<a name=\"get-a-random-galaxy\"></a>\n\n<span style=\"color:#93CAED\">_A tutorial notebook is available [here](https://github.com/Junyu474/GMAG/blob/main/notebooks/Tutorial_Get_Random_Galaxy.ipynb)._</span>\n\n```python\nfrom gmag.sdss import get_random_galaxy\n\ngalaxy = get_random_galaxy()\n```\n\nGet galaxy information:\n\n```python\ngalaxy.info()\n\n# ---example output---\n# SDSS DR17 ObjID:       1237655370354851898\n# RA(deg):                         152.99248\n# DEC(deg):                         58.86462\n```\n\nShow galaxy (jpg image):\n\n```python\ngalaxy.show()\n```\n\n![main](https://user-images.githubusercontent.com/48139961/203444598-947ec45f-7e43-4a45-9ca0-a6e99e1770b2.png)\n\n### Plotting\n\nOther than the `show()` method to plot the jpg image,\nyou can also plot each of the bands (u, g, r, i, z) using the `show_band()` method:\n\n```python\ngalaxy.show_band('r')\n```\n\n![r](https://user-images.githubusercontent.com/48139961/203445080-1bc738aa-bd44-46ae-bca6-64211e53201e.png)\n\nmore control over the plot:\n\n```python\ngalaxy.show_band('r', cmap='viridis', high_contrast=True, colorbar=True)\n```\n\n![r_more](https://user-images.githubusercontent.com/48139961/203445176-5219608e-1a99-4e92-8ffb-23959460f94d.png)\n\nor show all bands:\n\n```python\ngalaxy.show_all_bands(high_contrast=True)\n```\n\n![all](https://user-images.githubusercontent.com/48139961/203445308-a2ad538c-847a-4dbd-9b28-70f8c13d4187.png)\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2022 Junyu Chen  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": "Give Me A Galaxy! | Fast SDSS Galaxy Image Download",
    "version": "2.1.6",
    "split_keywords": [
        "astronomy",
        "sdss",
        "fits",
        "galaxy",
        "image processing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "03837cebf07c0cb660a1bf957e81eff7",
                "sha256": "3bfa27abe820bb3dd8cb3a6d0acb42bb9523e85d15b41ed9f9df5ca97ef2a2b5"
            },
            "downloads": -1,
            "filename": "gmag-2.1.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "03837cebf07c0cb660a1bf957e81eff7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 11711,
            "upload_time": "2022-12-13T17:04:06",
            "upload_time_iso_8601": "2022-12-13T17:04:06.341581Z",
            "url": "https://files.pythonhosted.org/packages/b1/7d/bcb8de9cf35c1464b5d173f5b4a8d0f798fa03b8338931ea1d4906f98db1/gmag-2.1.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "d83bba0cc234f2888fb50a88e0c73239",
                "sha256": "873338f6df93511cab016fb88744d32203d0912b183ae95d5be380c1b39acab7"
            },
            "downloads": -1,
            "filename": "gmag-2.1.6.tar.gz",
            "has_sig": false,
            "md5_digest": "d83bba0cc234f2888fb50a88e0c73239",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 12954,
            "upload_time": "2022-12-13T17:04:07",
            "upload_time_iso_8601": "2022-12-13T17:04:07.932689Z",
            "url": "https://files.pythonhosted.org/packages/7b/76/660f2f2afed1e7f46daba36c38fbab7c5a9ae1c72c26d0e9d2b6dac870a5/gmag-2.1.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-13 17:04:07",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "gmag"
}
        
Elapsed time: 0.02154s