A Library For Generating Morphological Semantic Segmentation Maps of Astronomical Images
Project description
Morpheus
Morpheus is a neural network model used to generate pixel-level morphological classifications for astronomical sources. This model can be used to generate segmentation maps or to inform other photometric measurements with granular morphological information.
Installation
Morpheus is implemented using TensorFlow. TensorFlow is not listed in the dependencies for the package. So you need to install TensorFlow before you install Morpheus. It has to be done this way to support the GPU accelerated version of TensorFlow, which has a different package name. For more information on installing TensorFlow visit the TensorFlow website.
pip install morpheus-astro
Docker
Morpheus has two main flavors of Docker Image: gpu for the GPU enabled version of TensorFlow and cpu for the standard CPU implementation of TensorFlow. Visit the Docker Hub page for relevant tags.
For GPU support:
docker run --runtime=nvidia -it morpheusastro/morpheus:lastest-gpu
For CPU only:
docker run -it morpheusastro/morpheus:latest-cpu
Usage
There are two ways to use morpheus on images: the python API and the command line interface
Python API
The morpheus.classifier.Classifier class is the interface to the various functionalities of Morpheus.
Morphological classification
To perform a pixel-level morphological classification, the image needs to be provided in the H, J, Z, and V bands. See classify for more information.
from morpheus.classifier import Classifier
from morpheus.data import example
h, j, v, z = example.get_sample()
classified = Classifier.classify(h=h, j=j, v=v, z=z)
The classify function returns a dictionary where the keys indicate the output for example spheroid, and the value is the corresponding numpy ndarray.
Using the output from classify you can:
Make a segmap
Make a morphgological catalog
Make colorized version of the morphological classifications
Segmentation Map
To create a segmentation map using Morpheus, you need to provide the output from the classify function and a single flux band. In the below example we use H. For more information see segmap
from morpheus.classifier import Classifier
from morpheus.data import example
h, j, v, z = example.get_sample()
classified = Classifier.classify(h=h, j=j, v=v, z=z)
segmap = Classifier.segmap_from_classified(classified, h)
Catalog
To create a catalog using Morpheus, you need to provide the output from the classify function, the flux in a single band (we use H), and a segmentation map. The segmentation map doesn’t have to be generated by Morpheus, but it must be similar in form. It should assign pixels values greater than 0 for all pixels that are associated with a source. Each source should be assigned a unique ID. Background should be set to 0 and excluded regions should be assigned -1. The catalog returned is a JSON compatible list of morphological classifications for each source in the segmap. For more information, see catalog.
from morpheus.classifier import Classifier
from morpheus.data import example
h, j, v, z = example.get_sample()
classified = Classifier.classify(h=h, j=j, v=v, z=z)
segmap = Classifier.segmap_from_classified(classified, h)
catalog = Classifier.catalog_from_classified(classified, h, segmap)
Colorized Classifications
A colorized classification is a way of making a single image to interpret the pixel level morphological classifications. For more information see colorize.
from morpheus.classifier import Classifier
from morpheus.data import example
h, j, v, z = example.get_sample()
classified = Classifier.classify(h=h, j=j, v=v, z=z)
color_rgb = Classifier.colorize_classified(classified)
Parallelization
Morpheus supports simple parallelization by breaking an image into equally sized pieces along the y axis, classifying them in seperate processes, and stitching them back into a single image. Parallelization can be split into CPU jobs or GPU jobs. Importantly, you cannot specify both at the same time.
GPUS
The gpus argument should be a list of integers that are the ids assigned to the GPUS to be used. These ids can be found by using nvidia-smi.
from morpheus.classifier import Classifier
from morpheus.data import example
h, j, v, z = example.get_sample()
classified = Classifier.classify(h=h, j=j, v=v, z=z, gpus=[0,1])
CPUS
The cpus argument should be an integer indicating how many processes to spin off.
from morpheus.classifier import Classifier
from morpheus.data import example
h, j, v, z = example.get_sample()
classified = Classifier.classify(h=h, j=j, v=v, z=z, cpus=2)
Command Line Interface
Morpheus can be used from the terminal using the morpheus command. To classify an image, it needs to be available in the H, J, V, and Z bands. From the terminal the following actions can be performed:
Per pixel morphological classification
Make segmentation map
Make a catalog of morphological classifications
Make a colorized version of the morphological classifications
Morphological classification
morpheus h.fits j.fits v.fits z.fits
Order is important when calling the Morpheus from the terminal. The files should be in the order H, J, V, and Z, as displayed in the above example. The output classification will be saved in the current working directory unless otherwise indicated by the --out_dir optional argument.
Segmentation Map
morpheus h.fits j.fits v.fits z.fits --action segmap
To create a segmap, append the optional --action flag with the argument segmap. This will save both the classifications and the segmap to the same directory.
Catalog
morpheus h.fits j.fits v.fits z.fits --action catalog
This will create a catalog by classifying the input images, creating a segmap, and using both of those to generate a morphological catalog. The morphological classifications, segmap, and catalog are all saved to the same place.
Colorized Classifications
morpheus h.fits j.fits v.fits z.fits --action colorize
Using --action colorize will classify the image and then generate a colorized version of that classification and save the classification and colorized version to the same place.
Parallelization
Morpheus supports simple parallelization by breaking an image into equally sized pieces along the y axis, classifying them in separate processes, and stitching them back into a single image. Parallelization can be split into CPU jobs or GPU jobs. Importantly, you cannot specify both at the same time.
GPUS
The gpus optional flag should be a comma-separated list of ids for the GPUS to be used. These ids can be found by using nvidia-smi.
morpheus h.fits j.fits v.fits z.fits --gpus 0,1
CPUS
The cpus optional flag should be an integer indicating how many processes to spin off.
morpheus h.fits j.fits v.fits z.fits --cpus 2
Python Demo
Try it out on Google Colab!
Documentation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file morpheus-astro-0.5.1.tar.gz
.
File metadata
- Download URL: morpheus-astro-0.5.1.tar.gz
- Upload date:
- Size: 1.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e782504df09548b6e4bc450c9db9e453cd38d887726a2080706f82ddf5a7382 |
|
MD5 | 885eef51d3195246be1722655582be7b |
|
BLAKE2b-256 | 4b1ad62ce3b2a0e8629012b0221a40104fcb86c17b5d25a6ef65cc78b61519dd |
File details
Details for the file morpheus_astro-0.5.1-py3-none-any.whl
.
File metadata
- Download URL: morpheus_astro-0.5.1-py3-none-any.whl
- Upload date:
- Size: 1.1 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38b5138a9c1a49a2a12d05861a7d88b88b157d9095103e6e1398c898fd5a3e3f |
|
MD5 | 9aaf263a3216875701973523ab2bfb20 |
|
BLAKE2b-256 | ae8adbd857a218300a70ee94c5239ae10bc4e89b82b577fd43d4ada91ad4ed7e |