Returns the size of a FITS image, given a valid FITS image file


filename (str) – The fully-qualified path of the FITS image file


Tuple of horizontal/vertical dimensions

Return type



Checks if a file is a valid FITS image by checking if any header contains ‘SCI’ in the ‘EXTNAME’.


file – The file to be checked.


True if the file is a FITS image, False otherwise

Return type


tom_dataproducts.models.data_product_path(instance, filename)

Returns the TOM-style path for a DataProduct file. Default behavior can be overridden by user in settings.DATA_PRODUCT_PATH DATA_PRODUCT_PATH must be a dot separated method name pointing to a method that takes two arguments: instance: The specific instance of the DataProduct class. filename: The filename to add to the path. The method must return a string representing the path to the file.

The default structure is <target identifier>/<facility>/<filename>. DataProduct objects not associated with a facility will save with ‘None’ as the facility.

  • instance (DataProduct) – The specific instance of the DataProduct class.

  • filename (str) – The filename to add to the path.


The TOM-style path of the file

Return type


class tom_dataproducts.models.DataProductGroup(*args, **kwargs)

Class representing a group of DataProduct objects in a TOM.

  • name (str) – The name of the group of DataProduct objects

  • created (datetime) – The time at which this object was created.

  • modified (datetime) – The time at which this object was last changed.

class tom_dataproducts.models.DataProduct(*args, **kwargs)

Class representing a data product object in a TOM.

A DataProduct corresponds to any file containing data, from a FITS, to a PNG, to a CSV. It can optionally be associated with a specific observation, and is required to be associated with a target.

  • product_id (str) – The identifier of the data product used by its original source.

  • target (Target) – The Target with which this object is associated.

  • observation_record (ObservationRecord) – The ObservationRecord with which this object is optionally associated.

  • data (django.core.files.File) – The file this object refers to.

  • extra_data (str) – Arbitrary text field for storing additional information about this object.

  • group – Set of DataProductGroup objects this object is associated with.

  • created (datetime) – The time at which this object was created.

  • modified (datetime) – The time at which this object was last modified.

  • data_product_type (str) – The type of data referred to by this object. Default options are photometry, fits_file, spectroscopy, or image_file. Can be configured in

  • featured (boolean) – Whether or not the data product is intended to be featured, used by default on the target detail page as a “display” option. Only one DataProduct can be featured per Target.

  • thumbnail (FileField) – The thumbnail file associated with this object. Only generated for FITS image files.

save(*args, **kwargs)

Saves the current DataProduct instance. Before saving, validates the data_product_type against those specified in


Gets the corresponding display value for a data_product_type.


Display value for a given data_product_type.

Return type



Returns the extension of the file associated with this data product


File extension

Return type


get_preview(size=(200, 200), redraw=False)

Returns path to the thumbnail of this data product, and creates a thumbnail if none exists

Keyword Arguments
  • size (tuple): Desired size of the thumbnail, as a 2-tuple of ints for width/height

  • redraw (boolean): True if the thumbnail will be recreated despite existing, False otherwise


Path to the thumbnail image



create_thumbnail(width=None, height=None)

Creates a thumbnail image of this data product (if it is a valid FITS image file) with specified width and height, or the original width and height if none is specified.

Keyword Arguments
  • width (int): Desired width of the thumbnail

  • height (int): Desired height of the thumbnail


Thumbnail file if created, None otherwise

Return type


class tom_dataproducts.models.ReducedDatum(*args, **kwargs)

Class representing a datum in a TOM.

A ReducedDatum generally refers to a single piece of data–e.g., a spectrum, or a photometry point. It is associated with a target, and optionally with the data product it came from. An example of a ReducedDatum without an associated data product would be photometry ingested from a broker.

  • target – The Target with which this object is associated.

  • data_product – The DataProduct with which this object is optionally associated.

  • data_type (str) – The type of data this datum represents. Default choices are the default values found in DATA_PRODUCT_TYPES in

  • source_name (str) – The original source of this datum. The current major use of this field is to track the broker a datum came from, but can be used for other sources.

  • source_location – A reference to the location that this datum was originally sourced from. The current major use of this field is the URL path to the alert that this datum came from.

  • timestamp (datetime) – The timestamp of this datum.

  • value (dict) –

    The value of the datum. This is a dict, intended to store data with a variety of scopes. As an example, a photometry value might contain the following:

      'magnitude': 18.5,
      'error': .5

    but could also contain a filter, a telescope, an instrument, and/or a unit:

      'magnitude': 18.5,
      'error': .5,
      'filter': 'r',
      'telescope': 'ELP.domeA.1m0a',
      'instrument': 'fa07',

  • message (ManyRelatedManager object) – Set of AlertStreamMessage objects this object is associated with.

validate_unique(*args, **kwargs)

Validates that the ReducedDatum is unique. Because the value field is a JSONField, it is not possible to rely on standard validation.

Do nothing if the uniqueness test passes. Otherwise, raise a ValidationError.