Models

tom_dataproducts.models.find_fits_img_size(filename)

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

Parameters

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

Returns

Tuple of horizontal/vertical dimensions

Return type

tuple

tom_dataproducts.models.is_fits_image_file(file)

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

Parameters

file – The file to be checked.

Returns

True if the file is a FITS image, False otherwise

Return type

boolean

tom_dataproducts.models.data_product_path(instance, filename)

Returns the TOM-style path for a DataProduct file. Structure is <target identifier>/<facility>/<filename>. DataProduct objects not associated with a facility will save with ‘None’ as the facility.

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

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

Returns

The TOM-style path of the file

Return type

str

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

Class representing a group of DataProduct objects in a TOM.

Parameters
  • 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.

Parameters
  • 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 settings.py.

  • 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 settings.py.

get_type_display()

Gets the corresponding display value for a data_product_type.

Returns

Display value for a given data_product_type.

Return type

str

get_file_extension()

Returns the extension of the file associated with this data product

Returns

File extension

Return type

str

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

returns

Path to the thumbnail image

rtype

str

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

Returns

Thumbnail file if created, None otherwise

Return type

file

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.

Parameters
  • 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 settings.py.

  • 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:

    {
      'magnitude': 18.5,
      'magnitude_error': .5,
      'filter': 'r'
    }