astronomaly.utils package

Submodules

astronomaly.utils.utils module

class astronomaly.utils.utils.ImageCycler(images, xlabels=None)

Bases: object

cycle()

Creates the plots and binds the event handler

onkeypress(event)

Matplotlib event handler for left and right arrows to cycle through images.

Parameters:event
astronomaly.utils.utils.convert_pybdsf_catalogue(catalogue_file, image_file, remove_point_sources=False, merge_islands=False, read_csv_kwargs={}, colnames={})

Converts a pybdsf fits file to a pandas dataframe to be given directly to an ImageDataset object.

Parameters:
  • catalogue_files (string) – Pybdsf catalogue in fits table format
  • image_file – The image corresponding to this catalogue (to extract pixel information and naming information)
  • remove_point_sources (bool, optional) – If true will remove all sources with an S_Code of ‘S’
  • merge_islands (bool, optional) – If true, will locate all sources belonging to a particular island and merge them, maintaining only the brightest source
  • read_csv_kwargs (dict, optional) – Will pass these directly to panda’s read_csv function to allow reading in of a variety of file structures (e.g. different delimiters)
  • colnames (dict, optional) – Allows you to choose the column names for “source_identifier” (which column to use to identify the source), “Isl_id”, “Peak_flux” and “S_Code” (if remove_point_sources is true)
astronomaly.utils.utils.convert_tractor_catalogue(catalogue_file, image_file, image_name='')

Converts a tractor fits file to a pandas dataframe to be given directly to an ImageDataset object.

Parameters:
  • catalogue_files (string) – tractor catalogue in fits table format
  • image_file – The image corresponding to this catalogue (to extract pixel information and naming information)
astronomaly.utils.utils.create_catalogue_spreadsheet(image_dataset, scores, filename='anomaly_catalogue.xlsx', ignore_nearby_sources=True, source_radius=0.016)

Creates a catalogue of the most anomalous sources in the form of an excel spreadsheet that includes cutout images.

Parameters:
  • image_dataset (astronomaly.data_management.image_reader.ImageDataset) – The image dataset
  • scores (pd.DataFrame) – The list of objects to convert to spreadsheet. NOTE: This must already be sorted in the order you want in the spreadsheet and limited to the number you want displayed.
  • filename (str, optional) – Filename for spreadsheet, by default ‘anomaly_catalogue.xlsx’
  • ignore_nearby_sources (bool, optional) – If true, will search for nearby objects before adding to the spreadsheet and will only add if no source is found within source_radius degrees, by default True
  • source_radius (float, optional) – Number of degrees to exclude nearby sources by in degrees, default 0.016 degrees
astronomaly.utils.utils.create_ellipse_check_catalogue(image_dataset, features, filename='ellipse_catalogue.csv')

Creates a catalogue that contains sources which require a larger window or cutout size. Also contains the recommended windows size required.

Parameters:
  • image_dataset (astronomaly.data_management.image_reader.ImageDataset) – The image dataset
  • features (pd.DataFrame) – Dataframe containing the extracted features about the sources. Used to obtain the ellipse warning column.
  • filename (str, optional) – Filename for spreadsheet, by default ‘ellipse_catalogue.csv’
astronomaly.utils.utils.create_png_output(image_dataset, number_of_images, data_dir)

Simple function that outputs a certain number of png files from the input fits files

Parameters:
  • image_dataset (astronomaly.data_management.image_reader.ImageDataset) – The image dataset
  • number_of_images (integer) – Sets the number of images to be created by the function
  • data_dir (directory) – Location of data directory. Needed to create output folder for the images.
Returns:

png – Images are created and saved in the output folder

Return type:

image object

astronomaly.utils.utils.get_file_paths(image_dir, catalogue_file, file_type='.fits')

Finds and appends the pathways of the relevant files to the catalogue. Required to access the files when passing a catalogue to the ImageThumbnailsDataset.

Parameters:
  • image_dir (str) – Directory where images are located (can be a single fits file or several)
  • catalogue_file (pd.DataFrame) – Dataframe that contains the information pertaining to the data.
  • file_type (str) – Sets the type of files used. Commonly used file types are .fits or .jpgs.
Returns:

catalogue_file – Dataframe with the required file pathways attached.

Return type:

pd.DataFrame

astronomaly.utils.utils.get_visualisation_sample(features, anomalies, anomaly_column='score', N_anomalies=20, N_total=2000)

Convenience function to downsample a set of data for a visualisation plot (such as t-SNE or UMAP). You can choose how many anomalies to highlight against a backdrop of randomly selected samples. :param features: Input feature set :type features: pd.DataFrame :param anomalies: Contains the anomaly score to rank the objects by. :type anomalies: pd.DataFrame :param anomaly_column: The column used to rank the anomalies by (always assumes higher is more

anomalous), by default ‘score’
Parameters:
  • N_anomalies (int, optional) – Number of most anomalous objects to plot, by default 20
  • N_total (int, optional) – Total number to plot (not recommended to be much more than 2000 for t-SNE), by default 2000
astronomaly.utils.utils.remove_corrupt_file(met, ind, idx)

Function that removes the corrupt or missing file from the metadata and from the metadata index.

Parameters:
  • met (pd.DataFrame) – The metadata of the dataset
  • ind (string) – The index of the metadata
  • idx (string) – The index of the source file

Module contents