PyCDA Submodules

Detectors

class pycda.detectors.DetectorBaseClass[source]

Bases: object

This is the base class for a detector object. Attributes in the __init__ method should be specified by child detectors.

predict(batch)[source]

Predict method takes a batch and returns a batch of predictions. Output should be a batch of single-channel images of shape: (batch_size, self.output_dims[0], self.output_dims[1], 1)

class pycda.detectors.DummyDetector(input_dims=(256, 256), output_dims=(172, 172), n_channels=1, batch_size=5)[source]

Bases: pycda.detectors.DetectorBaseClass

The dummy detector is used for testing. It returns predictions when called; the predictions contain random values between 0 and 1, in the dimensions specified at initialization.

predict(batch)[source]

returns a batch of random-pixel images with appropriate shape.

class pycda.detectors.TinyDetector[source]

Bases: pycda.detectors.DetectorBaseClass

A tiny version of U-Net downsized for speed. Its output is a per-pixel likelihood that a given pixel is a part of a crater surface feature. Single color channel (grayscale).

predict(batch)[source]

returns a batch of random-pixel images with appropriate shape.

class pycda.detectors.UnetDetector[source]

Bases: pycda.detectors.DetectorBaseClass

U-net convolutional model to generate pixel-wise prediction. Its output is a per-pixel likelihood that a given pixel is a part of a crater surface feature. Single color channel (grayscale).

predict(batch)[source]

returns a batch of random-pixel images with appropriate shape.

pycda.detectors.get(identifier)[source]

handles argument to CDA pipeline for detector specification. returns an initialized detector.

Extractors

class pycda.extractors.CircleExtractor(sensitivity=0.5)[source]

Bases: pycda.extractors.ExtractorBaseClass

Circle Extractor assumes all objects in detection map are circles. It identifies groups of pixels, computes their mean location (centroid), and diameter based on the number of pixels in the group.

get_crater_pixels(label_matrix, idx)[source]

Takes a label matrix and a number and gets all the pixel locations from that crater object.

get_crater_proposals(detection_map)[source]

Takes a pixel-wise prediction map and returns a list of crater proposals as x, y, d.

get_label_map(detection_map, threshold=0.5)[source]

Takes a pixel-wise prediction map and returns a matrix of unique objects on the map. Threshold is a hyperparameter for crater/non-crater pixel determination. Higher threshold may help distinguish merged crater detections.

get_pixel_objects(label_matrix)[source]

Takes the label matrix and returns a list of objects. Each element in the list is a unique object, defined by an array of pixel locations belonging to it.

class pycda.extractors.DummyExtractor[source]

Bases: pycda.extractors.ExtractorBaseClass

Dummy Extractor takes an input image and returns a list of random predictions for testing. Proposals are a list of tuples. Each tuple in the list has the crater proposal as (in pixels): (x position, y position, diameter).

class pycda.extractors.ExtractorBaseClass[source]

Bases: object

Base class for an extractor object. The extractor converts a prediction map into a list of crater candidates.

pycda.extractors.get(identifier)[source]

handles argument to CDA pipeline for extractor specification. returns an initialized extractor.

Classifiers

class pycda.classifiers.ClassifierBaseClass[source]

Bases: object

Base object for crater classifier. Classifiers make a binary prediction on a crater proposal and return a value between zero and one; one represents a true crater and zero represents a false proposal.

predict(batch)[source]

Prediction call should return an array of predictions of length of batch.

class pycda.classifiers.ConvolutionalClassifier[source]

Bases: pycda.classifiers.ClassifierBaseClass

12x12 pixel classifier using 2D convolution implimented with Keras on tensorflow backend. Built for nice performance and speed.

predict(batch)[source]

Performs prediction on batch.

class pycda.classifiers.DummyClassifier(input_dims=(20, 20), n_channels=1)[source]

Bases: pycda.classifiers.ClassifierBaseClass

Dummy classifier for testing.

predict(batch)[source]

Returns an array of randomly-generated predictions of length of batch.

class pycda.classifiers.NullClassifier(input_dims=(1, 1))[source]

Bases: pycda.classifiers.ClassifierBaseClass

For use when classifier is not wanted. Returns a likelihood of 1 for every proposal.

predict(batch)[source]

Returns an array of randomly-generated predictions of length of batch.

pycda.classifiers.get(identifier)[source]

handles argument to CDA pipeline for classifier specification. returns an initialized classifier.

Predictions

class pycda.predictions.Prediction(image, id_no, cda)[source]

Bases: object

A prediction object is a specialized data handler for pycda. It tracks the progress of predictions on an input image, helps the pipeline track information, and can perform auxiliary functions that help the user inspect the prediction, save the results, export csv files, and modify hyperparameters.

get_proposals(threshold=0.5)[source]

Returns a dataframe of detected craters. Threshold determines a cutoff for proposal likelihood.

record_detection(detection, index)[source]

Records a detection in the prediction map. Uses index to determine location of detection.

set_scale(scale)[source]

User can set scale for statistics in meters. scale should be meters per pixel.

show(threshold=0.5, include_ticks=True)[source]

Displays the input image with the predicted craters overlaid. Threshold determines the likelihood for which a proposal should be displayed.

show_detection()[source]

Plots the detection map alongside the input image.

Error Stats

class pycda.error_stats.ErrorAnalyzer[source]

Bases: object

Error Analyzer is used to measure predictive performance of cda. It is intended for use on images where all craters have been hand labeled and so are “known”. The PyCDA prediction object accepts known craters as a pandas dataframe under the attribute .known_craters; the columns ‘x’, ‘y’, and ‘diameter’ should be populated with approprate values for known crater objects for use with ErrorAnalyzer.

analyze(prediction)[source]

Takes a prediction object and performs analysis on it. Raises an exception if no known crater labels are attributed to the input prediction object.

plot_densities()[source]

Generates histogram plot with predicted and actual crater densities by size.

print_report()[source]

Prints performance statistics for prediction.

return_results()[source]

Returns matched lists of known craters and detections.

show()[source]

Displays the input image with predictions and known craters displayed by colors.

Sample Data

pycda.sample_data.get_sample_csv(filename='holdout_tile_labels.csv')[source]

Retrieves hand-labeled crater annotations

pycda.sample_data.get_sample_image(filename='holdout_tile.pgm')[source]

Retrieves sample data from the in-package directory.