morpheus package

Submodules

morpheus.classifier module

An interface for interacting with Morpheus

class morpheus.classifier.Classifier[source]

Bases: object

The primary interface for the use of Morpheus.

Images can be classified by calling classify() and passing numpy arrays or string FITS file locations.

After an image this this class offers some post processing functionality by generating segmentation maps using segmap_from_classified(), colorized morphological classifications using colorize_classification(), and generating catalogs using catalog_from_classified().

For more examples, see the documentation.

static aggregation_scheme_flux_weighted(data: dict, flux: numpy.ndarray, segmap: numpy.ndarray) → List[float][source]

Aggregates pixel level morphological classifications to the source level.

Uses a flux-weighted mean of the pixel level morphologies to calculate the aggregate source level morphology.

Parameters:
  • data (dict) – A dictionary containing the output from morpheus.
  • flux (np.ndarray) – The corresponding flux image in H band
  • segmap (int) – The binary map indicating pixels that belong to the source
Returns:

The morphological classification as a list of floats in the following order: [‘spheroid’, ‘disk’, ‘irregular’, ‘point source’]

static catalog_from_classified(classified: dict, flux: numpy.ndarray, segmap: numpy.ndarray, aggregation_scheme: Callable = None, out_file: str = None) → List[Dict][source]

Creates a catalog of sources and their morphologies.

Parameters:
  • classified (dict) – A dictionary containing the output from morpheus.
  • flux (np.ndarray) – The corresponding flux image in H band
  • segmap (np.ndarray) – A labeled segmap where every pixel with a value > 0 is associated with a source.
  • aggregation_scheme (func) – Function that takes three arguments classified, flux, and segmap, same as this function, then returns a numpy array containing the morphological classification in the following order-spheroid, disk, irregular, and point source/compact. If None, then the flux weighting scheme in
  • out_file (str) – a location to save the catalog. Can either be .csv or .json. Anything else will raise a ValueError.
Returns:

{

‘id’: the id from the segmap ‘location’: a (y,x) location – the max pixel within the segmap ‘morphology’: a dictionary containing the morphology values.

}

Return type:

A JSON-compatible list of dictionary objects with the following keys

static classify(h: Union[numpy.ndarray, str] = None, j: Union[numpy.ndarray, str] = None, z: Union[numpy.ndarray, str] = None, v: Union[numpy.ndarray, str] = None, out_dir: str = None, batch_size: int = 1000, out_type: str = 'rank_vote', gpus: List[int] = None, cpus: int = None, parallel_check_interval: float = 1) → dict[source]

Generates per-pixel classifications from input images.

Parameters:
  • h (Union[np.ndarray, str]) – The H band image or the path to it
  • j (Union[np.ndarray, str]) – The J band image or the path to it
  • v (Union[np.ndarray, str]) – The V band image or the path to it
  • z (Union[np.ndarray, str]) – The Z band image or the path to it
  • out_dir (str) – If provided, a directory to save the output to
  • batch_size (int) – The size of the batches to use when classifying the input
  • out_type (str) – The method by which to aggregate classifications for a single pixel. Can be one of “rank_vote”, “mean_var”, or “both”
  • gpus (List[int]) – The GPU ids to use for parallel classification the ids can be found using nvidia-smi
  • cpus (int) – The number of cpus to use for parallel classification.
  • parallel_check_interval (float) – If running a parallel job, how often to check on the running sub-processes in minutes.
Returns:

Dictionary containing the classification output for the given input

Raises:
  • ValueError if both gpus and cpus are given
  • ValueError if mixed string and numpy arrays are given for h, j, v, z
  • ValueError if h, j, v, or z are None
static colorize_classified(classified: dict, out_dir: str = None, hide_unclassified: bool = True) → numpy.ndarray[source]

Makes a color image from the classification output.

The colorization scheme is defined in HSV and is as follows:

  • Spheroid = Red
  • Disk = Blue
  • Irregular = Green
  • Point Source = Yellow

The hue is set to be the color associated with the highest ranked class for a given pixel. The saturation is set to be the difference between the highest ranked class and the second highest ranked class for a given pixel. For example, if the top two classes have nearly equal values given by the classifier, then the saturation will be low and the pixel will appear more white. If the top two classes have very different values, then the saturation will be high and the pixel’s color will be vibrant and not white. The value for a pixel is set to be 1-bkg, where bkg is value given to the background class. If the background class has a high value, then the pixel will appear more black. If the background value is low, then the pixel will take on the color given by the hue and saturation values.

Parameters:
  • data (dict) – A dictionary containing the output from Morpheus.
  • out_dir (str) – a path to save the image in.
  • hide_unclassified (bool) – If true, black out the edges of the image that are unclassified. If false, show the borders as white.
Returns:

A [width, height, 3] array representing the RGB image.

static segmap_from_classified(classified: dict, flux: numpy.ndarray, bkg_src_threshold: float = 0.0, out_dir: str = None, min_distance: int = 20, mask: numpy.ndarray = None, deblend: bool = True) → numpy.ndarray[source]

Generate a segmentation map from the classification output.

For more information about the segmentation process, see: https://arxiv.org/abs/1906.11248

Parameters:
  • data (dict) – A dictionary containing the output from morpheus.
  • flux (np.ndarray) – The flux to use when making the segmap
  • bkg_src_threshold (float) – The max value that a background classification pixel can take and be considered a source. The default is 0. Should be between [0,1]
  • out_dir (str) – A path to save the segmap in.
  • min_distance (int) – The minimum distance for deblending
  • mask (np.ndarry) – A boolean mask indicating which pixels
  • deblend (bool) – If True, perform deblending as described in 2. in the algorithm description. If False return segmap without deblending.
Returns:

A np.ndarray segmentation map

Module contents